Skip to content

Fix hardcoded metricstore ES extended lookback - #9102

Open
HESleagacy wants to merge 9 commits into
jaegertracing:mainfrom
HESleagacy:fix/es-metricstore-dynamic-lookback-window
Open

Fix hardcoded metricstore ES extended lookback#9102
HESleagacy wants to merge 9 commits into
jaegertracing:mainfrom
HESleagacy:fix/es-metricstore-dynamic-lookback-window

Conversation

@HESleagacy

@HESleagacy HESleagacy commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The extendedStartTime for Elasticsearch range queries was hardcoded to 10 minutes prior to startTime. When a client queries metrics with RatePer larger than 10 minutes (e.g., RatePer = 30m or 1h), the initial metric window fails to find preceding data points, producing NaN rates for the first portion of the graph.

This fix dynamically computes extendedStartTime based on params.RatePer and adds a nil check for RatePer. It also includes comprehensive test coverage for calculateTimeRange and updates the error case tests.

Which problem is this PR solving?

Description of the changes

  • Dynamically size extendedStartTime using *params.RatePer.
  • Add RatePer to the nil guard in calculateTimeRange and update the error message.
  • Remove unused time import in reader.go.
  • Add table-driven unit tests for calculateTimeRange to time_range_test.go covering nil edge cases and multiple RatePer window variations.
  • Add nil RatePer error test in reader_test.go.

How was this change tested?

  • Added time_range_test.go for explicit unit testing.
  • Existing reader_test.go snapshot and error tests pass.
  • make test passes successfully.

Checklist

AI Usage in this PR (choose one)

See AI Usage Policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

The extendedStartTime for Elasticsearch range queries was hardcoded to 10 minutes prior to startTime. When a client queries metrics with RatePer larger than 10 minutes (e.g., RatePer = 30m or 1h), the initial metric window fails to find preceding data points, producing NaN rates for the first portion of the graph.

This fix dynamically computes extendedStartTime based on params.RatePer and adds a nil check for RatePer. It also includes comprehensive test coverage for calculateTimeRange and updates the error case tests.

Signed-off-by: Sarva Dubey <sarvadubey@gmail.com>
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.80%. Comparing base (3d5058c) to head (69c5838).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9102   +/-   ##
=======================================
  Coverage   97.80%   97.80%           
=======================================
  Files         377      377           
  Lines       19728    19728           
=======================================
  Hits        19295    19295           
  Misses        293      293           
  Partials      140      140           
Flag Coverage Δ
badger_direct 7.77% <ø> (ø)
badger_e2e 11.92% <0.00%> (-0.01%) ⬇️
cassandra-4.x-direct-manual 12.72% <ø> (ø)
cassandra-4.x-e2e-auto 18.05% <0.00%> (ø)
cassandra-4.x-e2e-manual 18.05% <0.00%> (ø)
cassandra-5.x-direct-manual 12.72% <ø> (ø)
cassandra-5.x-e2e-auto 18.05% <0.00%> (ø)
cassandra-5.x-e2e-manual 18.05% <0.00%> (ø)
clickhouse-direct 7.85% <ø> (ø)
clickhouse-e2e 13.34% <0.00%> (+0.09%) ⬆️
elasticsearch-7.x-direct 21.35% <ø> (ø)
elasticsearch-8.x-direct 21.38% <ø> (ø)
elasticsearch-8.x-e2e 19.53% <0.00%> (ø)
elasticsearch-9.x-direct 21.38% <ø> (ø)
elasticsearch-9.x-e2e 19.53% <0.00%> (ø)
grpc_direct 6.86% <ø> (ø)
grpc_e2e 12.45% <0.00%> (ø)
kafka-3.x-v2 9.62% <0.00%> (ø)
memory_v2 14.44% <0.00%> (+0.01%) ⬆️
opensearch-1.x-direct 21.37% <ø> (ø)
opensearch-2.x-direct 21.37% <ø> (ø)
opensearch-2.x-e2e 19.83% <0.00%> (+0.30%) ⬆️
opensearch-3.x-direct 21.37% <ø> (ø)
opensearch-3.x-e2e 19.53% <0.00%> (ø)
query 12.40% <0.00%> (ø)
tailsampling-processor 6.86% <0.00%> (ø)
unittests 96.52% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HESleagacy

Copy link
Copy Markdown
Contributor Author

@yurishkuro Please take a look

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Hardcoded 10-minute lookback window in calculateTimeRange causes NaN rates when RatePer > 10m

1 participant