You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
which seems quite the downgrade in terms of usability.
It would be cool if the library provided some helpers to collect data.
I created this
extensionMetricsSystem{staticvarprometheus:PrometheusMetricsFactory{get throws{
guard let factory =Self.factory as?PrometheusMetricsFactoryelse{throwAbort(.internalServerError, reason:"Metrics factory is not Prometheus")}return factory
}}}extensionPrometheusMetricsFactory{func emit()->String{varbuffer=[UInt8]()self.registry.emit(into:&buffer)returnString(bytes: buffer, encoding:.utf8)??""}}
to account for it and the result is quite a bit simpler
tryMetricsSystem.prometheus.emit()
so I was wondering if a PR would be accepted with this or a similar addition, maybe a [UInt8] version too if needed, especially as the use case is often likely to be an endpoint which we just want to return the data too and we probably won't need a buffer. I'm happy to be proven wrong in case there's a simpler way already or a reason for it to just be like this!
The text was updated successfully, but these errors were encountered:
I have been bitten by this as well, but if you look into the implementation of registry.emit, it in the end the will call emit on all the the metrics, and they will all just append to a buffer. So when the buffer is small, it will cause frequent reallocations. If you do this every 15 seconds, and emitting a lot of metrics, you are essentially causing lot of unnecessary reallocations which may or may not affect your server app.
So I'd assume given the knowledge of how much metrics you expect to emit, you can pre-allocate the buffer once and use that on every emit call.
I'm not entirely sure if my understanding is correct, but if it is, I'd love to open a PR against the README and API docs to clarify this... as it looks like a FAQ
I've switched from v1 to v2 and this was the switch I've had to make to collect metrics
which seems quite the downgrade in terms of usability.
It would be cool if the library provided some helpers to collect data.
I created this
to account for it and the result is quite a bit simpler
so I was wondering if a PR would be accepted with this or a similar addition, maybe a
[UInt8]
version too if needed, especially as the use case is often likely to be an endpoint which we just want to return the data too and we probably won't need a buffer. I'm happy to be proven wrong in case there's a simpler way already or a reason for it to just be like this!The text was updated successfully, but these errors were encountered: