From d103706c60180f132d33beab916d2ead94c4fc22 Mon Sep 17 00:00:00 2001 From: Sambhav Jain Date: Fri, 15 Nov 2024 16:22:10 +0530 Subject: [PATCH] workload: fix quantile values in openmetrics exporter `hdrHistogram` library has quantiles in percentages rather than absolute values. Openmetrics standard forces the quantiles values in `summary` metric to be absolute values b/w 0 and 1 inclusive. Earlier the exporter would export the percentage value, this change intends to make it absolute to adhere to openmetrics standard Epic: none Release note: None --- pkg/workload/histogram/exporter/exporter_test.go | 2 +- pkg/workload/histogram/exporter/testdata/kv | 8 ++++---- pkg/workload/histogram/exporter/testdata/tpcc_delivery | 8 ++++---- pkg/workload/histogram/exporter/testdata/ycsb | 8 ++++---- pkg/workload/histogram/exporter/util.go | 7 ++++++- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/workload/histogram/exporter/exporter_test.go b/pkg/workload/histogram/exporter/exporter_test.go index 58aefb2183a1..f21d10586c37 100644 --- a/pkg/workload/histogram/exporter/exporter_test.go +++ b/pkg/workload/histogram/exporter/exporter_test.go @@ -209,7 +209,7 @@ func TestOpenMetricsFileWithJson(t *testing.T) { return errors.Errorf("invalid summary count: %f", countValue) } } - + quantile *= 100 if int64(countValue) != hist.ValueAtQuantile(quantile) { return errors.Errorf("invalid summary quantile: %f", quantile) } diff --git a/pkg/workload/histogram/exporter/testdata/kv b/pkg/workload/histogram/exporter/testdata/kv index acbbf326eb7b..33f6311a73a5 100644 --- a/pkg/workload/histogram/exporter/testdata/kv +++ b/pkg/workload/histogram/exporter/testdata/kv @@ -2,10 +2,10 @@ echo {"Name":"write","Hist":{"LowestTrackableValue":100000,"HighestTrackableValue":100000000000,"SignificantFigures":1,"Counts":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,5,9,20,41,42,54,83,92,103,141,400,586,828,913,982,1127,1223,1236,1123,1009,976,850,713,706,590,483,793,438,277,154,84,52,52,29,19,22,14,9,5,3,1,5,4,4,10,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"Elapsed":5031363856,"Now":"2024-06-24T13:38:53.446733522Z"} ---- # TYPE write summary -write{quantile="50.0"} 3.276799e+06 1.719236333446e+09 -write{quantile="95.0"} 4.718591e+06 1.719236333446e+09 -write{quantile="99.0"} 6.291455e+06 1.719236333446e+09 -write{quantile="100.0"} 4.294967295e+09 1.719236333446e+09 +write{quantile="0.5"} 3.276799e+06 1.719236333446e+09 +write{quantile="0.95"} 4.718591e+06 1.719236333446e+09 +write{quantile="0.99"} 6.291455e+06 1.719236333446e+09 +write{quantile="1.0"} 4.294967295e+09 1.719236333446e+09 write_sum 0.0 1.719236333446e+09 write_count 16379 1.719236333446e+09 # TYPE write_elapsed gauge diff --git a/pkg/workload/histogram/exporter/testdata/tpcc_delivery b/pkg/workload/histogram/exporter/testdata/tpcc_delivery index c15691db5c30..2266717614fe 100644 --- a/pkg/workload/histogram/exporter/testdata/tpcc_delivery +++ b/pkg/workload/histogram/exporter/testdata/tpcc_delivery @@ -3,10 +3,10 @@ echo {"Name":"delivery","Hist":{"LowestTrackableValue":100000,"HighestTrackableValue":100000000000,"SignificantFigures":1,"Counts":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,1,2,4,2,4,5,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"Elapsed":992259494,"Now":"2024-06-24T15:47:43.790887915Z"} ---- # TYPE delivery summary -delivery{quantile="50.0"} 3.7748735e+07 1.71924406379e+09 -delivery{quantile="95.0"} 4.4040191e+07 1.71924406379e+09 -delivery{quantile="99.0"} 4.6137343e+07 1.71924406379e+09 -delivery{quantile="100.0"} 4.6137343e+07 1.71924406379e+09 +delivery{quantile="0.5"} 3.7748735e+07 1.71924406379e+09 +delivery{quantile="0.95"} 4.4040191e+07 1.71924406379e+09 +delivery{quantile="0.99"} 4.6137343e+07 1.71924406379e+09 +delivery{quantile="1.0"} 4.6137343e+07 1.71924406379e+09 delivery_sum 0.0 1.71924406379e+09 delivery_count 24 1.71924406379e+09 # TYPE delivery_elapsed gauge diff --git a/pkg/workload/histogram/exporter/testdata/ycsb b/pkg/workload/histogram/exporter/testdata/ycsb index 4b89a537dc09..a19807826d86 100644 --- a/pkg/workload/histogram/exporter/testdata/ycsb +++ b/pkg/workload/histogram/exporter/testdata/ycsb @@ -3,10 +3,10 @@ echo ---- # TYPE read summary -read{quantile="50.0"} 1.048575e+06 1.719230907083e+09 -read{quantile="95.0"} 1.835007e+06 1.719230907083e+09 -read{quantile="99.0"} 3.276799e+06 1.719230907083e+09 -read{quantile="100.0"} 1.3631487e+07 1.719230907083e+09 +read{quantile="0.5"} 1.048575e+06 1.719230907083e+09 +read{quantile="0.95"} 1.835007e+06 1.719230907083e+09 +read{quantile="0.99"} 3.276799e+06 1.719230907083e+09 +read{quantile="1.0"} 1.3631487e+07 1.719230907083e+09 read_sum 0.0 1.719230907083e+09 read_count 34540 1.719230907083e+09 # TYPE read_elapsed gauge diff --git a/pkg/workload/histogram/exporter/util.go b/pkg/workload/histogram/exporter/util.go index 6c4b756460b0..10543e186e8a 100644 --- a/pkg/workload/histogram/exporter/util.go +++ b/pkg/workload/histogram/exporter/util.go @@ -34,8 +34,13 @@ func ConvertHdrHistogramToPrometheusMetricFamily( if value == 0 { continue } + + // Openmetrics standard mandates that quantile should be b/w 0 to 1. + // https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md#summary + // Since hdrHistogram has quantiles in percentage, we need to convert it + openMetricsQuantile := quantile / 100 valueQuantile := prom.Quantile{ - Quantile: &quantile, + Quantile: &openMetricsQuantile, Value: &value, }