Usiel opened a new issue, #32480:
URL: https://github.com/apache/superset/issues/32480

   ### Bug description
   
   Preconditions: Be connected to a Slack workspace with thousands of channels 
and even more archived channels.
   
   1. Make sure Slack is connected (v1 or v2)
   2. Edit an alert and open the "Notification method" section
   3. Select Slack
   
   Actual: The request to `/api/v1/report/slack_channels/?...` errors out with 
a rate-limit error from the Slack client.
   Expected: User can select a channel/group without much delay.
   
   ### Screenshots/recordings
   
   
![Image](https://github.com/user-attachments/assets/7dd01bf5-e827-45d3-ac44-4743d968cb7e)
   
   ### Superset version
   
   4.1.1
   
   ### Python version
   
   3.11
   
   ### Node version
   
   Not applicable
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   ### Why?
   
   From what I could see this is due to Slack's implementation of the 
`conversation.list` endpoint. When the connected workspace has lots of archived 
channels, then the cursor will return far less conversations than specified in 
the request (using `limit=999`). This means we end up doing a lot of requests 
to fully iterate all conversations, eventually running into the rate-limit.
   
   I applied a diff to properly handle rate-limit errors. This allows the 
request to eventually finish (6 minutes for our workspace) but it's not a great 
user experience 😆 (It may still be useful to add the rate-limit handler to 
preempt other Slack API issues).
   
   ```diff
   diff --git a/superset/utils/slack.py b/superset/utils/slack.py
   index 468429fb60..5d0cbfe507 100644
   --- a/superset/utils/slack.py
   +++ b/superset/utils/slack.py
   @@ -22,6 +22,7 @@ from typing import Optional
    from flask import current_app
    from slack_sdk import WebClient
    from slack_sdk.errors import SlackApiError
   +from slack_sdk.http_retry.builtin_handlers import RateLimitErrorRetryHandler
   
    from superset import feature_flag_manager
    from superset.exceptions import SupersetException
   @@ -43,7 +44,12 @@ def get_slack_client() -> WebClient:
        token: str = current_app.config["SLACK_API_TOKEN"]
        if callable(token):
            token = token()
   -    return WebClient(token=token, proxy=current_app.config["SLACK_PROXY"])
   +    client = WebClient(token=token, proxy=current_app.config["SLACK_PROXY"])
   +
   +    rate_limit_handler = RateLimitErrorRetryHandler(max_retry_count=2)
   +    client.retry_handlers.append(rate_limit_handler)
   +
   +    return client
   
   
    def get_channels_with_search(
   ```
   
   ### Options
   
   - Update the Slack conversations asynchronously with a configurable Celery 
task and then use the cached conversation list when a user makes it to the edit 
alert window? Make sure rate-limiting errors are handled.
   - Allow users to enter any string as recipient and map to a channel ID 
asynchronously?
   - ...?
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [x] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to