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

GetOrRegisterHistogram requires us to track samples separately or risk wasteful allocations #224

Open
sandipb opened this issue Feb 1, 2018 · 2 comments

Comments

@sandipb
Copy link

sandipb commented Feb 1, 2018

I usually use counters, gauges and timers in code somewhat like this:

metrics.GetOrRegisterCounter(metricName, metricsRegistry).Inc(amount)

But doing the same thing with Histograms are a problem. This is the call signature.

GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram

If I want to use an UniformSample, am I supposed to use it like this?

metrics.GetOrRegisterHistogram(metricName, metricsRegistry, NewUniformSample(size)).Inc(amount)

But that would create a new sample on every call.

To prevent that, we would need to make sure we create a sample only if a histogram is not present. At present, I am doing this with a mutex protected dict, but this is annoying.

Can we turn this function into accepting a Sample generator callback instead?

type NewSampleFunc func() Sample

// GetOrRegisterHistogramWithSampleFunc(name string,
//                                      r Registry,
//                                      s NewSampleFunc) Histogram

metrics.GetOrRegisterHistogramWithSampleFunc(metricName,
                                             metricsRegistry,
                                             func(){return NewUniformSample(size)}).Inc(amount)
@davidstrauss
Copy link

+1 on this change. It's otherwise awkward to efficiently use lazy sample instantiations.

@karalabe
Copy link

+1, though I don't think this will ever land :)

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

No branches or pull requests

3 participants