Skip to content

feat: notify template owner on manual build failures #14262

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

Closed
wants to merge 8 commits into from

Conversation

BrunoQuaresma
Copy link
Collaborator

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
@@ -1020,7 +1020,23 @@ func (s *server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*proto.
return nil, err
}

s.notifyWorkspaceBuildFailed(ctx, workspace, build)
// Only notify auto build failures
Copy link
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
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
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
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
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
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
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
Copy link
Member

mtojek commented Aug 23, 2024

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

@BrunoQuaresma
Copy link
Collaborator 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
Copy link
Member

mtojek commented Aug 26, 2024

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