From 2d5e2891420c07f8bc4368c8b85c81536068d2b5 Mon Sep 17 00:00:00 2001 From: Federico Nafria Date: Fri, 19 Jul 2024 17:02:50 +0000 Subject: [PATCH] Fix Nginx request-duration query `nginx_ingress_controller_ingress_upstream_latency_seconds_sum` measures the connection latency, not the time it takes the backend to respond. Fixes #1685 Signed-off-by: Federico Nafria --- pkg/metrics/observers/nginx.go | 4 ++-- pkg/metrics/observers/nginx_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/metrics/observers/nginx.go b/pkg/metrics/observers/nginx.go index a49440f60..06e1745b2 100644 --- a/pkg/metrics/observers/nginx.go +++ b/pkg/metrics/observers/nginx.go @@ -50,7 +50,7 @@ var nginxQueries = map[string]string{ "request-duration": ` sum( rate( - nginx_ingress_controller_ingress_upstream_latency_seconds_sum{ + nginx_ingress_controller_response_duration_seconds_sum{ namespace="{{ namespace }}", ingress="{{ ingress }}", canary!="" @@ -60,7 +60,7 @@ var nginxQueries = map[string]string{ / sum( rate( - nginx_ingress_controller_ingress_upstream_latency_seconds_count{ + nginx_ingress_controller_response_duration_seconds_count{ namespace="{{ namespace }}", ingress="{{ ingress }}", canary!="" diff --git a/pkg/metrics/observers/nginx_test.go b/pkg/metrics/observers/nginx_test.go index 66b7f20bc..c7dd8ee34 100644 --- a/pkg/metrics/observers/nginx_test.go +++ b/pkg/metrics/observers/nginx_test.go @@ -89,7 +89,7 @@ func TestNginxObserver_GetRequestSuccessRate(t *testing.T) { } func TestNginxObserver_GetRequestDuration(t *testing.T) { - expected := ` sum( rate( nginx_ingress_controller_ingress_upstream_latency_seconds_sum{ namespace="nginx", ingress="podinfo", canary!="" }[1m] ) ) / sum( rate( nginx_ingress_controller_ingress_upstream_latency_seconds_count{ namespace="nginx", ingress="podinfo", canary!="" }[1m] ) ) * 1000` + expected := ` sum( rate( nginx_ingress_controller_response_duration_seconds_sum{ namespace="nginx", ingress="podinfo", canary!="" }[1m] ) ) / sum( rate( nginx_ingress_controller_response_duration_seconds_count{ namespace="nginx", ingress="podinfo", canary!="" }[1m] ) ) * 1000` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { promql := r.URL.Query()["query"][0]