Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions Sources/Prometheus/MetricDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,25 @@ public struct MetricNameDescriptor {
/// The required, descriptive base name of the metric.
public let metricName: String

/// An optional suffix describing the metric's unit (e.g., `total`).
public let unitName: String?
/// The required suffix describing the metric's unit (e.g., `total`).
public let unitName: String

/// Optional help text for the metric. If a non-empty string is provided, it will be emitted as a `# HELP` line in the exposition format.
/// If the parameter is omitted or an empty string is passed, the `# HELP` line will not be generated for this metric.
public let helpText: String?
/// The required help text for the metric. If a non-empty string is provided, it will be emitted as a `# HELP` line in the exposition format.
public let helpText: String

/// Creates a new ``MetricNameDescriptor`` that defines the components of a fully qualified Prometheus metric name.
///
/// - Parameter namespace: An optional top-level namespace for the metric.
/// - Parameter subsystem: An optional subsystem to group related metrics within a namespace.
/// - Parameter metricName: The required, descriptive base name of the metric.
/// - Parameter unitName: An optional suffix describing the metric's unit (e.g., `total`).
/// - Parameter helpText: Optional help text for the metric. If a non-empty string is provided, it will be emitted as a `# HELP` line in the exposition format.
/// If the parameter is omitted or an empty string is passed, the `# HELP` line will not be generated for this metric.
/// - Parameter unitName: The required suffix describing the metric's unit (e.g., `total`).
/// - Parameter helpText: The required help text for the metric. If a non-empty string is provided, it will be emitted as a `# HELP` line in the exposition format.
public init(
namespace: String? = nil,
subsystem: String? = nil,
metricName: String,
unitName: String? = nil,
helpText: String? = nil
unitName: String,
helpText: String
) {
precondition(!metricName.isEmpty, "metricName must not be empty")
self.namespace = namespace
Expand All @@ -64,3 +62,36 @@ public struct MetricNameDescriptor {
.joined(separator: "_")
}
}

// MARK: - Deprecated

extension MetricNameDescriptor {
/// Creates a new ``MetricNameDescriptor`` that defines the components of a fully qualified Prometheus metric name.
///
/// - Parameter namespace: An optional top-level namespace for the metric.
/// - Parameter subsystem: An optional subsystem to group related metrics within a namespace.
/// - Parameter metricName: The required, descriptive base name of the metric.
/// - Parameter unitName: An optional suffix describing the metric's unit (e.g., `total`).
/// - Parameter helpText: Optional help text for the metric. If a non-empty string is provided, it will be emitted as a `# HELP` line in the exposition format.
/// If the parameter is omitted or an empty string is passed, the `# HELP` line will not be generated for this metric.
@available(
*,
deprecated,
message: "This initializer is deprecated; 'unitName' and 'helpText' are now required parameters."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd keep it in a single line but not a deal breaker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the auto-formatter caused these line breaks.

public init(
namespace: String? = nil,
subsystem: String? = nil,
metricName: String,
unitName: String? = nil,
helpText: String? = nil
) {
self.init(
namespace: namespace,
subsystem: subsystem,
metricName: metricName,
unitName: unitName ?? "",
helpText: helpText ?? ""
)
}
}
Loading
Loading