Using histogram metrics instead of summary

pull/564/head
danielqsj 2018-12-12 16:50:32 +08:00
parent b828bc1a50
commit 42214c5ac4
3 changed files with 19 additions and 12 deletions

View File

@ -65,23 +65,25 @@ func (prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMet
return adds return adds
} }
func (prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.SummaryMetric { func (prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.HistogramMetric {
latency := prometheus.NewSummary(prometheus.SummaryOpts{ latency := prometheus.NewHistogram(prometheus.HistogramOpts{
Subsystem: WorkQueueSubsystem, Subsystem: WorkQueueSubsystem,
Name: QueueLatencyKey, Name: QueueLatencyKey,
Help: "How long in seconds an item stays in workqueue before being requested.", Help: "How long in seconds an item stays in workqueue before being requested.",
ConstLabels: prometheus.Labels{"name": name}, ConstLabels: prometheus.Labels{"name": name},
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 10),
}) })
prometheus.Register(latency) prometheus.Register(latency)
return latency return latency
} }
func (prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.SummaryMetric { func (prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.HistogramMetric {
workDuration := prometheus.NewSummary(prometheus.SummaryOpts{ workDuration := prometheus.NewHistogram(prometheus.HistogramOpts{
Subsystem: WorkQueueSubsystem, Subsystem: WorkQueueSubsystem,
Name: WorkDurationKey, Name: WorkDurationKey,
Help: "How long in seconds processing an item from workqueue takes.", Help: "How long in seconds processing an item from workqueue takes.",
ConstLabels: prometheus.Labels{"name": name}, ConstLabels: prometheus.Labels{"name": name},
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 10),
}) })
prometheus.Register(workDuration) prometheus.Register(workDuration)
return workDuration return workDuration

View File

@ -57,6 +57,11 @@ type SummaryMetric interface {
Observe(float64) Observe(float64)
} }
// HistogramMetric counts individual observations.
type HistogramMetric interface {
Observe(float64)
}
type noopMetric struct{} type noopMetric struct{}
func (noopMetric) Inc() {} func (noopMetric) Inc() {}
@ -73,9 +78,9 @@ type defaultQueueMetrics struct {
// total number of adds handled by a workqueue // total number of adds handled by a workqueue
adds CounterMetric adds CounterMetric
// how long an item stays in a workqueue // how long an item stays in a workqueue
latency SummaryMetric latency HistogramMetric
// how long processing an item from a workqueue takes // how long processing an item from a workqueue takes
workDuration SummaryMetric workDuration HistogramMetric
addTimes map[t]time.Time addTimes map[t]time.Time
processingStartTimes map[t]time.Time processingStartTimes map[t]time.Time
@ -190,8 +195,8 @@ func (m *defaultRetryMetrics) retry() {
type MetricsProvider interface { type MetricsProvider interface {
NewDepthMetric(name string) GaugeMetric NewDepthMetric(name string) GaugeMetric
NewAddsMetric(name string) CounterMetric NewAddsMetric(name string) CounterMetric
NewLatencyMetric(name string) SummaryMetric NewLatencyMetric(name string) HistogramMetric
NewWorkDurationMetric(name string) SummaryMetric NewWorkDurationMetric(name string) HistogramMetric
NewUnfinishedWorkSecondsMetric(name string) SettableGaugeMetric NewUnfinishedWorkSecondsMetric(name string) SettableGaugeMetric
NewLongestRunningProcessorSecondsMetric(name string) SettableGaugeMetric NewLongestRunningProcessorSecondsMetric(name string) SettableGaugeMetric
NewRetriesMetric(name string) CounterMetric NewRetriesMetric(name string) CounterMetric
@ -214,11 +219,11 @@ func (_ noopMetricsProvider) NewAddsMetric(name string) CounterMetric {
return noopMetric{} return noopMetric{}
} }
func (_ noopMetricsProvider) NewLatencyMetric(name string) SummaryMetric { func (_ noopMetricsProvider) NewLatencyMetric(name string) HistogramMetric {
return noopMetric{} return noopMetric{}
} }
func (_ noopMetricsProvider) NewWorkDurationMetric(name string) SummaryMetric { func (_ noopMetricsProvider) NewWorkDurationMetric(name string) HistogramMetric {
return noopMetric{} return noopMetric{}
} }

View File

@ -155,11 +155,11 @@ func (m *testMetricsProvider) NewAddsMetric(name string) CounterMetric {
return &m.adds return &m.adds
} }
func (m *testMetricsProvider) NewLatencyMetric(name string) SummaryMetric { func (m *testMetricsProvider) NewLatencyMetric(name string) HistogramMetric {
return &m.latency return &m.latency
} }
func (m *testMetricsProvider) NewWorkDurationMetric(name string) SummaryMetric { func (m *testMetricsProvider) NewWorkDurationMetric(name string) HistogramMetric {
return &m.duration return &m.duration
} }