-
Notifications
You must be signed in to change notification settings - Fork 870
[Prometheus.HttpListener] Avoid array lookup #6851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Prometheus.HttpListener] Avoid array lookup #6851
Conversation
- Avoid array lookup and implicit bounds checks by converting to a switch statement. - Apply analyzer suggestions to simplify/modernize code.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6851 +/- ##
==========================================
+ Coverage 86.90% 87.27% +0.36%
==========================================
Files 263 263
Lines 12382 12385 +3
==========================================
+ Hits 10761 10809 +48
+ Misses 1621 1576 -45
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Add unit tests for missing coverage of metric conversions.
Add more coverage.
There was a problem hiding this 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 optimizes the GetPrometheusType method by replacing array lookup with a switch statement, applies modern C# patterns to simplify method bodies, and significantly expands test coverage for metric unit mapping.
Changes:
- Replaced array lookup in
GetPrometheusTypewith a switch statement to avoid bounds checks and improve clarity - Converted several methods to expression-bodied members for modern, concise code
- Added comprehensive test coverage for unit mapping, metric type mapping, and edge cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusMetric.cs | Replaced array-based metric type lookup with switch statement; converted methods to expression-bodied members |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusMetricTests.cs | Added 225 lines of comprehensive unit tests covering metric unit mapping, type conversion, and edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cfc2d0c
Changes
Merge requirement checklist
AppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)