Skip to content

Commit 5ee836d

Browse files
authored
Merge branch 'main' into benchmark
2 parents a92d909 + 24c3874 commit 5ee836d

File tree

10 files changed

+1435
-73
lines changed

10 files changed

+1435
-73
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ jobs:
1616
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
1717
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
1818
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
19+
20+
release-builds:
21+
name: Release builds
22+
uses: apple/swift-nio/.github/workflows/release_builds.yml@main

.github/workflows/pull_request.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ jobs:
2828
cxx-interop:
2929
name: Cxx interop
3030
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
31+
32+
release-builds:
33+
name: Release builds
34+
uses: apple/swift-nio/.github/workflows/release_builds.yml@main

Sources/Prometheus/Docs.docc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ text representation:
6060
```swift
6161
var buffer = [UInt8]()
6262
buffer.reserveCapacity(1024) // potentially smart moves to reduce the number of reallocations
63-
registry.emit(into: buffer)
63+
registry.emit(into: &buffer)
6464

6565
print(String(decoding: buffer, as: Unicode.UTF8.self))
6666
```

Sources/Prometheus/Histogram.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class Histogram<Value: Bucketable>: Sendable {
5656
self.box = .init(.init(buckets: buckets))
5757
}
5858

59+
@inlinable
5960
public func record(_ value: Value) {
6061
self.box.withLockedValue { state in
6162
for i in state.buckets.startIndex..<state.buckets.endIndex {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftPrometheus open source project
4+
//
5+
// Copyright (c) 2018-2025 SwiftPrometheus project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftPrometheus project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// A descriptor that defines the components of a fully qualified Prometheus metric name.
16+
///
17+
/// The final, underscore-separated metric name is generated by the ``name`` computed property. The ``helpText``
18+
/// is used to generate the corresponding `# HELP` line in the Prometheus exposition format.
19+
/// - Warning: This initializer will trigger a `preconditionFailure` if ``metricName`` is an empty string.
20+
public struct MetricNameDescriptor {
21+
/// An optional top-level namespace for the metric.
22+
public let namespace: String?
23+
24+
/// An optional subsystem to group related metrics.
25+
public let subsystem: String?
26+
27+
/// The required, descriptive base name of the metric.
28+
public let metricName: String
29+
30+
/// An optional suffix describing the metric's unit (e.g., `total`).
31+
public let unitName: String?
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+
public let helpText: String?
36+
37+
/// Creates a new ``MetricNameDescriptor`` that defines the components of a fully qualified Prometheus metric name.
38+
///
39+
/// - Parameter namespace: An optional top-level namespace for the metric.
40+
/// - Parameter subsystem: An optional subsystem to group related metrics within a namespace.
41+
/// - 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.
45+
public init(
46+
namespace: String? = nil,
47+
subsystem: String? = nil,
48+
metricName: String,
49+
unitName: String? = nil,
50+
helpText: String? = nil
51+
) {
52+
precondition(!metricName.isEmpty, "metricName must not be empty")
53+
self.namespace = namespace
54+
self.subsystem = subsystem
55+
self.metricName = metricName
56+
self.unitName = unitName
57+
self.helpText = helpText
58+
}
59+
60+
/// The fully qualified metric name, joining non-empty components with underscores (e.g. `namespace_subsytem_metricName_unitName`).
61+
public var name: String {
62+
[namespace, subsystem, metricName, unitName]
63+
.compactMap { $0?.isEmpty == false ? $0 : nil }
64+
.joined(separator: "_")
65+
}
66+
}

0 commit comments

Comments
 (0)