Skip to content

wip: refactor: uniquely identify metric time series by name and label sets #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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

incertum
Copy link
Contributor

@incertum incertum commented Aug 5, 2025

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:

  1. I can split this work into a few smaller, more focused PRs.
  2. We can finalize the overall approach in this PR, and I can push the remaining changes here next week.

Fixes #125 opened by @blindspotbounty

}

private enum MetricType {
case counterMetrics(String, MetricContainer<Counter>)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general not sure yet about naming, ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I would love to benefit from your Swift expertise re below ... it's probably the Type? It should be typed out for each metric type?

 note: consider making enum 'MetricType' conform to the 'Sendable' protocol
    private enum MetricType {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah Type isn't right, this isn't a type, it's a container. Something feels off with the names here, this is a container but why do we need MetricContainer if it's a single field?

By what is this supposed to be keyed, MetricsByLabel or some MetricGroup maybe?


If you're seeing a note there's an associated warning (or error) that is the actual problem somewhere. Sendable is about concurrency safety, and yeah this may want to be Sendable if able to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A revised version of the names is ready for review. Let me know your thoughts? I’ve also addressed the Sendable error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once the names are agreed upon, I propose implementing the changes for Gauge in this PR and then creating a separate PR for the rest.

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.

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?

}

private enum MetricType {
case counterMetrics(String, MetricContainer<Counter>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah Type isn't right, this isn't a type, it's a container. Something feels off with the names here, this is a container but why do we need MetricContainer if it's a single field?

By what is this supposed to be keyed, MetricsByLabel or some MetricGroup maybe?


If you're seeing a note there's an associated warning (or error) that is the actual problem somewhere. Sendable is about concurrency safety, and yeah this may want to be Sendable if able to?

@incertum incertum force-pushed the refactor/metrics-storage-enable-shared-names-same-type branch 2 times, most recently from a3bb1e5 to fd0e483 Compare August 18, 2025 23:39
private enum Metric {
case counter(Counter, help: String)
case counterWithLabels([String], [LabelsKey: Counter], help: String)
case counter(name: String, CounterGroup)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the name duplicated here now in both the box dictionary and then this enum case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed that way before for labeled cases, so I thought it was a design preference.

Based on your comment, I understand that you approve of removing the small duplicative part. I’ve just re-pushed it.

Could you let me know if the design is now ok? If so, I’ll proceed to implement the changes for Gauge in this PR as well.

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 <[email protected]>
@incertum incertum force-pushed the refactor/metrics-storage-enable-shared-names-same-type branch from fd0e483 to c697ee8 Compare August 19, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
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)
3 participants