I use to read about the power border agents have over foreigners and was amazed at how easily they can destroy me. The only reason this hasn't happened seems to be that they're mostly decent, professional people. And now that's gone.
I travel a lot and I’ve interacted with a lot of border agents. I’d say luck is important for a lot of countries. I’ve had great experiences flying in US, Egypt, UK and Turkey I’ve also had terrible experiences with US, and Iceland. Most other places have been somewhere in between.