Skip to content

Commit

Permalink
chore: rename to just "Severity". Removed "Test" prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 3, 2023
1 parent 8719d10 commit 2430cb9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
22 changes: 11 additions & 11 deletions checks/runchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
20 changes: 10 additions & 10 deletions checks/runchecks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -27,7 +27,7 @@ func Test_measureTestSeverity(t *testing.T) {
Critical: "duration > 1500",
},
},
want: pkg.TestSeverityCritical,
want: pkg.SeverityCritical,
},
{
name: "simple - high",
Expand All @@ -38,7 +38,7 @@ func Test_measureTestSeverity(t *testing.T) {
High: "duration > 1000",
},
},
want: pkg.TestSeverityHigh,
want: pkg.SeverityHigh,
},
{
name: "simple - medium",
Expand All @@ -51,7 +51,7 @@ func Test_measureTestSeverity(t *testing.T) {
Low: "duration > 500",
},
},
want: pkg.TestSeverityMedium,
want: pkg.SeverityMedium,
},
{
name: "simple - low",
Expand All @@ -63,7 +63,7 @@ func Test_measureTestSeverity(t *testing.T) {
Low: "duration > 500",
},
},
want: pkg.TestSeverityLow,
want: pkg.SeverityLow,
},
{
name: "complex expression",
Expand All @@ -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",
Expand All @@ -94,7 +94,7 @@ func Test_measureTestSeverity(t *testing.T) {
Low: "duration > 500",
},
},
want: pkg.TestSeverityInfo,
want: pkg.SeverityInfo,
},
{
name: "invalid expression",
Expand All @@ -106,7 +106,7 @@ func Test_measureTestSeverity(t *testing.T) {
Low: "duration > 500",
},
},
want: pkg.TestSeverityInfo,
want: pkg.SeverityInfo,
},
{
name: "use of undefined var",
Expand All @@ -118,7 +118,7 @@ func Test_measureTestSeverity(t *testing.T) {
Low: "Duration > 500",
},
},
want: pkg.TestSeverityInfo,
want: pkg.SeverityInfo,
},
}
for _, tt := range tests {
Expand Down
23 changes: 11 additions & 12 deletions pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 2430cb9

Please sign in to comment.