[Prometheus.HttpListener] Make loop async#7121
Open
martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
Open
[Prometheus.HttpListener] Make loop async#7121martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
Conversation
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()`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Contributor
There was a problem hiding this comment.
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
ProcessingLoopAsyncand use async waiting forGetContextAsyncon modern TFMs. - Add new tests for stop behavior with an in-flight scrape and for concurrent scrapes.
- Simplify a parallel test path by using
WaitAsyncfor completion underNET.
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.
Simplify test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Make the worker task for processing requests asynchronous.
Mainly this is just me trying to get rid of the
.Result.Merge requirement checklist
AppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)