Skip to content

Commit

Permalink
Add support for specifying 'Gatherer' in prometheus Reporter options. (
Browse files Browse the repository at this point in the history
…#80)

Passing the Gatherer is required to be able return the HTTPHandler
appropriate for a customer Registerer that is passed in. Without this
change, the HTTPHandler is *always* associated with the Gatherer for the
promhttp.DefaultRegisterer, which is confusing if a custom Registerer is
passed.
  • Loading branch information
klueska authored and robskillington committed May 15, 2019
1 parent 1ed35a1 commit f2b9562
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion prometheus/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type metricID string
type reporter struct {
sync.RWMutex
registerer prom.Registerer
gatherer prom.Gatherer
timerType TimerType
objectives map[float64]float64
buckets []float64
Expand Down Expand Up @@ -224,7 +225,7 @@ func (m noopMetric) DurationBucket(lower, upper time.Duration) tally.CachedHisto
}

func (r *reporter) HTTPHandler() http.Handler {
return promhttp.Handler()
return promhttp.HandlerFor(r.gatherer, promhttp.HandlerOpts{})
}

// TimerType describes a type of timer
Expand All @@ -244,6 +245,10 @@ type Options struct {
// metrics with. Use nil to specify the default registerer.
Registerer prom.Registerer

// Gatherer is the prometheus gatherer to gather
// metrics with. Use nil to specify the default gatherer.
Gatherer prom.Gatherer

// DefaultTimerType is the default type timer type to create
// when using timers. It's default value is a summary timer type.
DefaultTimerType TimerType
Expand All @@ -269,6 +274,9 @@ func NewReporter(opts Options) Reporter {
if opts.Registerer == nil {
opts.Registerer = prom.DefaultRegisterer
}
if opts.Gatherer == nil {
opts.Gatherer = prom.DefaultGatherer
}
if opts.DefaultHistogramBuckets == nil {
opts.DefaultHistogramBuckets = DefaultHistogramBuckets()
}
Expand All @@ -280,8 +288,10 @@ func NewReporter(opts Options) Reporter {
panic(err)
}
}

return &reporter{
registerer: opts.Registerer,
gatherer: opts.Gatherer,
timerType: opts.DefaultTimerType,
buckets: opts.DefaultHistogramBuckets,
objectives: opts.DefaultSummaryObjectives,
Expand Down

0 comments on commit f2b9562

Please sign in to comment.