From 593e21e3d153c9a1006c6e0c9638d574dd4e90f8 Mon Sep 17 00:00:00 2001 From: Rohit Agrawal Date: Thu, 7 Jul 2022 09:54:34 -0700 Subject: [PATCH] fix(analysis): Fix Analysis Terminal Decision For Dry-Run Metrics Signed-off-by: Rohit Agrawal --- utils/analysis/helpers.go | 4 +++- utils/analysis/helpers_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/utils/analysis/helpers.go b/utils/analysis/helpers.go index 64506ebae0..77583136af 100644 --- a/utils/analysis/helpers.go +++ b/utils/analysis/helpers.go @@ -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 } } return false diff --git a/utils/analysis/helpers_test.go b/utils/analysis/helpers_test.go index c7bd003c18..f9baf89f14 100644 --- a/utils/analysis/helpers_test.go +++ b/utils/analysis/helpers_test.go @@ -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{}