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

feat: add errors to wrong mssql configuration #34472

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

Conversation

saiprabhu-dandanayak
Copy link
Contributor

@saiprabhu-dandanayak saiprabhu-dandanayak commented Jun 25, 2024

Description

Fixes #24726

Automation

/ok-to-test tags=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced validation for SQL Server datasource configurations, including connection mode, endpoints, and authentication details.
  • Bug Fixes

    • Improved error messages for missing hostname and database name in SQL Server datasource configurations.
  • Tests

    • Added tests to ensure proper validation of datasources with missing or null credentials, endpoints, hosts, and authentication details.

Shirisha-Manthoju and others added 4 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 appsmithorg#24726 regarding MSSQL configuration fix
…tion' of https://github.com/appsmithorg/appsmith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

The recent updates to the MssqlPlugin involve enhancing datasource validation by adding methods to check connection mode, endpoints, and authentication details. Additionally, error messages for missing hostname and database name were introduced. Corresponding tests were added to ensure these validations.

Changes

Files / Grouped Files Change Summary
.../appsmith-plugins/mssqlPlugin/src/main/java/... Added methods for validating connection mode, endpoints, and authentication in MssqlPlugin.java. Enhanced error messages in MssqlErrorMessages.
.../appsmith-plugins/mssqlPlugin/src/test/java/... Added tests for validating datasource with various null configurations in MssqlPluginTest.java.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MssqlPlugin
    participant DriverManager
    participant Database

    Client->>MssqlPlugin: validateDatasource(config)
    MssqlPlugin->>MssqlPlugin: validateConnectionMode(config)
    MssqlPlugin->>MssqlPlugin: validateEndpoints(config)
    MssqlPlugin->>MssqlPlugin: validateAuthentication(config)
    alt Valid Configuration
        MssqlPlugin->>DriverManager: getConnection()
        DriverManager->>Database: Connect
        Database->>DriverManager: Connection Success
        DriverManager->>MssqlPlugin: Connection Success
    else Invalid Configuration
        MssqlPlugin->>Client: Return error message
    end
Loading

Poem

In the world of code so tight,
New checks bring to light,
Hostnames and modes,
For cleaner data roads,
Bugs take flight,
Errors now in sight.
🌟🔧🐇


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.

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 519b53e and f108573.

Files selected for processing (3)
  • app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (3 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 (2 hunks)
Additional comments not posted (6)
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/exceptions/MssqlErrorMessages.java (1)

29-30: New error messages added for missing hostname and database name

The addition of these error messages enhances the robustness of the error handling by providing more specific feedback when critical configuration details are missing.

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

52-52: Added import for java.sql.DriverManager

This import is necessary for establishing database connections directly, which is used later in the createConnectionPool method to validate the configuration. This is a good practice as it ensures that the connection parameters are correct before proceeding further.


367-371: New validation methods added for datasource configuration

These methods enhance the robustness of the datasource configuration by checking for null or invalid values in connection mode, endpoints, and authentication details. This is crucial for preventing runtime errors due to misconfiguration.


613-628: Connection validation in createConnectionPool method

The direct use of DriverManager.getConnection to validate the connection is a robust way to ensure that the datasource is correctly configured before attempting to create a connection pool. This preemptive check helps in identifying issues early in the deployment cycle, reducing downtime and user frustration.

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

12-19: Added imports for various models and exceptions

These imports are necessary for the new tests that have been added, ensuring that all required classes and packages are available. This helps maintain the modularity and readability of the test code.


236-252: New tests added to validate datasource configurations

These tests are crucial for ensuring that the datasource validation logic works as expected under various edge cases, such as null credentials, endpoints, and authentication details. This helps in catching potential issues early, improving the reliability of the application.

Also applies to: 253-260, 261-269, 271-278

@saiprabhu-dandanayak saiprabhu-dandanayak changed the title External contri/issue #24726/feat wrong mssql configuration Issue #24726/feat wrong mssql configuration Jun 25, 2024
@saiprabhu-dandanayak saiprabhu-dandanayak changed the title Issue #24726/feat wrong mssql configuration feat: add errors to wrong mssql configuration Jun 25, 2024
Copy link

github-actions bot commented Jul 2, 2024

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 Jul 2, 2024
@saiprabhu-dandanayak
Copy link
Contributor Author

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

Hi @rohan-arthur
I hope you're well. I’m curious and excited to hear your thoughts on my pull request raised a while ago. Looking forward to your review!
Thank you.

@github-actions github-actions bot removed the Stale label Jul 3, 2024
@akshayvijayjain
Copy link

akshayvijayjain commented Jul 8, 2024

Hi @Nikhil-Nandagopal , @rohan-arthur

this pr is also pending from long if it is possible to prioritize

@rohan-arthur
Copy link
Contributor

@saiprabhu-dandanayak I have created a shadow PR for running some automated tests and checks.
PR link: #34877

  1. spotless checks are failing, see this link.

  2. server unit tests are running currently, you can check the status here.

  3. integration tests are running here.

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f108573 and b0c35ca.

Files ignored due to path filters (2)
  • app/server/appsmith-plugins/jsPlugin/bin/src/main/java/com/external/plugins/JSPlugin$JSPluginExecutor.class is excluded by !**/*.class
  • app/server/appsmith-plugins/jsPlugin/bin/src/main/java/com/external/plugins/JSPlugin.class is excluded by !**/*.class
Files selected for processing (2)
  • app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (3 hunks)
  • app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (3 hunks)
Additional comments not posted (10)
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (5)

367-370: Ensure comprehensive validation.

The integration of the new validation methods into validateDatasource is correct. Ensure that all potential error cases are covered.


373-378: Improve error message clarity.

Consider providing more detailed error messages that specify which part of the configuration is missing or misconfigured.

- invalids.add(MssqlErrorMessages.DS_MISSING_CONNECTION_MODE_ERROR_MSG);
+ invalids.add("Connection mode is missing in the datasource configuration. Please ensure it is specified.");

380-391: Improve error message clarity.

Consider providing more detailed error messages that specify which part of the configuration is missing or misconfigured.

- invalids.add(MssqlErrorMessages.DS_MISSING_ENDPOINT_ERROR_MSG);
+ invalids.add("Endpoint is missing in the datasource configuration. Please ensure it is specified.");

393-406: Improve error message clarity.

Consider providing more detailed error messages that specify which part of the configuration is missing or misconfigured.

- invalids.add(MssqlErrorMessages.DS_MISSING_AUTHENTICATION_DETAILS_ERROR_MSG);
+ invalids.add("Authentication details are missing in the datasource configuration. Please ensure they are specified.");

613-628: Connection validation and error handling improvements are effective.

The additions to validate the connection using DriverManager.getConnection() and the improved error handling are effective. Ensure thorough testing of these changes.

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

236-251: Test for null credentials is effective.

The test method correctly validates the datasource and identifies missing credentials. Ensure that similar tests cover all potential error cases.


253-260: Test for null endpoint is effective.

The test method correctly validates the datasource and identifies a missing endpoint. Ensure that similar tests cover all potential error cases.


262-269: Test for null host is effective.

The test method correctly validates the datasource and identifies a missing host. Ensure that similar tests cover all potential error cases.


271-278: Test for null authentication details is effective.

The test method correctly validates the datasource and identifies missing authentication details. Ensure that similar tests cover all potential error cases.


236-278: Comprehensive datasource validation tests.

The added tests comprehensively cover various error scenarios for datasource validation. Ensure that any new potential error cases are also covered in the future.

@saiprabhu-dandanayak
Copy link
Contributor Author

@saiprabhu-dandanayak I have created a shadow PR for running some automated tests and checks. PR link: #34877

  1. spotless checks are failing, see this link.
  2. server unit tests are running currently, you can check the status here.
  3. integration tests are running here.

Hi @rohan-arthur , fixed testcases by running mvn spotless:apply as suggested in the error logs , and verified through running testcases.

Testcase screenshot

image

@saiprabhu-dandanayak
Copy link
Contributor Author

saiprabhu-dandanayak commented Jul 16, 2024

Hi @rishabhrathod01 , I have checked it twice , and i have attached a screenshot for the same , there was an error in mssqlpugin testcases due to missing imports statements , but I have fixed it , will recheck it again.

@rishabhrathod01
Copy link
Contributor

@saiprabhu-dandanayak won't be required. That was a false alert by the initial CI run. All the tests have passed now. #34877

…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
@saiprabhu-dandanayak
Copy link
Contributor Author

@saiprabhu-dandanayak won't be required. That was a false alert by the initial CI run. All the tests have passed now. #34877

Hi @rishabhrathod01 , took recent changes from release branch and updated this branch.

Copy link
Contributor

@sneha122 sneha122 left a comment

Choose a reason for hiding this comment

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

@saiprabhu-dandanayak Why is it showing changes in these two files?
JSPlugin$JSPluginExecutor.class and JSPlugin.class? I don't think these changes should be part of the PR

@saiprabhu-dandanayak
Copy link
Contributor Author

@saiprabhu-dandanayak Why is it showing changes in these two files? JSPlugin$JSPluginExecutor.class and JSPlugin.class? I don't think these changes should be part of the PR

Hi @sneha122 , deleted those files

@@ -592,13 +610,27 @@ private static HikariDataSource createConnectionPool(DatasourceConfiguration dat

hikariConfig.setJdbcUrl(urlBuilder.toString());

try {
// Try to establish a connection to validate the configuration
DriverManager.getConnection(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to explicitly do establish connection using DriverManager? When we create HikariDataSource it should automatically send us valid error message with PoolInitializationException, is it not happening now?

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are not explicitly establishing connection using DriverManager , when i give wrong host name like prabhu and invalid port like 3434 we are not getting any error.

when invalid host address is given

image

when invalid host address and port no are given

image

Copy link
Contributor

Choose a reason for hiding this comment

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

@saiprabhu-dandanayak As we can see in above screenshot, we do get errors when no port and invalid host and port is entered, I am not understanding why establishing connection with driver manager is required. If you check the snowflake connection code here, This also behaves in the similar manner, when we create a new datasource using HikariDataSource constructor. It tries establishing connection with underlying database, if it fails it throws an exception called PoolInitializationException with error message from the driver. We can simply then show this error message in the UI, we wont have to establish connection using driverManager, I hope this makes sense. Please check out the snowflake plugin code as well for reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok , tq for your feedback.

@sneha122
Copy link
Contributor

sneha122 commented Aug 6, 2024

Hello @saiprabhu-dandanayak Any updates on the code review comments? I am still seeing changes in pom.xml

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @sneha122 , i have removed explicit Driver Manager connection and added updated the code in the catch block to raise exceptions and error alerts

@sneha122
Copy link
Contributor

sneha122 commented Aug 6, 2024

Hi @sneha122 , i have removed explicit Driver Manager connection and added updated the code in the catch block to raise exceptions and error alerts

Can you please check the pom.xml once? I am still seeing changes in it. Can you please check once what formatter you are using? I am seeing changes to existing code as well where its getting cut off to next line, I believe you may have a line limit formatter on which is causing longer lines to get cut into multiple lines, we don't want to do that.

@NilanshBansal NilanshBansal added Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Community Contributor Meant to track issues that are assigned to external contributors labels Aug 10, 2024
@NilanshBansal
Copy link
Contributor

NilanshBansal commented Aug 22, 2024

@saiprabhu-dandanayak any updates on this? We haven't heard back from you since the last 2 weeks.
This PR will be closed in the next 7 days if there are no more updates.
@rohan-arthur @sneha122 @appsmithorg/query-js-pod

SQLServerException sqlException = (SQLServerException) cause;
String sqlState = sqlException.getSQLState();

if ("08S01".equals(sqlState)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@saiprabhu-dandanayak Can you please create error constants for such errors? instead of using magic strings in the code


throw new AppsmithPluginException(
AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR,
"Could not connect to server. Check host and port.",
Copy link
Contributor

Choose a reason for hiding this comment

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

@saiprabhu-dandanayak Can we please check how we have defined error messages in case of postgres plugin and follow the same strategy here? In postgres we are also using something call PSQLState object for error codes, can we follow similar approach here?

@@ -607,7 +680,8 @@ private static HikariDataSource createConnectionPool(DatasourceConfiguration dat
private static void addSslOptionsToUrlBuilder(
DatasourceConfiguration datasourceConfiguration, StringBuilder urlBuilder) throws AppsmithPluginException {
/*
* - Ideally, it is never expected to be null because the SSL dropdown is set to a initial value.
* - Ideally, it is never expected to be null because the SSL dropdown is set to
Copy link
Contributor

Choose a reason for hiding this comment

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

@saiprabhu-dandanayak Can you please fix the indentation here? It is messing up the code and makes it difficult to understand the actual changes made

@sneha122
Copy link
Contributor

Hi @saiprabhu-dandanayak, Any updates on this?

I have created shadow PR here for running test cases: #36603

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contributor Meant to track issues that are assigned to external contributors Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: show a better error for wrong mssql configuration
7 participants