From 20dbb128d9f6c764e63edff1a400b8e1e6ebaad8 Mon Sep 17 00:00:00 2001 From: Andrew Bloomgarden Date: Wed, 23 Mar 2022 10:26:58 -0400 Subject: [PATCH] Switch per-step stats to serialize ints Per Julien's feedback on #10369, we're choosing to be consistent with data types inside the stats structure (ints) rather than with the points format that is part of the normal query responses (strings). We have this option because this data cannot be NaN/Inf. Signed-off-by: Andrew Bloomgarden --- util/stats/query_stats.go | 11 ++++------- util/stats/stats_test.go | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/util/stats/query_stats.go b/util/stats/query_stats.go index 85f9a99c3..e1afd3038 100644 --- a/util/stats/query_stats.go +++ b/util/stats/query_stats.go @@ -17,7 +17,6 @@ import ( "context" "encoding/json" "fmt" - "strconv" "github.com/prometheus/client_golang/prometheus" "go.opentelemetry.io/otel" @@ -81,18 +80,16 @@ func (s QueryTiming) SpanOperation() string { // stepStat represents a single statistic for a given step timestamp. type stepStat struct { T int64 - V float64 + V int64 } func (s stepStat) String() string { - v := strconv.FormatFloat(s.V, 'f', -1, 64) - return fmt.Sprintf("%v @[%v]", v, s.T) + return fmt.Sprintf("%v @[%v]", s.V, s.T) } // MarshalJSON implements json.Marshaler. func (s stepStat) MarshalJSON() ([]byte, error) { - v := strconv.FormatFloat(s.V, 'f', -1, 64) - return json.Marshal([...]interface{}{float64(s.T) / 1000, v}) + return json.Marshal([...]interface{}{float64(s.T) / 1000, s.V}) } // queryTimings with all query timers mapped to durations. @@ -185,7 +182,7 @@ func (qs *QuerySamples) totalSamplesPerStepPoints() []stepStat { ts := make([]stepStat, len(qs.TotalSamplesPerStep)) for i, c := range qs.TotalSamplesPerStep { - ts[i] = stepStat{T: qs.startTimestamp + int64(i)*qs.interval, V: float64(c)} + ts[i] = stepStat{T: qs.startTimestamp + int64(i)*qs.interval, V: int64(c)} } return ts } diff --git a/util/stats/stats_test.go b/util/stats/stats_test.go index 860775280..28753b95f 100644 --- a/util/stats/stats_test.go +++ b/util/stats/stats_test.go @@ -61,7 +61,7 @@ func TestQueryStatsWithTimersAndSamples(t *testing.T) { require.True(t, match, "Expected timings with one non-zero entry.") require.Regexpf(t, `[,{]"totalQueryableSamples":10[,}]`, string(actual), "expected totalQueryableSamples") - require.Regexpf(t, `[,{]"totalQueryableSamplesPerStep":\[\[20001,"5"\],\[21001,"0"\],\[22001,"0"\],\[23001,"0"\],\[24001,"0"\],\[25001,"5"\]\]`, string(actual), "expected totalQueryableSamplesPerStep") + require.Regexpf(t, `[,{]"totalQueryableSamplesPerStep":\[\[20001,5\],\[21001,0\],\[22001,0\],\[23001,0\],\[24001,0\],\[25001,5\]\]`, string(actual), "expected totalQueryableSamplesPerStep") } func TestQueryStatsWithSpanTimers(t *testing.T) {