Skip to content

fix: stop logging errors on cancel in notifier #15186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: stop logging errors on cancel in notifier
  • Loading branch information
spikecurtis committed Oct 23, 2024
commit 04b17fd946b41a0f1bb1cd979d3693759ee774c1
4 changes: 0 additions & 4 deletions coderd/notifications/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import (
"text/template"

"golang.org/x/xerrors"

"cdr.dev/slog"
)

func (n *notifier) fetchHelpers(ctx context.Context) (map[string]any, error) {
appName, err := n.fetchAppName(ctx)
if err != nil {
n.log.Error(ctx, "failed to fetch app name", slog.Error(err))
return nil, xerrors.Errorf("fetch app name: %w", err)
}
logoURL, err := n.fetchLogoURL(ctx)
if err != nil {
n.log.Error(ctx, "failed to fetch logo URL", slog.Error(err))
return nil, xerrors.Errorf("fetch logo URL: %w", err)
}

Expand Down
28 changes: 24 additions & 4 deletions coderd/notifications/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notifications
import (
"context"
"encoding/json"
"fmt"
"sync"
"text/template"

Expand All @@ -27,7 +28,22 @@ const (
notificationsDefaultAppName = "Coder"
)

var errDecorateHelpersFailed = xerrors.New("failed to decorate helpers")
type decorateHelpersError struct {
inner error
}

func (e decorateHelpersError) Error() string {
return fmt.Sprintf("failed to decorate helpers: %s", e.inner.Error())
}

func (e decorateHelpersError) Unwrap() error {
return e.inner
}

func (decorateHelpersError) Is(other error) bool {
_, ok := other.(decorateHelpersError)
return ok
}

// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
// through a pipeline of fetch -> prepare -> render -> acquire handler -> deliver.
Expand Down Expand Up @@ -164,8 +180,12 @@ func (n *notifier) process(ctx context.Context, success chan<- dispatchResult, f
// A message failing to be prepared correctly should not affect other messages.
deliverFn, err := n.prepare(ctx, msg)
if err != nil {
n.log.Warn(ctx, "dispatcher construction failed", slog.F("msg_id", msg.ID), slog.Error(err))
failure <- n.newFailedDispatch(msg, err, xerrors.Is(err, errDecorateHelpersFailed))
if database.IsQueryCanceledError(err) {
n.log.Debug(ctx, "dispatcher construction canceled", slog.F("msg_id", msg.ID), slog.Error(err))
} else {
n.log.Error(ctx, "dispatcher construction failed", slog.F("msg_id", msg.ID), slog.Error(err))
}
failure <- n.newFailedDispatch(msg, err, xerrors.Is(err, decorateHelpersError{}))
n.metrics.PendingUpdates.Set(float64(len(success) + len(failure)))
continue
}
Expand Down Expand Up @@ -226,7 +246,7 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification

helpers, err := n.fetchHelpers(ctx)
if err != nil {
return nil, errDecorateHelpersFailed
return nil, decorateHelpersError{err}
}

var title, body string
Expand Down
Loading