Skip to content

Commit

Permalink
Start adding inline analysis content
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunn1 committed Oct 23, 2023
1 parent 6db37f3 commit 737c6ca
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
kind: AnalysisTemplate
apiVersion: argoproj.io/v1alpha1
metadata:
name: smoke-tests
spec:
args:
- name: query
- name: route-url
- name: api-token
valueFrom:
secretKeyRef:
name: monitor-auth-secret
key: token
metrics:
- name: success-rate
interval: 30s
count: 4
# Prometheus queries return results in the form of a vector so it is
# common to access the index 0 of the returned array to obtain the value
successCondition: result[0].value[1] == '0'
failureLimit: 0
provider:
web:
url: https://thanos-querier.openshift-monitoring:9091/api/v1/query?query={{ args.query }}
insecure: true
headers:
- key: Authorization
value: "Bearer {{args.api-token}}"
jsonPath: "{$.data.result}"
- name: run-load
provider:
job:
spec:
backoffLimit: 1
template:
spec:
containers:
- name: siege
image: quay.io/gnunn/tools:latest
command: [sh, -c]
args: ["siege -c 20 -r 15 -d10 -v http://{{args.route-url}}"]
restartPolicy: Never
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
- analysistemplate.yaml
- rollout.yaml
- services.yaml
- routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollouts-demo
spec:
replicas: 8
revisionHistoryLimit: 10
selector:
matchLabels:
app: rollouts-demo
template:
metadata:
labels:
app: rollouts-demo
spec:
containers:
- name: rollouts-demo
image: quay.io/openshiftdemos/rollouts-demo:blue
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
strategy:
canary:
canaryService: canary
stableService: stable
steps:
- setWeight: 20
- analysis:
args:
- name: query
# Note encoded so it can be used as a query parameter, unencode:
# irate(haproxy_backend_http_responses_total{exported_namespace='rollouts-demo-prod',route=~'rollout-bluegreen-preview',code='5xx'}[1m])>5 or on() vector(0)
value: irate(haproxy_backend_http_responses_total%7Bexported_namespace='user%USER%-prod',route=~'canary',code='5xx'%7D%5B1m%5D)%3E5%20or%20on()%20vector(0)
- name: route-url
value: canary-user%USER%-prod.%SUB_DOMAIN%
templates:
- templateName: smoke-tests
- pause: {duration: 10s}
- setWeight: 60
- pause: {duration: 10s}
- setWeight: 80
- pause: {duration: 10s}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: stable
spec:
port:
targetPort: http
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: stable
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: canary
spec:
port:
targetPort: http
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: canary
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: all
annotations:
haproxy.router.openshift.io/disable_cookies: 'true'
haproxy.router.openshift.io/balance: roundrobin
spec:
port:
targetPort: http
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: all
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
name: stable
spec:
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: rollouts-demo
---
apiVersion: v1
kind: Service
metadata:
name: canary
spec:
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: rollouts-demo
---
apiVersion: v1
kind: Service
metadata:
name: all
spec:
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: rollouts-demo
83 changes: 82 additions & 1 deletion documentation/modules/ROOT/pages/05-canary-rollout.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,88 @@ oc argo rollouts promote rollouts-demo -n user%USERNUM%-prod
Observe the dashboard once it has been promoted, the dashboard will show the progression
of the steps by highlight each step as it is being executed.

Prior to moving on to the next section, perform a cleanup to remove the current rollout
and reset the Deployment in the dev environment back to blue.

Update the deployment:

[.console-input]
[source,bash,subs="attributes+,+macros"]
----
oc apply -k ./deploy/base -n user%USERNUM%-dev
----

Delete the current rollout:

[.console-input]
[source,bash,subs="attributes+,+macros"]
----
oc delete -k ./canary/base -n user%USERNUM%-prod
----

[#inline-analysis]
== Inline Analysis

In the last section there was a pause step that provided an opportunity
In the last section there was a pause step that provided an opportunity to test the canary
before progressing further. However we can accomplish the same goal my using an analysis. With
respect the canary strategy, an analysis can be performed in the link:https://argo-rollouts.readthedocs.io/en/stable/features/analysis/#background-analysis[background,window='_blank']
or as an link:https://argo-rollouts.readthedocs.io/en/stable/features/analysis/#inline-analysis[inline] analysis.

A background analysis happens asynchronously and does not block the progression of steps, however
if the analysis fails it will abort the rollout similar to what we saw in the previous module with
the blue-green strategy. In the case of an inline analysis, the analysis is performed as a step
and will block the progression of the rollout until it completes.

The files for this example are in the `./canary-analysis/base` folder, to view the list of files
perform an `ls` as follows:

[.console-input]
[source,bash,subs="attributes+,+macros"]
----
ls ./canary-analysis/base
----

Note that the files are identical to the previous example other then the `rollout.yaml` and the
`analysistemplate.yaml` file. The AnalysisTemplate being used here is identical to the one
we used in the blue-green example so we will not cover it again here.

The one change in the rollout is that it now as an inline analysis step.

.link:https://github.com/OpenShiftDemos/argo-rollouts-workshop/blob/main/documentation/modules/ROOT/examples/canary-analysis/base/rollout.yaml[./canary-analysis/base/rollout.yaml,window='_blank']
[source,yaml,subs="+macros,attributes+"]
----
include::ROOT:example$canary-analysis/base/rollout.yaml[]
----

Notice that the structure of the inline analysis is identical to what was used in the `prePromotionAnalysis`
in the blue-green rollout with analysis.

To deploy the canary with the inline analysis execute the following command:

[.console-input]
[source,bash,subs="attributes+,+macros"]
----
kustomize build ./canary-analysis/base | sed "s/%SUB_DOMAIN%/$SUB_DOMAIN/" | sed "s/%USER%/%USERNUM%/" | oc delete -n user%USERNUM%-prod -f -
----

Once the command has been executed, verify that the rollout was deployed:

[.console-input]
[source,bash,subs="attributes+,+macros"]
----
oc argo rollouts get rollout rollouts-demo -n user%USERNUM%-prod
----

You should see output as follows:

[.console-output]
[source,bash,subs="attributes+,+macros"]
----


----
Since we no longer have a manual pause step the promotion will occur automatically as long as the analysis step completes successfully.
While the analysis is executing, or at anytime during the promotion, you can view the progress either in the dashboard or with the
Argo Rollouts kubectl command.

0 comments on commit 737c6ca

Please sign in to comment.