Skip to content

Commit e7b448c

Browse files
committed
Use an error to indicate stopping investigations.
The error can convey more information than a simple bool. If it's nil = all good, otherwise the error can be returned why the investigation was stopped.
1 parent dcb1c9d commit e7b448c

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

cadctl/cmd/investigate/investigate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func run(cmd *cobra.Command, _ []string) error {
120120
}
121121
return err
122122
}
123-
if result.StopInvestigations {
124-
return nil
123+
if result.StopInvestigations != nil {
124+
return result.StopInvestigations
125125
}
126126

127127
ccamInvestigation := ccam.Investigation{}

pkg/investigations/investigation/investigation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type InvestigationResult struct {
2424
ServiceLogSent InvestigationStep
2525

2626
// If multiple investigations might be run this can indicate a fatal error that makes running additional investigations useless.
27-
// Uses a false-default so it must be set expclicitly by an investigation.
28-
StopInvestigations bool
27+
// If nil, investigations should continue. If not nil, should contain a meaningful error message explaining why investigations must stop.
28+
StopInvestigations error
2929
}
3030

3131
func NewResourceBuilder(pdClient pagerduty.Client, clusterId string, name string, logLevel string, pipelineName string) (ResourceBuilder, error) {

pkg/investigations/precheck/precheck.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package precheck
22

33
import (
4+
"errors"
5+
46
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
57
investigation "github.com/openshift/configuration-anomaly-detection/pkg/investigations/investigation"
68
"github.com/openshift/configuration-anomaly-detection/pkg/logging"
@@ -23,13 +25,13 @@ func (c *ClusterStatePrecheck) Run(rb investigation.ResourceBuilder) (investigat
2325
ocmClient := r.OcmClient
2426
if cluster.State() == cmv1.ClusterStateUninstalling {
2527
logging.Info("Cluster is uninstalling and requires no investigation. Silencing alert.")
26-
result.StopInvestigations = true
28+
result.StopInvestigations = errors.New("cluster is already uninstalling")
2729
return result, pdClient.SilenceIncidentWithNote("CAD: Cluster is already uninstalling, silencing alert.")
2830
}
2931

3032
if cluster.AWS() == nil {
3133
logging.Info("Cloud provider unsupported, forwarding to primary.")
32-
result.StopInvestigations = true
34+
result.StopInvestigations = errors.New("unsupported cloud provider (non-AWS)")
3335
return result, pdClient.EscalateIncidentWithNote("CAD could not run an automated investigation on this cluster: unsupported cloud provider.")
3436
}
3537

@@ -39,7 +41,7 @@ func (c *ClusterStatePrecheck) Run(rb investigation.ResourceBuilder) (investigat
3941
}
4042
if isAccessProtected {
4143
logging.Info("Cluster is access protected. Escalating alert.")
42-
result.StopInvestigations = true
44+
result.StopInvestigations = errors.New("cluster is access protected")
4345
return result, pdClient.EscalateIncidentWithNote("CAD is unable to run against access protected clusters. Please investigate.")
4446
}
4547
return result, nil

pkg/investigations/precheck/precheck_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package precheck
22

33
import (
4+
"errors"
45
"reflect"
56
"testing"
67

@@ -35,7 +36,7 @@ func TestInvestigation_Run(t *testing.T) {
3536
PdClient: pdClient,
3637
},
3738
}},
38-
investigation.InvestigationResult{StopInvestigations: true},
39+
investigation.InvestigationResult{StopInvestigations: errors.New("unsupported cloud provider (non-AWS)")},
3940
false,
4041
},
4142
}

0 commit comments

Comments
 (0)