Skip to content

Commit 26433be

Browse files
authored
Fix: Failed analysis to degrade rollout when multiple metrics are analyzed (argoproj#1535)
* fix: analysis fail for inline multi metric analysis Signed-off-by: hari rongali <[email protected]> * fix: cleanup Signed-off-by: hari rongali <[email protected]>
1 parent 1ea418d commit 26433be

File tree

4 files changed

+106
-10
lines changed

4 files changed

+106
-10
lines changed

analysis/analysis.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,19 @@ func (c *Controller) assessRunStatus(run *v1alpha1.AnalysisRun, metrics []v1alph
434434
} else {
435435
// metric hasn't started running. possible cases where some of the metrics starts with delay
436436
everythingCompleted = false
437-
if terminating {
438-
// we have yet to take a single measurement, but have already been instructed to stop
439-
log.Infof("metric assessed %s: run terminated", v1alpha1.AnalysisPhaseSuccessful)
440-
return v1alpha1.AnalysisPhaseSuccessful, worstMessage
441-
}
442437
}
443438
}
444-
if !everythingCompleted {
445-
return v1alpha1.AnalysisPhaseRunning, ""
446-
}
447-
if worstStatus == "" {
448-
if terminating {
439+
440+
if terminating {
441+
if worstStatus == "" {
442+
// we have yet to take a single measurement, but have already been instructed to stop
443+
log.Infof("metric assessed %s: run terminated", v1alpha1.AnalysisPhaseSuccessful)
449444
return v1alpha1.AnalysisPhaseSuccessful, worstMessage
450445
}
446+
log.Infof("metric assessed %s: run terminated", worstStatus)
447+
return worstStatus, worstMessage
448+
}
449+
if !everythingCompleted || worstStatus == "" {
451450
return v1alpha1.AnalysisPhaseRunning, ""
452451
}
453452
return worstStatus, worstMessage

test/e2e/analysis_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (s *AnalysisSuite) SetupSuite() {
2828
s.ApplyManifests("@functional/analysistemplate-web-background.yaml")
2929
s.ApplyManifests("@functional/analysistemplate-sleep-job.yaml")
3030
s.ApplyManifests("@functional/analysistemplate-multiple-job.yaml")
31+
s.ApplyManifests("@functional/analysistemplate-fail-multiple-job.yaml")
3132
}
3233

3334
// convenience to generate a new service with a given name
@@ -109,6 +110,29 @@ func (s *AnalysisSuite) TestCanaryInlineMultipleAnalysis() {
109110
Then().
110111
ExpectAnalysisRunCount(1)
111112
}
113+
114+
func (s *AnalysisSuite) TestCanaryFailInlineMultipleAnalysis() {
115+
s.Given().
116+
RolloutObjects("@functional/rollout-degraded-inline-multiple-analysis.yaml").
117+
When().
118+
ApplyManifests().
119+
WaitForRolloutStatus("Healthy").
120+
Then().
121+
ExpectAnalysisRunCount(0).
122+
When().
123+
UpdateSpec().
124+
WaitForRolloutStatus("Paused").
125+
PromoteRollout().
126+
Sleep(1*time.Second). // promoting too fast causes test to flake
127+
Then().
128+
ExpectRolloutStatus("Progressing").
129+
When().
130+
WaitForInlineAnalysisRunPhase("Failed").
131+
WaitForRolloutStatus("Degraded").
132+
Then().
133+
ExpectRolloutStatus("Degraded")
134+
}
135+
112136
// TestBlueGreenAnalysis tests blue-green with pre/post analysis and then fast-tracked rollback
113137
func (s *AnalysisSuite) TestBlueGreenAnalysis() {
114138
original := `
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# AnalysisTemplate which sleeps for a specified duration and exits with a specified exit-code
2+
kind: AnalysisTemplate
3+
apiVersion: argoproj.io/v1alpha1
4+
metadata:
5+
name: multiple-job-fail
6+
spec:
7+
args:
8+
- name: duration
9+
value: 0s
10+
- name: exit-code
11+
value: "0"
12+
- name: count
13+
value: "1"
14+
metrics:
15+
- name: sleep-job
16+
initialDelay: 10000s
17+
count: 1
18+
provider:
19+
job:
20+
spec:
21+
template:
22+
spec:
23+
containers:
24+
- name: sleep-job
25+
image: nginx:1.19-alpine
26+
command: [sh, -c, -x]
27+
args: ["sleep {{args.duration}} && exit {{args.exit-code}}"]
28+
restartPolicy: Never
29+
backoffLimit: 0
30+
- name: sleep-job-rep
31+
count: 2
32+
interval: 1s
33+
failureLimit: 1
34+
provider:
35+
job:
36+
spec:
37+
template:
38+
spec:
39+
containers:
40+
- name: sleep-job
41+
image: nginx:1.19-alpine
42+
command: [sh, -c, -x]
43+
args: ["sleep {{args.duration}} && exit 1"]
44+
restartPolicy: Never
45+
backoffLimit: 0
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Rollout
3+
metadata:
4+
name: rollout-inline-analysis
5+
spec:
6+
strategy:
7+
canary:
8+
steps:
9+
- setWeight: 10
10+
- pause: {}
11+
- analysis:
12+
templates:
13+
- templateName: multiple-job-fail
14+
selector:
15+
matchLabels:
16+
app: rollout-inline-analysis
17+
template:
18+
metadata:
19+
labels:
20+
app: rollout-inline-analysis
21+
spec:
22+
containers:
23+
- name: rollouts-demo
24+
image: nginx:1.19-alpine
25+
resources:
26+
requests:
27+
memory: 16Mi
28+
cpu: 5m

0 commit comments

Comments
 (0)