Skip to content

Commit d52a5ce

Browse files
committed
chore: switch to duty const for severity
1 parent b63bedd commit d52a5ce

File tree

7 files changed

+33
-40
lines changed

7 files changed

+33
-40
lines changed

checks/runchecks.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/flanksource/canary-checker/pkg"
1010
"github.com/flanksource/canary-checker/pkg/db"
1111
"github.com/flanksource/commons/logger"
12+
"github.com/flanksource/duty/models"
1213
)
1314

1415
func RunChecks(ctx *context.Context) []*pkg.CheckResult {
@@ -127,29 +128,30 @@ func processTemplates(ctx *context.Context, r *pkg.CheckResult) *pkg.CheckResult
127128
return r
128129
}
129130

130-
func measureTestSeverity(ctx *context.Context, threshold *v1.TestThreshold) pkg.Severity {
131+
func measureTestSeverity(ctx *context.Context, threshold *v1.TestThreshold) models.Severity {
131132
if threshold == nil {
132-
return pkg.SeverityInfo
133+
return models.SeverityInfo
133134
}
134135

135136
thresholds := []struct {
136-
severity pkg.Severity
137+
severity models.Severity
137138
expr string
138139
}{
139-
{pkg.SeverityCritical, threshold.Critical},
140-
{pkg.SeverityHigh, threshold.High},
141-
{pkg.SeverityMedium, threshold.Medium},
142-
{pkg.SeverityLow, threshold.Low},
143-
{pkg.SeverityInfo, threshold.Info},
140+
{models.SeverityCritical, threshold.Critical},
141+
{models.SeverityHigh, threshold.High},
142+
{models.SeverityMedium, threshold.Medium},
143+
{models.SeverityLow, threshold.Low},
144+
{models.SeverityInfo, threshold.Info},
144145
}
145146

146147
for _, t := range thresholds {
147148
if res, err := template(ctx, v1.Template{Expression: t.expr}); err != nil {
148-
return pkg.SeverityInfo
149+
logger.Errorf("failed to run expression for severity: %s", t.severity)
150+
continue
149151
} else if res == "true" {
150152
return t.severity
151153
}
152154
}
153155

154-
return pkg.SeverityInfo
156+
return models.SeverityInfo
155157
}

checks/runchecks_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/flanksource/canary-checker/api/context"
88
v1 "github.com/flanksource/canary-checker/api/v1"
9-
"github.com/flanksource/canary-checker/pkg"
9+
"github.com/flanksource/duty/models"
1010
)
1111

