Skip to content

Commit

Permalink
Add metrics templates
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong committed Sep 15, 2023
1 parent efc5880 commit 04a1f2f
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 11 deletions.
72 changes: 69 additions & 3 deletions docs/gitbook/tutorials/linkerd-progressive-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
58 changes: 52 additions & 6 deletions test/linkerd/test-canary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ set -o errexit

REPO_ROOT=$(git rev-parse --show-toplevel)

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: success-rate
namespace: linkerd
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
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
Expand Down Expand Up @@ -59,12 +93,14 @@ spec:
maxWeight: 50
stepWeight: 10
metrics:
- name: request-success-rate
- name: success-rate
templateRef:
name: success-rate
namespace: linkerd
threshold: 99
interval: 1m
- name: request-duration
threshold: 500
interval: 30s
templateVariables:
direction: inbound
- name: latency
templateRef:
name: latency
Expand Down Expand Up @@ -218,12 +254,22 @@ spec:
maxWeight: 50
stepWeight: 10
metrics:
- name: request-success-rate
- name: success-rate
templateRef:
name: success-rate
namespace: linkerd
threshold: 99
interval: 1m
- name: request-duration
templateVariables:
direction: inbound
- name: latency
templateRef:
name: latency
namespace: linkerd
threshold: 500
interval: 30s
templateVariables:
direction: inbound
webhooks:
- name: http-acceptance-test
type: pre-rollout
Expand Down
73 changes: 71 additions & 2 deletions test/linkerd/test-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,65 @@

set -o errexit

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: success-rate
namespace: linkerd
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
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: latency
namespace: linkerd
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)
)
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: Canary
Expand Down Expand Up @@ -32,12 +91,22 @@ spec:
maxWeight: 50
stepWeights: [10, 20, 30, 40, 50, 60]
metrics:
- name: request-success-rate
- name: success-rate
templateRef:
name: success-rate
namespace: linkerd
threshold: 99
interval: 1m
- name: request-duration
templateVariables:
direction: inbound
- name: latency
templateRef:
name: latency
namespace: linkerd
threshold: 500
interval: 30s
templateVariables:
direction: inbound
webhooks:
- name: load-test
url: http://flagger-loadtester.test/
Expand Down

0 comments on commit 04a1f2f

Please sign in to comment.