diff --git a/checks/runchecks.go b/checks/runchecks.go index 4ee8cd6b7..6c6cca748 100644 --- a/checks/runchecks.go +++ b/checks/runchecks.go @@ -9,6 +9,7 @@ import ( "github.com/flanksource/canary-checker/pkg" "github.com/flanksource/canary-checker/pkg/db" "github.com/flanksource/commons/logger" + "github.com/flanksource/duty/models" ) func RunChecks(ctx *context.Context) []*pkg.CheckResult { @@ -127,29 +128,30 @@ func processTemplates(ctx *context.Context, r *pkg.CheckResult) *pkg.CheckResult return r } -func measureTestSeverity(ctx *context.Context, threshold *v1.TestThreshold) pkg.Severity { +func measureTestSeverity(ctx *context.Context, threshold *v1.TestThreshold) models.Severity { if threshold == nil { - return pkg.SeverityInfo + return models.SeverityInfo } thresholds := []struct { - severity pkg.Severity + severity models.Severity expr string }{ - {pkg.SeverityCritical, threshold.Critical}, - {pkg.SeverityHigh, threshold.High}, - {pkg.SeverityMedium, threshold.Medium}, - {pkg.SeverityLow, threshold.Low}, - {pkg.SeverityInfo, threshold.Info}, + {models.SeverityCritical, threshold.Critical}, + {models.SeverityHigh, threshold.High}, + {models.SeverityMedium, threshold.Medium}, + {models.SeverityLow, threshold.Low}, + {models.SeverityInfo, threshold.Info}, } for _, t := range thresholds { if res, err := template(ctx, v1.Template{Expression: t.expr}); err != nil { - return pkg.SeverityInfo + logger.Errorf("failed to run expression for severity: %s", t.severity) + continue } else if res == "true" { return t.severity } } - return pkg.SeverityInfo + return models.SeverityInfo } diff --git a/checks/runchecks_test.go b/checks/runchecks_test.go index e3f471817..c8229cdd3 100644 --- a/checks/runchecks_test.go +++ b/checks/runchecks_test.go @@ -6,7 +6,7 @@ import ( "github.com/flanksource/canary-checker/api/context" v1 "github.com/flanksource/canary-checker/api/v1" - "github.com/flanksource/canary-checker/pkg" + "github.com/flanksource/duty/models" ) func Test_measureTestSeverity(t *testing.T) { @@ -17,7 +17,7 @@ func Test_measureTestSeverity(t *testing.T) { tests := []struct { name string args args - want pkg.Severity + want models.Severity }{ { name: "simple - critical", @@ -27,7 +27,7 @@ func Test_measureTestSeverity(t *testing.T) { Critical: "duration > 1500", }, }, - want: pkg.SeverityCritical, + want: models.SeverityCritical, }, { name: "simple - high", @@ -38,7 +38,7 @@ func Test_measureTestSeverity(t *testing.T) { High: "duration > 1000", }, }, - want: pkg.SeverityHigh, + want: models.SeverityHigh, }, { name: "simple - medium", @@ -51,7 +51,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.SeverityMedium, + want: models.SeverityMedium, }, { name: "simple - low", @@ -63,7 +63,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.SeverityLow, + want: models.SeverityLow, }, { name: "complex expression", @@ -75,14 +75,14 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500 && duration < 1000", }, }, - want: pkg.SeverityInfo, + want: models.SeverityInfo, }, { name: "no threshold defined", args: args{ duration: 600, }, - want: pkg.SeverityInfo, + want: models.SeverityInfo, }, { name: "no severity match", @@ -94,7 +94,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.SeverityInfo, + want: models.SeverityInfo, }, { name: "invalid expression", @@ -106,7 +106,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.SeverityInfo, + want: models.SeverityInfo, }, { name: "use of undefined var", @@ -118,7 +118,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "Duration > 500", }, }, - want: pkg.SeverityInfo, + want: models.SeverityInfo, }, } for _, tt := range tests { diff --git a/go.mod b/go.mod index b8473af16..d5057c091 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/elastic/go-elasticsearch/v8 v8.1.0 github.com/fergusstrange/embedded-postgres v1.21.0 github.com/flanksource/commons v1.10.0 - github.com/flanksource/duty v1.0.113 + github.com/flanksource/duty v1.0.116 github.com/flanksource/kommons v0.31.1 github.com/friendsofgo/errors v0.9.2 github.com/go-ldap/ldap/v3 v3.4.1 diff --git a/go.sum b/go.sum index deb0c11f5..50b362b2d 100644 --- a/go.sum +++ b/go.sum @@ -1091,8 +1091,6 @@ github.com/fergusstrange/embedded-postgres v1.21.0 h1:Sups0nR31+OB4iOZ0ZU4IwUDsB github.com/fergusstrange/embedded-postgres v1.21.0/go.mod h1:wL562t1V+iuFwq0UcgMi2e9rp8CROY9wxWZEfP8Y874= github.com/flanksource/commons v1.10.0 h1:Mc+fzxq1rOJ08lapF0cc0bo9ZKNDxA7/81q2D/5jt0Q= github.com/flanksource/commons v1.10.0/go.mod h1:HpVjPtNe7v0UPk97kO/uUhOrYQ8yFD/mGglrTCkc9Ag= -github.com/flanksource/duty v1.0.113 h1:iQeMhn/Vjz+Rap4TpniGEwLOXcFeg9+X1GtcUsWp3+g= -github.com/flanksource/duty v1.0.113/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk= github.com/flanksource/gomplate/v3 v3.20.1/go.mod h1:LPpzujBIg9HBXRUngDKK/zNmEjHpEUieKa/2oRjkCzI= github.com/flanksource/gomplate/v3 v3.20.3 h1:mnNaO37uwvv8Kvi4Xswj1tHKP5UMre3FLNaKvAwqhSw= github.com/flanksource/gomplate/v3 v3.20.3/go.mod h1:l4iCvp30TdhZk89eRGuNkPwlRjJLXdUSblr+VyuZfAk= @@ -3621,3 +3619,5 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= +github.com/flanksource/duty v1.0.116 h1:BU1Go53xj/P3LfZFrusP48e3lAo1KCJk0qcp+ye/p7s= +github.com/flanksource/duty v1.0.116/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk= \ No newline at end of file diff --git a/hack/generate-schemas/go.mod b/hack/generate-schemas/go.mod index 276823dba..df8fc8df0 100644 --- a/hack/generate-schemas/go.mod +++ b/hack/generate-schemas/go.mod @@ -73,7 +73,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect github.com/emirpasic/gods v1.18.1 // indirect - github.com/flanksource/duty v1.0.113 // indirect + github.com/flanksource/duty v1.0.116 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/inflect v0.19.0 // indirect diff --git a/hack/generate-schemas/go.sum b/hack/generate-schemas/go.sum index cd4aa426e..5b535f67d 100644 --- a/hack/generate-schemas/go.sum +++ b/hack/generate-schemas/go.sum @@ -811,8 +811,8 @@ github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/fergusstrange/embedded-postgres v1.21.0 h1:Sups0nR31+OB4iOZ0ZU4IwUDsB+dVGmcqj4S2ko0qTI= github.com/flanksource/commons v1.10.0 h1:Mc+fzxq1rOJ08lapF0cc0bo9ZKNDxA7/81q2D/5jt0Q= github.com/flanksource/commons v1.10.0/go.mod h1:HpVjPtNe7v0UPk97kO/uUhOrYQ8yFD/mGglrTCkc9Ag= -github.com/flanksource/duty v1.0.113 h1:iQeMhn/Vjz+Rap4TpniGEwLOXcFeg9+X1GtcUsWp3+g= -github.com/flanksource/duty v1.0.113/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk= +github.com/flanksource/duty v1.0.116 h1:BU1Go53xj/P3LfZFrusP48e3lAo1KCJk0qcp+ye/p7s= +github.com/flanksource/duty v1.0.116/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk= github.com/flanksource/gomplate/v3 v3.20.1/go.mod h1:LPpzujBIg9HBXRUngDKK/zNmEjHpEUieKa/2oRjkCzI= github.com/flanksource/gomplate/v3 v3.20.3 h1:mnNaO37uwvv8Kvi4Xswj1tHKP5UMre3FLNaKvAwqhSw= github.com/flanksource/gomplate/v3 v3.20.3/go.mod h1:l4iCvp30TdhZk89eRGuNkPwlRjJLXdUSblr+VyuZfAk= @@ -1481,8 +1481,8 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= diff --git a/pkg/api.go b/pkg/api.go index 0c4e69cc5..249312c34 100644 --- a/pkg/api.go +++ b/pkg/api.go @@ -12,6 +12,7 @@ import ( "github.com/flanksource/canary-checker/pkg/utils" "github.com/flanksource/commons/console" "github.com/flanksource/commons/logger" + "github.com/flanksource/duty/models" "github.com/google/uuid" "github.com/lib/pq" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -53,7 +54,7 @@ type CheckStatus struct { Error string `json:"error,omitempty"` Detail interface{} `json:"-"` Check *external.Check `json:"check,omitempty"` - TestSeverity Severity `json:"test_severity,omitempty"` + TestSeverity models.Severity `json:"severity,omitempty"` } func (s CheckStatus) GetTime() (time.Time, error) { @@ -394,16 +395,6 @@ type URL struct { type SystemResult struct{} -type Severity int - -const ( - SeverityInfo Severity = iota - SeverityLow - SeverityMedium - SeverityHigh - SeverityCritical -) - type CheckResult struct { Start time.Time Pass bool @@ -418,7 +409,7 @@ type CheckResult struct { Metrics []Metric Check external.Check // Check is the configuration Canary v1.Canary - Severity Severity + Severity models.Severity } func (result CheckResult) GetDescription() string {