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

Commit5c60065

Browse files
feat: add notification for prebuilds failure
1 parent1d51dfc commit5c60065

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELETEFROM notification_templatesWHERE id='414d9331-c1fc-4761-b40c-d1f4702279eb';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSERT INTO notification_templates
2+
(id, name, title_template, body_template,"group", actions)
3+
VALUES ('414d9331-c1fc-4761-b40c-d1f4702279eb',
4+
'Prebuild Failure Limit Reached',
5+
E'There is a problem creating prebuilt workspaces for the preset',
6+
$$
7+
Thenumber of failed prebuilds has reached the hardlimit for template**{{ .Labels.template }}**and preset**{{ .Labels.preset }}**
8+
$$,
9+
'Template Events',
10+
'[]'::jsonb);

‎coderd/notifications/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040

4141
TemplateWorkspaceBuildsFailedReport=uuid.MustParse("34a20db2-e9cc-4a93-b0e4-8569699d7a00")
4242
TemplateWorkspaceResourceReplaced=uuid.MustParse("89d9745a-816e-4695-a17f-3d0a229e2b8d")
43+
PrebuildFailureLimitReached=uuid.MustParse("414d9331-c1fc-4761-b40c-d1f4702279eb")
4344
)
4445

4546
// Notification-related events.

‎enterprise/coderd/prebuilds/reconcile.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,50 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
362362
)
363363

364364
ifps.IsHardLimited {
365-
logger.Debug(ctx,"skipping hard limited preset",slog.F("preset_id",ps.Preset.ID),slog.F("name",ps.Preset.Name))
365+
logger.Warn(ctx,"skipping hard limited preset",slog.F("preset_id",ps.Preset.ID),slog.F("name",ps.Preset.Name))
366+
367+
// TODO: rename ctx?
368+
// nolint:gocritic // Necessary to query all the required data.
369+
ctx:=dbauthz.AsSystemRestricted(ctx)
370+
371+
// TODO(yevhenii): move into separate function
372+
// Send notification to template admins.
373+
ifc.notifEnq==nil {
374+
c.logger.Warn(ctx,"notification enqueuer not set, cannot send resource replacement notification(s)")
375+
returnnil
376+
}
377+
378+
// TODO(yevhenii): remove owner from the list
379+
templateAdmins,err:=c.store.GetUsers(ctx, database.GetUsersParams{
380+
RbacRole: []string{codersdk.RoleTemplateAdmin,codersdk.RoleOwner},
381+
})
382+
iferr!=nil {
383+
returnxerrors.Errorf("fetch template admins: %w",err)
384+
}
385+
386+
for_,templateAdmin:=rangetemplateAdmins {
387+
if_,err:=c.notifEnq.EnqueueWithData(ctx,templateAdmin.ID,notifications.PrebuildFailureLimitReached,
388+
map[string]string{
389+
"org":ps.Preset.OrganizationName,
390+
"template":ps.Preset.TemplateName,
391+
"template_version":ps.Preset.TemplateVersionName,
392+
"preset":ps.Preset.Name,
393+
},
394+
map[string]any{},
395+
"prebuilds_reconciler",
396+
// Associate this notification with all the related entities.
397+
ps.Preset.TemplateID,ps.Preset.TemplateVersionID,ps.Preset.ID,
398+
);err!=nil {
399+
c.logger.Error(ctx,
400+
"failed to send notification",
401+
slog.Error(err),
402+
slog.F("template_admin_id",templateAdmin.ID.String()),
403+
)
404+
405+
continue
406+
}
407+
}
408+
366409
returnnil
367410
}
368411

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp