Skip to content

Make TestMetrics.FullKey tolerate repeated dimension names - #244

Merged
kukushechkin merged 1 commit into
apple:mainfrom
lenamonj:testmetrics-fullkey-repeated-dimensions
Sep 10, 2026
Merged

kukushechkin merged 1 commit into
apple:mainfrom
lenamonj:testmetrics-fullkey-repeated-dimensions

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

TestMetrics traps when a metric is created with a repeated dimension name.

Motivation:

TestMetrics.FullKey hashes and compares its dimensions through Dictionary(uniqueKeysWithValues:), which traps on a repeated name:

let metrics = TestMetrics()
Counter(label: "requests", dimensions: [("tag", "a"), ("tag", "b")], factory: metrics)
// Fatal error: Duplicate values for key: 'tag'

The metrics API accepts that input and every other factory carries it through.

Modifications:

hash(into:) and == read the dimensions sorted by name then value: identity stays order-insensitive, both read the same representation, and repeated names are kept. One test, which crashes without the fix.

Result:

TestMetrics records the instrument instead of killing the test process.

@kukushechkin kukushechkin added the 🔨 semver/patch No public API change. label Sep 9, 2026

@kukushechkin kukushechkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @lenamonj!

@kukushechkin
kukushechkin merged commit 1b1d245 into apple:main Sep 10, 2026
51 checks passed
@lenamonj
lenamonj deleted the testmetrics-fullkey-repeated-dimensions branch September 13, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants