-
Notifications
You must be signed in to change notification settings - Fork 73
Retry API requests in case of temporary network issues #190
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
Conversation
main.go
Outdated
@@ -61,7 +61,8 @@ func run(ctx context.Context, wg *sync.WaitGroup, globalCollectionOpts state.Col | |||
prefixedLogger := logger.WithPrefix(server.SectionName) | |||
prefixedLogger.PrintVerbose("Identified as api_system_type: %s, api_system_scope: %s, api_system_id: %s", server.SystemType, server.SystemScope, server.SystemID) | |||
|
|||
conf.Servers[idx].HTTPClient = config.CreateHTTPClient(server) | |||
conf.Servers[idx].HTTPClient = config.CreateHTTPClient(server, false) | |||
conf.Servers[idx].HTTPClientWithRetry = config.CreateHTTPClient(server, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could pass the prefixedLogger
here so HTTP error logs have the right prefix (I suspect we may also need that for the existing HTTP client?)
Okay @lfittl I pushed updates to this branch. Unfortunately, my attempt at unifying the loggers is introducing formatting issues: Maybe this would fix it? hashicorp/go-retryablehttp#101 |
Hmm, interesting. Yeah, I think at the very least we'd need something that hides the verbose messages (unless one is running with I wonder if we should just set
Additionally, when looking at the log output, I noticed something else we should consider. Previously when the server collection failed, e.g. because the API server isn't reachable at all, the actual error message from the collector (ignoring any extra output we'd get from the HTTP client) was like this:
Now the message looks like this:
I wonder if we can get rid of the first |
Okay, Retryablehttp adds the URL twice to error messages, and we then wrap that error, causing it to show the URL three times. I settled on a regex hack to remove extra URLs from the message so we can still keep the Not perfect, but here's the current version of the errors when the server is down:
And when the server responds with an error:
If you think this isn't a terrible approach and would like them to be more consistent, I'll revisit the error parsing. |
I think something that modifies the error message with a regexp could work, but I'm not a fan of doing this in the central logger, since we're introducing knowledge about a very specific error into the generic codepath. Maybe instead we could do this at the individual call sites, e.g. by having a |
Okay, the log cleaner is now in a separate
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This PR adds https://github.com/hashicorp/go-retryablehttp to retry any network requests not directly handled by the AWS SDK (since it has its own retry mechanism).
If any of these non-SDK requests should be only tried once we'll need to switch them back to
server.Config.HTTPClient
.Here's an example of a request being retried: