Fix metrics with same label but different dimensions being merged #1242
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
<a href="https://easycla.lfx.linuxfoundation.org/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-signed.svg?v=2" alt="CLA Signed" align="left" height="28" width="328" ></a><br >The committers listed above are authorized under a signed CLA.<ul><li>:white_check_mark: login: linktimo / name: Timo Link (42e3e60bb7b289d95670a2b44524b2ab2b563498, b5f2976d4e2bb6ce601c828d84757479cae83a48, d473b08710e04362d97953ed9e2fccc2123b5ec9, ee9d69d9ffeac0de924fbfe0eaad933d0307878d, fd4cdc6eaedf82ef70a888e557bdabcd04b4778f)</li></ul>
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
LongPointData.value is declared as Int in Sources/OpenTelemetrySdk/Metrics/Data/Internal/LongPointData.swift:10, so this closure returns Int?, not Int64?. Swift does not implicitly convert between these types, preventing the test target from compiling. Change the closure's return type to Int?.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
The new regression test returns Int? from an Int64? closure, preventing the test target from compiling.
<details open>
<summary><strong>1 open issue</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
let valueForEnv: (_ env: String) -> Int? = {
let dataPoints = stableMetrics.first { $0.name == "requests" }?.data.points.compactMap { $0 as? LongPointData }
Dictionary<String, String> is already Hashable and Equatable. With a custom implementation there is a risk of non-synchronized implementation with the structure content.
Requested changes.
Thanks for pointing this out!
Agreed, I’ll remove the custom implementation and use the default Hashable and Equatable conformance.
Thanks @kukushechkin for the suggested fix in #1231 — implemented accordingly (MetricKey now includes dimensions).
Approved these changes.
Approved these changes.
Please extend the existing destroy test to cover two counters with the same label and different dimensions. After destroying one, the other should still be cached, and creating the destroyed dimensions again should return a new handler.
Hi @linktimo it seems that you applied @kukushechkin feedback directly and those commit appear as signed by him. He has still not been approved to sign his CLA, could you revert those changes and apply them yourself after? It would fix the CLA signing
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 78.58%. Comparing base (
7bad8ae) to head (ee9d69d).:warning: Report is 499 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## main #1242 +/- ##
===========================================
+ Coverage 67.89% 78.58% +10.69%
===========================================
Files 344 341 -3
Lines 15169 17174 +2005
===========================================
+ Hits 10299 13497 +3198
+ Misses 4870 3677 -1193
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
nachoBonafonte
linktimo
Fixes #1231. MetricKey only tracked name and type, so a second metric with the same label but different dimensions reused the first handler's cached series. MetricKey now includes dimensions, with a custom Hashable/Equatable implementation.