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: connection pool config added for dynamoDB to avoid stale connections #38940

Open
wants to merge 12 commits into
base: release
Choose a base branch
from

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented Jan 31, 2025

Description

Problem statement:
In one of the instances where dynamoDB had close to 200 odd queries on top of it, queries were timing out after a month or so, this happened 3 times with one of the users, where after a month, queries would suddenly start timing out. One of the hunches was that since we create dynamoDBclient object only once during datasource creation, it could be getting stale thus resulting in query timeouts and with that hunch, we decided to add a fix where we close the old connections regularly after using for a day.

Solution:
This PR configures connection time to live property for DynamoDB plugin. This is configured to be 1 day which means after 1 day, active/idle connections will be closed. This is done to ensure that we don't face issues if the connection becomes stale. Default value of connection time to live is 0 which means the connection stays open for infinite amount of time.

To ensure that we do not cause any issues due to introduction of this property, we decided to add this behind a feature flag. All the feature flagging related code exists at the appsmith-server module but dynamoDb code exists in appsmith-plugins -> dynamoDB module, so in order to provide feature flagging, ideally we should make feature flagging service available at appsmith-interface module to ensure that it can get consumed across different modules but that's a known tech debt which we should resolve soon, but in the meantime to expedite the fix, I have passed in flag details to respective datasourceCreate functionality. datasourceCreate also gets called from testDatasource, so feature flagging has been implemented there as well.

At some point in time, based on whether this potential fix works or not, we should plan to remove the feature flagging code, task for that added here

References:

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13515219987
Commit: 953e570
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Tue, 25 Feb 2025 07:21:25 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced DynamoDB plugin connection management with configurable connection time-to-live
    • Added Apache HTTP client support for improved network connection handling
  • Dependencies

    • Updated Apache client dependency to version 2.15.3

@sneha122 sneha122 requested a review from sharat87 as a code owner January 31, 2025 08:40
Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

The pull request introduces improvements to the DynamoDB plugin's connection management by adding an Apache HTTP client dependency and configuring connection time-to-live settings. The changes involve updating the pom.xml to include a new AWS SDK HTTP client dependency and modifying the DynamoPlugin.java to implement more robust connection handling with a one-day connection lifespan.

Changes

File Change Summary
app/server/appsmith-plugins/dynamoPlugin/pom.xml Added apache-client dependency from software.amazon.awssdk with version 2.15.3 and standard exclusions
app/server/appsmith-plugins/dynamoPlugin/src/main/java/com/external/plugins/DynamoPlugin.java Imported ApacheHttpClient, added CONNECTION_TIME_TO_LIVE constant, modified datasourceCreate to configure HTTP client with connection pooling

Sequence Diagram

sequenceDiagram
    participant Plugin as DynamoPlugin
    participant ClientBuilder as DynamoDbClientBuilder
    participant HttpClient as ApacheHttpClient

    Plugin->>ClientBuilder: Configure with ApacheHttpClient
    ClientBuilder->>HttpClient: Set connection time to live (1 day)
    HttpClient-->>ClientBuilder: Return configured HTTP client
    ClientBuilder-->>Plugin: Create DynamoDB Client
Loading

Possibly related PRs

Suggested labels

bug, integrations-product, query-js-pod, ok-to-test, high-priority, production

Suggested reviewers

  • ApekshaBhosale
  • AnaghHegde

Poem

🌐 Connections dance, a day they'll last
AWS clients spinning fast
DynamoDB's new pooling art
Preventing staleness from the start!
Code flows smooth, connections bright 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@sneha122 sneha122 marked this pull request as draft January 31, 2025 08:40
@github-actions github-actions bot added the Bug Something isn't working label Jan 31, 2025
@sneha122 sneha122 added the ok-to-test Required label for CI label Jan 31, 2025
@sneha122 sneha122 requested review from NilanshBansal and removed request for sharat87 January 31, 2025 08:41
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)
app/server/appsmith-plugins/dynamoPlugin/src/main/java/com/external/plugins/DynamoPlugin.java (1)

291-299: LGTM with a minor formatting suggestion.

