Skip to content

Commit

Permalink
Flip meaning of metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed Jun 11, 2024
1 parent d2f65bf commit b74d87f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tools/querytee/proxy_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 7 additions & 8 deletions tools/querytee/proxy_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions tools/querytee/proxy_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
}
Expand Down

0 comments on commit b74d87f

Please sign in to comment.