Repository navigation
Conversation
Avoid unsupported instant queries with 32-day lookbacks when discovering historical pod owners in Amazon Managed Prometheus. Assisted-by: OpenAI Codex Signed-off-by: yongdadaoye <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughAMP historical-series lookups now use range queries for lookbacks of at least 32 days, with one-hour steps and a 95-day query cap. Runner also caps AMP history duration and adjusts timeframe duration when the step count exceeds 11,000. ChangesAMP Historical Queries
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant load_pods
participant historical_series_helper
participant query_range
participant AMP
load_pods->>historical_series_helper: Request owner history
historical_series_helper->>query_range: Send historical query with period and step
query_range->>AMP: Submit range query
AMP-->>query_range: Return series results
query_range-->>historical_series_helper: Return query results
historical_series_helper-->>load_pods: Return historical series
Merge Risk: ⚪ Minimal · up to
|
|
Hi maintainers, a gentle follow-up on this fix for #522. Could someone take a look when you have a chance? I've addressed CodeRabbit's docstring coverage warning in 5230315. CodeRabbit now reports 81.82% coverage (above the 80% threshold), and all five of its pre-merge checks pass. This follow-up only adds docstrings; it does not change the query logic. Validation on macOS with Python 3.10: The PR has no merge conflicts and is awaiting the required maintainer review. I'd appreciate your feedback, including whether you'd like any additional validation before approval. Thank you! |
Description
Fixes an issue where Pod owner lookups failed when using
--eks-managed-promwith a history duration of 32 days or more.To address the
--history_duration 960(40 days) case reported in Issue #522, Pod owner lookups now use range queries when querying 32 days or more of history with Amazon Managed Service for Prometheus (AMP).The existing behavior is preserved for non-AMP Prometheus backends and for AMP queries with a history duration of less than 32 days.
Fixes #522
What was changed
Long-term Pod owner queries for AMP
Added
_query_historical_series()to centralize historical Pod owner lookups.The query type is selected as follows:
query_rangeRange queries use
last_over_time()and evaluate the history at one-hour intervals.The PromQL window and the
query_rangestep use the same one-hour value. When the requested history duration is not evenly divisible by the step, the number of evaluation points is rounded up so that the full requested period is covered.This logic is applied to the following owner lookups:
Centralized AMP-specific limits
AMP-specific limits are now defined in
prometheus_utils.py:This avoids duplicating AMP-specific values across multiple implementation points.
The PromQL window and range query step are also derived from the same value to prevent them from becoming inconsistent in the future.
History duration adjustment above 95 days
When AMP is enabled and
history_durationexceeds 95 days, it is adjusted to 95 days (2,280 hours) before metric collection begins.A warning is logged when this adjustment is applied.
The adjusted history duration is used consistently across the entire collection process, including Pod owner, CPU, and memory queries.
This prevents cases where owner lookups use a 95-day history while other metrics continue using the originally requested duration.
The existing AMP-specific step adjustment remains part of the same processing flow.
Step conversion
Changed step conversion from
timedelta.secondstotimedelta.total_seconds().This ensures that steps of one day or longer are converted correctly instead of wrapping at the day boundary.
For example, a one-day step is now correctly passed as
86400s.Type annotations
Updated the return types of
query()andquery_range()tolist[dict]to match their actual responses.Why
The existing implementation queried historical Pod owner data using an instant query with a range selector such as:
AMP cannot retrieve the required long-term lookback using this approach once the history duration reaches the relevant limit.
Instead of simply limiting the history duration to 32 days, this change switches to a range query only when AMP is used with a history duration of 32 days or more.
The change is intentionally limited to AMP-specific cases so that existing short-duration queries and non-AMP Prometheus backends keep their current behavior.
For requests exceeding AMP's 95-day maximum query duration, the history duration is normalized before collection begins rather than being limited independently in individual queries.
This keeps the history period consistent across Pod owner, CPU, memory, and other metric collection.
Behavior and compatibility
Non-AMP Prometheus backends
Existing instant queries continue to be used.
The AMP-specific 32-day and 95-day limits introduced by this change do not apply, so existing behavior is unchanged.
AMP with less than 32 days of history
Instant queries continue to be used as before.
AMP with 32 to 95 days of history
Pod owner history is queried using range queries, covering the requested duration at one-hour intervals.
AMP with more than 95 days of history
history_durationis adjusted to 95 days (2,280 hours), and a warning is logged.The adjusted duration is used consistently across Pod owner, CPU, and memory collection.
Configuration
No new CLI options or configuration fields were added.
There are no changes to the existing values or configuration file formats.
Testing
The following cases are covered by tests:
86400shistory_durationis adjusted to 95 days only when it exceeds the limit, with a warning logged when the adjustment occursTest results
The same steps used by the regular push CI were reproduced in a Linux environment.
Environment:
Commands:
pip install --upgrade pip pip install -r requirements.txt pip install -e . pip install pytest pytestResult:
Additional checks:
pip check: passedgit diff --check: passedIntegration testing against an actual Amazon Managed Service for Prometheus environment has not been performed.