Skip to content

Commit

Permalink
Allow histograms with no buckets and summary without quantiles (influ…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored Jun 30, 2020
1 parent 9700f8e commit 7dddede
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
59 changes: 59 additions & 0 deletions plugins/outputs/prometheus_client/prometheus_client_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ func TestMetricVersion2(t *testing.T) {
# HELP cpu_time_idle Telegraf collected metric
# TYPE cpu_time_idle untyped
cpu_time_idle{host="example.org"} 42
`),
},
{
name: "summary no quantiles",
output: &PrometheusClient{
Listen: ":0",
MetricVersion: 2,
CollectorsExclude: []string{"gocollector", "process"},
Path: "/metrics",
Log: Logger,
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"prometheus",
map[string]string{},
map[string]interface{}{
"rpc_duration_seconds_sum": 1.7560473e+07,
"rpc_duration_seconds_count": 2693,
},
time.Unix(0, 0),
telegraf.Summary,
),
},
expected: []byte(`
# HELP rpc_duration_seconds Telegraf collected metric
# TYPE rpc_duration_seconds summary
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
`),
},
{
Expand Down Expand Up @@ -239,6 +267,37 @@ cpu_usage_idle_bucket{cpu="cpu1",le="100"} 20
cpu_usage_idle_bucket{cpu="cpu1",le="+Inf"} 20
cpu_usage_idle_sum{cpu="cpu1"} 2000
cpu_usage_idle_count{cpu="cpu1"} 20
`),
},
{
name: "histogram no buckets",
output: &PrometheusClient{
Listen: ":0",
MetricVersion: 2,
CollectorsExclude: []string{"gocollector", "process"},
Path: "/metrics",
Log: Logger,
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"cpu",
map[string]string{
"cpu": "cpu1",
},
map[string]interface{}{
"usage_idle_sum": 2000.0,
"usage_idle_count": 20.0,
},
time.Unix(0, 0),
telegraf.Histogram,
),
},
expected: []byte(`
# HELP cpu_usage_idle Telegraf collected metric
# TYPE cpu_usage_idle histogram
cpu_usage_idle_bucket{cpu="cpu1",le="+Inf"} 20
cpu_usage_idle_sum{cpu="cpu1"} 2000
cpu_usage_idle_count{cpu="cpu1"} 20
`),
},
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/serializers/prometheus/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,6 @@ func (c *Collection) GetProto() []*dto.MetricFamily {
})
}

if len(buckets) == 0 {
continue
}

m.Histogram = &dto.Histogram{
Bucket: buckets,
SampleCount: proto.Uint64(metric.Histogram.Count),
Expand All @@ -464,10 +460,6 @@ func (c *Collection) GetProto() []*dto.MetricFamily {
})
}

if len(quantiles) == 0 {
continue
}

m.Summary = &dto.Summary{
Quantile: quantiles,
SampleCount: proto.Uint64(metric.Summary.Count),
Expand Down
26 changes: 26 additions & 0 deletions plugins/serializers/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ http_requests_total{code="400",method="post"} 3
telegraf.Histogram,
),
expected: []byte(`
# HELP http_request_duration_seconds Telegraf collected metric
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="+Inf"} 144320
http_request_duration_seconds_sum 53423
http_request_duration_seconds_count 144320
`),
},
{
Expand Down Expand Up @@ -645,6 +650,27 @@ cpu_time_user{cpu="cpu0"} 92904.33
cpu_time_user{cpu="cpu1"} 96912.57
cpu_time_user{cpu="cpu2"} 96034.08
cpu_time_user{cpu="cpu3"} 94148
`),
},
{
name: "summary with no quantile",
metrics: []telegraf.Metric{
testutil.MustMetric(
"prometheus",
map[string]string{},
map[string]interface{}{
"rpc_duration_seconds_sum": 1.7560473e+07,
"rpc_duration_seconds_count": 2693,
},
time.Unix(0, 0),
telegraf.Summary,
),
},
expected: []byte(`
# HELP rpc_duration_seconds Telegraf collected metric
# TYPE rpc_duration_seconds summary
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
`),
},
}
Expand Down

0 comments on commit 7dddede

Please sign in to comment.