feat: output +Inf bucket
parent
7e39051c1f
commit
08d95965af
10
prometheus.v
10
prometheus.v
|
@ -109,5 +109,15 @@ pub fn (mut e PrometheusExporter) export_to_writer(mut writer io.Writer) ! {
|
||||||
|
|
||||||
writer.write('${e.serialize_metric(m)} ${bucket_counts[j]}\n'.bytes())!
|
writer.write('${e.serialize_metric(m)} ${bucket_counts[j]}\n'.bytes())!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always output the +Inf bucket
|
||||||
|
le_labels[le_labels.len - 1][1] = '+Inf'
|
||||||
|
|
||||||
|
m = Metric{
|
||||||
|
name: '${hist.name}_bucket'
|
||||||
|
labels: le_labels
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write('${e.serialize_metric(m)} $total_count\n'.bytes())!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,10 @@ fn test_single_histogram() {
|
||||||
mut m := new_default_collector()
|
mut m := new_default_collector()
|
||||||
|
|
||||||
m.histogram_record(5.0, name: 'test')
|
m.histogram_record(5.0, name: 'test')
|
||||||
|
m.histogram_record(7.0, name: 'test')
|
||||||
|
|
||||||
mut e := new_prometheus_exporter([0.5, 5.0])
|
mut e := new_prometheus_exporter([0.5, 5.0])
|
||||||
e.load('hi_', m)
|
e.load('hi_', m)
|
||||||
|
|
||||||
assert e.export_to_string()! == 'hi_test_count 1\nhi_test_sum 5.0\nhi_test_bucket{le="0.5"} 0\nhi_test_bucket{le="5.0"} 1\n'
|
assert e.export_to_string()! == 'hi_test_count 2\nhi_test_sum 12.0\nhi_test_bucket{le="0.5"} 0\nhi_test_bucket{le="5.0"} 1\nhi_test_bucket{le="+Inf"} 2\n'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue