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

Add retries to sendgrid emailer (#618) #6164

Merged

Conversation

katrogan
Copy link
Contributor

@katrogan katrogan commented Jan 13, 2025

Why are the changes needed?

Nice to have for transient network failures.

What changes were proposed in this pull request?

See PR title

How was this patch tested?

Unit tests

Labels

Done

This is important to improve the readability of release notes.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

Implementation of a retry mechanism for Sendgrid email sender to handle transient network failures, featuring configurable retry attempts and delay settings. The changes introduce a SendgridClient interface and enhanced error logging capabilities. The implementation includes comprehensive test coverage for various retry scenarios to ensure reliable email notifications.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 2

@katrogan katrogan added the fixed For any bug fixes label Jan 13, 2025
@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 13, 2025

Code Review Agent Run #63207a

Actionable Suggestions - 2
  • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer.go - 1
    • Consider storing only required config fields · Line 101-101
  • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer_test.go - 1
    • Consider removing duplicate test case description · Line 140-141
Review Details
  • Files reviewed - 3 · Commit Range: 95b4554..95b4554
    • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer.go
    • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer_test.go
    • flyteadmin/pkg/async/notifications/mocks/sendgrid_client.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Signed-off-by: Katrina Rogan <katroganGH@gmail.com>
@katrogan katrogan force-pushed the union/upstream-6b28174a9b7cefe9e612668e8d9cbb85b93ee43a branch from 95b4554 to 665ec44 Compare January 13, 2025 14:41
@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 13, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Email Service Reliability Enhancement

sendgrid_emailer.go - Added retry mechanism and improved error handling for email sending

sendgrid_emailer_test.go - Added comprehensive tests for retry functionality

sendgrid_client.go - Created mock SendgridClient for testing

@@ -79,5 +98,6 @@ func NewSendGridEmailer(config runtimeInterfaces.NotificationsConfig, scope prom
return &SendgridEmailer{
client: sendgrid.NewSendClient(getAPIKey(config.NotificationsEmailerConfig.EmailerConfig)),
systemMetrics: newEmailMetrics(scope.NewSubScope("sendgrid")),
cfg: &config,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider storing only required config fields

Consider initializing the cfg field with just the required NotificationsEmailerConfig instead of storing the entire config struct. This would reduce memory usage and coupling.

Code suggestion
Check the AI-generated fix before applying
Suggested change
cfg: &config,
cfg: &config.NotificationsEmailerConfig,

Code Review Run #63207a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines 140 to 141
t.Run("succeed within allowed retry attempts", func(t *testing.T) {
t.Run("exhaust all retry attempts", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider removing duplicate test case description

Consider removing the nested t.Run() with identical description. The outer and inner test cases have the same name 'exhaust all retry attempts'.

Code suggestion
Check the AI-generated fix before applying
 -		t.Run("exhaust all retry attempts", func(t *testing.T) {
 			ctx := context.TODO()
 			sendgridClient := &mocks.SendgridClient{}
 			expectedEmail := getSendgridEmail(emailNotification)
 @@ -165,7 +164,6 @@
 		# TYPE goodemailer:send_error counter
 		goodemailer:send_error 0
 		`)))
 -		})
 	})

Code Review Run #63207a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 37.04%. Comparing base (b8fb68d) to head (52f75e7).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...n/pkg/async/notifications/mocks/sendgrid_client.go 64.00% 5 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6164      +/-   ##
==========================================
+ Coverage   37.02%   37.04%   +0.02%     
==========================================
  Files        1317     1318       +1     
  Lines      132534   132568      +34     
==========================================
+ Hits        49067    49107      +40     
+ Misses      79221    79211      -10     
- Partials     4246     4250       +4     
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 54.33% <75.00%> (+0.10%) ⬆️
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 62.29% <ø> (-0.05%) ⬇️
unittests-flyteidl 7.23% <ø> (ø)
unittests-flyteplugins 53.85% <ø> (ø)
unittests-flytepropeller 42.64% <ø> (ø)
unittests-flytestdlib 55.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Signed-off-by: Katrina Rogan <katroganGH@gmail.com>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 13, 2025

Code Review Agent Run #255086

Actionable Suggestions - 1
  • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer_test.go - 1
    • Consider test data scope placement · Line 22-23
Review Details
  • Files reviewed - 3 · Commit Range: 665ec44..52f75e7
    • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer.go
    • flyteadmin/pkg/async/notifications/implementations/sendgrid_emailer_test.go
    • flyteadmin/pkg/async/notifications/mocks/sendgrid_client.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +22 to +23
var (
emailNotification = &admin.EmailMessage{
Copy link
Collaborator

@flyte-bot flyte-bot Jan 13, 2025

Choose a reason for hiding this comment

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

Consider test data scope placement

Consider keeping test data within test functions rather than as package-level variables to maintain test isolation and clarity. Each test should be self-contained with its own test data.

Code suggestion
Check the AI-generated fix before applying
 -var (
 -	emailNotification = &admin.EmailMessage{
 -		SubjectLine: "Notice: Execution \"name\" has succeeded in \"domain\".",
 -		SenderEmail: "no-reply@example.com",
 -		RecipientsEmail: []string{
 -			"my@example.com",
 -			"john@example.com",
 -		},
 -		Body: "Execution \"name\" has succeeded in \"domain\". View details at " +
 -			"<a href=\"https://example.com/executions/T/B/D\">" +
 -			"https://example.com/executions/T/B/D</a>.",
 -	}
 -)
 @@ -43,1 +43,14 @@
  func TestGetEmail(t *testing.T) {
 +	emailNotification := &admin.EmailMessage{
 +		SubjectLine: "Notice: Execution \"name\" has succeeded in \"domain\".",
 +		SenderEmail: "no-reply@example.com",
 +		RecipientsEmail: []string{
 +			"my@example.com",
 +			"john@example.com",
 +		},
 +		Body: "Execution \"name\" has succeeded in \"domain\". View details at " +
 +			"<a href=\"https://example.com/executions/T/B/D\">" +
 +			"https://example.com/executions/T/B/D</a>.",
 +	}

Code Review Run #255086


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@Future-Outlier Future-Outlier merged commit 6ea9531 into master Jan 13, 2025
53 checks passed
@Future-Outlier Future-Outlier deleted the union/upstream-6b28174a9b7cefe9e612668e8d9cbb85b93ee43a branch January 13, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed For any bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants