From 2430cb939efac248b115b10257a574cfe9fad875 Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 15 Jun 2023 16:57:09 +0545 Subject: [PATCH] chore: rename to just "Severity". Removed "Test" prefix --- checks/runchecks.go | 22 +++++++++++----------- checks/runchecks_test.go | 20 ++++++++++---------- pkg/api.go | 23 +++++++++++------------ 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/checks/runchecks.go b/checks/runchecks.go index b9c3813a4..35bfb2ab4 100644 --- a/checks/runchecks.go +++ b/checks/runchecks.go @@ -105,7 +105,7 @@ func processTemplates(ctx *context.Context, r *pkg.CheckResult) *pkg.CheckResult switch v := r.Check.(type) { case v1.TestFunction: data := map[string]any{"duration": r.Duration} - r.TestSeverity = measureTestSeverity(ctx.New(data), v.GetTestThreshold()) + r.Severity = measureTestSeverity(ctx.New(data), v.GetTestThreshold()) tpl := v.GetTestTemplate() if tpl.IsEmpty() { @@ -127,29 +127,29 @@ func processTemplates(ctx *context.Context, r *pkg.CheckResult) *pkg.CheckResult return r } -func measureTestSeverity(ctx *context.Context, threshold *v1.TestThreshold) pkg.TestSeverity { +func measureTestSeverity(ctx *context.Context, threshold *v1.TestThreshold) pkg.Severity { if threshold == nil { - return pkg.TestSeverityInfo + return pkg.SeverityInfo } thresholds := []struct { - severity pkg.TestSeverity + severity pkg.Severity expr string }{ - {pkg.TestSeverityCritical, threshold.Critical}, - {pkg.TestSeverityHigh, threshold.High}, - {pkg.TestSeverityMedium, threshold.Medium}, - {pkg.TestSeverityLow, threshold.Low}, - {pkg.TestSeverityInfo, threshold.Info}, + {pkg.SeverityCritical, threshold.Critical}, + {pkg.SeverityHigh, threshold.High}, + {pkg.SeverityMedium, threshold.Medium}, + {pkg.SeverityLow, threshold.Low}, + {pkg.SeverityInfo, threshold.Info}, } for _, t := range thresholds { if res, err := template(ctx, v1.Template{Expression: t.expr}); err != nil { - return pkg.TestSeverityInfo + return pkg.SeverityInfo } else if res == "true" { return t.severity } } - return pkg.TestSeverityInfo + return pkg.SeverityInfo } diff --git a/checks/runchecks_test.go b/checks/runchecks_test.go index 3fd588b3b..e3f471817 100644 --- a/checks/runchecks_test.go +++ b/checks/runchecks_test.go @@ -17,7 +17,7 @@ func Test_measureTestSeverity(t *testing.T) { tests := []struct { name string args args - want pkg.TestSeverity + want pkg.Severity }{ { name: "simple - critical", @@ -27,7 +27,7 @@ func Test_measureTestSeverity(t *testing.T) { Critical: "duration > 1500", }, }, - want: pkg.TestSeverityCritical, + want: pkg.SeverityCritical, }, { name: "simple - high", @@ -38,7 +38,7 @@ func Test_measureTestSeverity(t *testing.T) { High: "duration > 1000", }, }, - want: pkg.TestSeverityHigh, + want: pkg.SeverityHigh, }, { name: "simple - medium", @@ -51,7 +51,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.TestSeverityMedium, + want: pkg.SeverityMedium, }, { name: "simple - low", @@ -63,7 +63,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.TestSeverityLow, + want: pkg.SeverityLow, }, { name: "complex expression", @@ -75,14 +75,14 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500 && duration < 1000", }, }, - want: pkg.TestSeverityInfo, + want: pkg.SeverityInfo, }, { name: "no threshold defined", args: args{ duration: 600, }, - want: pkg.TestSeverityInfo, + want: pkg.SeverityInfo, }, { name: "no severity match", @@ -94,7 +94,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.TestSeverityInfo, + want: pkg.SeverityInfo, }, { name: "invalid expression", @@ -106,7 +106,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "duration > 500", }, }, - want: pkg.TestSeverityInfo, + want: pkg.SeverityInfo, }, { name: "use of undefined var", @@ -118,7 +118,7 @@ func Test_measureTestSeverity(t *testing.T) { Low: "Duration > 500", }, }, - want: pkg.TestSeverityInfo, + want: pkg.SeverityInfo, }, } for _, tt := range tests { diff --git a/pkg/api.go b/pkg/api.go index 1fb1160ad..0c4e69cc5 100644 --- a/pkg/api.go +++ b/pkg/api.go @@ -53,7 +53,7 @@ type CheckStatus struct { Error string `json:"error,omitempty"` Detail interface{} `json:"-"` Check *external.Check `json:"check,omitempty"` - TestSeverity TestSeverity `json:"test_severity,omitempty"` + TestSeverity Severity `json:"test_severity,omitempty"` } func (s CheckStatus) GetTime() (time.Time, error) { @@ -235,7 +235,7 @@ func FromResult(result CheckResult) CheckStatus { Error: result.Error, Detail: result.Detail, Check: &result.Check, - TestSeverity: result.TestSeverity, + TestSeverity: result.Severity, } } func FromV1(canary v1.Canary, check external.Check, statuses ...CheckStatus) Check { @@ -394,14 +394,14 @@ type URL struct { type SystemResult struct{} -type TestSeverity int +type Severity int const ( - TestSeverityInfo TestSeverity = iota - TestSeverityLow - TestSeverityMedium - TestSeverityHigh - TestSeverityCritical + SeverityInfo Severity = iota + SeverityLow + SeverityMedium + SeverityHigh + SeverityCritical ) type CheckResult struct { @@ -416,10 +416,9 @@ type CheckResult struct { Message string Error string Metrics []Metric - // Check is the configuration - Check external.Check - Canary v1.Canary - TestSeverity TestSeverity + Check external.Check // Check is the configuration + Canary v1.Canary + Severity Severity } func (result CheckResult) GetDescription() string {