-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for setting list of dimensions on record
, rather than on Metric creation
#85
Comments
The idea behind the swift-metrics metric types is that they should be "throw away" types. So create one when you need it, increment it, and then drop it again. In your example this would mean creating the timer inside of the func handle(request: Request) {
var statusCodeClass: String = "2XX"
let startTime = DispatchTime.now()
defer {
Timer(label: "request_duration", dimensions: [("statusCode": statusCodeClass, "uri": request.uri)])
.recordNanoseconds(since: startTime)
}
do {
try handleRequest(request)
} catch let error as ServerError {
// recovery routine
statusCodeClass = "5XX"
} catch let error as UserError {
statusCodeClass = "4XX"
}
} I hope this helps 😄 |
Thanks for the feedback @MrLotU!
|
cc @ktoso, do you think this API would make sense in context of you swift-cluster-membership instrumentation? |
Yes, sorry I didn't chime in -- your points capture it exactly @avolokhov 👍 Metrics are not to be assumed to be free to keep creating ad hoc every single time exactly because they may hit a registry and touch locks which may become contended then. If possible keeping a metric object around is a good pattern. Of course this depends on specific backends, but in many that's the case (as is the case with the prom impl actually). |
So by adding this to the API we'd actually make backend work more difficult - if we allow dimensions on |
I too ran into a lot of confusion with the current API and what the expectation is here. I think #139 is another example of this. In addition to all the great points @avolokhov makes, I think the current Swift Metrics API deviates from patterns in other languages enough to make it very unclear how to use the API for recording multi-dimensional metrics. I think the documentation needs to confront this difference by calling it out and providing examples so confused folks like me aren't driven to the issue tracker. |
Current metrics api only supports setting dimensions on metric creation. I think to fully leverage dimensions and express in code that certain set of metrics report into a same metric label, we need to allow setting dimensions on
record
as well as in constructor. E.g. imagine we're trying to instrument an http server. With custom dimensions we could do something like this:We won't have to create a separate requestDurationTimer for each "uri" as well as a separate timer for each uri/error class combination. This also applies to more complex state machines instrumentation when we may want to express certain event belongs to a certain state/command.
The text was updated successfully, but these errors were encountered: