From 04a1f2fa68f1124eaa8d1f1bab96b61a30782d7d Mon Sep 17 00:00:00 2001 From: Alex Leong Date: Fri, 15 Sep 2023 15:08:32 -0700 Subject: [PATCH] Add metrics templates Signed-off-by: Alex Leong --- .../tutorials/linkerd-progressive-delivery.md | 72 +++++++++++++++++- test/linkerd/test-canary.sh | 58 +++++++++++++-- test/linkerd/test-steps.sh | 73 ++++++++++++++++++- 3 files changed, 192 insertions(+), 11 deletions(-) diff --git a/docs/gitbook/tutorials/linkerd-progressive-delivery.md b/docs/gitbook/tutorials/linkerd-progressive-delivery.md index 63a319535..afd26adc3 100644 --- a/docs/gitbook/tutorials/linkerd-progressive-delivery.md +++ b/docs/gitbook/tutorials/linkerd-progressive-delivery.md @@ -75,9 +75,65 @@ Create a deployment and a horizontal pod autoscaler: kubectl apply -k https://github.com/fluxcd/flagger//kustomize/podinfo?ref=main ``` -Create a canary custom resource for the podinfo deployment: +Create a metrics template and canary custom resources for the podinfo deployment: ```yaml +--- +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: success-rate + namespace: test +spec: + provider: + type: prometheus + address: http://prometheus.linkerd-viz:9090 + query: | + sum( + rate( + response_total{ + namespace="{{ namespace }}", + deployment=~"{{ target }}", + classification!="failure", + direction="{{ variables.direction }}" + }[{{ interval }}] + ) + ) + / + sum( + rate( + response_total{ + namespace="{{ namespace }}", + deployment=~"{{ target }}", + direction="{{ variables.direction }}" + }[{{ interval }}] + ) + ) + * 100 +--- +apiVersion: flagger.app/v1beta1 +kind: MetricTemplate +metadata: + name: latency + namespace: test +spec: + provider: + type: prometheus + address: http://prometheus.linkerd-viz:9090 + query: | + histogram_quantile( + 0.99, + sum( + rate( + response_latency_ms_bucket{ + namespace="{{ namespace }}", + deployment=~"{{ target }}", + direction="{{ variables.direction }}" + }[{{ interval }}] + ) + ) by (le) + ) +--- apiVersion: flagger.app/v1beta1 kind: Canary metadata: @@ -122,18 +178,28 @@ spec: stepWeight: 5 # Linkerd Prometheus checks metrics: - - name: request-success-rate + - name: success-rate + templateRef: + name: success-rate + namespace: test # minimum req success rate (non 5xx responses) # percentage (0-100) thresholdRange: min: 99 interval: 1m - - name: request-duration + templateVariables: + direction: inbound + - name: latency + templateRef: + name: latency + namespace: test # maximum req duration P99 # milliseconds thresholdRange: max: 500 interval: 30s + templateVariables: + direction: inbound # testing (optional) webhooks: - name: acceptance-test diff --git a/test/linkerd/test-canary.sh b/test/linkerd/test-canary.sh index 69b3a032b..5abe335c3 100755 --- a/test/linkerd/test-canary.sh +++ b/test/linkerd/test-canary.sh @@ -6,6 +6,40 @@ set -o errexit REPO_ROOT=$(git rev-parse --show-toplevel) +cat <