Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Analysis and Metrics

  • AnalysisTemplate - reusable definition of metrics, providers and success criteria (ClusterAnalysisTemplate is the cluster-scoped version)
  • AnalysisRun - an instance of a template, created by a Rollout (or manually)
  • Result decides whether the rollout proceeds or aborts
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate
spec:
  args:
  - name: service-name
  metrics:
  - name: success-rate
    interval: 1m
    count: 5
    successCondition: result[0] >= 0.95
    failureLimit: 2
    provider:
      prometheus:
        address: http://prometheus.monitoring:9090
        query: |
          sum(rate(http_requests_total{service="{{args.service-name}}",status=~"2.."}[5m])) /
          sum(rate(http_requests_total{service="{{args.service-name}}"}[5m]))
  • Prometheus returns a vector so use result[0]

Metric fields

  • interval - how often to measure
  • initialDelay - wait before first measurement
  • count - number of measurements. If omitted it runs until terminated (background)
  • successCondition / failureCondition / inconclusiveCondition - expressions on result
  • failureLimit - failed measurements tolerated, default 0
  • inconclusiveLimit - inconclusive measurements tolerated
  • consecutiveErrorLimit - consecutive errors tolerated, default 4
  • provider
  • Template level: args, dryRun (metric evaluated but never fails the rollout), measurementRetention
successCondition: result >= 0.90 && result <= 1.00
failureCondition: result >= 0.10
inconclusiveCondition: result >= 0.05 && result < 0.10
successCondition: result == "healthy"
  • Expression language is expr
  • Inconclusive pauses the rollout for manual decision

Providers

  • Prometheus - address + query
  • Datadog
    • query with interval
    • credentials in a Secret named datadog (address, api-key, app-key)
  • CloudWatch - metricDataQueries, uses AWS credentials of the controller
  • New Relic - NRQL query, Secret named newrelic (personal-api-key, account-id)
  • Wavefront - address + query
  • Web - HTTP call, extract with jsonPath
  • Job - runs a Kubernetes Job, success if it exits 0
provider:
  web:
    url: "http://my-server/api/v1/measurement?service={{args.service-name}}"
    timeoutSeconds: 20
    headers:
    - key: Authorization
      value: "Bearer {{ secret.token }}"
    jsonPath: "{$.success}"
provider:
  job:
    spec:
      template:
        spec:
          containers:
          - name: test
            image: curlimages/curl:latest
            command: ["/bin/sh", "-c", "curl -f http://my-app/health"]
          restartPolicy: Never
      backoffLimit: 1

AnalysisRun

  • Phases: Pending, Running, Successful, Failed, Error, Inconclusive
  • status.metricResults holds the measurements
kubectl get analysisrun
kubectl describe analysisrun <name>
kubectl argo rollouts get rollout my-app     # shows runs
kubectl argo rollouts terminate analysisrun <name>

Using it in a Rollout

  • Background analysis (canary):
strategy:
  canary:
    analysis:
      templates:
      - templateName: success-rate
      startingStep: 1
      args:
      - name: service-name
        value: my-app-canary
  • Step analysis (blocks until done):
steps:
- setWeight: 20
- analysis:
    templates:
    - templateName: smoke-tests
  • Blue-green: prePromotionAnalysis and postPromotionAnalysis, see blue-green
  • Failed analysis aborts and rolls back automatically