defaultRecorderBuckets not respected with swift-metrics
Sherlouk opened this issue · comments
Steps to reproduce
Setup Prometheus and Swift Metrics:
let client = PrometheusClient()
// Setup Factory
let factory = PrometheusMetricsFactory(client: client, configuration: .init(defaultRecorderBuckets: [
0.05, 0.1, 0.5, 1, 5, 10, 25, 50, 75, 100
]))
MetricsSystem.bootstrap(factory)
// Collect Metrics
app.get("metrics") { _ async throws -> String in
return await client.collect()
}
Create a Recorder and record a value:
Recorder(label: "x").record(100)
View output and see that bucket sizes are the default bucket sizes rather than the ones I've provided in the setup.
Expected behavior
Bucket sizes should be those which I provided to the factory
Actual behavior
Bucket sizes are instead the defaulted bucket sizes hard coded into the library
Environment
- OS version: 12.4
- Swift version: 5.6
- Serverside Swift Framework: Vapor
- Framework version: 4
Solution
The root cause appears to be that the makeHistogram
function calls createHistogram
which has a variable called buckets: Buckets = .defaultBuckets
. This defaults to defaultBuckets which is incorrect, it should instead be set to configuration.defaultRecorderBuckets
(which itself defaults to defaultBuckets
but can be overridden by the user, me, as above).