Skip to content

Commit

Permalink
Fix Nginx request-duration query
Browse files Browse the repository at this point in the history
`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 <[email protected]>
  • Loading branch information
driv committed Jul 19, 2024
1 parent f38183b commit 2d5e289
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/metrics/observers/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!=""
Expand All @@ -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!=""
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/observers/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2d5e289

Please sign in to comment.