Skip to content

Commit

Permalink
Merge pull request #1023 from Infomaniak/hotfix/use-nginx-controller-…
Browse files Browse the repository at this point in the history
…canary-metrics

Use nginx controller canary metrics
  • Loading branch information
stefanprodan committed Sep 30, 2021
2 parents bce1d02 + 7d2f3de commit 01d4780
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/gitbook/tutorials/nginx-progressive-delivery.md
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
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
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
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
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

0 comments on commit 01d4780

Please sign in to comment.