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: add slackv2 notification #29264

Merged
merged 7 commits into from
Jul 17, 2024
Merged

feat: add slackv2 notification #29264

merged 7 commits into from
Jul 17, 2024

Conversation

eschutho
Copy link
Member

@eschutho eschutho commented Jun 15, 2024

SUMMARY

SeeSIP

This PR adds a new Notification SlackV2Notification that uses the Slack upload files v1 method. It is required for slack workspace owners to add the channels:read scope to their workspace in order to use this api. It also fetches all slack channels in order to convert user-inputed names to api-required ids. Because of this, I added a UI to support this.

Per the SIP, the both the api and UI will attempt to convert the notification to SlackV2 if the scopes are in place.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After:

With feature flag on:

Screen.Recording.2024-07-10.at.4.33.54.PM.mov

With feature flag off (after it has been turned on once, so the existing v2 slack reports do not convert back to v1):

Screen.Recording.2024-07-10.at.4.35.23.PM.mov

TESTING INSTRUCTIONS

Create a new slack application and connect it to Superset.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@github-actions github-actions bot added api Related to the REST API packages labels Jun 15, 2024
@eschutho eschutho changed the title [POC] feat: add slackv2 notification feat: add slackv2 notification Jun 17, 2024
@eschutho eschutho force-pushed the elizabeth/slackv2 branch 5 times, most recently from cfbe2ec to c156187 Compare June 19, 2024 01:24
@eschutho eschutho force-pushed the elizabeth/slackv2 branch 5 times, most recently from 026ac4c to eccc201 Compare June 21, 2024 00:53
@eschutho eschutho marked this pull request as ready for review June 21, 2024 15:55
@dosubot dosubot bot added alert-reports Namespace | Anything related to the Alert & Reports feature change:backend Requires changing the backend change:frontend Requires changing the frontend labels Jun 21, 2024
get_slack_channels_schema = {
"type": "object",
"properties": {
"seach_string": {"type": "string"},
Copy link
Member

Choose a reason for hiding this comment

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

NIT: "search_string" vs "seach_string"?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks for catching!

@eschutho eschutho mentioned this pull request Jul 10, 2024
9 tasks
@eschutho eschutho force-pushed the elizabeth/slackv2 branch 2 times, most recently from 1e048b2 to a0ea944 Compare July 10, 2024 23:58
@eschutho
Copy link
Member Author

/testenv up

Copy link
Contributor

@eschutho Ephemeral environment spinning up at http://35.87.151.148:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@eschutho
Copy link
Member Author

/testenv up FEATURE_ALERT_REPORTS=true

Copy link
Contributor

@eschutho Ephemeral environment spinning up at http://35.94.230.149:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

search.lower()
for search in (search_string.split(",") if search_string else [])
]
print(channels)
Copy link
Member

Choose a reason for hiding this comment

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

Did you want to print out channels?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching!

Copy link
Member

@sadpandajoe sadpandajoe left a comment

Choose a reason for hiding this comment

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

LGTM

for search in (search_string.split(",") if search_string else [])
]

channels = [
Copy link
Member

Choose a reason for hiding this comment

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

I'm just staring at this section of the code more and more, do we have good coverage for this function? Looking a this logic, I could see someone making a change and breaking the channels that are returned.

Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard work on this!

@@ -31,6 +46,80 @@ def get_slack_client() -> WebClient:
return WebClient(token=token, proxy=current_app.config["SLACK_PROXY"])


def get_channels_with_search(
Copy link
Member

Choose a reason for hiding this comment

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

So bad that we need this function that seems prone to errors but if Slack does not allow searching, then we are out of luck

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, agree

@@ -94,7 +94,7 @@ def execute(self: Celery.task, report_schedule_id: int) -> None:
).run()
except ReportScheduleUnexpectedError:
logger.exception(
"An unexpected occurred while executing the report: %s", task_id
"An unexpected error occurred while executing the report: %s", task_id
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch

Copy link
Member

@geido geido left a comment

Choose a reason for hiding this comment

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

A bunch of minor comments from a second look. Still LGTM.

);

const recipientsInput = screen.getByTestId('recipients');
fireEvent.change(recipientsInput, {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use userEvent here instead and everywhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can in two places, but it doesn't work in the others.

return self.response(200, result=channels)
except SupersetException as ex:
logger.error("Error fetching slack channels %s", str(ex))
return self.response_422(message=str(ex))
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to expose the original error message here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, because it gives information about how to fix the slack issue. Whether it's missing a scope or the channel doesn't exist. Otherwise, it's difficult to know how to unblock the error.

@eschutho eschutho merged commit 6dbfe2a into master Jul 17, 2024
34 checks passed
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

eschutho added a commit that referenced this pull request Jul 24, 2024
@rusackas rusackas deleted the elizabeth/slackv2 branch September 27, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alert-reports Namespace | Anything related to the Alert & Reports feature api Related to the REST API change:backend Requires changing the backend change:frontend Requires changing the frontend packages preset-io size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants