Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logcli: Add retries to unsuccessful log queries #3879

Merged
merged 2 commits into from
Jun 24, 2021

Conversation

vyzigold
Copy link
Contributor

What this PR does / why we need it:
This adds a possibility to retry unsuccessful queries when using logcli
Example output of a failed query (there is no server running on that port):

./logcli query "{type=\"logtest\"}" --addr="http://127.0.0.1" --retries 3
2021/06/22 15:28:02 http://127.0.0.1/loki/api/v1/query_range?direction=BACKWARD&end=1624368482937234835&limit=30&query=%7Btype%3D%22logtest%22%7D&start=1624364882937234835
2021/06/22 15:28:02 error sending request Get "http://127.0.0.1/loki/api/v1/query_range?direction=BACKWARD&end=1624368482937234835&limit=30&query=%7Btype%3D%22logtest%22%7D&start=1624364882937234835": dial tcp 127.0.0.1:80: connect: connection refused
2021/06/22 15:28:02 error sending request Get "http://127.0.0.1/loki/api/v1/query_range?direction=BACKWARD&end=1624368482937234835&limit=30&query=%7Btype%3D%22logtest%22%7D&start=1624364882937234835": dial tcp 127.0.0.1:80: connect: connection refused
2021/06/22 15:28:02 error sending request Get "http://127.0.0.1/loki/api/v1/query_range?direction=BACKWARD&end=1624368482937234835&limit=30&query=%7Btype%3D%22logtest%22%7D&start=1624364882937234835": dial tcp 127.0.0.1:80: connect: connection refused
2021/06/22 15:28:02 Query failed: Run out of retries while querying the server

Which issue(s) this PR fixes:
Fixes #3855

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated

@CLAassistant
Copy link

CLAassistant commented Jun 22, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@ronensc ronensc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this feature

Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a minor suggestion but otherwise the code LGTM!
Thanks for the PR!

retries := c.Retries
success := false

for retries > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user sets the retries flag value to 0 by mistake then they would unexpectedly skip making any calls. Also, retried calls should be the ones done after seeing a failure in the initial call, so let us initialise the retries above to c.Retries + 1.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but I enhanced your idea a little bit. I renamed the variable to "attempts", which seemed like a better name to me now. I implemented your suggestion, so attempts = c.Retries + 1 and I made the default value for c.Retries = 0. So there still is 1 attempt unless the user sets the retries flag to something other than 0.

Number of attempts for each query = retries + 1
Default number of retries = 0
So by default, there is always 1 attempt for each query
Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sandeepsukhani sandeepsukhani merged commit 67b6c1a into grafana:main Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logcli doesn't do retries on timeout failures
4 participants