1212
func Test_measureTestSeverity(t *testing.T) {
@@ -17,7 +17,7 @@ func Test_measureTestSeverity(t *testing.T) {
1717
tests := []struct {
1818
name string
1919
args args
20-
want pkg.Severity
20+
want models.Severity
2121
}{
2222
{
2323
name: "simple - critical",
@@ -27,7 +27,7 @@ func Test_measureTestSeverity(t *testing.T) {
2727
Critical: "duration > 1500",
2828
},
2929
},
30-
want: pkg.SeverityCritical,
30+
want: models.SeverityCritical,
3131
},
3232
{
3333
name: "simple - high",
@@ -38,7 +38,7 @@ func Test_measureTestSeverity(t *testing.T) {
3838
High: "duration > 1000",
3939
},
4040
},
41-
want: pkg.SeverityHigh,
41+
want: models.SeverityHigh,
4242
},
4343
{
4444
name: "simple - medium",
@@ -51,7 +51,7 @@ func Test_measureTestSeverity(t *testing.T) {
5151
Low: "duration > 500",
5252
},
5353
},
54-
want: pkg.SeverityMedium,
54+
want: models.SeverityMedium,
5555
},
5656
{
5757
name: "simple - low",
@@ -63,7 +63,7 @@ func Test_measureTestSeverity(t *testing.T) {
6363
Low: "duration > 500",
6464
},
6565
},
66-
want: pkg.SeverityLow,
66+
want: models.SeverityLow,
6767
},
6868
{
6969
name: "complex expression",
@@ -75,14 +75,14 @@ func Test_measureTestSeverity(t *testing.T) {
7575
Low: "duration > 500 && duration < 1000",
7676
},
7777
},
78-
want: pkg.SeverityInfo,
78+
want: models.SeverityInfo,
7979
},
8080
{
8181
name: "no threshold defined",
8282
args: args{
8383
duration: 600,
8484
},
85-
want: pkg.SeverityInfo,
85+
want: models.SeverityInfo,
8686
},
8787
{
8888
name: "no severity match",
@@ -94,7 +94,7 @@ func Test_measureTestSeverity(t *testing.T) {
9494
Low: "duration > 500",
9595
},
9696
},
97-
want: pkg.SeverityInfo,
97+
want: models.SeverityInfo,
9898
},
9999
{
100100
name: "invalid expression",
@@ -106,7 +106,7 @@ func Test_measureTestSeverity(t *testing.T) {
106106
Low: "duration > 500",
107107
},
108108
},
109-
want: pkg.SeverityInfo,
109+
want: models.SeverityInfo,
110110
},
111111
{
112112
name: "use of undefined var",
@@ -118,7 +118,7 @@ func Test_measureTestSeverity(t *testing.T) {
118118
Low: "Duration > 500",
119119
},
120120
},
121-
want: pkg.SeverityInfo,
121+
want: models.SeverityInfo,
122122
},
123123
}
124124
for _, tt := range tests {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/elastic/go-elasticsearch/v8 v8.1.0
2323
github.com/fergusstrange/embedded-postgres v1.21.0
2424
github.com/flanksource/commons v1.10.0
25-
github.com/flanksource/duty v1.0.113
25+
github.com/flanksource/duty v1.0.116
2626
github.com/flanksource/kommons v0.31.1
2727
github.com/friendsofgo/errors v0.9.2
2828
github.com/go-ldap/ldap/v3 v3.4.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,6 @@ github.com/fergusstrange/embedded-postgres v1.21.0 h1:Sups0nR31+OB4iOZ0ZU4IwUDsB
10911091
github.com/fergusstrange/embedded-postgres v1.21.0/go.mod h1:wL562t1V+iuFwq0UcgMi2e9rp8CROY9wxWZEfP8Y874=
10921092
github.com/flanksource/commons v1.10.0 h1:Mc+fzxq1rOJ08lapF0cc0bo9ZKNDxA7/81q2D/5jt0Q=
10931093
github.com/flanksource/commons v1.10.0/go.mod h1:HpVjPtNe7v0UPk97kO/uUhOrYQ8yFD/mGglrTCkc9Ag=
1094-
github.com/flanksource/duty v1.0.113 h1:iQeMhn/Vjz+Rap4TpniGEwLOXcFeg9+X1GtcUsWp3+g=
1095-
github.com/flanksource/duty v1.0.113/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk=
10961094
github.com/flanksource/gomplate/v3 v3.20.1/go.mod h1:LPpzujBIg9HBXRUngDKK/zNmEjHpEUieKa/2oRjkCzI=
10971095
github.com/flanksource/gomplate/v3 v3.20.3 h1:mnNaO37uwvv8Kvi4Xswj1tHKP5UMre3FLNaKvAwqhSw=
10981096
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=
36213619
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
36223620
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
36233621
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
3622+
github.com/flanksource/duty v1.0.116 h1:BU1Go53xj/P3LfZFrusP48e3lAo1KCJk0qcp+ye/p7s=
3623+
github.com/flanksource/duty v1.0.116/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk=

hack/generate-schemas/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ require (
7373
github.com/dustin/go-humanize v1.0.1 // indirect
7474
github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect
7575
github.com/emirpasic/gods v1.18.1 // indirect
76-
github.com/flanksource/duty v1.0.113 // indirect
76+
github.com/flanksource/duty v1.0.116 // indirect
7777
github.com/ghodss/yaml v1.0.0 // indirect
7878
github.com/go-logr/logr v1.2.4 // indirect
7979
github.com/go-openapi/inflect v0.19.0 // indirect

hack/generate-schemas/go.sum

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@ github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
811811
github.com/fergusstrange/embedded-postgres v1.21.0 h1:Sups0nR31+OB4iOZ0ZU4IwUDsB+dVGmcqj4S2ko0qTI=
812812
github.com/flanksource/commons v1.10.0 h1:Mc+fzxq1rOJ08lapF0cc0bo9ZKNDxA7/81q2D/5jt0Q=
813813
github.com/flanksource/commons v1.10.0/go.mod h1:HpVjPtNe7v0UPk97kO/uUhOrYQ8yFD/mGglrTCkc9Ag=
814-
github.com/flanksource/duty v1.0.113 h1:iQeMhn/Vjz+Rap4TpniGEwLOXcFeg9+X1GtcUsWp3+g=
815-
github.com/flanksource/duty v1.0.113/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk=
814+
github.com/flanksource/duty v1.0.116 h1:BU1Go53xj/P3LfZFrusP48e3lAo1KCJk0qcp+ye/p7s=
815+
github.com/flanksource/duty v1.0.116/go.mod h1:RJ/kcZ7dbL8/52tem757szVIA3IomS8bOAZIK0xb4rk=
816816
github.com/flanksource/gomplate/v3 v3.20.1/go.mod h1:LPpzujBIg9HBXRUngDKK/zNmEjHpEUieKa/2oRjkCzI=
817817
github.com/flanksource/gomplate/v3 v3.20.3 h1:mnNaO37uwvv8Kvi4Xswj1tHKP5UMre3FLNaKvAwqhSw=
818818
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
14811481
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
14821482
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
14831483
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
1484+
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
14841485
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
1485-
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
14861486
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
14871487
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
14881488
github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=

pkg/api.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/flanksource/canary-checker/pkg/utils"
1313
"github.com/flanksource/commons/console"
1414
"github.com/flanksource/commons/logger"
15+
"github.com/flanksource/duty/models"
1516
"github.com/google/uuid"
1617
"github.com/lib/pq"
1718
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -53,7 +54,7 @@ type CheckStatus struct {
5354
Error string `json:"error,omitempty"`
5455
Detail interface{} `json:"-"`
5556
Check *external.Check `json:"check,omitempty"`
56-
TestSeverity Severity `json:"test_severity,omitempty"`
57+
TestSeverity models.Severity `json:"severity,omitempty"`
5758
}
5859

5960
func (s CheckStatus) GetTime() (time.Time, error) {
@@ -394,16 +395,6 @@ type URL struct {
394395

395396
type SystemResult struct{}
396397

397-
type Severity int
398-
399-
const (
400-
SeverityInfo Severity = iota
401-
SeverityLow
402-
SeverityMedium
403-
SeverityHigh
404-
SeverityCritical
405-
)
406-
407398
type CheckResult struct {
408399
Start time.Time
409400
Pass bool
@@ -418,7 +409,7 @@ type CheckResult struct {
418409
Metrics []Metric
419410
Check external.Check // Check is the configuration
420411
Canary v1.Canary
421-
Severity Severity
412+
Severity models.Severity
422413
}
423414

424415
func (result CheckResult) GetDescription() string {

0 commit comments

Comments
 (0)