Skip to content

Commit 1e52def

Browse files
harikrongalijessesuen
authored andcommitted
fix: analysis runs to wait for all metrics to complete (argoproj#1407)
Signed-off-by: hari rongali <[email protected]>
1 parent 6d84b7e commit 1e52def

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

analysis/analysis.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,14 @@ func (c *Controller) assessRunStatus(run *v1alpha1.AnalysisRun) (v1alpha1.Analys
396396
}
397397
}
398398
}
399+
} else {
400+
// metric hasn't started running. possible cases where some of the metrics starts with delay
401+
everythingCompleted = false
402+
if terminating {
403+
// we have yet to take a single measurement, but have already been instructed to stop
404+
log.Infof("metric assessed %s: run terminated", v1alpha1.AnalysisPhaseSuccessful)
405+
return v1alpha1.AnalysisPhaseSuccessful, worstMessage
406+
}
399407
}
400408
}
401409
if !everythingCompleted {

test/e2e/analysis_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func (s *AnalysisSuite) SetupSuite() {
2525
// shared analysis templates for suite
2626
s.ApplyManifests("@functional/analysistemplate-web-background.yaml")
2727
s.ApplyManifests("@functional/analysistemplate-sleep-job.yaml")
28+
s.ApplyManifests("@functional/analysistemplate-multiple-job.yaml")
2829
}
2930

3031
// convenience to generate a new service with a given name
@@ -84,6 +85,28 @@ func (s *AnalysisSuite) TestCanaryInlineAnalysis() {
8485
ExpectAnalysisRunCount(3)
8586
}
8687

88+
func (s *AnalysisSuite) TestCanaryInlineMultipleAnalysis() {
89+
s.Given().
90+
RolloutObjects("@functional/rollout-inline-multiple-analysis.yaml").
91+
When().
92+
ApplyManifests().
93+
WaitForRolloutStatus("Healthy").
94+
Then().
95+
ExpectAnalysisRunCount(0).
96+
When().
97+
UpdateSpec().
98+
WaitForRolloutStatus("Paused").
99+
PromoteRollout().
100+
Sleep(5 * time.Second).
101+
Then().
102+
ExpectAnalysisRunCount(1).
103+
ExpectInlineAnalysisRunPhase("Running").
104+
When().
105+
WaitForInlineAnalysisRunPhase("Successful").
106+
WaitForRolloutStatus("Healthy").
107+
Then().
108+
ExpectAnalysisRunCount(1)
109+
}
87110
// TestBlueGreenAnalysis tests blue-green with pre/post analysis and then fast-tracked rollback
88111
func (s *AnalysisSuite) TestBlueGreenAnalysis() {
89112
original := `
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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
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: 10s
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: 1
32+
provider:
33+
job:
34+
spec:
35+
template:
36+
spec:
37+
containers:
38+
- name: sleep-job
39+
image: nginx:1.19-alpine
40+
command: [sh, -c, -x]
41+
args: ["sleep {{args.duration}} && exit {{args.exit-code}}"]
42+
restartPolicy: Never
43+
backoffLimit: 0

test/e2e/functional/analysistemplate-sleep-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ spec:
2525
command: [sh, -c, -x]
2626
args: ["sleep {{args.duration}} && exit {{args.exit-code}}"]
2727
restartPolicy: Never
28-
backoffLimit: 0
28+
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
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

test/fixtures/then.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,26 @@ func (t *Then) ExpectBackgroundAnalysisRunPhase(phase string) *Then {
194194
)
195195
}
196196

197+
func (t *Then) ExpectInlineAnalysisRun(expectation string, expectFunc AnalysisRunExpectation) *Then {
198+
t.t.Helper()
199+
bgArun := t.GetInlineAnalysisRun()
200+
if !expectFunc(bgArun) {
201+
t.log.Errorf("Inline AnalysisRun expectation '%s' failed", expectation)
202+
t.t.FailNow()
203+
}
204+
t.log.Infof("Inline AnalysisRun expectation '%s' met", expectation)
205+
return t
206+
}
207+
208+
func (t *Then) ExpectInlineAnalysisRunPhase(phase string) *Then {
209+
t.t.Helper()
210+
return t.ExpectInlineAnalysisRun(fmt.Sprintf("inline analysis phase == %s", phase),
211+
func(run *rov1.AnalysisRun) bool {
212+
return string(run.Status.Phase) == phase
213+
},
214+
)
215+
}
216+
197217
// ExpectStableRevision verifies the ReplicaSet with the specified revision is marked stable
198218
func (t *Then) ExpectStableRevision(revision string) *Then {
199219
t.t.Helper()

0 commit comments

Comments
 (0)