Skip to content

Commit

Permalink
Use nginx controller canary metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Léopold Jacquot <leopold.jacquot@infomaniak.com>
  • Loading branch information
L3o-pold committed Sep 29, 2021
1 parent 374a55d commit bd723a7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 49 deletions.
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=3.38.0 # ingress v1.0.2
REPO_ROOT=$(git rev-parse --show-toplevel)

mkdir -p ${REPO_ROOT}/bin
Expand Down
45 changes: 3 additions & 42 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,10 +81,7 @@ spec:
maxWeight: 40
stepWeight: 20
metrics:
- name: error-rate
templateRef:
name: error-rate
namespace: ingress-nginx
- name: request-success-rate
thresholdRange:
max: 1
interval: 30s
Expand All @@ -135,6 +98,7 @@ spec:
metadata:
type: cmd
cmd: "hey -z 2m -q 10 -c 2 -host app.example.com http://ingress-nginx-controller.ingress-nginx"
logCmdOutput: "true"
EOF

echo '>>> Waiting for primary to be ready'
Expand Down Expand Up @@ -255,10 +219,7 @@ spec:
x-user:
exact: "insider"
metrics:
- name: error-rate
templateRef:
name: error-rate
namespace: ingress-nginx
- name: request-success-rate
thresholdRange:
max: 1
interval: 30s
Expand Down

0 comments on commit bd723a7

Please sign in to comment.