← Back to Pull requests

Fix metrics with same label but different dimensions being merged #1242

Merged
linktimo merged 4 files (55 lines) on Nov 20, 2026 08:00 UTC
View on GitHub
linktimo linktimo commented on Oct 18, 2026 15:40 UTC
Author

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.

Diff: 55 lines (+45 / -10) across 4 files Reviewer: nachoBonafonte Review duration: 47060m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.31) × (1 − Review Confidence (0.73)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.31 · 55 lines diff across 4 files
0.31
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.48 · 5 substantive comment(s)
0.48
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
72%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.241
Real PR Conversation Timeline
17 items
copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 18, 2026 15:40 UTC
Reviewer

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

linux-foundation-easycla[bot] linux-foundation-easycla[bot] commented on Oct 18, 2026 15:40 UTC
Bot

<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-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 18, 2026 17:36 UTC
Reviewer

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot Copilot commented on code on Oct 19, 2026 06:57 UTC
Code Review
Tests/ImportersTests/SwiftMetricsShim/SwiftMetricsShimTests.swift:1
@@ -111,6 +111,24 @@ class SwiftMetricsShimTests: XCTestCase {
     XCTAssertEqual(data.attributes["label_one"]?.description, "value")
   }
 
+  func testCounter_sameLabelDifferentDimensions() throws {
+    let counterA = metrics.makeCounter(label: "requests", dimensions: [("env", "a")])
+    let counterB = metrics.makeCounter(label: "requests", dimensions: [("env", "b")])
+    counterA.increment(by: 1)
+    counterB.increment(by: 1)
+
+    XCTAssertEqual(metrics.metrics.count, 2)
+
+    wait(for: [metricsExportExpectation], timeout: 10)
+
+    let dataPoints = try stableMetrics.first { $0.name == "requests" }?.data.points.compactMap { $0 as? LongPointData }
+    let valueForEnv: (String) -> Int64? = { env in

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?.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 19, 2026 06:57 UTC
Reviewer

<!-- 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>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Fix closure return type mismatch in LongPointData test · New

  • </details>

    <sub>Review effort: Balanced</sub>

    kukushechkin kukushechkin commented on code on Oct 20, 2026 12:08 UTC
    Code Review
    Tests/ImportersTests/SwiftMetricsShim/SwiftMetricsShimTests.swift:1
    @@ -111,6 +111,24 @@ class SwiftMetricsShimTests: XCTestCase {
         XCTAssertEqual(data.attributes["label_one"]?.description, "value")
       }
     
    +  func testCounter_sameLabelDifferentDimensions() throws {
    +    let counterA = metrics.makeCounter(label: "requests", dimensions: [("env", "a")])
    +    let counterB = metrics.makeCounter(label: "requests", dimensions: [("env", "b")])
    +    counterA.increment(by: 1)
    +    counterB.increment(by: 1)
    +
    +    XCTAssertEqual(metrics.metrics.count, 2)
    +
    +    wait(for: [metricsExportExpectation], timeout: 10)
    +
    +    let dataPoints = try stableMetrics.first { $0.name == "requests" }?.data.points.compactMap { $0 as? LongPointData }
    +    let valueForEnv: (String) -> Int64? = { env in

        let valueForEnv: (_ env: String) -> Int? = {
    

    kukushechkin kukushechkin commented on code on Oct 20, 2026 12:09 UTC
    Code Review
    Tests/ImportersTests/SwiftMetricsShim/SwiftMetricsShimTests.swift:1
    @@ -111,6 +111,24 @@ class SwiftMetricsShimTests: XCTestCase {
         XCTAssertEqual(data.attributes["label_one"]?.description, "value")
       }
     
    +  func testCounter_sameLabelDifferentDimensions() throws {
    +    let counterA = metrics.makeCounter(label: "requests", dimensions: [("env", "a")])
    +    let counterB = metrics.makeCounter(label: "requests", dimensions: [("env", "b")])
    +    counterA.increment(by: 1)
    +    counterB.increment(by: 1)
    +
    +    XCTAssertEqual(metrics.metrics.count, 2)
    +
    +    wait(for: [metricsExportExpectation], timeout: 10)
    +
    +    let dataPoints = try stableMetrics.first { $0.name == "requests" }?.data.points.compactMap { $0 as? LongPointData }

        let dataPoints = stableMetrics.first { $0.name == "requests" }?.data.points.compactMap { $0 as? LongPointData }
    

    kukushechkin kukushechkin commented on code on Oct 20, 2026 12:09 UTC
    Code Review
    Sources/Importers/SwiftMetricsShim/MetricHandlers.swift:1
    @@ -112,4 +121,18 @@ enum MetricType: String {
     struct MetricKey: Hashable {
       let name: String
       let type: MetricType
    +  let dimensions: [String: String]
    +
    +  static func == (lhs: MetricKey, rhs: MetricKey) -> Bool {
    +    lhs.name == rhs.name && lhs.type == rhs.type && lhs.dimensions == rhs.dimensions
    +  }
    +
    +  func hash(into hasher: inout Hasher) {
    +    hasher.combine(name)
    +    hasher.combine(type)
    +    for key in dimensions.keys.sorted() {
    +      hasher.combine(key)
    +      hasher.combine(dimensions[key])
    +    }
    +  }

    Dictionary<String, String> is already Hashable and Equatable. With a custom implementation there is a risk of non-synchronized implementation with the structure content.

    kukushechkin kukushechkin requested changes on Oct 20, 2026 12:18 UTC
    Changes Requested Reviewer

    Requested changes.

    linktimo linktimo commented on code on Oct 20, 2026 17:57 UTC
    Code Review
    Sources/Importers/SwiftMetricsShim/MetricHandlers.swift:1
    @@ -112,4 +121,18 @@ enum MetricType: String {
     struct MetricKey: Hashable {
       let name: String
       let type: MetricType
    +  let dimensions: [String: String]
    +
    +  static func == (lhs: MetricKey, rhs: MetricKey) -> Bool {
    +    lhs.name == rhs.name && lhs.type == rhs.type && lhs.dimensions == rhs.dimensions
    +  }
    +
    +  func hash(into hasher: inout Hasher) {
    +    hasher.combine(name)
    +    hasher.combine(type)
    +    for key in dimensions.keys.sorted() {
    +      hasher.combine(key)
    +      hasher.combine(dimensions[key])
    +    }
    +  }

    Thanks for pointing this out!
    Agreed, I’ll remove the custom implementation and use the default Hashable and Equatable conformance.

    linktimo linktimo commented on Oct 20, 2026 18:09 UTC
    Author

    Thanks @kukushechkin for the suggested fix in #1231 — implemented accordingly (MetricKey now includes dimensions).

    nachoBonafonte nachoBonafonte approved these changes on Oct 22, 2026 12:21 UTC
    Approved Reviewer

    Approved these changes.

    kukushechkin kukushechkin approved these changes on Oct 22, 2026 16:23 UTC
    Approved Reviewer

    Approved these changes.

    aranhave aranhave commented on code on Nov 03, 2026 11:18 UTC
    Code Review
    Sources/Importers/SwiftMetricsShim/SwiftMetricsShim.swift:1
    @@ -92,8 +92,8 @@ public final class OpenTelemetrySwiftMetrics: MetricsFactory, @unchecked Sendabl
     
       private func destroyMetric(_ metric: SwiftMetric?) {
         lock.withLock {
    -      if let name = metric?.metricName, let type = metric?.metricType {
    -        metrics.removeValue(forKey: .init(name: name, type: type))
    +      if let name = metric?.metricName, let type = metric?.metricType, let dimensions = metric?.dimensions {
    +        metrics.removeValue(forKey: .init(name: name, type: type, dimensions: dimensions))

    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.

    nachoBonafonte nachoBonafonte commented on Nov 17, 2026 07:40 UTC
    Contributor

    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[bot] codecov[bot] commented on Nov 20, 2026 07:51 UTC
    Bot

    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>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    Assignees
    linktimo linktimo
    Labels
    risk: low confidence: 72.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 31.5% (LOW) · Higher = larger blast radius
    31.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 72.8% · Lower = rushed or shallow review
    72.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 8.6% · Safe to merge
    8.6%