Skip to content

new: MetricNameDescriptor overload option #126

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

Merged
merged 2 commits into from
Jul 30, 2025

Conversation

incertum
Copy link
Contributor

@incertum incertum commented Jul 25, 2025

This change adds a new way to create metrics using an FQMetricDescriptor, which makes it easier to build metric names programmatically. The changes are fully backward compatible.

Also, while the descriptor has an optional helpText property, it doesn't generate the corresponding HELP line in the output yet. I believe it would be best to handle this in a separate, follow-up PR, which I'm happy to create.

CC @fabianfett, @ktoso

@incertum incertum force-pushed the new/FQMetricDescriptor branch from 3cab56b to 0ab5efd Compare July 25, 2025 23:10
@incertum
Copy link
Contributor Author

Fixes #127

FYI: Proposing to update docs separately at the end in new PRs.

@incertum incertum changed the title new: FQMetricDescriptor override option wip: new: FQMetricDescriptor overload option Jul 25, 2025
self.helpText = helpText
}

public var FQMetricName: String {
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things:

  • This is already nested in a type called FQ so we can drop the prefix`
  • We usually don't capability variables or method names in Swift
Suggested change
public var FQMetricName: String {
public var metricName: String {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

name seemed simplest given metricName is already taken.

@incertum incertum force-pushed the new/FQMetricDescriptor branch from 0ab5efd to acef547 Compare July 29, 2025 00:15
/// - Parameter descriptor: An ``FQMetricDescriptor`` that provides the fully qualified name for the metric.
/// - Returns: A ``Counter`` that is registered with this ``PrometheusCollectorRegistry``
public func makeCounter(descriptor: FQMetricDescriptor) -> Counter {
return self.makeCounter(name: descriptor.name)
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 a follow up PR will adjust this to enable printing the HELP line if applicable for all cases.

@incertum incertum changed the title wip: new: FQMetricDescriptor overload option new: FQMetricDescriptor overload option Jul 29, 2025
@incertum incertum force-pushed the new/FQMetricDescriptor branch from acef547 to 5580757 Compare July 29, 2025 00:30
/// - Parameter unitName: An optional suffix describing the metric's unit (e.g., `_seconds`, `_total`).
/// - Parameter helpText: Optional descriptive text for the metric.
/// - Returns: A new ``FQMetricDescriptor`` instance with the specified components.
public struct FQMetricDescriptor {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like FQ is not a term of art in the prometheus space. Can we rather name this FullyQualifiedMetricNameDescriptor. We try to use as little abbreviations as possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hah, seems I missed to send my comment huh -- yeah, agreed we should not be doing FQ/FQN. We could also just skip the FullyQualified part and call it some thing else.

It doesn't seem like we have MetricDescriptor either, we could just call it that even

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about MetricNameDescriptor?

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good 👍

@incertum incertum force-pushed the new/FQMetricDescriptor branch from 5580757 to 322da1d Compare July 29, 2025 14:27
Adds a new way to create metrics using a MetricNameDescriptor, which makes it easier to build metric names programmatically. The changes are fully backward compatible.

Signed-off-by: Melissa Kilby <[email protected]>
@incertum incertum force-pushed the new/FQMetricDescriptor branch from 322da1d to 1532037 Compare July 29, 2025 19:47
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 to me, thank you!

@ktoso ktoso added the 🆕 semver/minor Adds new public API. label Jul 30, 2025
@ktoso ktoso merged commit b546409 into swift-server:main Jul 30, 2025
28 checks passed
@incertum incertum changed the title new: FQMetricDescriptor overload option new: MetricNameDescriptor overload option Jul 31, 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.

3 participants