Add end_epoch for query time range customization#541
Conversation
Introduce a new `end_epoch` option that specifies the end of the Prometheus query window. When used together with the existing history duration option, users can define an arbitrary time range instead of being limited to querying metrics relative to the current time.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe metrics pipeline now accepts an explicit end timestamp. Strategy settings provide it, the runner forwards it through Prometheus services, and metric queries derive their start time while preserving the end time across batched requests. ChangesExplicit metrics end time
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant StrategySettings
participant Runner
participant PrometheusMetricsLoader
participant PrometheusMetricsService
participant PrometheusMetric
participant Prometheus
StrategySettings->>Runner: provide end_datetime
Runner->>PrometheusMetricsLoader: gather_data(end_time)
PrometheusMetricsLoader->>PrometheusMetricsService: gather_data(end_time)
PrometheusMetricsService->>PrometheusMetric: load_data(end_time)
PrometheusMetric->>Prometheus: query from end_time - period to end_time
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
robusta_krr/core/runner.py (1)
333-333: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftPropagate
end_timetoload_podsfor historical pod discovery.
load_podsqueries Prometheus for pods that existed withinhistory_timedelta. Becauseend_datetimeis not passed to it, the search window is evaluated relative to the current time (now()).If a user configures
end_epochto query a historical event (e.g., a week ago), KRR will search for pods that existed in the current window rather than the historical window. This will result in missing pods or falling back to the current Kubernetes API state, breaking historical evaluation.Please update the
load_podsmethod signature across the loader chain to acceptend_timeand pass it down to the underlying Prometheus query.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@robusta_krr/core/runner.py` at line 333, Update the runner call that invokes prometheus_loader.load_pods to pass the configured historical end time, and propagate this end_time parameter through each load_pods implementation and delegation in the loader chain to the underlying Prometheus query. Ensure the query uses the supplied end_time as the window endpoint instead of defaulting to now(), while preserving current behavior for callers without a historical end time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@robusta_krr/core/abstract/strategies.py`:
- Line 52: Update the end_epoch field definition to use Pydantic’s
default_factory with time.time instead of evaluating time.time() during class
definition, so each new instance receives its creation-time timestamp while
retaining the existing nonnegative constraint.
---
Outside diff comments:
In `@robusta_krr/core/runner.py`:
- Line 333: Update the runner call that invokes prometheus_loader.load_pods to
pass the configured historical end time, and propagate this end_time parameter
through each load_pods implementation and delegation in the loader chain to the
underlying Prometheus query. Ensure the query uses the supplied end_time as the
window endpoint instead of defaulting to now(), while preserving current
behavior for callers without a historical end time.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 30d6a25f-a138-4806-8970-ae58ddfb0735
📒 Files selected for processing (7)
robusta_krr/core/abstract/metrics.pyrobusta_krr/core/abstract/strategies.pyrobusta_krr/core/integrations/prometheus/loader.pyrobusta_krr/core/integrations/prometheus/metrics/base.pyrobusta_krr/core/integrations/prometheus/metrics_service/base_metric_service.pyrobusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.pyrobusta_krr/core/runner.py
Use `fromtimestamp` with utc timezone instead
Introduce a new
end_epochoption that specifies the end of the Prometheus query window. When used together with the existing history duration option, users can define an arbitrary time range instead of being limited to querying metrics relative to the current time.Closes #474