Skip to content
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

metrics.Gauge should get an Add method #393

Closed
hardcoar opened this issue Nov 15, 2016 · 2 comments
Closed

metrics.Gauge should get an Add method #393

hardcoar opened this issue Nov 15, 2016 · 2 comments

Comments

@hardcoar
Copy link

type Gauge interface from pkg github.com/go-kit/kit/metrics has no field or method Add

hi guys i need help. i want to have reference on the current gauge using native prometheus (i don't want to implement it myself). since only method available on the interface in metrics package is Set i don't have any reference to the current gauge number.

is strange that pkg metrics/prometheus has Add method and pkg metrics don't?
is there an opinionated way to do this and am i missing something?
is it a generalization for other collectors aside from prometheus?
what's the correct way to Add in gauge (for prometheus)?

@peterbourgon
Copy link
Member

It was my original opinions that Gauges should only support the Set method. But I've discovered that many important uses of Gauges are modeled by +N/-N semantics. For example, consider inflight requests. Right now, you'd have to do

func (s *Server) Handle() {
    s.Inflight.Set(atomic.AddInt64(&s.inflight, 1))
    defer s.Inflight.Set(atomic.AddInt64(&s.inflight, -1))
    // ...
}

versus the much nicer

func (s *Server) Handle() {
    s.Inflight.Add(1)
    defer s.Inflight.Add(-1)
    // ...
}

In the short term you can do as above. In the medium term I think I will need to re-add the Add method to the Gauge interface. Marking this as TODO.

@peterbourgon peterbourgon changed the title metrics prometheus metrics.Gauge should get an Add method Nov 17, 2016
@peterbourgon
Copy link
Member

Closed in #428. Huge thanks to @dlmiddlecote! Amazing work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants