Swift Prometheus has been in development since 2018. The previous maintainer (@MrLotU) stepped down about a year ago. Since then @ktoso and @fabianfett have maintained the existing code base.
In order to improve performance in the Prometheus library, we want to replace the existing implementation with a new one for version 2.0. While we do this we also want to get the general API closer to what the prometheus project recommends in their Writing client libraries guide. This means that we will also start to enforce Prometheus rules. For example having two counter with the same name, but one with labels and one without, is illegal in the Prometheus format. Lastly we want to remove the SwiftNIO dependency that is not needed anymore.
I'm well aware that this is a very large PR that changes lots of moving things.
Changes
Remove SwiftNIO dependency. Vendor in NIOLock from NIOConcurrencyHelpers
Replace PrometheusClient with PrometheusCollectorRegistry
Remove Summary implementation
Replace Counter, Gauge and Histogram implementations
Add Sendability annotations
Require Swift 5.7
Enforces that label names remain constant for a metric name.
Performance difference
In simple testing scenarios:
Exporting values from 1k counters into the prometheus format: ~10x speedup
Exporting values from 1k gauges into the prometheus format: ~10x speedup
Exporting values from 1k histograms into the prometheus format: ~25x speedup
Motivation
Swift Prometheus has been in development since 2018. The previous maintainer (@MrLotU) stepped down about a year ago. Since then @ktoso and @fabianfett have maintained the existing code base.
In order to improve performance in the Prometheus library, we want to replace the existing implementation with a new one for version 2.0. While we do this we also want to get the general API closer to what the prometheus project recommends in their Writing client libraries guide. This means that we will also start to enforce Prometheus rules. For example having two counter with the same name, but one with labels and one without, is illegal in the Prometheus format. Lastly we want to remove the SwiftNIO dependency that is not needed anymore.
I'm well aware that this is a very large PR that changes lots of moving things.
Changes
NIOConcurrencyHelpers
PrometheusClient
withPrometheusCollectorRegistry
Summary
implementationCounter
,Gauge
andHistogram
implementationsPerformance difference
In simple testing scenarios:
Differences to Writing client libraries guide
Collector
protocol, that users could implement to create their own instruments.Collector
PrometheusCollectorRegistry
does not offer aregister
andunregister
method forCollector
sPrometheusCollectorRegistry
PrometheusCollectorRegistry
scollector
Do we want to offer this API? With the current patch we could add this API later.