diff --git a/prometheus.v b/prometheus.v index e922ebd..93f41e4 100644 --- a/prometheus.v +++ b/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())! } + + // 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())! } } diff --git a/prometheus_test.v b/prometheus_test.v index d78d315..ac42a21 100644 --- a/prometheus_test.v +++ b/prometheus_test.v @@ -41,9 +41,10 @@ fn test_single_histogram() { mut m := new_default_collector() m.histogram_record(5.0, name: 'test') + m.histogram_record(7.0, name: 'test') mut e := new_prometheus_exporter([0.5, 5.0]) 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' }