What does it look like to give thanks in everything and how do we find this perspective during those moments in life that are unpleasant, inconvenient, ugly, or painful?
I believe it is a principle of agency. We choose to see the good to focus on the blessings. I love the example of Job in the Old testament. I don't know of any person in the scriptures besides Jesus Christ who was given more hardships than Job was. Even with all the trials Joseph Smith went through, the Lord said to him "Thou art not yet as Job."
Job's perspective was this: "Naked came I out of my mother’s womb, and naked shall I return thither: the Lord gave, and the Lord hath taken away; blessed be the name of the Lord." - Job 1:21
Basically, Job's view on his life was that all of it was a gift from God, every last bit of it "the good, the bad, the ugly." He understood that he was born into the world completely empty-handed and that anything tangibly given unto him would eventually be taken away through the portal of death. "In all this Job sinned not, nor charged God foolishly."- Job 1:22
In our family scripture study we just read about the people of Alma who lived for a time under the persecution of Amulon and the Lamanites. They were chastened. Their patience and faith was tried. ( Mosiah 23:21) But they trusted in God and continued to cry out to him in prayer, which practice deepened their faith even more. (Mosiah 23:22&23, 27&28)
What I find interesting is that their burdens were not removed for quite some time but that they were only "eased." Even though the struggle and weight of trial remained, the Lord strengthened their ability to carry it all. And they did so "cheerfully and with patience to all the will of the Lord." - Mosiah 24: 13-15 Eventually they escaped their enemies and looking back they acknowledged the hand of God with the heartfelt praise, just as Job did.
This is faith: Knowing that even in the moment where we can't see the end from the beginning, where we can't see the reason for certain trials, it won't really matter when we leave this life. What will matter is "Did we trust God?" Did we trust that no matter what our struggles were we continued to do good and choose gratitude. The Good Shepherd KNOWS us!