Skip to content

Handle rate limit errors from Slack on new alert creation #1986

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

Merged
merged 1 commit into from
Apr 28, 2025

Conversation

myftija
Copy link
Collaborator

@myftija myftija commented Apr 28, 2025

This PR creates a workaround to handle rate limiting issues from Slack when listing all channels of a workspace.

This is a workaround to the current way we handle Slack channels for creating alerts. For workspaces with a lot of channels (>10000) we might hit the rate limit for this slack endpoint, as multiple requests are needed to fetch all channels. We use the largest allowed page size of 999 to reduce the chance of hitting the rate limit.

This is mainly due to workspaces with a large number of archived channels, which this slack endpoint unfortunately filters out only after fetching the page of channels without applying any filters first:
https://api.slack.com/methods/conversations.list#markdown

We expect most workspaces not to run into this issue, but if they do, we at least return some channels.
In the future, we might revisit the way we handle Slack channels and cache them on our side to support
proper searching. Until then, we track occurrences of this issue using a metric.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of Slack rate limiting when fetching channel lists, allowing partial results to be returned if rate limits are hit.
    • Enhanced reliability when retrieving Slack channels, especially in large workspaces with many channels.
  • Performance

    • Reduced the number of requests to Slack by increasing the page size when fetching channel lists.

Copy link

changeset-bot bot commented Apr 28, 2025

⚠️ No Changeset found

Latest commit: 0639d8b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 28, 2025

Walkthrough

The update consolidates Slack conversation pagination logic into a single function by removing the helper getSlackConversationsPage and inlining its functionality into getAllSlackConversations. Error handling is now managed directly within a try/catch block, replacing the use of an external utility. The Slack API call has been adjusted to use a maximum page size via a limit parameter to minimize the number of API requests. Handling for Slack rate limiting errors has been improved, allowing partial results to be returned if rate limits are hit, while other errors result in exceptions.

Changes

File(s) Change Summary
apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts Removed getSlackConversationsPage. Inlined pagination logic into getAllSlackConversations. Improved error handling, added limit, and adjusted control flow for rate limiting.

Sequence Diagram(s)

sequenceDiagram
    participant Client as WebClient
    participant Presenter as getAllSlackConversations
    loop While more pages
        Presenter->>Client: conversations.list (limit: 999, cursor)
        Client-->>Presenter: Response (channels, next_cursor)
    end
    alt Rate limited error
        Presenter->>Presenter: Log warning, return partial channels
    else Other error
        Presenter->>Presenter: Throw error with details
    end
Loading

Suggested reviewers

  • matt-aitken

Poem

A bunny hopped through code so neat,
Tidied up the Slack repeat.
One function now, with errors caught,
Handles limits, as it ought.
If rate-limited, don’t despair—
Partial channels, handled with care!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e406e6 and 0639d8b.

📒 Files selected for processing (1)
  • apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts (1)

107-147: Solid implementation of rate limit handling for Slack API calls

This approach effectively handles rate limit errors by returning partial results instead of failing completely. The code is well-commented and explains the issue, workaround, and future plans clearly.

Consider adding the metric tracking mentioned in your comment on line 138 to monitor occurrences of this rate limiting issue, if not implemented elsewhere:

      // proper searching. Until then, we track occurrences of this issue using a metric.
+      // TODO: Add metric tracking for rate limiting occurrences
      return channels;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b0e4f2 and 9e406e6.

📒 Files selected for processing (1)
  • apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
🔇 Additional comments (2)
apps/webapp/app/presenters/v3/NewAlertChannelPresenter.server.ts (2)

110-116: Good optimization with the maximum page size

Using the maximum allowed page size of 999 is an excellent approach to reduce the number of API requests needed and mitigate rate limiting issues.


142-147: Well-structured error handling

The error handling is comprehensive, with appropriate error type checking and informative error messages.

@myftija myftija force-pushed the fix-slack-channel-fetching branch from 9e406e6 to 0639d8b Compare April 28, 2025 03:31
@matt-aitken matt-aitken merged commit 7bdbbdc into triggerdotdev:main Apr 28, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants