Add Exponential/Backoff retry to GetResourceTags #4710
Merged
+375
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the ECS Agent's GetResourceTags function by implementing exponential backoff and retry logic for resource tag retrieval. The implementation addresses potential transient failures when interacting with the ECS API, particularly focusing on handling throttling and rate limiting scenarios.
Implementation details
The GetResourceTags function now includes an exponential backoff mechanism using
retry.NewExponentialBackoff
with configurable parameters. It implements context-aware retry logic, usingcontext.WithTimeout
for overall operation timeout and properly handling context cancellation. The function now differentiates between transient and non-transient errors, with special handling for throttling and rate limit exceeded cases. Structured logging has been implemented, providing detailed error information including resource ARN and attempt counts.Testing
${ECS_CONTAINER_METADATA_URI_V4}/taskWithTags
New tests cover the changes: yes
The
TestGetResourceTags
and `TestGetResourceTagsError functions verify successful tag retrieval and error handling respectively. The TestGetResourceTagsWithRetry function covers various retry scenarios including success after throttling, server exceptions, and mixed transient errors. It also tests non-transient error handling and multiple throttling retry scenarios. The tests verify retry behavior, error message formatting, attempt counting, and different error type handling.Description for the changelog
Add Exponential/Backoff retry to GetResourceTags
Additional Information
Does this PR include breaking model changes? If so, Have you added transformation functions?
Does this PR include the addition of new environment variables in the README?
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.