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

Feat: Support per-launch plan notification template #6064

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion flyteadmin/pkg/async/notifications/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,17 @@ func ToEmailMessageFromWorkflowExecutionEvent(
request *admin.WorkflowExecutionEventRequest,
execution *admin.Execution) *admin.EmailMessage {

var emailBody string
if emailNotification.GetTemplate() != "" {
emailBody = emailNotification.GetTemplate()
} else {
emailBody = config.NotificationsEmailerConfig.Body
}

return &admin.EmailMessage{
SubjectLine: substituteEmailParameters(config.NotificationsEmailerConfig.Subject, request, execution),
SenderEmail: config.NotificationsEmailerConfig.Sender,
RecipientsEmail: emailNotification.GetRecipientsEmail(),
Body: substituteEmailParameters(config.NotificationsEmailerConfig.Body, request, execution),
Body: substituteEmailParameters(emailBody, request, execution),
}
}
38 changes: 38 additions & 0 deletions flyteadmin/pkg/async/notifications/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,41 @@ func TestToEmailMessageFromWorkflowExecutionEvent(t *testing.T) {
assert.True(t, emailMessage.GetSenderEmail() == expected.GetSenderEmail())
assert.True(t, len(emailMessage.GetRecipientsEmail()) == len(expected.GetRecipientsEmail()))
}

func TestToEmailMessageFromWorkflowExecutionEventWithTemplate(t *testing.T) {
notificationsConfig := runtimeInterfaces.NotificationsConfig{
NotificationsEmailerConfig: runtimeInterfaces.NotificationsEmailerConfig{
Body: "Execution \"{{ name }}\" has succeeded in \"{{ domain }}\". View details at " +
"<a href=\"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}\">" +
"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}</a>.",
Sender: "[email protected]",
Subject: "Notice: Execution \"{{ name }}\" has succeeded in \"{{ domain }}\".",
},
}
emailNotification := &admin.EmailNotification{
RecipientsEmail: []string{
"[email protected]", "[email protected]",
},
Template: "LP custom template: Execution \"{{ name }}\" has succeeded in \"{{ domain }}\". View details at " +
"<a href=\"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}\">" +
"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}</a>.",
}
request := &admin.WorkflowExecutionEventRequest{
Event: &event.WorkflowExecutionEvent{
Phase: core.WorkflowExecution_ABORTED,
},
}
emailMessage := ToEmailMessageFromWorkflowExecutionEvent(notificationsConfig, emailNotification, request, workflowExecution)
expected := &admin.EmailMessage{
RecipientsEmail: []string{
"[email protected]", "[email protected]",
},
SenderEmail: "[email protected]",
SubjectLine: `Notice: Execution "e124" has succeeded in "prod".`,
Body: `LP custom template: Execution "e124" has succeeded in "prod". View details at <a href="https://example.com/executions/proj/prod/e124">https://example.com/executions/proj/prod/e124</a>.`,
}
assert.True(t, emailMessage.GetBody() == expected.GetBody())
assert.True(t, emailMessage.GetSubjectLine() == expected.GetSubjectLine())
assert.True(t, emailMessage.GetSenderEmail() == expected.GetSenderEmail())
assert.True(t, len(emailMessage.GetRecipientsEmail()) == len(expected.GetRecipientsEmail()))
}
12 changes: 12 additions & 0 deletions flyteidl/clients/go/assets/admin.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions flyteidl/gen/pb-es/flyteidl/admin/common_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading