I am a bit confused about how to use the Histogram style of metrics successfully with swift-metrics.
When interacting with the Timer interface from swift-metrics you can specify the unit of your time measurements. But when configuring PrometheusMetricsFactory I cannot specify the unit of my histogram buckets. If I use the default values ([0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]), most measurements will end up in the +Inf bucket, because internally the MetricsHistogramTimer always records nanoseconds. I think the only way to make it work right know would be to change the buckets to be in ns, [0.005e9, 0.01e9, 0.025e9, 0.05e9, 0.1e9, 0.25e9, 0.5e9, 1e9, 2.5e9, 5e9, 10e9] which seems quite unintuitive.
Probably it would make sense to default to seconds for the unit and change the MetricsHistogramTimer implementation to convert the nanoseconds to seconds. Since this is a global setting it will apply to ALL "timer" metrics emitted by any library in the process. So maybe this should be part of the TimerImplementation configuration.
Example
let prometheusClient = PrometheusClient()
MetricsSystem.bootstrap(PrometheusMetricsFactory(client: prometheusClient,
configuration: .init( timerImplementation: .histogram())))
let timer = Timer(label: "my_timer")
timer.record(.seconds(5))
prometheusClient.collect { (metrics : String) -> () in
print(metrics)
}
I am a bit confused about how to use the Histogram style of metrics successfully with
swift-metrics
.When interacting with the
Timer
interface fromswift-metrics
you can specify the unit of your time measurements. But when configuringPrometheusMetricsFactory
I cannot specify the unit of my histogram buckets. If I use the default values ([0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
), most measurements will end up in the+Inf
bucket, because internally theMetricsHistogramTimer
always records nanoseconds. I think the only way to make it work right know would be to change the buckets to be in ns,[0.005e9, 0.01e9, 0.025e9, 0.05e9, 0.1e9, 0.25e9, 0.5e9, 1e9, 2.5e9, 5e9, 10e9]
which seems quite unintuitive.Probably it would make sense to default to seconds for the unit and change the
MetricsHistogramTimer
implementation to convert the nanoseconds to seconds. Since this is a global setting it will apply to ALL "timer" metrics emitted by any library in the process. So maybe this should be part of theTimerImplementation
configuration.Example