Skip to content

[Prometheus.HttpListener] Make loop async#7121

Open
martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
martincostello:make-worker-loop-async
Open

[Prometheus.HttpListener] Make loop async#7121
martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
martincostello:make-worker-loop-async

Conversation

@martincostello
Copy link
Copy Markdown
Member

Changes

Make the worker task for processing requests asynchronous.

Mainly this is just me trying to get rid of the .Result.

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)

Make the worker task for processing requests asynchronous.
Apply some minor refactoring to apply IDE suggestions and use `Task.WaitAsync()` where available.
Await, rather than `GetAwaiter().GetResult()`.
@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package label Apr 20, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.08%. Comparing base (7dd46f4) to head (072bd10).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7121      +/-   ##
==========================================
- Coverage   89.09%   89.08%   -0.01%     
==========================================
  Files         271      271              
  Lines       13065    13074       +9     
==========================================
+ Hits        11640    11647       +7     
- Misses       1425     1427       +2     
Flag Coverage Δ
unittests-Project-Experimental 88.89% <100.00%> (-0.18%) ⬇️
unittests-Project-Stable 89.08% <100.00%> (+0.06%) ⬆️
unittests-UnstableCoreLibraries-Experimental 40.89% <100.00%> (+0.13%) ⬆️

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

Files with missing lines Coverage Δ
....Prometheus.HttpListener/PrometheusHttpListener.cs 92.15% <100.00%> (+7.21%) ⬆️

... and 2 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review April 21, 2026 13:34
@martincostello martincostello requested a review from a team as a code owner April 21, 2026 13:34
Copilot AI review requested due to automatic review settings April 21, 2026 13:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Prometheus HttpListener worker loop to be asynchronous (removing blocking .Result/Wait patterns where possible) and adds/updates tests to validate stop behavior and concurrent scrape handling.

Changes:

  • Convert the listener worker loop to ProcessingLoopAsync and use async waiting for GetContextAsync on modern TFMs.
  • Add new tests for stop behavior with an in-flight scrape and for concurrent scrapes.
  • Simplify a parallel test path by using WaitAsync for completion under NET.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs Replaces the synchronous worker proc with an async processing loop and async context acquisition.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs Adds tests for stop behavior and concurrent scrapes; introduces a helper to start the listener on a random port.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs Uses WaitAsync for the Parallel.ForAsync completion path under NET.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

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