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

fix: Super user cache eviction when user is added via env #37785

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Nov 27, 2024

Description

PR to fix the issue with evicting the cache lines for super users added via env. Migration was getting stuck at updateSuperUsers repetitive migration as Mongock was not able to complete the eviction with PermissionGroupRepository which underneath have dependency on mongo driver.

Fixes #37703

/test Sanity

🔍 Cypress test results

Tip

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


Wed, 27 Nov 2024 17:23:12 UTC

Communication

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

  • Yes
  • No

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes in this pull request focus on the DatabaseChangelog2 and MigrationHelperMethods classes, primarily enhancing database migration operations. Key updates include method signature changes, the introduction of new migration methods for MSSQL and Oracle plugins, and adjustments to permission cache management. These modifications aim to streamline database interactions, improve error handling, and ensure proper permission assignments during migrations.

Changes

File Path Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java - Updated updateSuperUsers method to use CacheableRepositoryHelper.
- Added methods: addSslModeSettingsForExistingMssqlDatasource, addOraclePlugin, updateOraclePluginName.
- Included index management and error handling for duplicate keys.
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java - Replaced PermissionGroupRepository with CacheableRepositoryHelper in evictPermissionCacheForUsers method.
- Adjusted cache eviction logic accordingly.

Possibly related PRs

Suggested labels

Bug, Low, Production, Needs Triaging, Platform Administration Pod, RBAC Product, ok-to-test

Suggested reviewers

  • sharat87
  • AnaghHegde
  • nidhi-nair

🎉 In the realm of code, where migrations flow,
New methods emerge, like a bright, shining glow.
Permissions updated, and caches they clear,
With Oracle and MSSQL, we have nothing to fear!
So here’s to the changes, both clever and bright,
In the world of Appsmith, everything feels right! 🌟


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>, 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 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.

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 Bug Something isn't working label Nov 27, 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

🧹 Outside diff range and nitpick comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java (2)

453-456: Consider Refactoring Method Parameters for Improved Readability

The updateSuperUsers method now accepts multiple parameters, which can impact readability and maintainability. Encapsulating these parameters into a configuration object or builder pattern can streamline the method signature and enhance code clarity.


499-499: Add Error Handling for Cache Eviction

To ensure robustness, consider adding error handling around the evictPermissionCacheForUsers call. This will help catch and log any exceptions that might occur during cache eviction, improving observability and debuggability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94768bd and fccb1b3.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java (3 hunks)
🧰 Additional context used
📓 Learnings (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java (1)
Learnt from: sharat87
PR: appsmithorg/appsmith#33602
File: app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/AppsmithRepository.java:29-29
Timestamp: 2024-11-12T08:11:36.416Z
Learning: The codebase has mechanisms to gracefully handle `null` values, making the use of `Optional` for `AclPermission` unnecessary in certain contexts.
🔇 Additional comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java (3)

24-24: LGTM!

The import statement is correctly placed and follows the package naming convention.


214-214: LGTM!

The parameter type change from PermissionGroupRepository to CacheableRepositoryHelper aligns with the new caching strategy while maintaining the method's interface compatibility.


226-228: Consider the impact of blocking operations

While the blocking call ensures immediate cache eviction, it could impact performance in high-throughput scenarios. Consider if non-blocking alternatives are feasible.

Consider returning the Mono<Void> and letting the caller decide the blocking behavior if appropriate for your use case:

-                cacheableRepositoryHelper
-                        .evictPermissionGroupsUser(user.getEmail(), user.getTenantId())
-                        .block();
+                return cacheableRepositoryHelper
+                        .evictPermissionGroupsUser(user.getEmail(), user.getTenantId());
✅ Verification successful

Blocking operation is necessary in this migration context

The blocking call is intentional and appropriate here:

  • The code is within a migration method where synchronous execution is required
  • There's an explicit comment indicating the blocking is needed for cache eviction before proceeding
  • The implementation of evictPermissionGroupsUser is a lightweight cache eviction operation (returns Mono.empty())
  • Other cache eviction operations in the codebase follow similar patterns, particularly in migration and test scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other blocking operations in cache eviction flows
# Look for similar patterns of cache eviction in the codebase
rg -A 2 "evictPermissionGroupsUser.*block\(\)"

# Check for any performance-related comments or issues
rg -A 2 "TODO.*performance|FIXME.*performance" 

Length of output: 97


Script:

#!/bin/bash
# Let's check the implementation of evictPermissionGroupsUser and its usage context
ast-grep --pattern 'class $_ {
  $$$
  evictPermissionGroupsUser($$$) {
    $$$
  }
  $$$
}'

# Check for other block() calls in similar cache eviction patterns
rg "evict.*block\(\)" -A 2

# Look for the method usage to understand the execution context
rg "evictPermissionGroupsUser" -A 2 -B 2

Length of output: 8183

@github-actions github-actions bot added Admin Settings Product Issues in admin settings pages Needs Triaging Needs attention from maintainers to triage Platform Administration Pod Issues related to platform administration & management Production Release Blocker This issue must be resolved before the release labels Nov 27, 2024
@abhvsn abhvsn added the ok-to-test Required label for CI label Nov 27, 2024
@abhvsn abhvsn changed the title fix: Revert the permission group repo from updateSuperUser migration fix: Super user cache eviction when user is added via env Nov 27, 2024
@abhvsn
Copy link
Contributor Author

abhvsn commented Nov 27, 2024

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12054814563.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37785.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-37785.dp.appsmith.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Settings Product Issues in admin settings pages Bug Something isn't working Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Platform Administration Pod Issues related to platform administration & management Production Release Blocker This issue must be resolved before the release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Adding external Mongo DB URI in the Advance Settings of Admin section is bringing instance down.
1 participant