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: improve slack app addon scalability #4284

Merged
merged 13 commits into from
Jul 20, 2023

Conversation

nunogois
Copy link
Member

https://linear.app/unleash/issue/2-1237/explore-slack-app-addon-scalability-and-limitations

Relevant document: https://linear.app/unleash/document/894e12b7-802c-4bc5-8c22-75af0e66fa4b

  • Implements 30s cache layer for Slack channels;
  • Adds error logging;
  • Adds respective tests;
  • Slight refactors and improvements for overall robustness;

@sonatype-lift
Copy link

sonatype-lift bot commented Jul 19, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@vercel
Copy link

vercel bot commented Jul 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 0:25am
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2023 0:25am

src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
Comment on lines 108 to 112
} else if (error.code === ErrorCode.RateLimitedError) {
this.logger.error(
`Error handling event ${event.type}. A rate limit error occurred: retry after ${error.retryAfter} seconds`,
error,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, WebClient will handle all these for us, right? If that's the case, should the log be an error or just a warn? Maybe it could be an info message saying that "It will be retried" more than "Retry later" which seems to indicate the client/user has to do something

Copy link
Member Author

@nunogois nunogois Jul 20, 2023

Choose a reason for hiding this comment

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

In this case, this is still an error and should only happen in case WebClient does not handle rate limiting for us.
https://slack.dev/node-slack-sdk/web-api#rate-limits

You might not want to the WebClient to handle rate limits in this way. Perhaps the operation was time sensitive, and it won’t be useful by the time Slack is ready for another request. Or, you have a more sophisticated approach. In these cases, you can set the rejectRateLimitedCalls option on the client to true. Once you set this option, method calls can fail with rate limiting related errors. These errors have a code property set to ErrorCode.RateLimitedError. See error handling for more details.

I've added a callback for the RATE_LIMITED event so we can log it. I'm keeping this error handling for now, but we can remove it if you think it's better. Addressed in 1d2db10

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I wasn't concerned about logging when WebClient receives a rate limit and handles it internally, I was rather thinking that the error might not happen.

It's ok what you did in 1d2db10 I'm not sure if client.on(WebClientEvent.RATE_LIMITED is needed (or if it has to be a warn, could be maybe a debug), but we can change this later, so no worries for now

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah, fair point. I'll keep it for now then, but I changed it to debug for now: a8a7410

src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
src/lib/addons/slack-app.ts Outdated Show resolved Hide resolved
Co-authored-by: Gastón Fournier <gaston@getunleash.io>
Copy link
Contributor

@gastonfournier gastonfournier left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for looking into all my comments!

Comment on lines +145 to +154
it('should refresh Slack channels cache after 30 seconds', async () => {
await addon.handleEvent(event, { accessToken });

jest.advanceTimersByTime(30000);

await addon.handleEvent(event, { accessToken });

expect(slackApiCalls.length).toBe(2);
expect(conversationsList).toHaveBeenCalledTimes(2);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants