Skip to content

Conversation

incertum
Copy link
Contributor

refactor: uniquely identify {Value,Duration}Histograms by name and label sets

Previously, {Value,Duration}Histograms could only be identified by their name. This change allows multiple {Value,Duration}Histograms to share the same name, with each unique set of labels defining a distinct time series.

However, the buckets are immutable for a MetricGroup once initialized with the first metric.

Additionally, the internal data structure for a stored metric has been refactored, providing a more robust and programmatic representation.

CC @ktoso @FranzBusch

Follow for #131, fixes #125

…bel sets

Previously, {Value,Duration}Histograms could only be identified by their name. This change allows multiple {Value,Duration}Histograms to share the same name, with each unique set of labels defining a distinct time series.

However, the buckets are immutable for a MetricGroup once initialized with the first metric.

Additionally, the internal data structure for a stored metric has been refactored, providing a more robust and programmatic representation.

Signed-off-by: Melissa Kilby <[email protected]>
@incertum incertum force-pushed the refactor/metrics-storage-enable-shared-names-same-type-2 branch from 0dadeef to 7808b75 Compare August 26, 2025 22:52
let help: String
}

private enum BucketType: Sendable, Hashable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't feel like a "type" it is the actual buckets - plural because of collection of bucket which is one value in here

Suggested change
private enum BucketType: Sendable, Hashable {
private enum HistogramBuckets: Sendable, Hashable {

self.buckets = buckets
}

init(metricsByLabelSets: [LabelsKey: MetricWithHelp<Metric>] = [:]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think we need this init; it can be just the previous one with buckets = nil

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
@incertum incertum force-pushed the refactor/metrics-storage-enable-shared-names-same-type-2 branch from 61dbf5b to 697b697 Compare August 26, 2025 23:31
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Looks good :)

@ktoso ktoso added the semver/none No version bump required. label Aug 26, 2025
@incertum incertum merged commit 5d5cf01 into swift-server:main Aug 26, 2025
34 of 35 checks passed
histogram2.recordNanoseconds(150_000_000) // 150ms
histogram1.recordNanoseconds(1_500_000_000) // 1500ms
histogram0.recordNanoseconds(800_000_000) // 800ms
histogram2.recordNanoseconds(100_000_000) // 100ms
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is easier to write as

histogram.record(.milliseconds(100))

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.

Crash if tags and not the same (allow different tags for the same metric name)
2 participants