mjlshen opened a new pull request, #42074: URL: https://github.com/apache/superset/pull/42074
### SUMMARY #### Problem Users could not edit Slack recipients in Alerts & Reports when their Slack workspace had a large number of channels. The dropdown failed to load, showing a timeout after 30+ seconds, making the feature unusable for large organizations. #### Root Cause The previous implementation loaded **all** Slack channels in a single blocking request: - For large workspaces this meant fetching thousands of channels before returning anything. - The Slack `conversations.list` API is paginated but has no server-side search. - The request timed out before any results were returned. #### Solution Server-side pagination + search, backed by an optional cache, continuing the work started in https://github.com/apache/superset/pull/35832 **Backend — pagination & search** (`superset/utils/slack.py`, `superset/reports/api.py`, `superset/reports/schemas.py`) - New `get_channels_with_search()` with two paths: - **No search** — returns a single page directly from the Slack API (fast). - **With search** — streams Slack API pages, filtering matches until the page limit is reached; supports comma-separated OR terms (e.g. `engineering,marketing`). - `GET /api/v1/report/slack_channels/` now accepts `search_string`, `types`, `exact_match`, `cursor`, `limit` (bounded 1–999), and `force`. - Page size raised 200 → 999 to cut API calls and reduce rate-limiting. - Removed the legacy fetch-everything `get_channels()` helper. **Backend — caching** (`superset/tasks/slack.py`, `superset/config.py`) - The `slack.cache_channels` Celery task warms an in-memory cache of the full channel list; `get_channels_with_search` serves paginated/filtered results from cache when warm (no Slack API calls). - Bounded by `SLACK_CACHE_MAX_CHANNELS`; when a workspace exceeds it, a continuation cursor is stored so lookups transparently fall back to the API past the cache boundary. - `force=true` clears the cache and re-triggers warm-up. - **Works without a Celery worker**: on a cold cache, an unfiltered first page that returns the whole workspace in one page is written through to the cache (non-blocking); larger workspaces rely on the async warm-up task. - New config: `SLACK_ENABLE_CACHING` (default on), `SLACK_CACHE_MAX_CHANNELS` (20000), `SLACK_CACHE_WARMUP_TIMEOUT` (300s, applied per dispatch so operator overrides are honored). Reuses existing `SLACK_CACHE_TIMEOUT`. **Frontend** (`NotificationMethod.tsx`, `hooks/useSlackChannels.ts`, `AlertReportModal.tsx`) - Replaced the load-everything dropdown with `AsyncSelect` incremental pagination + debounced server-side search, extracted into a `useSlackChannels` hook. - Added a "refresh channels" button (cache-bypass) that preserves current selections. - Graceful fallback to Slack V1 manual input on fetch errors, **without clearing already-saved recipients**. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF #### Before  #### After  ### TESTING INSTRUCTIONS #### Automated (no Slack workspace needed) ```bash pytest tests/unit_tests/utils/slack_test.py tests/unit_tests/tasks/test_slack.py -v pytest tests/integration_tests/reports/api_tests.py -k slack_channels -v cd superset-frontend && npm run test -- NotificationMethod useSlackChannels ``` #### Manual Prereqs: `FEATURE_FLAGS = {"ALERT_REPORTS": True, "ALERT_REPORT_SLACK_V2": True}` and `SLACK_API_TOKEN` set (bot scopes `channels:read`, `groups:read`). 1. Open an Alert/Report → **Notification method → Slack**. The channel dropdown loads quickly and paginates as you scroll; typing filters server-side — no timeout even on very large workspaces. 2. Select channels, click **refresh** — selections are preserved. 3. (No Celery worker) open the dropdown on a small workspace; server logs show `Warmed Slack channel cache ... without a Celery worker`, and a second load shows `Using cache path`. 4. (With Celery worker) set `SLACK_CACHE_WARMUP_TIMEOUT`; a `force` refresh dispatches `slack.cache_channels` with the configured time limit. ### ADDITIONAL INFORMATION - [ ] Has associated issue: Closely related to #35661 - [x] Required feature flags: `ALERT_REPORTS`, `ALERT_REPORT_SLACK_V2` - [x] Changes UI - [ ] Includes DB Migration - [ ] Introduces new feature or API - [ ] Removes existing feature or API -- 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]
