Skip to content

Commit

Permalink
fix panic in observability call
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed Aug 23, 2024
1 parent fa6193c commit fe429b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,11 @@ func (s *Service) executeAsyncCalls(ctx context.Context) (interval time.Duration
logger.Tracef("No async calls to execute")
return time.Second * 2, nil
} else if err != nil {
observability.AsyncCalls.Acquired(ctx, call.Verb, call.CatchVerb, call.Origin.String(), call.ScheduledAt, call.Catching, err)
if call == nil {
observability.AsyncCalls.AcquireFailed(ctx, err)
} else {
observability.AsyncCalls.Acquired(ctx, call.Verb, call.CatchVerb, call.Origin.String(), call.ScheduledAt, call.Catching, err)
}
return 0, err
}

Expand Down
3 changes: 2 additions & 1 deletion backend/controller/cronjobs/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"fmt"
"time"

"github.com/alecthomas/types/optional"

"github.com/TBD54566975/ftl/backend/controller/cronjobs/sql"
"github.com/TBD54566975/ftl/backend/controller/observability"
dalerrs "github.com/TBD54566975/ftl/backend/dal"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal/model"
"github.com/TBD54566975/ftl/internal/slices"
"github.com/alecthomas/types/optional"
)

type DAL struct {
Expand Down
5 changes: 5 additions & 0 deletions backend/controller/observability/async_calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func (m *AsyncCallMetrics) Acquired(ctx context.Context, verb schema.RefKey, cat
m.acquired.Add(ctx, 1, metric.WithAttributes(attrs...))
}

// AcquireFailed should be called if an acquisition failed before any call data could be retrieved.
func (m *AsyncCallMetrics) AcquireFailed(ctx context.Context, err error) {
m.acquired.Add(ctx, 1, metric.WithAttributes(observability.SuccessOrFailureStatusAttr(false)))
}

func (m *AsyncCallMetrics) Executed(ctx context.Context, verb schema.RefKey, catchVerb optional.Option[schema.RefKey], origin string, scheduledAt time.Time, isCatching bool, maybeFailureMode optional.Option[string]) {
attrs := extractAsyncCallAttrs(verb, catchVerb, origin, scheduledAt, isCatching)

Expand Down

0 comments on commit fe429b8

Please sign in to comment.