Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
prom: skip summary/histogram NaN values (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Dec 16, 2022
1 parent f7f50df commit 0b0ba23
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
8 changes: 4 additions & 4 deletions modules/prometheus/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (p *Prometheus) addSummaryCharts(id, name, help string, labels labels.Label
Ctx: getChartContext(p.application(), name) + "_sum",
Priority: getChartPriority(name),
Dims: module.Dims{
{ID: id + "_sum", Algo: module.Incremental, Div: precision},
{ID: id + "_sum", Name: name + "_sum", Algo: module.Incremental, Div: precision},
},
},
{
Expand All @@ -140,7 +140,7 @@ func (p *Prometheus) addSummaryCharts(id, name, help string, labels labels.Label
Ctx: getChartContext(p.application(), name) + "_count",
Priority: getChartPriority(name),
Dims: module.Dims{
{ID: id + "_count", Algo: module.Incremental},
{ID: id + "_count", Name: name + "_count", Algo: module.Incremental},
},
},
}
Expand Down Expand Up @@ -194,7 +194,7 @@ func (p *Prometheus) addHistogramCharts(id, name, help string, labels labels.Lab
Ctx: getChartContext(p.application(), name) + "_sum",
Priority: getChartPriority(name),
Dims: module.Dims{
{ID: id + "_sum", Algo: module.Incremental, Div: precision},
{ID: id + "_sum", Name: name + "_sum", Algo: module.Incremental, Div: precision},
},
},
{
Expand All @@ -205,7 +205,7 @@ func (p *Prometheus) addHistogramCharts(id, name, help string, labels labels.Lab
Ctx: getChartContext(p.application(), name) + "_count",
Priority: getChartPriority(name),
Dims: module.Dims{
{ID: id + "_count", Algo: module.Incremental},
{ID: id + "_count", Name: name + "_count", Algo: module.Incremental},
},
},
}
Expand Down
12 changes: 8 additions & 4 deletions modules/prometheus/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ func (p *Prometheus) collectSummary(mx map[string]int64, mf *prometheus.MetricFa
}

for _, v := range m.Summary().Quantiles() {
dimID := fmt.Sprintf("%s_quantile=%s", id, formatFloat(v.Quantile()))
mx[dimID] = int64(v.Value() * precision * precision)
if !math.IsNaN(v.Value()) {
dimID := fmt.Sprintf("%s_quantile=%s", id, formatFloat(v.Quantile()))
mx[dimID] = int64(v.Value() * precision * precision)
}
}

mx[id+"_sum"] = int64(m.Summary().Sum() * precision)
Expand All @@ -142,8 +144,10 @@ func (p *Prometheus) collectHistogram(mx map[string]int64, mf *prometheus.Metric
}

for _, v := range m.Histogram().Buckets() {
dimID := fmt.Sprintf("%s_bucket=%s", id, formatFloat(v.UpperBound()))
mx[dimID] = int64(v.CumulativeCount())
if !math.IsNaN(v.CumulativeCount()) {
dimID := fmt.Sprintf("%s_bucket=%s", id, formatFloat(v.UpperBound()))
mx[dimID] = int64(v.CumulativeCount())
}
}

mx[id+"_sum"] = int64(m.Histogram().Sum() * precision)
Expand Down
29 changes: 29 additions & 0 deletions modules/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,35 @@ test_summary_no_meta_1_duration_microseconds_count{label1="value1"} 31
},
},
},
"Summary with NaN": {
prepare: New,
steps: []testCaseStep{
{
desc: "Two first seen series, no meta series collected",
input: `
# HELP test_summary_1_duration_microseconds Test Summary Metric 1
# TYPE test_summary_1_duration_microseconds summary
test_summary_1_duration_microseconds{label1="value1",quantile="0.5"} NaN
test_summary_1_duration_microseconds{label1="value1",quantile="0.9"} NaN
test_summary_1_duration_microseconds{label1="value1",quantile="0.99"} NaN
test_summary_1_duration_microseconds_sum{label1="value1"} 283201.29
test_summary_1_duration_microseconds_count{label1="value1"} 31
test_summary_no_meta_1_duration_microseconds{label1="value1",quantile="0.5"} NaN
test_summary_no_meta_1_duration_microseconds{label1="value1",quantile="0.9"} NaN
test_summary_no_meta_1_duration_microseconds{label1="value1",quantile="0.99"} NaN
test_summary_no_meta_1_duration_microseconds_sum{label1="value1"} 283201.29
test_summary_no_meta_1_duration_microseconds_count{label1="value1"} 31
`,
wantCollected: map[string]int64{
"test_summary_1_duration_microseconds-label1=value1_count": 31,
"test_summary_1_duration_microseconds-label1=value1_sum": 283201290,
"test_summary_no_meta_1_duration_microseconds-label1=value1_count": 31,
"test_summary_no_meta_1_duration_microseconds-label1=value1_sum": 283201290,
},
wantCharts: 6,
},
},
},
"Histogram": {
prepare: New,
steps: []testCaseStep{
Expand Down

0 comments on commit 0b0ba23

Please sign in to comment.