You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deprecates all metric creation methods that accept loose string parameters for name and help text.
This standardizes metric creation on the MetricNameDescriptor type, which requires a metricName, unitName and helpText for all metrics. This improves compliance with official Prometheus client library guidelines ("A MetricFamily MUST have a name, HELP, TYPE, and UNIT metadata.").
The deprecated methods will be removed in a future major version (see #145).
Signed-off-by: Melissa Kilby <[email protected]>
Copy file name to clipboardExpand all lines: Sources/Prometheus/MetricDescriptor.swift
+37-10Lines changed: 37 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -27,27 +27,25 @@ public struct MetricNameDescriptor {
27
27
/// The required, descriptive base name of the metric.
28
28
publicletmetricName:String
29
29
30
-
/// An optional suffix describing the metric's unit (e.g., `total`).
31
-
publicletunitName:String?
30
+
/// The required suffix describing the metric's unit (e.g., `total`).
31
+
publicletunitName:String
32
32
33
-
/// 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.
34
-
/// If the parameter is omitted or an empty string is passed, the `# HELP` line will not be generated for this metric.
35
-
publiclethelpText:String?
33
+
/// 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.
34
+
publiclethelpText:String
36
35
37
36
/// Creates a new ``MetricNameDescriptor`` that defines the components of a fully qualified Prometheus metric name.
38
37
///
39
38
/// - Parameter namespace: An optional top-level namespace for the metric.
40
39
/// - Parameter subsystem: An optional subsystem to group related metrics within a namespace.
41
40
/// - Parameter metricName: The required, descriptive base name of the metric.
42
-
/// - Parameter unitName: An optional suffix describing the metric's unit (e.g., `total`).
43
-
/// - 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.
44
-
/// If the parameter is omitted or an empty string is passed, the `# HELP` line will not be generated for this metric.
41
+
/// - Parameter unitName: The required suffix describing the metric's unit (e.g., `total`).
42
+
/// - 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.
45
43
publicinit(
46
44
namespace:String?=nil,
47
45
subsystem:String?=nil,
48
46
metricName:String,
49
-
unitName:String?=nil,
50
-
helpText:String?=nil
47
+
unitName:String,
48
+
helpText:String
51
49
){
52
50
precondition(!metricName.isEmpty,"metricName must not be empty")
53
51
self.namespace = namespace
@@ -64,3 +62,32 @@ public struct MetricNameDescriptor {
64
62
.joined(separator:"_")
65
63
}
66
64
}
65
+
66
+
// MARK: - Deprecated
67
+
68
+
extensionMetricNameDescriptor{
69
+
/// Creates a new ``MetricNameDescriptor`` that defines the components of a fully qualified Prometheus metric name.
70
+
///
71
+
/// - Parameter namespace: An optional top-level namespace for the metric.
72
+
/// - Parameter subsystem: An optional subsystem to group related metrics within a namespace.
73
+
/// - Parameter metricName: The required, descriptive base name of the metric.
74
+
/// - Parameter unitName: An optional suffix describing the metric's unit (e.g., `total`).
75
+
/// - 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.
76
+
/// If the parameter is omitted or an empty string is passed, the `# HELP` line will not be generated for this metric.
77
+
@available(*, deprecated, message:"This initializer is deprecated; 'unitName' and 'helpText' are now required parameters.")
0 commit comments