Analysis Templates Reference
An AnalysisTemplate
is a resource that defines how to perform verification
testing, including:
- Container images and commands to run
- Queries to external monitoring tools
- How to interpret results from metric providers
- Success or failure criteria
- Frequency and duration of measurements
AnalysisTemplate
resources (and the AnalysisRun
resources that are spawned
from them) are CRDs re-used from the
Argo Rollouts project. They were
intentionally built to be useful in contexts other than Argo Rollouts. Re-using
this resource type to define verification processes means those processes
benefit from this rich and battle-tested feature of Argo Rollouts.
This reference guide is intended to give a brief introduction to
AnalysisTemplate
s for some common use cases. Please consult the
relevant sections
of the Argo Rollouts documentation for comprehensive coverage of the full
range of AnalysisTemplate
capabilities.
AnalysisTemplate
s integrate natively with many popular open-source and
commercial monitoring tools, including:
In addition to monitoring tools, analysis can integrate with internal systems by:
- Running containerized processes as Kubernetes
Job
s - Making HTTP requests and interpreting JSON responses
Arguments
AnalysisTemplate
s may declare a set of arguments that can be "passed" in by
the Stage
. The arguments are resolved at the time the AnalysisRun
is
created and can then be referenced in metrics configuration. Arguments are
dereferenced using the syntax: {{ args.<name> }}
.
Unlike Kargo promotion processes, which require expressions to be enclosed
within ${{ }}
, Argo Rollouts AnalysisTemplate
s require expressions to be
enclosed within {{ }}
(i.e. without $
).
The following example shows an AnalysisTemplate
with three arguments. Values
for arguments can have a default value, supplied by the Stage
, or obtained
from a Secret
if the value is sensitive (e.g. a bearer token for an HTTP
request):
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: args-example
spec:
args:
# An argument can specify a value to be used as its default.
# This will be overridden by a value supplied by the Stage.
- name: api-url
value: http://example/measure
# If an argument specifies no value, it is considered a required
# argument and must be supplied by the Stage.
- name: service-name
# Arguments can be obtained from a Secret in the Project Namespace
- name: api-token
valueFrom:
secretKeyRef:
name: token-secret
key: apiToken
metrics:
- name: webmetric
successCondition: result == 'true'
provider:
web:
# placeholders are resolved when an AnalysisRun is created
url: "{{ args.api-url }}?service={{ args.service-name }}"
headers:
- key: Authorization
value: "Bearer {{ args.api-token }}"
jsonPath: "{$.results.ok}"
Interval and Count
To collect multiple measurements over a longer duration, use the
count
and interval
fields. This allows you to define how many
measurements to take and how frequently to take them.
In the example below, the analysis is configured to take 20 measurements at 3-minute intervals, resulting in a total duration of approximately 1 hour:
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: count-interval-example
spec:
metrics:
- name: test
# Number of measurements to take
count: 20
# Time interval between each measurement as a duration string
interval: 3m
provider:
web:
url: https://pokeapi.co/api/v2/pokemon/pikachu
When specifying an interval
, you must also specify a count
. Without
it, the AnalysisRun would collect an indefinite amount of measurements
and never complete (until terminated).