Skip to content

Conversation

incertum
Copy link
Contributor

Add {emitToString, emitToBuffer} thread-safe internal buffer management variants to emit metrics.

Deduplicate TYPE and HELP lines per metric name by default on emit.

Fixes #118 @ptoffy

CC @ktoso and @FranzBusch

…per metric name

Add {emitToString, emitToBuffer} thread-safe internal buffer management variants to emit metrics.

Deduplicate TYPE and HELP lines per metric name by default on emit + enforce same HELP per metric name.

Signed-off-by: Melissa Kilby <[email protected]>
… sharing

Revert to stricter mutual exclusivity constraints for metric name sharing with respect to labeled and unlabeled cases while still allowing different label sets per metric name. While Prometheus wouldn't break with sharing a metric name for labeled and unlabeled variants, the client enforces that each unique metric name must either be labeled (allowing multiple label sets) or unlabeled in order to support correct Prometheus aggregations.

Use MetricFamily instead of MetricGroup.

Signed-off-by: Melissa Kilby <[email protected]>
@incertum incertum force-pushed the new/emit-to-string-alternative branch from 72e503b to 1184ea7 Compare August 28, 2025 18:29
@incertum
Copy link
Contributor Author

New emit variants should address thread-safety requirements #136.
Question: Is it even ok to feature a not thread-safe option?

@incertum
Copy link
Contributor Author

Fixes #137

@incertum
Copy link
Contributor Author

Fixes #138, amendment to #125 as initial fixes were slightly too permissive wrt metric name sharing.

Move constraint checks into MetricFamily and adopt an approach that favors immutability of MetricFamily members.

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
@ktoso ktoso added the semver/none No version bump required. label Aug 29, 2025
}
}

func add(metric: Metric, for labels: [(String, String)]) -> MetricFamily<Metric> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor and doesn’t have to be done, but fyi. In swift often the “add” would be mutating and the not mutating one would be “adding”. But this is fine, just internal api so no need to bikeshed too much

Reduce code duplication further by adding `removing`, `getMetric` and `forEachMetric` to `MetricFamily`.
Rename `add` -> `adding` to indicate non mutating nature (Swift convention).

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
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.

Lgtm!

@ktoso ktoso merged commit e9ca4f7 into swift-server:main Aug 30, 2025
34 checks passed
@ktoso ktoso added 🆕 semver/minor Adds new public API. and removed semver/none No version bump required. labels Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Awkward collection API

2 participants