Skip to content

Commit

Permalink
feat: handle db errors during check runs
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 25, 2024
1 parent d85f05b commit ab0fc06
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/flanksource/duty"
"github.com/flanksource/duty/connection"
"github.com/flanksource/duty/context"
"github.com/flanksource/duty/db"
"github.com/flanksource/duty/query"
"github.com/flanksource/duty/shutdown"
"github.com/spf13/cobra"
Expand All @@ -38,6 +39,9 @@ func InitContext() (context.Context, error) {
}

ctx.WithTracer(otel.GetTracerProvider().Tracer(app))
ctx.WithTracer(otel.GetTracerProvider().Tracer("canary-checker"))
ctx.WithTracer(otel.GetTracerProvider().Tracer("canary-checker"))
ctx.DB().Use(db.NewPlugin())

return ctx, nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

// replace github.com/flanksource/duty => ../duty
replace github.com/flanksource/duty => ../duty

// replace github.com/flanksource/artifacts => ../artifacts

Expand Down
2 changes: 2 additions & 0 deletions pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ type CheckResult struct {
// ParentCheck is the parent check of a transformed check
ParentCheck external.Check `json:"-"`
ErrorObject error `json:"-"`

InternalError bool `json:"-"`
}

func (result CheckResult) LoggerName() string {
Expand Down
7 changes: 7 additions & 0 deletions pkg/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/flanksource/canary-checker/api/external"
v1 "github.com/flanksource/canary-checker/api/v1"
"github.com/samber/lo"
"github.com/samber/oops"
)

type Results []*CheckResult
Expand Down Expand Up @@ -91,6 +93,11 @@ func (result *CheckResult) Failf(message string, args ...interface{}) *CheckResu
if result.Error != "" {
result.Error += ", "
}

if oe, ok := oops.AsOops(fmt.Errorf(message, args...)); ok {
result.InternalError = lo.Contains(oe.Tags(), "db")
}

result.Pass = false
result.Error += fmt.Sprintf(message, args...)
return result
Expand Down

0 comments on commit ab0fc06

Please sign in to comment.