In this lesson, you will learn how to automate the evaluation of your canary release health using Analysis Templates to ensure only stable code reaches your entire user base.
When performing a canary deployment, manually monitoring logs or metrics for errors is inefficient and error-prone. By integrating AnalysisTemplates, you define a declarative way for your orchestration tool (like Argo Rollouts) to "query" the state of your application during a rollout and make automated decisions.
How Automated Validation Works
An AnalysisTemplate acts as a reusable set of instructions that the controller executes while traffic is shifted to the canary version. It typically consists of a metric, which defines:
- The Provider: Where to fetch data (e.g., Prometheus).
- The Query: The specific metric to watch (e.g.,
http_requests_total{status="500"}). - The Threshold: What constitutes a "failure" (e.g., error rate > 1%).
By attaching this template to your canary strategy, the controller performs "checks" at set intervals. If the metrics exceed your thresholds, the controller triggers an automatic rollback to the stable version before the issue impacts a wider audience.
Example: Defining a Success Metric
Below is a simplified structure of an AnalysisTemplate checking for error rates via Prometheus:
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate-check
spec:
metrics:
- name: success-rate
successCondition: result[0] >= 0.99
provider:
prometheus:
address: http://prometheus.monitoring.svc:9090
query: |
sum(rate(http_requests_total{status!~"5.*"}[1m]))
/
sum(rate(http_requests_total[1m]))
In this setup, the deployment will pause during the canary phase, constantly polling this Prometheus query. If the success rate drops below 99%, the successCondition fails, the analysis terminates, and the system automatically halts the rollout—effectively decoupling your deployment speed from the human effort required for monitoring.
Key Takeaway: Integrating Analysis Templates transforms canary releases from static, timed traffic shifts into dynamic, self-validating deployments that automatically revert when performance metrics deviate from your defined objectives.