-
Notifications
You must be signed in to change notification settings - Fork 219
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
Fix #468 by implementing short-time cache for authorization middleware #502
Conversation
Will fix the build failure. It’s just a matter of test code. |
Codecov Report
@@ Coverage Diff @@
## master #502 +/- ##
============================================
+ Coverage 83.77% 83.93% +0.16%
- Complexity 2638 2665 +27
============================================
Files 294 294
Lines 7043 7097 +54
Branches 579 592 +13
============================================
+ Hits 5900 5957 +57
Misses 783 783
+ Partials 360 357 -3
Continue to review full report at Codecov.
|
} | ||
|
||
// token -> auth.test response | ||
private final ConcurrentMap<String, CachedAuthTestResponse> tokenToAuthTestCache = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to clean up very old cache data to avoid excessive memory usage in extreme cases. As I don't want to add any dependencies only for this, we can implement a simple mechanism on our own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -22,6 +28,9 @@ | |||
private final AppConfig appConfig; | |||
private final InstallationService installationService; | |||
|
|||
private Optional<AuthTestResponse> cachedAuthTestResponse = Optional.empty(); | |||
private AtomicLong lastCachedMillis = new AtomicLong(0L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to @aoberoi 's suggestion here: #468 (comment), we can remove this TTL and store the response when booting a Bolt app as with Bolt for JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I came to think removing TTL from only single team auth may be confusing. I decided to add a "permanent" option by giving a negative TTL value instead.
This PR is ready for review. I'll wait for other maintianers' responses for a few business days. |
* [kotlin-extension] slackapi#428 slackapi#469 slackapi#501 slackapi#503 slackapi#504 slackapi#513 Add Kotlin DSL modules for constructing Block Kit payloads - thnaks @emanguy @seratch * [bolt] slackapi#502 slackapi#468 short-time cache for authorization middleware - thanks @eamelink @seratch * [slack-api-client] slackapi#508 Bump okhttp version from 4.7.2 to 4.8.0 - thanks @seratch * [slack-api-client] slackapi#500 slackapi#499 Add proxy system properties support (http.proxyHost / http.proxyPort) - thanks @seratch * [slack-api-client] slackapi#512 Redact authorization header from debug logging outputs - thanks @seratch * [slack-api-client] slackapi#507 Add admin.conversations.restrictAccess.* APIs - thanks @seratch * [slack-api-client] slackapi#509 Add conversations.mark API - thanks @seratch * [slack-api-client] slackapi#505 Add calls.participants.remove, admin.usergroups.addTeams API - thanks @seratch * [slack-app-backend] slackapi#494 slackapi#496 Add file_share message events & files in message_changed events - thanks @Hariprasad-Ramakrishnan @seratch * [bolt-micronaut] slackapi#508 Bump micronaut from 1.3 to 2.0 - thanks @seratch
* [kotlin-extension] slackapi#428 slackapi#469 slackapi#501 slackapi#503 slackapi#504 slackapi#513 Add Kotlin DSL modules for constructing Block Kit payloads - thnaks @emanguy @seratch * [bolt] slackapi#502 slackapi#468 short-time cache for authorization middleware - thanks @eamelink @seratch * [slack-api-client] slackapi#508 Bump okhttp version from 4.7.2 to 4.8.0 - thanks @seratch * [slack-api-client] slackapi#500 slackapi#499 Add proxy system properties support (http.proxyHost / http.proxyPort) - thanks @seratch * [slack-api-client] slackapi#512 Redact authorization header from debug logging outputs - thanks @seratch * [slack-api-client] slackapi#507 Add admin.conversations.restrictAccess.* APIs - thanks @seratch * [slack-api-client] slackapi#509 Add conversations.mark API - thanks @seratch * [slack-api-client] slackapi#505 Add calls.participants.remove, admin.usergroups.addTeams API - thanks @seratch * [slack-app-backend] slackapi#494 slackapi#496 Add file_share message events & files in message_changed events - thanks @Hariprasad-Ramakrishnan @seratch * [bolt-micronaut] slackapi#508 Bump micronaut from 1.3 to 2.0 - thanks @seratch
* [kotlin-extension] slackapi#428 slackapi#469 slackapi#501 slackapi#503 slackapi#504 slackapi#513 Add Kotlin DSL modules for constructing Block Kit payloads - thnaks @emanguy @seratch * [bolt] slackapi#502 slackapi#468 short-time cache for authorization middleware - thanks @eamelink @seratch * [slack-api-client] slackapi#508 Bump okhttp version from 4.7.2 to 4.8.0 - thanks @seratch * [slack-api-client] slackapi#500 slackapi#499 Add proxy system properties support (http.proxyHost / http.proxyPort) - thanks @seratch * [slack-api-client] slackapi#512 Redact authorization header from debug logging outputs - thanks @seratch * [slack-api-client] slackapi#507 Add admin.conversations.restrictAccess.* APIs - thanks @seratch * [slack-api-client] slackapi#509 Add conversations.mark API - thanks @seratch * [slack-api-client] slackapi#505 Add calls.participants.remove, admin.usergroups.addTeams API - thanks @seratch * [slack-app-backend] slackapi#494 slackapi#496 Add file_share message events & files in message_changed events - thanks @Hariprasad-Ramakrishnan @seratch * [bolt-micronaut] slackapi#508 Bump micronaut from 1.3 to 2.0 - thanks @seratch
* [kotlin-extension] slackapi#428 slackapi#469 slackapi#501 slackapi#503 slackapi#504 slackapi#513 Add Kotlin DSL modules for constructing Block Kit payloads - thnaks @emanguy @seratch * [bolt] slackapi#502 slackapi#468 short-time cache for authorization middleware - thanks @eamelink @seratch * [slack-api-client] slackapi#508 Bump okhttp version from 4.7.2 to 4.8.0 - thanks @seratch * [slack-api-client] slackapi#500 slackapi#499 Add proxy system properties support (http.proxyHost / http.proxyPort) - thanks @seratch * [slack-api-client] slackapi#512 Redact authorization header from debug logging outputs - thanks @seratch * [slack-api-client] slackapi#507 Add admin.conversations.restrictAccess.* APIs - thanks @seratch * [slack-api-client] slackapi#509 Add conversations.mark API - thanks @seratch * [slack-api-client] slackapi#505 Add calls.participants.remove, admin.usergroups.addTeams API - thanks @seratch * [slack-app-backend] slackapi#494 slackapi#496 Add file_share message events & files in message_changed events - thanks @Hariprasad-Ramakrishnan @seratch * [bolt-micronaut] slackapi#508 Bump micronaut from 1.3 to 2.0 - thanks @seratch
Summary
This pull request fixes #468 by introducing new options as below.
The default behavior won't be changed. Only when a Bolt app turns the flag on, the cache will be enabled.
The cache layer doesn't support distributed cache implementations (e.g., the ones using Memcached, Redis) by design. As mentioned in #468, the purpose of this cache is to reduce the number of
auth.test
API calls in Bolt apps that tend to receive lots of incoming requests from Slack in a short time of period.TODO: Update document when releasing v1.1
Requirements (place an
x
in each[ ]
)