The Wesley Study Bible contains this little overview of the themes of Psalm 17:
Has anyone ever said to you, “Life is not fair,” and you thought, “Well, it should be!”? Life is filled with ups and downs, times when what seems fair to you is not fair to another. Psalm 17 begins with “Listen to what’s right, LORD; pay attention to my cry!” (17:1a). This is a prayer for deliverance from the wicked and for the freedom to live in God’s righteousness. While life is not fair all the time, it is right at all times to pray to God for deliverance from wrongdoing and for justice for all the children of God.
The Psalmist (David, we are told) begins by declaring his own faithfulness. Why would God want to listen to those who are not faithful to God’s purposes? Why would God listen to the deceitful? Surely God hears the prayers of the repentant and remorseful, but sincerity of heart is always a precondition of effective prayer. (more…)