Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe9d7aa

Browse files
committed
chore(coderd/notifications): avoid generating warning logs for trivial enqueue failures
1 parentf5fac29 commitbe9d7aa

File tree

12 files changed

+26
-20
lines changed

12 files changed

+26
-20
lines changed

‎coderd/agentapi/resources_monitoring.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (a *ResourcesMonitoringAPI) monitorMemory(ctx context.Context, datapoints [
161161
workspace.OwnerID,
162162
workspace.OrganizationID,
163163
)
164-
iferr!=nil {
164+
iferr!=nil&&notifications.IsSeriousEnqueueError(err){
165165
returnxerrors.Errorf("notify workspace OOM: %w",err)
166166
}
167167

@@ -254,7 +254,7 @@ func (a *ResourcesMonitoringAPI) monitorVolumes(ctx context.Context, datapoints
254254
workspace.ID,
255255
workspace.OwnerID,
256256
workspace.OrganizationID,
257-
);err!=nil {
257+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
258258
returnxerrors.Errorf("notify workspace OOD: %w",err)
259259
}
260260

‎coderd/autobuild/lifecycle_executor.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
442442
},"autobuild",
443443
// Associate this notification with all the related entities.
444444
ws.ID,ws.OwnerID,ws.TemplateID,ws.OrganizationID,
445-
);err!=nil {
445+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
446446
log.Warn(e.ctx,"failed to notify of autoupdated workspace",slog.Error(err))
447447
}
448448
}
@@ -476,7 +476,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
476476
ws.TemplateID,
477477
ws.OrganizationID,
478478
)
479-
iferr!=nil {
479+
iferr!=nil&&notifications.IsSeriousEnqueueError(err){
480480
log.Warn(e.ctx,"failed to notify of workspace marked as dormant",slog.Error(err),slog.F("workspace_id",ws.ID))
481481
}
482482
}

‎coderd/notifications/enqueuer.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ var (
2626
ErrDuplicate=xerrors.New("duplicate notification")
2727
)
2828

29+
// IsSeriousEnqueueError filters out trivial errors which can be ignored by
30+
// most callers of Enqueue.
31+
funcIsSeriousEnqueueError(errerror)bool {
32+
return!xerrors.Is(err,ErrCannotEnqueueDisabledNotification)&&!xerrors.Is(err,ErrDuplicate)
33+
}
34+
2935
typeInvalidDefaultNotificationMethodErrorstruct {
3036
Methodstring
3137
}

‎coderd/notifications/reports/generator.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func reportFailedWorkspaceBuilds(ctx context.Context, logger slog.Logger, db dat
205205
reportData,
206206
"report_generator",
207207
slice.Unique(targets)...,
208-
);err!=nil {
208+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
209209
logger.Warn(ctx,"failed to send a report with failed workspace builds",slog.Error(err))
210210
}
211211
}

‎coderd/provisionerdserver/provisionerdserver.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ func (s *server) notifyWorkspaceBuildFailed(ctx context.Context, workspace datab
13131313
},"provisionerdserver",
13141314
// Associate this notification with all the related entities.
13151315
workspace.ID,workspace.OwnerID,workspace.TemplateID,workspace.OrganizationID,
1316-
);err!=nil {
1316+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
13171317
s.Logger.Warn(ctx,"failed to notify of failed workspace autobuild",slog.Error(err))
13181318
}
13191319
}
@@ -1342,7 +1342,7 @@ func (s *server) notifyWorkspaceManualBuildFailed(ctx context.Context, workspace
13421342
labels,"provisionerdserver",
13431343
// Associate this notification with all the related entities.
13441344
workspace.ID,workspace.OwnerID,workspace.TemplateID,workspace.OrganizationID,
1345-
);err!=nil {
1345+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
13461346
s.Logger.Warn(ctx,"failed to notify of failed workspace manual build",slog.Error(err))
13471347
}
13481348
}
@@ -2441,7 +2441,7 @@ func (s *server) notifyWorkspaceDeleted(ctx context.Context, workspace database.
24412441
},"provisionerdserver",
24422442
// Associate this notification with all the related entities.
24432443
workspace.ID,workspace.OwnerID,workspace.TemplateID,workspace.OrganizationID,
2444-
);err!=nil {
2444+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
24452445
s.Logger.Warn(ctx,"failed to notify of workspace deletion",slog.Error(err))
24462446
}
24472447
}

‎coderd/templates.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (api *API) notifyTemplateDeleted(ctx context.Context, template database.Tem
151151
},"api-templates-delete",
152152
// Associate this notification with all the related entities.
153153
template.ID,template.OrganizationID,
154-
);err!=nil {
154+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
155155
api.Logger.Warn(ctx,"failed to notify of template deletion",slog.F("deleted_template_id",template.ID),slog.Error(err))
156156
}
157157
}
@@ -968,7 +968,7 @@ func (api *API) notifyUsersOfTemplateDeprecation(ctx context.Context, template d
968968
},
969969
"notify-users-of-template-deprecation",
970970
)
971-
iferr!=nil {
971+
iferr!=nil&&notifications.IsSeriousEnqueueError(err){
972972
errs=append(errs,xerrors.Errorf("enqueue notification: %w",err))
973973
}
974974
}

‎coderd/userauth.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (api *API) notifyUserRequestedOneTimePasscode(ctx context.Context, user dat
317317
"change-password-with-one-time-passcode",
318318
user.ID,
319319
)
320-
iferr!=nil {
320+
iferr!=nil&&notifications.IsSeriousEnqueueError(err){
321321
returnxerrors.Errorf("enqueue notification: %w",err)
322322
}
323323

‎coderd/users.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
606606
},
607607
"api-users-delete",
608608
user.ID,
609-
);err!=nil {
609+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
610610
api.Logger.Warn(ctx,"unable to notify about deleted user",slog.F("deleted_user",user.Username),slog.Error(err))
611611
}
612612
}
@@ -951,15 +951,15 @@ func (api *API) notifyUserStatusChanged(ctx context.Context, actingUserName stri
951951
if_,err:=api.NotificationsEnqueuer.EnqueueWithData(dbauthz.AsNotifier(ctx),u.ID,adminTemplateID,
952952
labels,data,"api-put-user-status",
953953
targetUser.ID,
954-
);err!=nil {
954+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
955955
api.Logger.Warn(ctx,"unable to notify about changed user's status",slog.F("affected_user",targetUser.Username),slog.Error(err))
956956
}
957957
}
958958
// nolint:gocritic // Need notifier actor to enqueue notifications
959959
if_,err:=api.NotificationsEnqueuer.EnqueueWithData(dbauthz.AsNotifier(ctx),targetUser.ID,personalTemplateID,
960960
labels,data,"api-put-user-status",
961961
targetUser.ID,
962-
);err!=nil {
962+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
963963
api.Logger.Warn(ctx,"unable to notify user about status change of their account",slog.F("affected_user",targetUser.Username),slog.Error(err))
964964
}
965965
returnnil
@@ -1518,7 +1518,7 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create
15181518
},
15191519
"api-users-create",
15201520
user.ID,
1521-
);err!=nil {
1521+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
15221522
api.Logger.Warn(ctx,"unable to notify about created user",slog.F("created_user",user.Username),slog.Error(err))
15231523
}
15241524
}

‎coderd/workspacebuilds.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ func (api *API) notifyWorkspaceUpdated(
605605
"api-workspaces-updated",
606606
// Associate this notification with all the related entities
607607
workspace.ID,workspace.OwnerID,workspace.TemplateID,workspace.OrganizationID,
608-
);err!=nil {
608+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
609609
log.Warn(ctx,"failed to notify of workspace update",slog.Error(err))
610610
}
611611
}

‎coderd/workspaces.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ func (api *API) notifyWorkspaceCreated(
974974
"api-workspaces-create",
975975
// Associate this notification with all the related entities
976976
workspace.ID,workspace.OwnerID,workspace.TemplateID,workspace.OrganizationID,
977-
);err!=nil {
977+
);err!=nil&&notifications.IsSeriousEnqueueError(err){
978978
log.Warn(ctx,"failed to notify of workspace creation",slog.Error(err))
979979
}
980980
}
@@ -1417,7 +1417,7 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
14171417
newWorkspace.TemplateID,
14181418
newWorkspace.OrganizationID,
14191419
)
1420-
iferr!=nil {
1420+
iferr!=nil&&notifications.IsSeriousEnqueueError(err){
14211421
api.Logger.Warn(ctx,"failed to notify of workspace marked as dormant",slog.Error(err))
14221422
}
14231423
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp