Skip to content

Commit

Permalink
finalize saving to severity in check status
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
adityathebe committed May 10, 2023
1 parent a9d4b86 commit 5a49443
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions checks/runchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ 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())

tpl := v.GetTestFunction()
if tpl.IsEmpty() {
break
Expand All @@ -108,9 +111,6 @@ func processTemplates(ctx *context.Context, r *pkg.CheckResult) *pkg.CheckResult
r.Failf("Test expression failed. Expecting true from: %v", tpl.Expression)
}
}

data := map[string]any{"duration": r.Duration}
r.TestSeverity = measureTestSeverity(ctx.New(data), v.GetTestThreshold())
}

return r
Expand Down
34 changes: 18 additions & 16 deletions pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ func (t *JSONTime) UnmarshalJSON(b []byte) error {
}

type CheckStatus struct {
Status bool `json:"status"`
Invalid bool `json:"invalid,omitempty"`
Time string `json:"time"`
Duration int `json:"duration"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Detail interface{} `json:"-"`
Check *external.Check `json:"check,omitempty"`
Status bool `json:"status"`
Invalid bool `json:"invalid,omitempty"`
Time string `json:"time"`
Duration int `json:"duration"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Detail interface{} `json:"-"`
Check *external.Check `json:"check,omitempty"`
TestSeverity TestSeverity `json:"test_severity,omitempty"`
}

func (s CheckStatus) GetTime() (time.Time, error) {
Expand Down Expand Up @@ -226,14 +227,15 @@ func FromExternalCheck(canary Canary, check external.Check) Check {

func FromResult(result CheckResult) CheckStatus {
return CheckStatus{
Status: result.Pass,
Invalid: result.Invalid,
Duration: int(result.Duration),
Time: time.Now().UTC().Format(time.RFC3339),
Message: result.Message,
Error: result.Error,
Detail: result.Detail,
Check: &result.Check,
Status: result.Pass,
Invalid: result.Invalid,
Duration: int(result.Duration),
Time: time.Now().UTC().Format(time.RFC3339),
Message: result.Message,
Error: result.Error,
Detail: result.Detail,
Check: &result.Check,
TestSeverity: result.TestSeverity,
}
}
func FromV1(canary v1.Canary, check external.Check, statuses ...CheckStatus) Check {
Expand Down
7 changes: 4 additions & 3 deletions pkg/cache/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,20 @@ func (c *postgresCache) AddCheckStatus(check pkg.Check, status pkg.CheckStatus)
invalid,
message,
status,
severity,
time,
created_at
)
VALUES($1,$2,$3,$4,$5,$6,$7,$8,NOW())
ON CONFLICT (check_id,time) DO NOTHING;
`,
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,NOW())
ON CONFLICT (check_id,time) DO NOTHING;`,
checks[0].ID,
string(jsonDetails),
status.Duration,
status.Error,
status.Invalid,
status.Message,
status.Status,
status.TestSeverity,
status.Time,
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/db/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/flanksource/canary-checker/pkg/utils"
"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/types"
"github.com/google/uuid"
"github.com/pkg/errors"
"gorm.io/gorm"
Expand Down Expand Up @@ -282,7 +283,7 @@ func PersistComponent(component *pkg.Component) ([]uuid.UUID, error) {
return persisted, tx.Error
}

func UpdateStatusAndSummaryForComponent(id uuid.UUID, status models.ComponentStatus, summary models.Summary) (int64, error) {
func UpdateStatusAndSummaryForComponent(id uuid.UUID, status types.ComponentStatus, summary types.Summary) (int64, error) {
tx := Gorm.Table("components").Where("id = ? and (status != ? or summary != ?)", id, status, summary).UpdateColumns(models.Component{Status: status, Summary: summary})
return tx.RowsAffected, tx.Error
}
Expand Down

0 comments on commit 5a49443

Please sign in to comment.