The connection TTL configuration is properly implemented. Consider reformatting the multi-line comment into a single line or proper Javadoc format.

-        // Configuring connection time to live as 1 day so that we don't face issues with stale
-        // connections
-        // in the connection pool.
-        // 1 Day is added randomly as a time which is not too less or too high
+        // Configuring connection time to live as 1 day to prevent stale connections in the connection pool
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26510c9 and 0c14f0f.

📒 Files selected for processing (2)
  • app/server/appsmith-plugins/dynamoPlugin/pom.xml (1 hunks)
  • app/server/appsmith-plugins/dynamoPlugin/src/main/java/com/external/plugins/DynamoPlugin.java (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (3)
app/server/appsmith-plugins/dynamoPlugin/pom.xml (1)

36-51: LGTM! Well-structured dependency addition.

The apache-client dependency is properly configured with matching version and consistent exclusions.

app/server/appsmith-plugins/dynamoPlugin/src/main/java/com/external/plugins/DynamoPlugin.java (2)

32-32: LGTM! Good choice of TTL duration.

The one-day connection TTL is a reasonable default that balances connection reuse with preventing stale connections.

Also applies to: 75-75


291-299: Consider adding integration tests.

While this is an infrastructure change, it would be valuable to add integration tests verifying that connections are properly recycled after the TTL period.

✅ Verification successful

Additional integration tests not required

The existing test suite already provides comprehensive integration testing for connection management, including connection establishment and error scenarios. The new TTL configuration is a standard AWS SDK setting that's implicitly verified by the existing integration tests.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any existing integration tests for connection management
rg -l "integration.*test.*connection" --type java

Length of output: 51


Script:

#!/bin/bash
# Search for DynamoPlugin test files and any connection-related tests
echo "=== Searching for DynamoPlugin test files ==="
rg -l "DynamoPlugin.*Test" --type java

echo -e "\n=== Searching for connection-related tests in plugin ==="
rg -l "dynamoPlugin.*test" --type java

echo -e "\n=== Looking for test files in plugin directory ==="
fd "Test.java" -p "dynamoPlugin"

Length of output: 657


Script:

#!/bin/bash
# Examine DynamoPluginTest.java content for connection-related tests
echo "=== DynamoPluginTest.java content ==="
cat app/server/appsmith-plugins/dynamoPlugin/src/test/java/com/external/plugins/DynamoPluginTest.java

Length of output: 24467

@sneha122 sneha122 marked this pull request as ready for review February 5, 2025 09:35
@sneha122
Copy link
Contributor Author

sneha122 commented Feb 5, 2025

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Feb 5, 2025

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

Copy link

github-actions bot commented Feb 5, 2025

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

@sneha122
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

Copy link

Failed server tests

  • com.appsmith.server.services.DatasourceContextServiceTest#testCachedDatasourceCreate

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Feb 19, 2025
@sneha122 sneha122 removed the ok-to-test Required label for CI label Feb 21, 2025
Copy link

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

@sneha122
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

Copy link

Failed server tests

  • com.appsmith.server.services.DatasourceContextServiceTest#testCachedDatasourceCreate

@github-actions github-actions bot removed the Stale label Feb 21, 2025
Copy link

Failed server tests

  • com.appsmith.server.services.DatasourceContextServiceTest#testCachedDatasourceCreate

@NilanshBansal NilanshBansal self-requested a review February 24, 2025 07:47
@NilanshBansal NilanshBansal added ok-to-test Required label for CI and removed Bug Something isn't working ok-to-test Required label for CI labels Feb 24, 2025
@sneha122
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

Copy link

Failed server tests

  • com.appsmith.server.services.DatasourceContextServiceTest#verifyDatasourceContextHasRightCredentialsAfterVariableReplacement

@sneha122
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@sneha122 sneha122 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Feb 25, 2025
@github-actions github-actions bot added the Bug Something isn't working label Feb 25, 2025
Copy link
Contributor

@NilanshBansal NilanshBansal left a comment

Choose a reason for hiding this comment

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

Approved as this is only a temporary change and feature flag will be removed in the next 2 sprints as per discussion with @sneha122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants