Open samhita-alla opened 7 months ago
🤖
Hey there, @samhita-alla! :wave: I'm Dosu, a friendly bot that's here to assist you with bugs, answer your queries, and guide you on your journey to become a contributor. While we're waiting for a human maintainer to join us, feel free to ask me anything. How can I assist you today?
Sure, I can provide some information on how Slack notifications work in Flyte.
Flyte allows you to set up notifications that are triggered based on the state of the execution. These notifications can be of different types such as email, pagerduty, and slack. The notifications are defined in the workflow execution spec and they are published when the execution reaches the specified phase.
The code snippet you provided shows how the notifications are published in the publishNotifications
function. For Slack notifications, the recipients are defined in the GetSlack().GetRecipientsEmail()
call. The email addresses returned by this call are used to send the notifications.
Here is the relevant part of the code:
var emailNotification admin.EmailNotification
if notification.GetEmail() != nil {
emailNotification.RecipientsEmail = notification.GetEmail().GetRecipientsEmail()
} else if notification.GetPagerDuty() != nil {
emailNotification.RecipientsEmail = notification.GetPagerDuty().GetRecipientsEmail()
} else if notification.GetSlack() != nil {
emailNotification.RecipientsEmail = notification.GetSlack().GetRecipientsEmail()
} else {
logger.Debugf(ctx, "failed to publish notification, encountered unrecognized type: %v", notification.Type)
m.systemMetrics.UnexpectedDataError.Inc()
// Unsupported notification types should have been caught when the launch plan was being created.
return errors.NewFlyteAdminErrorf(codes.Internal, "Unsupported notification type [%v] for execution [%+v]",
notification.Type, request.Event.ExecutionId)
}
// Convert the email Notification into an email message to be published.
// Currently there are no possible errors while creating an email message.
// Once customizable content is specified, errors are possible.
email := notifications.ToEmailMessageFromWorkflowExecutionEvent(
*m.config.ApplicationConfiguration().GetNotificationsConfig(), emailNotification, request, adminExecution)
// Errors seen while publishing a message are considered non-fatal to the method and will not result
// in the method returning an error.
if err = m.notificationClient.Publish(ctx, proto.MessageName(&emailNotification), email); err != nil {
m.systemMetrics.PublishNotificationError.Inc()
logger.Infof(ctx, "error publishing email notification [%+v] with err: [%v]", notification, err)
}
This code checks if the notification is of type Slack, and if so, it retrieves the recipient's email addresses. It then creates an email message and publishes it. If there is an error while publishing the message, it logs the error and increments a counter for publish notification errors.
Please note that the actual sending of the Slack notification is not handled in this code. This code only prepares the email message to be sent. The actual sending is handled by the m.notificationClient.Publish
method, which is not shown in the provided code.
The m.notificationClient.Publish
method is implemented in the Publish
function of the EventPublisher
struct in the event_publisher.go
file. The function first checks if the event of the given notification type should be published by calling the shouldPublishEvent
function. If the event type is not in the set of events to be published, the function returns without doing anything. If the event should be published, it increments the PublishTotal
counter in the system metrics. It then attempts to publish the message using the Publish
method of the pubsub.Publisher
interface, which is stored in the pub
field of the EventPublisher
struct. The Publish
method takes in the context, the notification type, and the message to be published. If the publish operation fails, it increments the PublishError
counter in the system metrics and logs an error message. If the operation is successful, it increments the PublishSuccess
counter in the system metrics.
However, the provided context does not show how Slack notifications are specifically handled. The pubsub.Publisher
interface could potentially handle Slack notifications, but the specific implementation is not provided in the context.
I hope this helps! If you have any more questions, feel free to ask.
Sources:
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Hi, I read the discussion thread and it's talking about how to fix a config error, not about Slack notification specifically. Would you like assistance in drafting documentation on setting up Slack notifications, or perhaps refining the notification documentation to encompass resolving this error? Thx!
Description
more context: https://discuss.flyte.org/t/14164511/hi-we-are-trying-to-implement-workflow-slack-notifications-w
Are you sure this issue hasn't been raised already?
Have you read the Code of Conduct?