Skip to content

feat: notify template owner on manual build failures - #14262

Closed
BrunoQuaresma wants to merge 8 commits into
mainfrom
bq/notify-manual-build-failure
Closed

feat: notify template owner on manual build failures#14262
BrunoQuaresma wants to merge 8 commits into
mainfrom
bq/notify-manual-build-failure

Conversation

@BrunoQuaresma

Copy link
Copy Markdown
Contributor

Preview:

Screenshot 2024-08-13 at 15 22 02

Related to coder/internal#16 and it depends on #14250

@BrunoQuaresma BrunoQuaresma self-assigned this Aug 13, 2024
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver.go Outdated
Comment thread coderd/provisionerdserver/provisionerdserver_test.go Outdated
}

s.notifyWorkspaceBuildFailed(ctx, workspace, build)
// Only notify auto build failures

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather that this comment explain what classifies as an auto build (i.e. not initiated by a user)

s.Logger.Warn(ctx, "failed to find template admins for template build failed notification", slog.Error(err))
} else {
for _, admin := range admins {
if admin.ID != build.InitiatorID && !autoBuild {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if admin.ID != build.InitiatorID && !autoBuild {
// Only notify users who did not initiate the action.
if admin.ID != build.InitiatorID && !autoBuild {

reason = string(build.Reason)

if _, err := s.NotificationsEnqueuer.Enqueue(ctx, workspace.OwnerID, notifications.TemplateWorkspaceAutobuildFailed,
func (s *server) notifyWorkspaceBuildFailed(ctx context.Context, workspace database.Workspace, build database.WorkspaceBuild, receiverID uuid.UUID) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you're passing in receiverID here. Can you elaborate pls?

func (s *server) notifyTemplateBuildFailed(ctx context.Context, workspace database.Workspace, build database.WorkspaceBuild, receiverID uuid.UUID) {
template, err := s.Database.GetTemplateByID(ctx, workspace.TemplateID)
if err != nil {
s.Logger.Warn(ctx, "failed to get template", slog.Error(err))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about how an operator might debug with these logs; how would they know that this is related to sending notifications?

Try think of log lines as communication. You're communicating with an operator who is a) possibly not familiar with the product or less experienced, and b) trying to debug an issue, possibly under stress. Vague log lines are almost as bad as no log lines at all, sometimes worse because they can mislead or distract.

for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
// Given: a template and a workspace build
isManualBuild := c.reason == database.BuildReasonInitiator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have this logic in multiple places, it might be worth creating a helper method.

for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
// Given: a template and a workspace build
isManualBuild := c.reason == database.BuildReasonInitiator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try and group your code into logical blocks, and use whitespace for visual assistance. Think of your code as having the same visual hierarchy that you'd design in your frontends.

For example, isManualBuild is only needed lower down: group them logically.

You've got a whole lot of code below which is doing several things; add a bit of spaces and/or comments to give the reader's "eye" some space to "breathe", and group related concepts/lines together to infer relationships.

// Then: send the template build failed notifications
var buildFailedNotifications []*testutil.Notification
for _, n := range notifEnq.Sent {
if n.TemplateID == notifications.TemplateTemplateBuildFailed {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if they're not the template you're expecting?

Your tests should not only prove that something works; it should also prove that it only works in precisely the way you're expecting, and any relevant deviation should fail the test.

@mtojek

mtojek commented Aug 23, 2024

Copy link
Copy Markdown
Member

@BrunoQuaresma I will take over this PR, not sure if I create a one or modify yours, just FYI 👍

@BrunoQuaresma

Copy link
Copy Markdown
Contributor Author

@BrunoQuaresma I will take over this PR, not sure if I create a one or modify yours, just FYI 👍

Sure, whatever you think is best. Just tag me on your PR so I can take a look and learn.

@mtojek

mtojek commented Aug 26, 2024

Copy link
Copy Markdown
Member

Close in favor of #14419

@mtojek mtojek closed this Aug 26, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 26, 2024
@github-actions
github-actions Bot deleted the bq/notify-manual-build-failure branch February 20, 2025 00:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants