mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 17:21:01 +00:00
Add default quantiles for summaries if no mapping file exists
Signed-off-by: Vitaliy Sakhartchouk <vsakhart@github.com>
This commit is contained in:
parent
4d0cb1992d
commit
cddeb87405
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 {
|
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,
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue