Skip to content

Commit b88e366

Browse files
incertumktoso
andcommitted
update: reviewers suggestions re optional HELP line support
Signed-off-by: Melissa Kilby <[email protected]> Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
1 parent 1ea08dd commit b88e366

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

Sources/Prometheus/PrometheusCollectorRegistry.swift

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ public final class PrometheusCollectorRegistry: Sendable {
4848
}
4949

5050
private enum Metric {
51-
case counter(Counter, String)
52-
case counterWithLabels([String], [LabelsKey: Counter], String)
53-
case gauge(Gauge, String)
54-
case gaugeWithLabels([String], [LabelsKey: Gauge], String)
55-
case durationHistogram(DurationHistogram, String)
56-
case durationHistogramWithLabels([String], [LabelsKey: DurationHistogram], [Duration], String)
57-
case valueHistogram(ValueHistogram, String)
58-
case valueHistogramWithLabels([String], [LabelsKey: ValueHistogram], [Double], String)
51+
case counter(Counter, help: String)
52+
case counterWithLabels([String], [LabelsKey: Counter], help: String)
53+
case gauge(Gauge, help: String)
54+
case gaugeWithLabels([String], [LabelsKey: Gauge], help: String)
55+
case durationHistogram(DurationHistogram, help: String)
56+
case durationHistogramWithLabels([String], [LabelsKey: DurationHistogram], [Duration], help: String)
57+
case valueHistogram(ValueHistogram, help: String)
58+
case valueHistogramWithLabels([String], [LabelsKey: ValueHistogram], [Double], help: String)
5959
}
6060

