From b74d87fd636a927eca9e1620aad7fa5bdb1c3765 Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Tue, 11 Jun 2024 15:30:33 +1000 Subject: [PATCH] Flip meaning of metrics --- tools/querytee/proxy_endpoint.go | 4 ++-- tools/querytee/proxy_endpoint_test.go | 15 +++++++-------- tools/querytee/proxy_metrics.go | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tools/querytee/proxy_endpoint.go b/tools/querytee/proxy_endpoint.go index 62615f3457b..c6d96044c87 100644 --- a/tools/querytee/proxy_endpoint.go +++ b/tools/querytee/proxy_endpoint.go @@ -224,8 +224,8 @@ func (p *ProxyEndpoint) executeBackendRequests(req *http.Request, resCh chan *ba ) } - relativeDuration := expectedResponse.elapsedTime - actualResponse.elapsedTime - proportionalDuration := expectedResponse.elapsedTime.Seconds() / actualResponse.elapsedTime.Seconds() + relativeDuration := actualResponse.elapsedTime - expectedResponse.elapsedTime + proportionalDuration := actualResponse.elapsedTime.Seconds() / expectedResponse.elapsedTime.Seconds() p.metrics.relativeDuration.WithLabelValues(p.routeName).Observe(relativeDuration.Seconds()) p.metrics.proportionalDuration.WithLabelValues(p.routeName).Observe(proportionalDuration) p.metrics.responsesComparedTotal.WithLabelValues(p.routeName, string(result)).Inc() diff --git a/tools/querytee/proxy_endpoint_test.go b/tools/querytee/proxy_endpoint_test.go index 6edbff84bd5..375da003231 100644 --- a/tools/querytee/proxy_endpoint_test.go +++ b/tools/querytee/proxy_endpoint_test.go @@ -462,17 +462,16 @@ func Test_ProxyEndpoint_RelativeDurationMetric(t *testing.T) { secondaryResponseLatency: 2 * time.Second, }, }, - expectedDurationSampleSum: 5, - expectedProportionalSampleSum: (3.0/1 + 5.0/2), + expectedDurationSampleSum: -5, + expectedProportionalSampleSum: 1.0/3 + 2.0/5, }, "preferred backend is 5 seconds faster than secondary": { latencyPairs: []latencyPair{{ preferredResponseLatency: 2 * time.Second, secondaryResponseLatency: 7 * time.Second, - }, - }, - expectedDurationSampleSum: -5, - expectedProportionalSampleSum: (2.0 / 7), + }}, + expectedDurationSampleSum: 5, + expectedProportionalSampleSum: 7.0 / 2, }, } @@ -511,12 +510,12 @@ func Test_ProxyEndpoint_RelativeDurationMetric(t *testing.T) { gotDuration := filterMetrics(got, []string{"cortex_querytee_backend_response_relative_duration_seconds"}) require.Equal(t, 1, len(gotDuration), "Expect only one metric after filtering") require.Equal(t, uint64(len(scenario.latencyPairs)), gotDuration[0].Metric[0].Histogram.GetSampleCount()) - require.Equal(t, scenario.expectedDurationSampleSum, gotDuration[0].Metric[0].Histogram.GetSampleSum()) + require.InDelta(t, scenario.expectedDurationSampleSum, gotDuration[0].Metric[0].Histogram.GetSampleSum(), 1e-9) gotProportional := filterMetrics(got, []string{"cortex_querytee_backend_response_relative_duration_proportional"}) require.Equal(t, 1, len(gotProportional), "Expect only one metric after filtering") require.Equal(t, uint64(len(scenario.latencyPairs)), gotProportional[0].Metric[0].Histogram.GetSampleCount()) - require.Equal(t, scenario.expectedProportionalSampleSum, gotProportional[0].Metric[0].Histogram.GetSampleSum()) + require.InDelta(t, scenario.expectedProportionalSampleSum, gotProportional[0].Metric[0].Histogram.GetSampleSum(), 1e-9) }) } } diff --git a/tools/querytee/proxy_metrics.go b/tools/querytee/proxy_metrics.go index 10459f1639d..1fc6c197198 100644 --- a/tools/querytee/proxy_metrics.go +++ b/tools/querytee/proxy_metrics.go @@ -48,13 +48,13 @@ func NewProxyMetrics(registerer prometheus.Registerer) *ProxyMetrics { relativeDuration: promauto.With(registerer).NewHistogramVec(prometheus.HistogramOpts{ Namespace: queryTeeMetricsNamespace, Name: "backend_response_relative_duration_seconds", - Help: "Time (in seconds) of preferred backend less secondary backend.", + Help: "Time (in seconds) of secondary backend less preferred backend.", NativeHistogramBucketFactor: 1.1, }, []string{"route"}), proportionalDuration: promauto.With(registerer).NewHistogramVec(prometheus.HistogramOpts{ Namespace: queryTeeMetricsNamespace, Name: "backend_response_relative_duration_proportional", - Help: "Response time of preferred backend, as a proportion of secondary backend response time.", + Help: "Response time of secondary backend, as a proportion of preferred backend response time.", NativeHistogramBucketFactor: 1.1, }, []string{"route"}), }