Skip to content

chore: Add cleanup and update stage for tenant at the server restart#35786

Merged
abhvsn merged 9 commits intoreleasefrom
fix-policies-caching
Aug 20, 2024
Merged

chore: Add cleanup and update stage for tenant at the server restart#35786
abhvsn merged 9 commits intoreleasefrom
fix-policies-caching

Conversation

@abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Aug 20, 2024

Description

PR to add the cleanup and update default tenant at the server restart. This was required because whenever we update tenant via migrations the result gets reverted because the cached tenant is not getting updated as we generally end up updating only the MongoDB state and not the cached entry.

/test Sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10471754877
Commit: e288cfe
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Tue, 20 Aug 2024 13:01:42 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Implemented a mechanism to refresh tenant policies and manage cache cleanup during server restarts, ensuring accurate policy enforcement for multi-tenant applications.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 20, 2024

Caution

Review failed

The head commit changed during the review from 36534dd to e288cfe.

Walkthrough

The newly added TenantConfig class enhances the server's capabilities for managing tenant policies effectively. This Spring configuration class ensures that the default tenant's policies are refreshed, and cached data is cleaned up during server restarts, thereby promoting accurate policy enforcement in multi-tenant environments. This change is crucial for maintaining operational integrity in applications that serve multiple tenants.

Changes

File(s) Change Summary
app/server/appsmith-server/src/main/java/com/... Introduced TenantConfig class for managing tenant policies and cache cleanup. Added cleanupAndUpdateRefreshDefaultTenantPolicies method to refresh tenant data on server restart.

Poem

In the realm of code, a change so bright,
TenantConfig shines, bringing policies to light.
With a sweep of the cache and a flick of the key,
Multi-tenancy thrives, as smooth as can be!
Refreshing our tenants, with data in tow,
Here’s to the updates, let progress flow! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Aug 20, 2024
@abhvsn abhvsn self-assigned this Aug 20, 2024
@abhvsn abhvsn requested a review from nidhi-nair August 20, 2024 11:16
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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c8d4a9 and 183605f.

Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TenantConfig.java (1 hunks)
Additional comments not posted (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TenantConfig.java (3)

1-10: Imports are appropriate.

The package and import statements are correctly defined and necessary for the functionality of the TenantConfig class.


12-14: Class declaration and annotations are appropriate.

The @Configuration and @RequiredArgsConstructor annotations are correctly used for a Spring configuration class.


16-17: Field declarations are appropriate.

The tenantService and cacheableRepositoryHelper fields are correctly declared as final, ensuring immutability and proper dependency injection.

@abhvsn abhvsn added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 20, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 183605f and f7f5184.

Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TenantConfig.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/TenantConfig.java


@Configuration
@RequiredArgsConstructor
public class TenantConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can we make this a listener on the Spring context refresh event so that the execution period for this eviction is predictable?

// Bean to cleanup the cache and update the default tenant policies on every server restart. This will make sure
// cache will be updated if we update the tenant via migrations.
@Bean
public void cleanupAndUpdateRefreshDefaultTenantPolicies() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that every time any pod restarts it will reset the cache? Do you see any downside to this with the current stability issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is by type, shall we consider making this a conditional eviction instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are cleaning up the cache so yeah definitely for the first call we will hit the DB, but we will have correct data. Ideally we want to hook this with the DB migrations which updates the default tenant. Any suggestions from your side?

@github-actions
Copy link

Failed server tests

  • com.appsmith.server.services.ConsolidatedAPIServiceImplTest#testErrorResponseWhenAnonymousUserAccessPrivateApp
  • com.appsmith.server.services.ConsolidatedAPIServiceImplTest#testErrorWhenModeIsNullAndPageIdAvailable
  • com.appsmith.server.services.ConsolidatedAPIServiceImplTest#testPageLoadResponseForEditMode
  • com.appsmith.server.services.ConsolidatedAPIServiceImplTest#testPageLoadResponseForViewMode
  • com.appsmith.server.services.ConsolidatedAPIServiceImplTest#testPageLoadResponseWhenPageIdAndApplicationIdMissing

@abhvsn abhvsn requested a review from nidhi-nair August 20, 2024 12:02
nidhi-nair
nidhi-nair previously approved these changes Aug 20, 2024
nidhi-nair
nidhi-nair previously approved these changes Aug 20, 2024
@appsmithorg appsmithorg deleted a comment from github-actions bot Aug 20, 2024
@appsmithorg appsmithorg deleted a comment from github-actions bot Aug 20, 2024
@abhvsn abhvsn requested a review from AnaghHegde August 20, 2024 12:37
Copy link
Contributor

@AnaghHegde AnaghHegde left a comment

Choose a reason for hiding this comment

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

Minor nit, rest looks good to me

@abhvsn abhvsn requested a review from AnaghHegde August 20, 2024 12:41
@github-actions
Copy link

Failed server tests

  • com.external.plugins.RestApiPluginTest#testHttpGetRequestRawBody

@abhvsn abhvsn merged commit d1de33b into release Aug 20, 2024
@abhvsn abhvsn deleted the fix-policies-caching branch August 20, 2024 13:06
abhvsn added a commit that referenced this pull request Aug 20, 2024
…35786)

## Description
PR to add the cleanup and update default tenant at the server restart.
This was required because whenever we update tenant via migrations the
result gets reverted because the cached tenant is not getting updated as
we generally end up updating only the MongoDB state and not the cached
entry.

/test Sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10471754877>
> Commit: e288cfe
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10471754877&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Tue, 20 Aug 2024 13:01:42 UTC
<!-- end of auto-generated comment: Cypress test results  -->

## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Implemented a mechanism to refresh tenant policies and manage cache
cleanup during server restarts, ensuring accurate policy enforcement for
multi-tenant applications.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

(cherry picked from commit d1de33b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants