Skip to content

[Exporter.Prometheus] Use Stopwatch for scrape cache freshness check#7253

Merged
martincostello merged 1 commit into
open-telemetry:mainfrom
unsafePtr:fix/prometheus-cache-stopwatch
May 6, 2026
Merged

[Exporter.Prometheus] Use Stopwatch for scrape cache freshness check#7253
martincostello merged 1 commit into
open-telemetry:mainfrom
unsafePtr:fix/prometheus-cache-stopwatch

Conversation

@unsafePtr

@unsafePtr unsafePtr commented May 5, 2026

Copy link
Copy Markdown
Contributor

Changes

Follow-up to #7193. The scrape-response cache added in #7189 still uses DateTime.UtcNow for its freshness check, which can keep stale entries indefinitely on a backward NTP step or evict valid ones on a forward step. Switch to Stopwatch.GetElapsedTime, matching the pattern #7193 applied elsewhere and mirroring dotnet/runtime#127303 which made the same change for EventCounter's polling timer.
CollectionResponse.GeneratedAtUtc is unchanged.

StopwatchExtensions.cs (added in #7193) is linked into the two Prometheus packages.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@unsafePtr unsafePtr requested a review from a team as a code owner May 5, 2026 22:27
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package labels May 5, 2026
@martincostello

Copy link
Copy Markdown
Member

I'm getting HTTP 500s from GitHub trying to post review comments, so I'm trying a PR comment instead:

I think the CHANGELOG entries are overly-verbose for a user-facing note. Can you slim them down please?

Also they need a link to this PR like all the other entries link to their corresponding PR.

@unsafePtr unsafePtr force-pushed the fix/prometheus-cache-stopwatch branch from e0401ff to d82ce59 Compare May 6, 2026 19:16
@unsafePtr

Copy link
Copy Markdown
Contributor Author

@martincostello, thank you. Updated.

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.91%. Comparing base (58b0202) to head (d82ce59).
⚠️ Report is 15 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7253      +/-   ##
==========================================
+ Coverage   89.88%   89.91%   +0.03%     
==========================================
  Files         273      273              
  Lines       13755    13787      +32     
==========================================
+ Hits        12363    12396      +33     
+ Misses       1392     1391       -1     
Flag Coverage Δ
unittests-Project-Experimental 89.78% <100.00%> (-0.03%) ⬇️
unittests-Project-Stable 89.80% <100.00%> (+0.02%) ⬆️
unittests-UnstableCoreLibraries-Experimental 45.81% <100.00%> (+0.07%) ⬆️

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

Files with missing lines Coverage Δ
...tpListener/Internal/PrometheusCollectionManager.cs 91.56% <100.00%> (+0.33%) ⬆️

... and 2 files with indirect coverage changes

@martincostello martincostello added this pull request to the merge queue May 6, 2026
Merged via the queue into open-telemetry:main with commit ec8a796 May 6, 2026
71 checks passed
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @unsafePtr! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

This was referenced Jun 10, 2026
This was referenced Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants