Skip to content

Commit 23d2bbd

Browse files
authored
Merge pull request #154 from incertum/deprecation/help-unit-required-future
refactor(API): deprecate non-descriptor metric creation methods
2 parents d09b797 + d53cfd7 commit 23d2bbd

File tree

11 files changed

+436
-288
lines changed

11 files changed

+436
-288
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
name: Unit tests
1515
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1616
with:
17-
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
18-
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
19-
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
20-
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
17+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
18+
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
19+
linux_6_2_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
20+
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
2121
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
2222

2323
release-builds:

.github/workflows/pull_request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
name: Unit tests
1717
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1818
with:
19-
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
20-
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
21-
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
22-
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
19+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
20+
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
21+
linux_6_2_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
22+
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
2323
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
2424

2525
benchmarks:

Sources/Prometheus/MetricDescriptor.swift

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,25 @@ public struct MetricNameDescriptor {
2727
/// The required, descriptive base name of the metric.
2828
public let metricName: String
2929

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

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.
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.
3534
public let helpText: String?
3635

3736
/// Creates a new ``MetricNameDescriptor`` that defines the components of a fully qualified Prometheus metric name.
3837
///
3938
/// - Parameter namespace: An optional top-level namespace for the metric.
4039
/// - Parameter subsystem: An optional subsystem to group related metrics within a namespace.
4140
/// - 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.
4543
public init(
4644
namespace: String? = nil,
4745
subsystem: String? = nil,
4846
metricName: String,
49-
unitName: String? = nil,
50-
helpText: String? = nil
47+
unitName: String,
48+
helpText: String
5149
) {
5250
precondition(!metricName.isEmpty, "metricName must not be empty")
5351
self.namespace = namespace
@@ -64,3 +62,36 @@ public struct MetricNameDescriptor {
6462
.joined(separator: "_")
6563
}
6664
}
65+
66+
// MARK: - Deprecated
67+
68+
extension MetricNameDescriptor {
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(
78+
*,
79+
deprecated,
80+
message: "This initializer is deprecated; 'unitName' and 'helpText' are now required parameters."
81+
)
82+
public init(
83+
namespace: String? = nil,
84+
subsystem: String? = nil,
85+
metricName: String,
86+
unitName: String? = nil,
87+
helpText: String? = nil
88+
) {
89+
self.init(
90+
namespace: namespace,
91+
subsystem: subsystem,
92+
metricName: metricName,
93+
unitName: unitName ?? "",
94+
helpText: helpText ?? ""
95+
)
96+
}
97+
}

0 commit comments

Comments
 (0)