-
Notifications
You must be signed in to change notification settings - Fork 58
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
Should Gauge gain add
in addition to record
?
#36
Comments
add
in addition to record
add
in addition to record
?
@ktoso if you feel strongly about this, it would be good time since we are working on 1.2.0 |
Thanks for reminder! I’ll give it a look on Monday if my workaround is a good general approach or it built in api would be much better :) |
Looking into it 💭 |
Spent some time with this expressing some metrics I wanted to capture with "add" and thanks to some great discussion with @yim-lee was able to figure out we can express everything we need by using a positive + negative counter pair; This is actually quite good, as one can track all those events separately and also get their independent progress as well as post process them nicely ( For curious people who'd bump into the same issue: @usableFromInline
internal struct MetricsPNCounter {
@usableFromInline
let positive: Counter
@usableFromInline
let negative: Counter
init(label: String, positive positiveDimensions: [(String, String)] = [], negative negativeDimensions: [(String, String)] = []) {
self.positive = Counter(label: label, dimensions: positiveDimensions)
self.negative = Counter(label: label, dimensions: negativeDimensions)
}
@inlinable
func increment(by value: Int64 = 1) {
assert(value > 0, "value MUST BE > 0")
self.positive.increment(by: value)
}
@inlinable
func decrement(by value: Int64 = 1) {
assert(value > 0, "value MUST BE > 0")
self.negative.increment(by: value)
}
} So in prometheus one could see those as
meaning that right now we have 6 active bananas; this is to be calculated in post processing though. |
Expected behavior
I'd like to use gauges to easily implement a metric of how many things I have alive in my system -- examples could be threads or connections.
Actual behavior
Can't implement this like that since we do not offer
add
, we only offerrecord
, so I have to implement my own thing which keep the total number and then use that to record into the actual metrics gauge:Implementation idea 1, which fails since Gauge is not open:
So what I end up is something like:
Main question:
add()
toGauge
as it enables this popular use case?Counter.add
which has to pattern match on the handler if it supports an add operation or not... it seems a bit weird though and would come at a cost.Other points:
The text was updated successfully, but these errors were encountered: