-
Notifications
You must be signed in to change notification settings - Fork 113
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
BugFix: Notification integration issues #339
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ package org.opensearch.indexmanagement.indexstatemanagement.util | |
import org.opensearch.OpenSearchStatusException | ||
import org.opensearch.client.Client | ||
import org.opensearch.client.node.NodeClient | ||
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT | ||
import org.opensearch.commons.authuser.User | ||
import org.opensearch.commons.destination.message.LegacyBaseMessage | ||
import org.opensearch.commons.notifications.NotificationsPluginInterface | ||
import org.opensearch.commons.notifications.action.LegacyPublishNotificationRequest | ||
|
@@ -45,18 +47,37 @@ suspend fun LegacyBaseMessage.publishLegacyNotification(client: Client) { | |
/** | ||
* Extension function for publishing a notification to a channel in the Notification plugin. | ||
*/ | ||
suspend fun Channel.sendNotification(client: Client, title: String, managedIndexMetaData: ManagedIndexMetaData, compiledMessage: String) { | ||
suspend fun Channel.sendNotification( | ||
client: Client, | ||
title: String, | ||
managedIndexMetaData: ManagedIndexMetaData, | ||
compiledMessage: String, | ||
user: User? | ||
) { | ||
val channel = this | ||
val res: SendNotificationResponse = NotificationsPluginInterface.suspendUntil { | ||
this.sendNotification( | ||
(client as NodeClient), | ||
managedIndexMetaData.getEventSource(title), | ||
ChannelMessage(compiledMessage, null, null), | ||
listOf(channel.id), | ||
it | ||
) | ||
client.threadPool().threadContext.stashContext().use { | ||
// We need to set the user context information in the thread context for notification plugin to correctly resolve the user object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we setting the user object twice in the threadContext? Here and above the calling stack in the runner? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the stash context will remove all the set variables but yes, we are setting it twice but in different format and in a different location in thread context It seems notification plugin has special requirement for internal transport action calls than rest of the cluster |
||
client.threadPool().threadContext.putTransient(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, generateUserString(user)) | ||
val res: SendNotificationResponse = NotificationsPluginInterface.suspendUntil { | ||
this.sendNotification( | ||
(client as NodeClient), | ||
managedIndexMetaData.getEventSource(title), | ||
ChannelMessage(compiledMessage, null, null), | ||
listOf(channel.id), | ||
it | ||
) | ||
} | ||
validateResponseStatus(res.getStatus(), res.notificationEvent.eventSource.referenceId) | ||
} | ||
validateResponseStatus(res.getStatus(), res.notificationEvent.eventSource.referenceId) | ||
} | ||
|
||
private fun generateUserString(user: User?): String { | ||
if (user == null) return "" | ||
val backendRoles = user.backendRoles.joinToString(",") | ||
val roles = user.roles.joinToString(",") | ||
val requestedTenant = user.requestedTenant | ||
val userName = user.name | ||
return "$userName|$backendRoles|$roles|$requestedTenant" | ||
} | ||
|
||
fun ManagedIndexMetaData.getEventSource(title: String): EventSource { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why these are added along with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems these are needed for the sending notification to legacy custom_webhook endpoints, the libraries are no longer in class path - I am not entirely sure where this was removed. Since IM needs it bundling it as part of the zip.
The PR is meant to fix bugs with notification plugin integration and since this is one of the bugs fixed it - I added a line in overview for this. However, I think I missed the renaming of PR - I updated it now