Skip to content
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

Send notification about stage executions #5440

Merged
merged 8 commits into from
Jan 24, 2025
Merged

Conversation

Warashi
Copy link
Contributor

@Warashi Warashi commented Dec 23, 2024

What this PR does:

  • Add notification event group about stage executions.
  • Send notification before/after stage executions.

image
I attached the screen capture of the Slack notification above, but this PR adds webhook notifications, too.

Why we need it:

To know the deployment progress systematically.

Which issue(s) this PR fixes:

Maybe fixes #5393

Does this PR introduce a user-facing change?: Yes

  • How are users affected by this change: Users receives new notifications.
  • Is this breaking change: No
  • How to migrate (if breaking change): N/A

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 1.11732% with 177 lines in your changes missing coverage. Please review.

Project coverage is 26.19%. Comparing base (b98a963) to head (e7bc90a).
Report is 60 commits behind head on master.

Files with missing lines Patch % Lines
pkg/app/piped/controller/scheduler.go 0.00% 50 Missing ⚠️
pkg/app/pipedv1/controller/scheduler.go 0.00% 49 Missing ⚠️
pkg/app/piped/notifier/slack.go 0.00% 39 Missing ⚠️
pkg/app/pipedv1/notifier/slack.go 0.00% 39 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5440      +/-   ##
==========================================
- Coverage   26.24%   26.19%   -0.05%     
==========================================
  Files         452      464      +12     
  Lines       48860    49815     +955     
==========================================
+ Hits        12821    13049     +228     
- Misses      35014    35733     +719     
- Partials     1025     1033       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Warashi Warashi marked this pull request as ready for review December 23, 2024 02:52
Copy link
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jan 23, 2025
Copy link
Member

@t-kikuc t-kikuc left a comment

Choose a reason for hiding this comment

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

It seems great!

I left a refactoring comment.

Comment on lines 348 to 394
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_STARTED,
Metadata: &model.NotificationEventStageStarted{
Deployment: s.deployment,
Stage: ps,
},
})

result = s.executeStage(sig, *ps, func(in executor.Input) (executor.Executor, bool) {
return s.executorRegistry.Executor(model.Stage(ps.Name), in)
})

switch result {
case model.StageStatus_STAGE_SUCCESS, model.StageStatus_STAGE_EXITED: // Exit stage is treated as success.
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_SUCCEEDED,
Metadata: &model.NotificationEventStageSucceeded{
Deployment: s.deployment,
Stage: ps,
},
})
case model.StageStatus_STAGE_FAILURE:
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_FAILED,
Metadata: &model.NotificationEventStageFailed{
Deployment: s.deployment,
Stage: ps,
},
})
case model.StageStatus_STAGE_CANCELLED:
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_CANCELLED,
Metadata: &model.NotificationEventStageCancelled{
Deployment: s.deployment,
Stage: ps,
},
})
case model.StageStatus_STAGE_SKIPPED:
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_SKIPPED,
Metadata: &model.NotificationEventStageSkipped{
Deployment: s.deployment,
Stage: ps,
},
})
}

Copy link
Member

Choose a reason for hiding this comment

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

[IMO] How about extracting into a method?
I just want to simplify scheduler.Run() for readability and maintenanceability.

For example:

Suggested change
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_STARTED,
Metadata: &model.NotificationEventStageStarted{
Deployment: s.deployment,
Stage: ps,
},
})
result = s.executeStage(sig, *ps, func(in executor.Input) (executor.Executor, bool) {
return s.executorRegistry.Executor(model.Stage(ps.Name), in)
})
switch result {
case model.StageStatus_STAGE_SUCCESS, model.StageStatus_STAGE_EXITED: // Exit stage is treated as success.
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_SUCCEEDED,
Metadata: &model.NotificationEventStageSucceeded{
Deployment: s.deployment,
Stage: ps,
},
})
case model.StageStatus_STAGE_FAILURE:
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_FAILED,
Metadata: &model.NotificationEventStageFailed{
Deployment: s.deployment,
Stage: ps,
},
})
case model.StageStatus_STAGE_CANCELLED:
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_CANCELLED,
Metadata: &model.NotificationEventStageCancelled{
Deployment: s.deployment,
Stage: ps,
},
})
case model.StageStatus_STAGE_SKIPPED:
s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_STAGE_SKIPPED,
Metadata: &model.NotificationEventStageSkipped{
Deployment: s.deployment,
Stage: ps,
},
})
}
s.notifyStageEvent(model.StageStatus_STAGE_STARTED, ps)
result = s.executeStage(sig, *ps, func(in executor.Input) (executor.Executor, bool) {
return s.executorRegistry.Executor(model.Stage(ps.Name), in)
})
s.notifyStageEvent(result, ps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!
It's nice, so I changed the codes on this commit.
e7bc90a

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!
StageStart and StageEnd are really good.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
@Warashi Warashi requested a review from t-kikuc January 23, 2025 06:19
Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot removed the Stale label Jan 24, 2025
@Warashi Warashi merged commit e842421 into master Jan 24, 2025
16 of 18 checks passed
@Warashi Warashi deleted the notify-start-or-end-stage branch January 24, 2025 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding WAIT_APPROVAL_TIMEOUT webhook event
3 participants