Merge pull request #212 from vsakhart/quantile_fix

Add default quantiles for summaries if no mapping file exists
This commit is contained in:
Matthias Rampke 2019-05-14 16:14:15 +00:00 committed by GitHub
commit f1c0052ce7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View file

@ -189,6 +189,10 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels, help
for _, q := range quantiles { for _, q := range quantiles {
objectives[q.Quantile] = q.Error 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( summaryVec = prometheus.NewSummaryVec(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Name: metricName, Name: metricName,

View file

@ -222,6 +222,51 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
ex.Listen(events) 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) { func TestHistogramUnits(t *testing.T) {
// Start exporter with a synchronous channel // Start exporter with a synchronous channel
events := make(chan Events) events := make(chan Events)