Skip to content

Commit 34598bf

Browse files
authored
Rename destroyMetric to unregisterMetric (#102)
1 parent bc4d19a commit 34598bf

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

Sources/Prometheus/PrometheusCollectorRegistry.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,13 @@ public final class PrometheusCollectorRegistry: Sendable {
386386
}
387387

388388
// MARK: Destroying Metrics
389-
390-
public func destroyCounter(_ counter: Counter) {
389+
390+
/// Unregisters a ``Counter`` from the ``PrometheusCollectorRegistry``. This means that the provided ``Counter``
391+
/// will not be included in future ``emit(into:)`` calls.
392+
///
393+
/// - Note: If the provided ``Counter`` is unknown to the registry this function call will be ignored
394+
/// - Parameter counter: The ``Counter`` that shall be removed from the registry
395+
public func unregisterCounter(_ counter: Counter) {
391396
self.box.withLockedValue { store in
392397
switch store[counter.name] {
393398
case .counter(let storedCounter):
@@ -404,7 +409,12 @@ public final class PrometheusCollectorRegistry: Sendable {
404409
}
405410
}
406411

407-
public func destroyGauge(_ gauge: Gauge) {
412+
/// Unregisters a ``Gauge`` from the ``PrometheusCollectorRegistry``. This means that the provided ``Gauge``
413+
/// will not be included in future ``emit(into:)`` calls.
414+
///
415+
/// - Note: If the provided ``Gauge`` is unknown to the registry this function call will be ignored
416+
/// - Parameter gauge: The ``Gauge`` that shall be removed from the registry
417+
public func unregisterGauge(_ gauge: Gauge) {
408418
self.box.withLockedValue { store in
409419
switch store[gauge.name] {
410420
case .gauge(let storedGauge):
@@ -421,7 +431,12 @@ public final class PrometheusCollectorRegistry: Sendable {
421431
}
422432
}
423433

424-
public func destroyTimeHistogram(_ histogram: DurationHistogram) {
434+
/// Unregisters a ``DurationHistogram`` from the ``PrometheusCollectorRegistry``. This means that this ``DurationHistogram``
435+
/// will not be included in future ``emit(into:)`` calls.
436+
///
437+
/// - Note: If the provided ``DurationHistogram`` is unknown to the registry this function call will be ignored
438+
/// - Parameter histogram: The ``DurationHistogram`` that shall be removed from the registry
439+
public func unregisterTimeHistogram(_ histogram: DurationHistogram) {
425440
self.box.withLockedValue { store in
426441
switch store[histogram.name] {
427442
case .durationHistogram(let storedHistogram):
@@ -438,7 +453,12 @@ public final class PrometheusCollectorRegistry: Sendable {
438453
}
439454
}
440455

441-
public func destroyValueHistogram(_ histogram: ValueHistogram) {
456+
/// Unregisters a ``ValueHistogram`` from the ``PrometheusCollectorRegistry``. This means that this ``ValueHistogram``
457+
/// will not be included in future ``emit(into:)`` calls.
458+
///
459+
/// - Note: If the provided ``ValueHistogram`` is unknown to the registry this function call will be ignored
460+
/// - Parameter histogram: The ``ValueHistogram`` that shall be removed from the registry
461+
public func unregisterValueHistogram(_ histogram: ValueHistogram) {
442462
self.box.withLockedValue { store in
443463
switch store[histogram.name] {
444464
case .valueHistogram(let storedHistogram):

Sources/Prometheus/PrometheusMetricsFactory.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,22 @@ extension PrometheusMetricsFactory: CoreMetrics.MetricsFactory {
119119
guard let counter = handler as? Counter else {
120120
return
121121
}
122-
self.registry.destroyCounter(counter)
122+
self.registry.unregisterCounter(counter)
123123
}
124124

125125
public func destroyFloatingPointCounter(_ handler: FloatingPointCounterHandler) {
126126
guard let counter = handler as? Counter else {
127127
return
128128
}
129-
self.registry.destroyCounter(counter)
129+
self.registry.unregisterCounter(counter)
130130
}
131131

132132
public func destroyRecorder(_ handler: CoreMetrics.RecorderHandler) {
133133
switch handler {
134134
case let gauge as Gauge:
135-
self.registry.destroyGauge(gauge)
135+
self.registry.unregisterGauge(gauge)
136136
case let histogram as Histogram<Double>:
137-
self.registry.destroyValueHistogram(histogram)
137+
self.registry.unregisterValueHistogram(histogram)
138138
default:
139139
break
140140
}
@@ -144,13 +144,13 @@ extension PrometheusMetricsFactory: CoreMetrics.MetricsFactory {
144144
guard let gauge = handler as? Gauge else {
145145
return
146146
}
147-
self.registry.destroyGauge(gauge)
147+
self.registry.unregisterGauge(gauge)
148148
}
149149

150150
public func destroyTimer(_ handler: CoreMetrics.TimerHandler) {
151151
guard let histogram = handler as? Histogram<Duration> else {
152152
return
153153
}
154-
self.registry.destroyTimeHistogram(histogram)
154+
self.registry.unregisterTimeHistogram(histogram)
155155
}
156156
}

0 commit comments

Comments
 (0)