Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(analysis): Fix Analysis Terminal Decision For Dry-Run Metrics #2131

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ func TestAssessRunStatusErrorMessageAnalysisPhaseFail(t *testing.T) {

func TestAssessRunStatusErrorMessageAnalysisPhaseFailInDryRunMode(t *testing.T) {
status, message, dryRunSummary := StartAssessRunStatusErrorMessageAnalysisPhaseFail(t, true)
assert.Equal(t, v1alpha1.AnalysisPhaseSuccessful, status)
assert.Equal(t, v1alpha1.AnalysisPhaseRunning, status)
Copy link
Contributor

@harikrongali harikrongali Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is Running?
after steps are completed, isn't the result successful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Running" is actually the correct state here as these are the background runs which would keep running if there is no count specified.

assert.Equal(t, "", message)
expectedDryRunSummary := v1alpha1.RunSummary{
Count: 2,
Expand Down Expand Up @@ -1545,7 +1545,7 @@ func TestAssessRunStatusErrorMessageFromProvider(t *testing.T) {
func TestAssessRunStatusErrorMessageFromProviderInDryRunMode(t *testing.T) {
providerMessage := "Provider Error"
status, message, dryRunSummary := StartAssessRunStatusErrorMessageFromProvider(t, providerMessage, true)
assert.Equal(t, v1alpha1.AnalysisPhaseSuccessful, status)
assert.Equal(t, v1alpha1.AnalysisPhaseRunning, status)
assert.Equal(t, "", message)
expectedDryRunSummary := v1alpha1.RunSummary{
Count: 2,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ func TestAssessRunStatusMultipleFailures(t *testing.T) {

func TestAssessRunStatusMultipleFailuresInDryRunMode(t *testing.T) {
status, message, dryRunSummary := StartAssessRunStatusMultipleFailures(t, true)
assert.Equal(t, v1alpha1.AnalysisPhaseSuccessful, status)
assert.Equal(t, v1alpha1.AnalysisPhaseRunning, status)
assert.Equal(t, "", message)
expectedDryRunSummary := v1alpha1.RunSummary{
Count: 2,
Expand Down Expand Up @@ -1623,7 +1623,7 @@ func TestAssessRunStatusWorstMessageInReconcileAnalysisRun(t *testing.T) {

func TestAssessRunStatusWorstMessageInReconcileAnalysisRunInDryRunMode(t *testing.T) {
newRun := StartAssessRunStatusWorstMessageInReconcileAnalysisRun(t, true)
assert.Equal(t, v1alpha1.AnalysisPhaseSuccessful, newRun.Status.Phase)
assert.Equal(t, v1alpha1.AnalysisPhaseRunning, newRun.Status.Phase)
assert.Equal(t, "", newRun.Status.Message)
expectedDryRunSummary := v1alpha1.RunSummary{
Count: 2,
Expand Down
4 changes: 3 additions & 1 deletion utils/analysis/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func IsTerminating(run *v1alpha1.AnalysisRun) bool {
for _, res := range run.Status.MetricResults {
switch res.Phase {
case v1alpha1.AnalysisPhaseFailed, v1alpha1.AnalysisPhaseError, v1alpha1.AnalysisPhaseInconclusive:
return true
// If this metric is running in the dryRun mode then we don't care about the failures and hence the terminal
// decision shouldn't be affected.
return !res.DryRun
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if analysisRun is completed, then dryRun will keep it in running mode (argoCD UI shows as spinning and that will confuse users).
Don't we need default state or ignore analysis run state when dryRun is enabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I am wrong here.. eventually, analysis run will be completed

Copy link
Member Author

@agrawroh agrawroh Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harikrongali Yes, it'll only keep running if it's a background analysis where the count is not specified. Think of it as the case where there are no failures/errors and the AR keeps running in background until the rollout finishes.

Since we are only ignoring the state of the dry-run metrics, if a wet-run metric fails then it'd terminate immediately as expected.

}
}
return false
Expand Down
14 changes: 14 additions & 0 deletions utils/analysis/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,34 @@ func TestIsFastFailTerminating(t *testing.T) {
Name: "success-rate",
Phase: v1alpha1.AnalysisPhaseRunning,
},
{
Name: "dry-run-metric",
Phase: v1alpha1.AnalysisPhaseRunning,
DryRun: true,
},
},
},
}
// Verify that when the metric is not failing or in the error state then we don't terminate.
successRate := run.Status.MetricResults[1]
assert.False(t, IsTerminating(run))
// Metric failing in the dryRun mode shouldn't impact the terminal decision.
dryRunMetricResult := run.Status.MetricResults[2]
dryRunMetricResult.Phase = v1alpha1.AnalysisPhaseError
run.Status.MetricResults[2] = dryRunMetricResult
assert.False(t, IsTerminating(run))
// Verify that a wet run metric failure/error results in terminal decision.
successRate.Phase = v1alpha1.AnalysisPhaseError
run.Status.MetricResults[1] = successRate
assert.True(t, IsTerminating(run))
successRate.Phase = v1alpha1.AnalysisPhaseFailed
run.Status.MetricResults[1] = successRate
assert.True(t, IsTerminating(run))
// Verify that an inconclusive wet run metric results in terminal decision.
successRate.Phase = v1alpha1.AnalysisPhaseInconclusive
run.Status.MetricResults[1] = successRate
assert.True(t, IsTerminating(run))
// Verify that we don't terminate when there are no metric results or when the status is empty.
run.Status.MetricResults = nil
assert.False(t, IsTerminating(run))
run.Status = v1alpha1.AnalysisRunStatus{}
Expand Down