Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 702 of 80210. Deployment Strategies and GitOpsFree lesson

Configuring Analysis Templates for Automated Promotion

Create reusable analysis templates that query monitoring systems to validate application health before promoting a rollout to the next phase.

In this lesson, you will learn how to leverage reusable AnalysisTemplates to programmatically validate your application’s health, enabling seamless automated promotion between deployment phases.

The Concept of Decoupled Validation

When performing progressive deliveries like Canary releases, you need a reliable way to decide if a new version is "healthy enough" to receive more traffic. Instead of hardcoding monitoring logic directly into your rollout strategy, we use AnalysisTemplates. These are Kubernetes custom resources that define how to query your observability stack (like Prometheus or Datadog) to verify metrics such as success rates or latency.

By defining these templates centrally, you can reuse them across multiple microservices. This ensures that your definition of "healthy" is consistent across your entire organization.

Anatomy of an Analysis Template

An AnalysisTemplate essentially acts as a function: you provide it with arguments (like the service-name or threshold), and it returns a result (Success, Failed, or Error).

apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate-check
spec:
  args:
  - name: service-name
  metrics:
  - name: success-rate
    successCondition: result[0] >= 0.95
    provider:
      prometheus:
        address: http://prometheus.monitoring.svc:9090
        query: |
          sum(rate(http_requests_total{service="{{args.service-name}}",status!~"5.*"}[1m])) 
          / sum(rate(http_requests_total{service="{{args.service-name}}"}[1m]))

Implementing Automated Promotion

Once your AnalysisTemplate is defined, your Rollout object references it during specific steps. By setting an analysis block within a canary step, the deployment controller pauses the traffic shift and triggers the template.

If the Prometheus query returns a value below 0.95, the analysis fails, and the controller triggers an automated rollback to the stable version. If it passes, the controller automatically proceeds to the next traffic weight increment. This creates a "closed-loop" system where the infrastructure self-regulates based on real-time performance data, removing the need for manual approval gates.

Key Takeaway: Analysis Templates allow you to standardize complex health-check logic, ensuring that automated promotions only occur when your monitoring data confirms the application meets predefined performance SLAs.