Skip to content

Commit

Permalink
Merge pull request #212 from vsakhart/quantile_fix
Browse files Browse the repository at this point in the history
Add default quantiles for summaries if no mapping file exists
  • Loading branch information
Matthias Rampke authored May 14, 2019
2 parents 4d0cb19 + cddeb87 commit f1c0052
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 45 additions & 0 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f1c0052

Please sign in to comment.