Skip to content

fix(logs): bound throttling backoff and recover the polling interval - #9404

Open
vinsymoyya wants to merge 4 commits into
aws:developfrom
vinsymoyya:improve/log-tail-backoff
Open

vinsymoyya wants to merge 4 commits into
aws:developfrom
vinsymoyya:improve/log-tail-backoff

Conversation

@vinsymoyya

@vinsymoyya vinsymoyya commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Which issue(s) does this change fix?

Fixes #9403.

Why is this change necessary?

CloudWatch and X-Ray tailers repeatedly square their polling interval after throttling. Five throttles at the default interval lead to a 65,536-second delay, and successful polls never restore the original interval.

How does it address the issue?

Double the interval up to 60 seconds and restore the configured interval after a successful poll, including an empty response. Preserve explicitly configured intervals longer than 60 seconds. Apply the policy to CloudWatch Logs and the shared X-Ray trace/service-graph tail loop, and document it in their constructor docstrings.

Add twelve regression cases for sustained throttling, recovery and custom intervals across CloudWatch Logs, X-Ray traces and X-Ray service graphs, using each service's actual throttle code. Update existing CloudWatch, trace and service-graph throttling expectations to the bounded doubling policy. Preserve #9413’s support for both X-Ray throttle codes and its "Next poll in %s seconds" warning.

What side effects does this change have?

After throttling, tailing retries sooner than the previous unbounded delays. Successful polling resumes the normal interval. SDK request parameters, event delivery and CLI options are unchanged.

Validation

  • Reproduced seven existing test failures on the reviewed merge head, plus three failures in the added service-graph cases, before restoring bounded doubling.
  • Python 3.12: all 183 observability/log-command tests passed. Ruff passed.
  • Full make pr on Linux/Python 3.11: 9,855 tests passed, 28 skipped, 59 subtests passed, 94.19% coverage. Schema generation, Black, Ruff and mypy (1,394 source files) passed.
  • Throttles and time are simulated; no live AWS throttling or real waits were used in the regression tests.

Mandatory Checklist

  • Reviewed the generative AI contribution guidelines
  • Added return type hints to the changed production methods
  • Design document: no new CLI, SAM Spec or public configuration interface
  • Added unit regressions and updated existing policy expectations
  • Integration tests: request shapes are unchanged; deterministic tail-loop tests and existing stubbed-client coverage exercise the polling behavior without live AWS load
  • Functional tests: no separate CLI/interface change
  • make pr passes
  • Reproducible requirements: no dependency changes
  • Documented the polling policy in constructor docstrings

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@vinsymoyya
vinsymoyya requested a review from a team as a code owner November 5, 2026 08:35
@github-actions github-actions Bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Nov 5, 2026
@vicheey

vicheey commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Thanks @vinsymoyya, this is a clean fix and the tests are solid. One thing I'd like to see in this PR, since X-Ray is in the stated scope. The X-Ray's throttle arrives under a different error code. It's ThrottledException (HTTP 429) — the only throttle error listed for GetTraceSummaries, BatchGetTraces and GetServiceGraph in botocore's X-Ray service model, which has no ThrottlingException shape. So xray_event_puller.py:56 won't match a real X-Ray throttle and tail re-raises instead of backing off. This predates your change; the X-Ray tests don't catch it because they build the ClientError with the CloudWatch code. Suggestion:

if error_code in ("ThrottlingException", "ThrottledException"):

A botocore Stubber with service_error_code="ThrottledException", http_status_code=429 is enough to pin it per puller.

Other non-blocking:

  • At the cap the warning still says "Increasing the poll interval … to 60 seconds" on every throttled poll, when nothing is increasing. "Next poll in %s seconds", or logging only on change, would read better.
  • The non-throttle re-raise is the one path in that try with no test. AccessDeniedException after a throttle, asserting it raises without another sleep, would cover it.
  • XRayServiceGraphPuller could join PULLERS to make the matrix explicit.

Separately, and not for this PR: a Ctrl-C during a backoff still waits out the current sleep, because tail runs in a ThreadPoolExecutor worker (ObservabilityCombinedPuller.tail → AsyncContext.run_async) and the signal lands on the main thread, so the worker only notices cancelled at the top of the next iteration. A threading.Event.wait() set by stop_tailing() would make it immediate — happy to follow up on this separately.

@vinsymoyya vinsymoyya mentioned this pull request Nov 9, 2026
9 tasks done

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Results

Reviewed: 0cfc34e..894b1cb
Files: 6
Comments: 1

@vicheey vicheey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @vinsymoyya! The develop merge after #9413 dropped the X-Ray half of the fix: the throttle branch in xray_event_puller.py still does += 1 then **= 2, so only the reset-on-success survived. The new X-Ray cases in test_tail_backoff.py and the trace/service-graph test_with_throttling_* tests fail on the current head. Could you re-apply the bounded doubling there, keeping #9413's ("ThrottlingException", "ThrottledException") check and its "Next poll in %s seconds" message?

@vinsymoyya

Copy link
Copy Markdown
Contributor Author

Restored bounded doubling in 4327e78, preserving #9413's ("ThrottlingException", "ThrottledException") check and "Next poll in %s seconds" warning. The interval now doubles up to 60 seconds, preserves configured intervals above 60 seconds, and resets after a successful poll.

Added service graphs to the shared backoff matrix and used each service's actual throttle code. All 183 observability/log-command tests pass. Full Linux make pr also passed: 9,855 tests, 94.19% coverage, with formatting, linting and type checks passing. Updated the PR validation details.

@vicheey vicheey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: bound log-tail throttling backoff and recover the polling interval

2 participants