Skip to content

Commit e61159e

Browse files
authored
Fix PrometheusExporter reporting duplicate samples (#863)
1 parent 16726a8 commit e61159e

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Sources/Exporters/Prometheus/PrometheusExporter.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ public class PrometheusExporter: MetricExporter {
3535

3636
public func export(metrics: [MetricData]) -> ExportResult {
3737
metricsLock.withLockVoid {
38-
self.metrics.append(contentsOf: metrics)
38+
self.metrics = metrics
3939
}
4040
return .success
4141
}
4242

43-
public func getAndClearMetrics() -> [MetricData] {
43+
public func getMetrics() -> [MetricData] {
4444
defer {
45-
metrics = [MetricData]()
4645
metricsLock.unlock()
4746
}
4847
metricsLock.lock()

Sources/Exporters/Prometheus/PrometheusExporterExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum PrometheusExporterExtensions {
2323

2424
public static func writeMetricsCollection(exporter: PrometheusExporter) -> String {
2525
var output = ""
26-
let metrics = exporter.getAndClearMetrics()
26+
let metrics = exporter.getMetrics()
2727
let now = String(Int64((Date().timeIntervalSince1970 * 1000.0).rounded()))
2828

2929
metrics.forEach { metric in

0 commit comments

Comments
 (0)