6161
private let box = NIOLockedValueBox([String: Metric]())
@@ -79,7 +79,7 @@ public final class PrometheusCollectorRegistry: Sendable {
7979
return self.box.withLockedValue { store -> Counter in
8080
guard let value = store[name] else {
8181
let counter = Counter(name: name, labels: [])
82-
store[name] = .counter(counter, help)
82+
store[name] = .counter(counter, help: help)
8383
return counter
8484
}
8585
guard case .counter(let counter, _) = value else {
@@ -131,7 +131,7 @@ public final class PrometheusCollectorRegistry: Sendable {
131131
let labelNames = labels.allLabelNames
132132
let counter = Counter(name: name, labels: labels)
133133

134-
store[name] = .counterWithLabels(labelNames, [LabelsKey(labels): counter], help)
134+
store[name] = .counterWithLabels(labelNames, [LabelsKey(labels): counter], help: help)
135135
return counter
136136
}
137137
guard case .counterWithLabels(let labelNames, var dimensionLookup, let help) = value else {
@@ -161,7 +161,7 @@ public final class PrometheusCollectorRegistry: Sendable {
161161

162162
let counter = Counter(name: name, labels: labels)
163163
dimensionLookup[key] = counter
164-
store[name] = .counterWithLabels(labelNames, dimensionLookup, help)
164+
store[name] = .counterWithLabels(labelNames, dimensionLookup, help: help)
165165
return counter
166166
}
167167
}
@@ -194,7 +194,7 @@ public final class PrometheusCollectorRegistry: Sendable {
194194
return self.box.withLockedValue { store -> Gauge in
195195
guard let value = store[name] else {
196196
let gauge = Gauge(name: name, labels: [])
197-
store[name] = .gauge(gauge, help)
197+
store[name] = .gauge(gauge, help: help)
198198
return gauge
199199
}
200200
guard case .gauge(let gauge, _) = value else {
@@ -246,7 +246,7 @@ public final class PrometheusCollectorRegistry: Sendable {
246246
let labelNames = labels.allLabelNames
247247
let gauge = Gauge(name: name, labels: labels)
248248

249-
store[name] = .gaugeWithLabels(labelNames, [LabelsKey(labels): gauge], help)
249+
store[name] = .gaugeWithLabels(labelNames, [LabelsKey(labels): gauge], help: help)
250250
return gauge
251251
}
252252
guard case .gaugeWithLabels(let labelNames, var dimensionLookup, let help) = value else {
@@ -276,7 +276,7 @@ public final class PrometheusCollectorRegistry: Sendable {
276276

277277
let gauge = Gauge(name: name, labels: labels)
278278
dimensionLookup[key] = gauge
279-
store[name] = .gaugeWithLabels(labelNames, dimensionLookup, help)
279+
store[name] = .gaugeWithLabels(labelNames, dimensionLookup, help: help)
280280
return gauge
281281
}
282282
}
@@ -310,7 +310,7 @@ public final class PrometheusCollectorRegistry: Sendable {
310310
return self.box.withLockedValue { store -> DurationHistogram in
311311
guard let value = store[name] else {
312312
let gauge = DurationHistogram(name: name, labels: [], buckets: buckets)
313-
store[name] = .durationHistogram(gauge, help)
313+
store[name] = .durationHistogram(gauge, help: help)
314314
return gauge
315315
}
316316
guard case .durationHistogram(let histogram, _) = value else {
@@ -369,7 +369,12 @@ public final class PrometheusCollectorRegistry: Sendable {
369369
let labelNames = labels.allLabelNames
370370
let histogram = DurationHistogram(name: name, labels: labels, buckets: buckets)
371371

372-
store[name] = .durationHistogramWithLabels(labelNames, [LabelsKey(labels): histogram], buckets, help)
372+
store[name] = .durationHistogramWithLabels(
373+
labelNames,
374+
[LabelsKey(labels): histogram],
375+
buckets,
376+
help: help
377+
)
373378
return histogram
374379
}
375380
guard
@@ -413,7 +418,7 @@ public final class PrometheusCollectorRegistry: Sendable {
413418

414419
let histogram = DurationHistogram(name: name, labels: labels, buckets: storedBuckets)
415420
dimensionLookup[key] = histogram
416-
store[name] = .durationHistogramWithLabels(labelNames, dimensionLookup, storedBuckets, help)
421+
store[name] = .durationHistogramWithLabels(labelNames, dimensionLookup, storedBuckets, help: help)
417422
return histogram
418423
}
419424
}
@@ -457,7 +462,7 @@ public final class PrometheusCollectorRegistry: Sendable {
457462
return self.box.withLockedValue { store -> ValueHistogram in
458463
guard let value = store[name] else {
459464
let gauge = ValueHistogram(name: name, labels: [], buckets: buckets)
460-
store[name] = .valueHistogram(gauge, help)
465+
store[name] = .valueHistogram(gauge, help: help)
461466
return gauge
462467
}
463468
guard case .valueHistogram(let histogram, _) = value else {
@@ -511,7 +516,7 @@ public final class PrometheusCollectorRegistry: Sendable {
511516
let labelNames = labels.allLabelNames
512517
let histogram = ValueHistogram(name: name, labels: labels, buckets: buckets)
513518

514-
store[name] = .valueHistogramWithLabels(labelNames, [LabelsKey(labels): histogram], buckets, help)
519+
store[name] = .valueHistogramWithLabels(labelNames, [LabelsKey(labels): histogram], buckets, help: help)
515520
return histogram
516521
}
517522
guard
@@ -531,7 +536,7 @@ public final class PrometheusCollectorRegistry: Sendable {
531536

532537
let histogram = ValueHistogram(name: name, labels: labels, buckets: storedBuckets)
533538
dimensionLookup[key] = histogram
534-
store[name] = .valueHistogramWithLabels(labelNames, dimensionLookup, storedBuckets, help)
539+
store[name] = .valueHistogramWithLabels(labelNames, dimensionLookup, storedBuckets, help: help)
535540
return histogram
536541
}
537542
}
@@ -582,7 +587,7 @@ public final class PrometheusCollectorRegistry: Sendable {
582587
if dimensions.isEmpty {
583588
store.removeValue(forKey: counter.name)
584589
} else {
585-
store[counter.name] = .counterWithLabels(labelNames, dimensions, help)
590+
store[counter.name] = .counterWithLabels(labelNames, dimensions, help: help)
586591
}
587592
default:
588593
return
@@ -608,7 +613,7 @@ public final class PrometheusCollectorRegistry: Sendable {
608613
if dimensions.isEmpty {
609614
store.removeValue(forKey: gauge.name)
610615
} else {
611-
store[gauge.name] = .gaugeWithLabels(labelNames, dimensions, help)
616+
store[gauge.name] = .gaugeWithLabels(labelNames, dimensions, help: help)
612617
}
613618
default:
614619
return
@@ -634,7 +639,7 @@ public final class PrometheusCollectorRegistry: Sendable {
634639
if dimensions.isEmpty {
635640
store.removeValue(forKey: histogram.name)
636641
} else {
637-
store[histogram.name] = .durationHistogramWithLabels(labelNames, dimensions, buckets, help)
642+
store[histogram.name] = .durationHistogramWithLabels(labelNames, dimensions, buckets, help: help)
638643
}
639644
default:
640645
return
@@ -660,7 +665,7 @@ public final class PrometheusCollectorRegistry: Sendable {
660665
if dimensions.isEmpty {
661666
store.removeValue(forKey: histogram.name)
662667
} else {
663-
store[histogram.name] = .valueHistogramWithLabels(labelNames, dimensions, buckets, help)
668+
store[histogram.name] = .valueHistogramWithLabels(labelNames, dimensions, buckets, help: help)
664669
}
665670
default:
666671
return

0 commit comments

Comments
 (0)