forked from mirrors/statsd_exporter
Merge pull request #212 from vsakhart/quantile_fix
Add default quantiles for summaries if no mapping file exists
This commit is contained in:
commit
f1c0052ce7
2 changed files with 49 additions and 0 deletions
|
@ -189,6 +189,10 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels, help
|
|||
for _, q := range quantiles {
|
||||
objectives[q.Quantile] = q.Error
|
||||
}
|
||||
// In the case of no mapping file, explicitly define the default quantiles
|
||||
if len(objectives) == 0 {
|
||||
objectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
|
||||
}
|
||||
summaryVec = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Name: metricName,
|
||||
|
|
|
@ -222,6 +222,51 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
|
|||
ex.Listen(events)
|
||||
}
|
||||
|
||||
// In the case of someone starting the statsd exporter with no mapping file specified
|
||||
// which is valid, we want to make sure that the default quantile metrics are generated
|
||||
// as well as the sum/count metrics
|
||||
func TestSummaryWithQuantilesEmptyMapping(t *testing.T) {
|
||||
// Start exporter with a synchronous channel
|
||||
events := make(chan Events)
|
||||
go func() {
|
||||
ex := NewExporter(&mapper.MetricMapper{})
|
||||
ex.Listen(events)
|
||||
}()
|
||||
|
||||
name := "default_foo"
|
||||
c := Events{
|
||||
&TimerEvent{
|
||||
metricName: name,
|
||||
value: 300,
|
||||
},
|
||||
}
|
||||
events <- c
|
||||
events <- Events{}
|
||||
close(events)
|
||||
|
||||
metrics, err := prometheus.DefaultGatherer.Gather()
|
||||
if err != nil {
|
||||
t.Fatal("Gather should not fail")
|
||||
}
|
||||
|
||||
var metricFamily *dto.MetricFamily
|
||||
for _, m := range metrics {
|
||||
if *m.Name == name {
|
||||
metricFamily = m
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if metricFamily == nil {
|
||||
t.Fatal("Metric could not be found")
|
||||
}
|
||||
|
||||
quantiles := metricFamily.Metric[0].Summary.Quantile
|
||||
if len(quantiles) == 0 {
|
||||
t.Fatal("Summary has no quantiles available")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHistogramUnits(t *testing.T) {
|
||||
// Start exporter with a synchronous channel
|
||||
events := make(chan Events)
|
||||
|
|
Loading…
Reference in a new issue