Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nginx controller canary metrics #1023

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/gitbook/tutorials/nginx-progressive-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This guide shows you how to use the NGINX ingress controller and Flagger to auto

## Prerequisites

Flagger requires a Kubernetes cluster **v1.19** or newer and NGINX ingress **v0.46** or newer.
Flagger requires a Kubernetes cluster **v1.19** or newer and NGINX ingress **v1.0.2** or newer.

Install the NGINX ingress controller with Helm v3:

Expand Down
10 changes: 7 additions & 3 deletions pkg/metrics/observers/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var nginxQueries = map[string]string{
nginx_ingress_controller_requests{
namespace="{{ namespace }}",
ingress="{{ ingress }}",
canary!="",
status!~"5.*"
}[{{ interval }}]
)
Expand All @@ -40,7 +41,8 @@ var nginxQueries = map[string]string{
rate(
nginx_ingress_controller_requests{
namespace="{{ namespace }}",
ingress="{{ ingress }}"
ingress="{{ ingress }}",
canary!=""
}[{{ interval }}]
)
)
Expand All @@ -50,7 +52,8 @@ var nginxQueries = map[string]string{
rate(
nginx_ingress_controller_ingress_upstream_latency_seconds_sum{
namespace="{{ namespace }}",
ingress="{{ ingress }}"
ingress="{{ ingress }}",
canary!=""
}[{{ interval }}]
)
)
Expand All @@ -59,7 +62,8 @@ var nginxQueries = map[string]string{
rate(
nginx_ingress_controller_ingress_upstream_latency_seconds_count{
namespace="{{ namespace }}",
ingress="{{ ingress }}"
ingress="{{ ingress }}",
canary!=""
}[{{ interval }}]
)
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/observers/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

func TestNginxObserver_GetRequestSuccessRate(t *testing.T) {
t.Run("ok", func(t *testing.T) {
expected := ` sum( rate( nginx_ingress_controller_requests{ namespace="nginx", ingress="podinfo", status!~"5.*" }[1m] ) ) / sum( rate( nginx_ingress_controller_requests{ namespace="nginx", ingress="podinfo" }[1m] ) ) * 100`
expected := ` sum( rate( nginx_ingress_controller_requests{ namespace="nginx", ingress="podinfo", canary!="", status!~"5.*" }[1m] ) ) / sum( rate( nginx_ingress_controller_requests{ namespace="nginx", ingress="podinfo", canary!="" }[1m] ) ) * 100`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
promql := r.URL.Query()["query"][0]
assert.Equal(t, expected, promql)
Expand Down 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" }[1m] ) ) / sum( rate( nginx_ingress_controller_ingress_upstream_latency_seconds_count{ namespace="nginx", ingress="podinfo" }[1m] ) ) * 1000`
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`

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
promql := r.URL.Query()["query"][0]
Expand Down
2 changes: 1 addition & 1 deletion test/nginx/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -o errexit

NGINX_HELM_VERSION=3.36.0 # ingress v0.49.0
NGINX_HELM_VERSION=4.0.3 # ingress v1.0.2
REPO_ROOT=$(git rev-parse --show-toplevel)

mkdir -p ${REPO_ROOT}/bin
Expand Down
48 changes: 4 additions & 44 deletions test/nginx/test-canary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,6 @@ spec:
EOF

echo '>>> Create metric templates'
cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: error-rate
namespace: ingress-nginx
spec:
provider:
type: prometheus
address: http://flagger-prometheus.ingress-nginx:9090
query: |
100 - sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="{{ namespace }}",
kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root",
status!~"5.*"
}[{{ interval }}]
)
)
/
sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="{{ namespace }}",
kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root"
}[{{ interval }}]
)
)
* 100
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
Expand Down Expand Up @@ -115,12 +81,9 @@ spec:
maxWeight: 40
stepWeight: 20
metrics:
- name: error-rate
templateRef:
name: error-rate
namespace: ingress-nginx
- name: request-success-rate
thresholdRange:
max: 1
min: 1
interval: 30s
- name: latency
templateRef:
Expand Down Expand Up @@ -255,12 +218,9 @@ spec:
x-user:
exact: "insider"
metrics:
- name: error-rate
templateRef:
name: error-rate
namespace: ingress-nginx
- name: request-success-rate
thresholdRange:
max: 1
min: 1
interval: 30s
- name: latency
templateRef:
Expand Down