diff --git a/exporter.go b/exporter.go index d62a4bb..9475d9e 100644 --- a/exporter.go +++ b/exporter.go @@ -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, diff --git a/exporter_test.go b/exporter_test.go index 160d053..945706a 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -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)