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

Logs Tail: Give the user better feedback when --from flag errors #201

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

jaredmorrow
Copy link
Contributor

This fixes two things:

  • When an unknown status code is returned we previously return from
    the function without and exit. This would just leave us in and endless
    loop doing nothing for the user.
  • When a user specifies a --from time that is too far in the past or
    future, we should let them know that so it doesn't just mysteriously
    give them a 404 warning and exit.

Previously it would respond like the following and just hang:

WARNING: non-200 resp 404

With this change it looks errors and exits:

ERROR: specified from time 1622362928 not found, either too far in the past or future

This fixes two things:
- When an unknown status code is returned we previously return from
the function without and exit. This would just leave us in and endless
loop doing nothing for the user.
- When a user specifies a --from time that is too far in the past or
future, we should let them know that so it doesn't just mysteriously
give them a 404 warning and exit.

Previously it would respond like the following and just hang:
```
WARNING: non-200 resp 404
```

With this change it looks errors and exits:
```
ERROR: specified from time 1622362928 not found, either too far in the past or future
```
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

One minor suggested change.

I would ideally like to see a test around this change.

pkg/logs/tail.go Outdated Show resolved Hide resolved
Co-authored-by: Mark McDonnell <Integralist@users.noreply.github.com>
@Integralist Integralist added the bug Something isn't working label Feb 3, 2021
@Integralist Integralist merged commit 4a265f6 into master Feb 3, 2021
@Integralist Integralist deleted the jm/log-tail-better-error-for-from branch February 3, 2021 15:35
// If the response was a 404, the from time was
// not valid, give them an error stating this and exit.
if resp.StatusCode == http.StatusNotFound &&
c.cfg.from != 0 {
Copy link

Choose a reason for hiding this comment

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

Sorry if I'm missing context, how does c.cfg.from != 0 mean the from date is invalid?
I fear this would catch and mislabel any 404 error?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jaredmorrow are you able to provide any extra context? I understand the point @ejthurgo is making but I was under the impression this logic was based on a specific behaviour inherent to your API (e.g. in the sense that the API would only return a 404 when an incorrect flag value was provided).

If that's not the case and the API is expected to return a 404 in other scenarios, then yes this could end up be an accidental match where the user provides a valid flag value but something else in their request has caused the API to return a 404.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The combination of the 404 & the from field being set is the key here. If from is set and it is out of range, the 404 returned would be due to the range being too far out from Now. There are currently no other 404s sent by the server, but just in case I added the from != 0 to be specific about the case.

Copy link

Choose a reason for hiding this comment

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

Surprising the server doesn't give any specific detail on why it failed? Relying on the fact it currently only sends a 404 for this circumstance seems awfully risky.
But thanks for the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants