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

TESTING EXTERNAL SCRIPT: external merge request from Contributor #36603

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

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented Sep 30, 2024

Description

Fixes #

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.Sanity, @tag.Datasource"

🔍 Cypress test results

Tip

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


Mon, 30 Sep 2024 07:47:11 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced connectivity to Microsoft SQL Server with the addition of the JDBC driver.
    • Improved error handling and validation for datasource configurations, providing clearer feedback for connection issues.
  • Bug Fixes

    • Added specific error messages for missing hostname and database name in datasource configurations.
  • Tests

    • Introduced new tests to validate various invalid datasource configurations, ensuring robust error reporting.

Shirisha-Manthoju and others added 14 commits June 4, 2024 10:08
…g-mssql-configuration' into external-contri/Issue-#24726/feat-wrong-mssql-configuration

$ the commit.
Merge changes from contributor for issue #24726 regarding MSSQL configuration fix
…tion' of https://github.com/appsmithorg/appsmith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…contri/Issue-#24726/feat-wrong-mssql-configuration' into chore/external-contribution-34472
@sneha122 sneha122 added the ok-to-test Required label for CI label Sep 30, 2024
Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The pull request introduces several enhancements to the mssqlPlugin for improved error handling and validation. Key changes include the addition of a Microsoft SQL Server JDBC driver dependency, modifications to the MssqlPlugin class for better connection pool error handling, and the introduction of new error messages for datasource validation. Additionally, the test suite for the plugin has been expanded to cover various invalid datasource configurations, ensuring comprehensive validation of the plugin's functionality.

Changes

Files Change Summary
app/server/appsmith-plugins/mssqlPlugin/pom.xml Added dependency: com.microsoft.sqlserver:mssql-jdbc:11.2.1.jre17.
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java Enhanced error handling and validation logic; refactored validation methods; updated executeParameterized.
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/exceptions/MssqlErrorMessages.java Added new error message constants for validation: DS_MISSING_HOSTNAME_ERROR_MSG, DS_MISSING_DATABASE_NAME_ERROR_MSG.
app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java Introduced new tests for datasource validation covering null credentials, endpoints, host, and authentication.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MssqlPlugin
    participant MssqlPluginExecutor

    User->>MssqlPlugin: Request to connect
    MssqlPlugin->>MssqlPluginExecutor: Validate datasource configuration
    MssqlPluginExecutor->>MssqlPluginExecutor: Check connection mode
    MssqlPluginExecutor->>MssqlPluginExecutor: Validate endpoints
    MssqlPluginExecutor->>MssqlPluginExecutor: Validate authentication
    MssqlPluginExecutor-->>MssqlPlugin: Return validation results
    MssqlPlugin-->>User: Connection status
Loading

🎉 In the realm of code, changes unfold,
With drivers added, and validations bold.
Errors handled with care,
Tests now cover every square.
MssqlPlugin shines, ready to behold! ✨


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.

@sneha122 sneha122 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 30, 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: 3

🧹 Outside diff range and nitpick comments (6)
app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (4)

238-253: Well done, class! This test method looks good.

The test effectively checks for null credentials in the datasource configuration. It's checking all the important aspects: username, password, and database name.

However, to make it even better, consider adding an assertion for the size of the expectedOutput set. This would ensure that only the expected number of error messages are returned.

Here's a suggested addition to improve the test:

 Set<String> expectedOutput = mssqlPluginExecutor.validateDatasource(dsConfig);
+assertEquals(3, expectedOutput.size(), "Expected exactly 3 error messages");
 assertTrue(expectedOutput.contains(MssqlErrorMessages.DS_MISSING_USERNAME_ERROR_MSG));
 assertTrue(expectedOutput.contains(MssqlErrorMessages.DS_MISSING_PASSWORD_ERROR_MSG));
 assertTrue(expectedOutput.contains(MssqlErrorMessages.DS_MISSING_DATABASE_NAME_ERROR_MSG));

255-262: Good job! This test method is short and sweet.

The test effectively checks for a null endpoint in the datasource configuration. It's focused and to the point.

To maintain consistency with the previous test, consider adding an assertion for the size of the output set.

Here's a suggested addition to improve the test:

 Set<String> output = mssqlPluginExecutor.validateDatasource(dsConfig);
+assertEquals(1, output.size(), "Expected exactly 1 error message");
 assertTrue(output.contains(MssqlErrorMessages.DS_MISSING_ENDPOINT_ERROR_MSG));

264-271: Excellent work! This test method is clear and focused.

The test effectively checks for an empty host in the datasource configuration. It's a good practice to test edge cases like this.

As with the previous tests, let's add an assertion for the size of the output set to maintain consistency.

Here's a suggested addition to improve the test:

 Set<String> output = mssqlPluginExecutor.validateDatasource(dsConfig);
+assertEquals(1, output.size(), "Expected exactly 1 error message");
 assertTrue(output.contains(MssqlErrorMessages.DS_MISSING_HOSTNAME_ERROR_MSG));

273-280: Very good, students! This test method is concise and effective.

The test correctly checks for null authentication in the datasource configuration. It's important to test these edge cases.

To maintain consistency with the other tests we've reviewed, let's add an assertion for the size of the output set.

Here's a suggested addition to improve the test:

 Set<String> output = mssqlPluginExecutor.validateDatasource(dsConfig);
+assertEquals(1, output.size(), "Expected exactly 1 error message");
 assertTrue(output.contains(MssqlErrorMessages.DS_MISSING_AUTHENTICATION_DETAILS_ERROR_MSG));
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (2)

541-548: Consider generalizing the CRUD template adjustment.

Overriding sanitizeGenerateCRUDPageTemplateInfo to modify the select query for MSSQL syntax is effective but specific to this plugin.

To improve extensibility, consider abstracting this logic into a common utility or configuration that can be reused across different database plugins. This approach will reduce code duplication and simplify maintenance.


Line range hint 598-687: Simplify the connection pool creation logic for clarity.

The createConnectionPool method contains deeply nested blocks and extensive exception handling, which can make the code harder to read and maintain.

Refactoring the method to reduce nesting and using helper methods for exception handling can improve readability. For instance, you could extract the SQLState-to-error-message mapping into a separate method or utilize a mapping structure like a Map<String, String> for cleaner code.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 73d3960 and b269ee6.

📒 Files selected for processing (4)
  • app/server/appsmith-plugins/mssqlPlugin/pom.xml (1 hunks)
  • app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (12 hunks)
  • app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/exceptions/MssqlErrorMessages.java (1 hunks)
  • app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (3 hunks)
🔇 Additional comments (6)
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/exceptions/MssqlErrorMessages.java (1)

29-30: Class, pay attention to these new error messages!

Well done on adding these new error messages! They're like signposts guiding our users to provide the correct information. Let's break it down:

  1. DS_MISSING_HOSTNAME_ERROR_MSG: This tells users they can't leave the host value empty. It's like reminding students to write their names on their homework!

  2. DS_MISSING_DATABASE_NAME_ERROR_MSG: This alerts users when they forget to specify the database name. It's similar to asking students which subject their homework is for!

These additions will help users understand exactly what's missing in their datasource configuration. It's like giving clear instructions before an exam - it helps everyone perform better!

app/server/appsmith-plugins/mssqlPlugin/pom.xml (1)

Line range hint 18-23: Excellent addition, class! Let's discuss the importance of this new dependency.

Students, pay attention to this new addition to our project's dependencies. The Microsoft SQL Server JDBC driver is a crucial component that allows our application to communicate effectively with Microsoft SQL Server databases.

Let's break it down:

  1. GroupId: com.microsoft.sqlserver
  2. ArtifactId: mssql-jdbc
  3. Version: 11.2.1.jre17

This version is quite recent, which is commendable. It ensures we're using up-to-date features and security patches. Remember, always strive to use the latest stable versions in your projects!

app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (1)

238-280: Class, I'm impressed with your work on these new test methods!

You've done an excellent job adding test coverage for various edge cases in datasource configuration validation. Each test is focused, clear, and effective. The consistent structure across all tests makes them easy to read and understand.

To make these tests even better, consider implementing the suggested improvements for consistency:

  1. Add assertions for the expected size of the error message set in each test.
  2. Ensure consistent naming of variables (e.g., expectedOutput vs output).

Keep up the good work! These tests will help ensure the robustness of the MssqlPlugin.

app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (3)

32-32: Excellent inclusion of SQLServerException for specific error handling.

By importing com.microsoft.sqlserver.jdbc.SQLServerException, you enable handling SQL Server-specific exceptions more precisely, which improves the granularity of your error handling.


396-400: Great job modularizing the validation logic.

By extracting validateConnectionMode, validateEndpoints, and validateAuthentication into separate methods, you've improved the readability and maintainability of the validateDatasource method. This approach enhances code organization and makes future updates easier.


652-687: Review the SQLState codes for accurate exception mapping.

Mapping SQLState codes to specific error messages improves user feedback. However, some SQLState codes used may not correspond to the intended errors.

Please verify that the SQLState codes used match the appropriate error conditions. For example, SQLState "08S02" typically indicates a "Duplicate cursor name," which might not align with "Could not connect to server."

Run the following script to confirm the SQLState codes and their meanings:

Ensuring the correct SQLState codes are used will enhance the accuracy of error reporting.

Comment on lines +73 to +75
import static com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages.CONNECTION_CLOSED_ERROR_MSG;
import static com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages.CONNECTION_INVALID_ERROR_MSG;
import static com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages.CONNECTION_NULL_ERROR_MSG;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid redundant imports of connection error messages.

You have imported CONNECTION_CLOSED_ERROR_MSG, CONNECTION_INVALID_ERROR_MSG, and CONNECTION_NULL_ERROR_MSG from both com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages and com.external.plugins.exceptions.MssqlErrorMessages. This redundancy could lead to confusion and potential conflicts in error messaging.

Consider consolidating these constants into a single source or ensuring you import them from only one class to maintain clarity and prevent redundancy.

Comment on lines +225 to +231
// The function can throw either StaleConnectionException or SQLException. The
// underlying
// hikari
// library throws SQLException in case the pool is closed or there is an issue initializing
// the connection pool which can also be translated in our world to StaleConnectionException
// library throws SQLException in case the pool is closed or there is an issue
// initializing
// the connection pool which can also be translated in our world to
// StaleConnectionException
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance exception handling for better specificity.

Wrapping all SQLException instances that are not StaleConnectionException into a StaleConnectionException may obscure the original cause of the exception. This could make debugging more challenging.

Consider handling specific SQLException subtypes separately to preserve the original exception information. For instance, you might catch SQLTransientConnectionException for transient issues while allowing other exceptions to propagate with their original messages.

Comment on lines +402 to +407
private void validateConnectionMode(DatasourceConfiguration datasourceConfiguration, Set<String> invalids) {
if (datasourceConfiguration.getConnection() != null
&& datasourceConfiguration.getConnection().getMode() == null) {
invalids.add(MssqlErrorMessages.DS_MISSING_CONNECTION_MODE_ERROR_MSG);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure null connection configurations are properly handled.

In validateConnectionMode, if datasourceConfiguration.getConnection() is null, no error is added to invalids. This might lead to scenarios where missing connection configurations go unnoticed.

Consider adding a null check and an appropriate error message:

if (datasourceConfiguration.getConnection() == null) {
    invalids.add(MssqlErrorMessages.DS_MISSING_CONNECTION_CONFIGURATION_ERROR_MSG);
    return;
}

This change will ensure that users are alerted when the connection configuration is missing entirely.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants