From ab0fc06aaf979037bbf3d354dacfeef3bbec5540 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 24 Oct 2024 20:02:01 +0545 Subject: [PATCH] feat: handle db errors during check runs --- cmd/root.go | 4 ++++ go.mod | 2 +- pkg/api.go | 2 ++ pkg/results.go | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 9770f0189..92cd91207 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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" @@ -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 } diff --git a/go.mod b/go.mod index e62ce7fb3..3a437ed0d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/pkg/api.go b/pkg/api.go index 6e24274dd..49799c6ea 100644 --- a/pkg/api.go +++ b/pkg/api.go @@ -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 { diff --git a/pkg/results.go b/pkg/results.go index 7e81607e7..440939770 100644 --- a/pkg/results.go +++ b/pkg/results.go @@ -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 @@ -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