-
Notifications
You must be signed in to change notification settings - Fork 38
refactor[Counter + Gauge]: uniquely identify metric time series by name and label sets (1/2) #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor[Counter + Gauge]: uniquely identify metric time series by name and label sets (1/2) #131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall ok, but the names are really confusing. Perhaps: keep Metric a type, drop MetricContainer, doesn't seem to have anything specific it's adding -- just a single field, and then rename "MetricType" to be the Container type?
a3bb1e5
to
fd0e483
Compare
Previously, counters could only be identified by their name. This change allows multiple counters to share the same name, with each unique set of labels defining a distinct time series. Additionally, the internal data structure for a stored metric has been refactored, providing a more robust and programmatic representation. Signed-off-by: Melissa Kilby <mkilby@apple.com>
fd0e483
to
c697ee8
Compare
Previously, gauges could only be identified by their name. This change allows multiple gauges to share the same name, with each unique set of labels defining a distinct time series. Additionally, the internal data structure for a stored metric has been refactored, providing a more robust and programmatic representation. Signed-off-by: Melissa Kilby <mkilby@apple.com>
I have also added the code changes for |
This could use some more use of generics rather than copying types around 1:1; here's a patch: Basically: - // Note: In order to support Sendable, need to explicitely define the types.
- private struct CounterWithHelp {
- var counter: Counter
+ private struct MetricWithHelp<Metric: AnyObject & Sendable>: Sendable {
+ var metric: Metric
let help: String
}
- private struct GaugeWithHelp {
- var gauge: Gauge
- let help: String
- }
-
- private struct CounterGroup {
- // A collection of Counter metrics, each with a unique label set, that share the same metric name.
- // Distinct help strings for the same metric name are permitted, but Prometheus retains only the
- // most recent one. For an unlabelled Counter, the empty label set is used as the key, and the
- // collection contains only one entry. Finally, for clarification, the same Counter metric name can
- // simultaneously be labeled and unlabeled.
- var countersByLabelSets: [LabelsKey: CounterWithHelp]
- }
-
- private struct GaugeGroup {
- var gaugesByLabelSets: [LabelsKey: GaugeWithHelp]
+ /// A collection of metrics, each with a unique label set, that share the same metric name.
+ /// Distinct help strings for the same metric name are permitted, but Prometheus retains only the
+ /// most recent one. For an unlabelled metric, the empty label set is used as the key, and the
+ /// collection contains only one entry. Finally, for clarification, the same metric name can
+ /// simultaneously be labeled and unlabeled.
+ private struct MetricGroup<Metric: Sendable & AnyObject>: Sendable {
+ var metricsByLabelSets: [LabelsKey: MetricWithHelp<Metric>]
}
private enum Metric {
- case counter(CounterGroup)
- case gauge(GaugeGroup)
+ case counter(MetricGroup<Counter>)
+ case gauge(MetricGroup<Gauge>) |
Co-authored-by: Konrad `ktoso` Malawski <ktoso@apple.com> Signed-off-by: Melissa Kilby <mkilby@apple.com>
/// Distinct help strings for the same metric name are permitted, but Prometheus retains only the | ||
/// most recent one. For an unlabelled metric, the empty label set is used as the key, and the | ||
/// collection contains only one entry. Finally, for clarification, the same metric name can | ||
/// simultaneously be labeled and unlabeled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: i'd move the comment onto the MetricGroup type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK I'll do it in the 2/2 PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you.
Previously, metrics were identified by their name. This change allows a shared metric name per metric type, with each unique set of labels defining a distinct time series.
Additionally, the internal data structure for a stored metric has been refactored, providing a more robust and programmatic representation.
CC @FranzBusch, @ktoso, @blindspotbounty
Let me know how you'd prefer to proceed. We have two main options:
Fixes #125 opened by @blindspotbounty