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

[MD] Add endpoint validation to create data source API #6631

Merged
merged 1 commit into from
Apr 26, 2024

Conversation

zhongnansu
Copy link
Member

@zhongnansu zhongnansu commented Apr 24, 2024

Description

Add endpoint validation to create data source API, by testing if endpoint is reachable, using the same logic as what's behind "test connection" feature

Issues Resolved

#6517

Screenshot

iShot_2024-04-25_15 02 52

Testing the changes

  1. go to create datasource page, and create one with invalid OpenSearch endpoint, e.g. google.com
  2. click test connection, it should fail as expected
  3. click create data source, it should fail too, as the endpoint is not a valid endpoint
  4. switch to use a valid opensearch domain
  5. both test connection and create data source should pass

Changelog

  • feat: Add endpoint validation to create data source API

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link

codecov bot commented Apr 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.80%. Comparing base (d2d410b) to head (6121267).
Report is 35 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6631       +/-   ##
===========================================
+ Coverage   32.93%   67.80%   +34.87%     
===========================================
  Files        2260     3413     +1153     
  Lines       45769    66755    +20986     
  Branches     7200    10861     +3661     
===========================================
+ Hits        15075    45266    +30191     
+ Misses      29984    18845    -11139     
- Partials      710     2644     +1934     
Flag Coverage Δ
Linux_1 33.18% <ø> (+0.25%) ⬆️
Linux_2 55.63% <ø> (?)
Linux_3 45.24% <100.00%> (?)
Linux_4 34.91% <ø> (?)
Windows_1 33.23% <ø> (?)
Windows_2 55.59% <ø> (?)
Windows_3 45.25% <100.00%> (?)
Windows_4 34.91% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zhongnansu zhongnansu force-pushed the md-validate-endpoint branch from abd7ffd to ec2f7c8 Compare April 25, 2024 20:35
Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

BionIT
BionIT previously approved these changes Apr 25, 2024
@BionIT
Copy link
Collaborator

BionIT commented Apr 25, 2024

Probably better to remove the credentials or modify the recording to hide it

Copy link
Member

@huyaboo huyaboo left a comment

Choose a reason for hiding this comment

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

Left nonblocking comment

throw SavedObjectsErrorHelpers.createBadRequestError(
'"title" attribute must be a non-empty string'
);
}

if (title.length > 32) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: could we make this a constant with a meaningful name?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to use constant

@@ -61,16 +61,24 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
const cryptographyServiceSetup: CryptographyServiceSetup = this.cryptographyService.setup(
config
);
const dataSourceService: DataSourceServiceSetup = await this.dataSourceService.setup(config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we name it dataSourceServiceSetUp as cryptographyServiceSetup

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

if (!auth) {
throw SavedObjectsErrorHelpers.createBadRequestError('"auth" attribute is required');
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

So from now on, we cannot choose no auth?

Copy link
Member Author

@zhongnansu zhongnansu Apr 25, 2024

Choose a reason for hiding this comment

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

creating data source with no auth auth type still has an an attribute in the request payload

image

@zhyuanqi
Copy link
Collaborator

Just a general thought. I see the error is 'Creation of the Data Source failed with some errors.'. Not sure if we need to give more specifc error in different error cases such as no auth found, please provide authentication

Signed-off-by: Zhongnan Su <szhongna@amazon.com>
@zhongnansu
Copy link
Member Author

Just a general thought. I see the error is 'Creation of the Data Source failed with some errors.'. Not sure if we need to give more specifc error in different error cases such as no auth found, please provide authentication

The error message is the existing behavior when failing to create data source , with/without my change, I agree we should improve by displaying the error with details to user. It could be a separate task to work on, and it should take care of both test connection and create data source

@xinruiba
Copy link
Member

xinruiba commented Apr 25, 2024

I remember datasource is able to be created even test connection failed used to be the expected behavior.
We decide to change it?

@zhongnansu
Copy link
Member Author

I remember datasource is able to be created even test connection failed used to be the expected behavior. We decide to change it?

AFAIK, yes, is there any concern? @xinruiba

@xinruiba
Copy link
Member

I remember datasource is able to be created even test connection failed used to be the expected behavior. We decide to change it?

AFAIK, yes, is there any concern? @xinruiba

No concerns if that's by design~

testClientDataSourceAttr: attributes as DataSourceAttributes,
authRegistry: await this.authRegistryPromise,
customApiSchemaRegistryPromise: this.customApiSchemaRegistryPromise,
});
Copy link
Member

@xinruiba xinruiba Apr 25, 2024

Choose a reason for hiding this comment

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

Thanks for this change.

Are there any chances we can reuse this function: https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/data_source_management/public/components/utils.ts#L206?

Since datasource and datasource_management plugin will both exist in the same time, so the validation path in datasource_management plugin should always been routed.

Then we depend on sending request to /internal/data-source-management/validate to test connection instead of creating a new datasource client here.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean when user click create data source button, we first call /internal/data-source-management/validate to validate and then call create data source API? @xinruiba

Copy link
Member

@xinruiba xinruiba Apr 25, 2024

Choose a reason for hiding this comment

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

Yes

Pros:

  • We rely on the URL for data source validation.

Cons:

  • If customers directly create a data source by calling the URL (using curl), the data source validation will be bypassed.

I'll leave the decision to you~

Copy link
Member Author

@zhongnansu zhongnansu Apr 26, 2024

Choose a reason for hiding this comment

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

Yes, the cons you mentioned is exactly the reason I choose to add validation to the saved object create data source API, this will almost make sure no invalid endpoint can be created as a data source. I use "almost", cuz user can still directly write data into .kibana index

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me. Approving~

Copy link
Member

@xinruiba xinruiba Apr 26, 2024

Choose a reason for hiding this comment

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

Non blocking comment.

Maybe a question to designer. Since we already do validation as a part of datasource creation. Do we sill need a separate test connection before clicking on datasource creation?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, @kgcreative @xeniatup, I wonder what's your thought on this

Copy link
Member

Choose a reason for hiding this comment

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

Given the updated validation, i don't think we need it in the create page.

@zhongnansu zhongnansu merged commit 0c114ce into opensearch-project:main Apr 26, 2024
57 of 58 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 26, 2024
Signed-off-by: Zhongnan Su <szhongna@amazon.com>
(cherry picked from commit 0c114ce)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
zhongnansu pushed a commit that referenced this pull request Apr 26, 2024
Signed-off-by: Zhongnan Su <szhongna@amazon.com>
(cherry picked from commit 0c114ce)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
LDrago27 pushed a commit to LDrago27/OpenSearch-Dashboards that referenced this pull request Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants