diff --git a/Sources/Prometheus/MetricTypes/Counter.swift b/Sources/Prometheus/MetricTypes/Counter.swift index f562a58..85dae80 100644 --- a/Sources/Prometheus/MetricTypes/Counter.swift +++ b/Sources/Prometheus/MetricTypes/Counter.swift @@ -3,10 +3,7 @@ import NIOConcurrencyHelpers /// Prometheus Counter metric /// /// See: https://prometheus.io/docs/concepts/metric_types/#counter -public class PromCounter: PromMetric, PrometheusHandled { - /// Prometheus instance that created this Counter - internal weak var prometheus: PrometheusClient? - +public class PromCounter: PromMetric { /// Name of the Counter, required public let name: String /// Help text of the Counter, optional @@ -34,12 +31,11 @@ public class PromCounter: PromMetric, PrometheusHandled { /// - help: Help text of the Counter /// - initialValue: Initial value to set the counter to /// - p: Prometheus instance that created this counter - internal init(_ name: String, _ help: String? = nil, _ initialValue: NumType = 0, _ p: PrometheusClient) { + internal init(_ name: String, _ help: String? = nil, _ initialValue: NumType = 0) { self.name = name self.help = help self.initialValue = initialValue self.value = initialValue - self.prometheus = p self.lock = Lock() } diff --git a/Sources/Prometheus/MetricTypes/Gauge.swift b/Sources/Prometheus/MetricTypes/Gauge.swift index 38fe198..a7ddbbe 100644 --- a/Sources/Prometheus/MetricTypes/Gauge.swift +++ b/Sources/Prometheus/MetricTypes/Gauge.swift @@ -5,10 +5,7 @@ import NIOConcurrencyHelpers /// Prometheus Gauge metric /// /// See https://prometheus.io/docs/concepts/metric_types/#gauge -public class PromGauge: PromMetric, PrometheusHandled { - /// Prometheus instance that created this Gauge - internal weak var prometheus: PrometheusClient? - +public class PromGauge: PromMetric { /// Name of the Gauge, required public let name: String /// Help text of the Gauge, optional @@ -37,12 +34,11 @@ public class PromGauge: PromMetric, PrometheusHand /// - initialValue: Initial value to set the Gauge to /// - p: Prometheus instance that created this Gauge /// - internal init(_ name: String, _ help: String? = nil, _ initialValue: NumType = 0, _ p: PrometheusClient) { + internal init(_ name: String, _ help: String? = nil, _ initialValue: NumType = 0) { self.name = name self.help = help self.initialValue = initialValue self.value = initialValue - self.prometheus = p self.lock = Lock() } diff --git a/Sources/Prometheus/MetricTypes/Histogram.swift b/Sources/Prometheus/MetricTypes/Histogram.swift index 2c1987b..3765ab8 100644 --- a/Sources/Prometheus/MetricTypes/Histogram.swift +++ b/Sources/Prometheus/MetricTypes/Histogram.swift @@ -66,10 +66,7 @@ public struct Buckets: ExpressibleByArrayLiteral { /// Prometheus Histogram metric /// /// See https://prometheus.io/docs/concepts/metric_types/#Histogram -public class PromHistogram: PromMetric, PrometheusHandled { - /// Prometheus instance that created this Histogram - internal weak var prometheus: PrometheusClient? - +public class PromHistogram: PromMetric { /// Name of this Histogram, required public let name: String /// Help text of this Histogram, optional @@ -100,20 +97,18 @@ public class PromHistogram: PromMetric, Prometheus /// - help: Help text of the Histogram /// - buckets: Buckets to use for the Histogram /// - p: Prometheus instance creating this Histogram - internal init(_ name: String, _ help: String? = nil, _ buckets: Buckets = .defaultBuckets, _ p: PrometheusClient) { + internal init(_ name: String, _ help: String? = nil, _ buckets: Buckets = .defaultBuckets) { self.name = name self.help = help - self.prometheus = p - - self.sum = .init("\(self.name)_sum", nil, 0, p) + self.sum = .init("\(self.name)_sum", nil, 0) self.upperBounds = buckets.buckets self.lock = Lock() buckets.buckets.forEach { _ in - self.buckets.append(.init("\(name)_bucket", nil, 0, p)) + self.buckets.append(.init("\(name)_bucket", nil, 0)) } } @@ -239,8 +234,7 @@ public class PromHistogram: PromMetric, Prometheus """) return histogram } - guard let prometheus = prometheus else { fatalError("Lingering Histogram") } - let newHistogram = PromHistogram(self.name, self.help, Buckets(self.upperBounds), prometheus) + let newHistogram = PromHistogram(self.name, self.help, Buckets(self.upperBounds)) self.subHistograms[labels] = newHistogram return newHistogram } diff --git a/Sources/Prometheus/MetricTypes/PromMetric.swift b/Sources/Prometheus/MetricTypes/PromMetric.swift index b2a444d..72f2ac8 100644 --- a/Sources/Prometheus/MetricTypes/PromMetric.swift +++ b/Sources/Prometheus/MetricTypes/PromMetric.swift @@ -44,9 +44,3 @@ extension PromMetric { buffer.writeString(collect()) } } - -/// Adding a prometheus instance to all metrics -internal protocol PrometheusHandled { - /// Prometheus client handling this metric - var prometheus: PrometheusClient? { get } -} diff --git a/Sources/Prometheus/MetricTypes/Summary.swift b/Sources/Prometheus/MetricTypes/Summary.swift index 1fb32d1..f527557 100644 --- a/Sources/Prometheus/MetricTypes/Summary.swift +++ b/Sources/Prometheus/MetricTypes/Summary.swift @@ -6,10 +6,7 @@ import Dispatch /// Prometheus Summary metric /// /// See https://prometheus.io/docs/concepts/metric_types/#summary -public class PromSummary: PromMetric, PrometheusHandled { - /// Prometheus instance that created this Summary - internal weak var prometheus: PrometheusClient? - +public class PromSummary: PromMetric { /// Name of this Summary, required public let name: String /// Help text of this Summary, optional @@ -49,17 +46,15 @@ public class PromSummary: PromMetric, PrometheusHa /// - capacity: Number of values to keep for calculating quantiles /// - quantiles: Quantiles to use for the Summary /// - p: Prometheus instance creating this Summary - internal init(_ name: String, _ help: String? = nil, _ capacity: Int = Prometheus.defaultSummaryCapacity, _ quantiles: [Double] = Prometheus.defaultQuantiles, _ p: PrometheusClient) { + internal init(_ name: String, _ help: String? = nil, _ capacity: Int = Prometheus.defaultSummaryCapacity, _ quantiles: [Double] = Prometheus.defaultQuantiles) { self.name = name self.help = help - self.prometheus = p - self.displayUnit = nil - self.sum = .init("\(self.name)_sum", nil, 0, p) + self.sum = .init("\(self.name)_sum", nil, 0) - self.count = .init("\(self.name)_count", nil, 0, p) + self.count = .init("\(self.name)_count", nil, 0) self.values = CircularBuffer(initialCapacity: capacity) @@ -197,10 +192,7 @@ public class PromSummary: PromMetric, PrometheusHa """) return summary } - guard let prometheus = prometheus else { - fatalError("Lingering Summary") - } - let newSummary = PromSummary(self.name, self.help, self.capacity, self.quantiles, prometheus) + let newSummary = PromSummary(self.name, self.help, self.capacity, self.quantiles) self.subSummaries[labels] = newSummary return newSummary } diff --git a/Sources/Prometheus/Prometheus.swift b/Sources/Prometheus/Prometheus.swift index 03d1c65..0975d31 100644 --- a/Sources/Prometheus/Prometheus.swift +++ b/Sources/Prometheus/Prometheus.swift @@ -138,7 +138,7 @@ public class PrometheusClient { return cachedCounter } - let counter = PromCounter(name, helpText, initialValue, self) + let counter = PromCounter(name, helpText, initialValue) let oldInstrument = self.metrics.updateValue(counter, forKey: name) precondition(oldInstrument == nil, "Label \(oldInstrument!.name) is already associated with a \(oldInstrument!._type).") return counter @@ -167,7 +167,7 @@ public class PrometheusClient { return cachedGauge } - let gauge = PromGauge(name, helpText, initialValue, self) + let gauge = PromGauge(name, helpText, initialValue) let oldInstrument = self.metrics.updateValue(gauge, forKey: name) precondition(oldInstrument == nil, "Label \(oldInstrument!.name) is already associated with a \(oldInstrument!._type).") return gauge @@ -196,7 +196,7 @@ public class PrometheusClient { return cachedHistogram } - let histogram = PromHistogram(name, helpText, buckets, self) + let histogram = PromHistogram(name, helpText, buckets) let oldInstrument = self.metrics.updateValue(histogram, forKey: name) precondition(oldInstrument == nil, "Label \(oldInstrument!.name) is already associated with a \(oldInstrument!._type).") return histogram @@ -226,7 +226,7 @@ public class PrometheusClient { if let cachedSummary: PromSummary = self._getMetricInstance(with: name, andType: .summary) { return cachedSummary } - let summary = PromSummary(name, helpText, capacity, quantiles, self) + let summary = PromSummary(name, helpText, capacity, quantiles) let oldInstrument = self.metrics.updateValue(summary, forKey: name) precondition(oldInstrument == nil, "Label \(oldInstrument!.name) is already associated with a \(oldInstrument!._type).") return summary