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

Make sure customer always have a default datasource #6237

Merged
merged 4 commits into from
Mar 26, 2024

Conversation

zhyuanqi
Copy link
Collaborator

@zhyuanqi zhyuanqi commented Mar 21, 2024

Description

Make sure customer always have a default datasource

Screenshot

Screen.Recording.2024-03-21.at.4.03.32.PM.mov

Testing the changes

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

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 82.75862% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 67.45%. Comparing base (2a94f32) to head (f9ace61).

Files Patch % Lines
...c/components/edit_data_source/edit_data_source.tsx 57.14% 2 Missing and 1 partial ⚠️
...components/data_source_table/data_source_table.tsx 87.50% 1 Missing ⚠️
src/plugins/data_source_management/public/mocks.ts 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6237      +/-   ##
==========================================
+ Coverage   67.44%   67.45%   +0.01%     
==========================================
  Files        3368     3368              
  Lines       65394    65423      +29     
  Branches    10553    10559       +6     
==========================================
+ Hits        44102    44134      +32     
+ Misses      18718    18716       -2     
+ Partials     2574     2573       -1     
Flag Coverage Δ
Linux_1 32.14% <ø> (ø)
Linux_2 55.58% <ø> (ø)
Linux_3 44.89% <82.75%> (+0.03%) ⬆️
Linux_4 34.98% <0.00%> (-0.01%) ⬇️
Windows_1 32.16% <ø> (ø)
Windows_2 55.54% <ø> (ø)
Windows_3 44.92% <82.75%> (?)
Windows_4 34.98% <0.00%> (-0.01%) ⬇️

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.

Copy link
Contributor

@yujin-emma yujin-emma left a comment

Choose a reason for hiding this comment

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

LGTM

@tianleh
Copy link
Member

tianleh commented Mar 21, 2024

One question about the flow: after you create the first data source, it goes back to the list page. But why would we require user to refresh page for the default icon to show up?

@zhyuanqi
Copy link
Collaborator Author

One question about the flow: after you create the first data source, it goes back to the list page. But why would we require user to refresh page for the default icon to show up?

Hi Tianle. Thanks for pointing this out. I have fixed the issue. Now it will show the default. You can check it on the video

@tianleh
Copy link
Member

tianleh commented Mar 21, 2024

  1. There is one more case to consider: If my OSD is in previous version and has 3 data sources, there will not be default data source after upgrading to the version with your current change. Customers have to either delete or add a data source for your logic to trigger. Is this expected?

  2. Customers cannot use UI to update their default data source. The data sources are sorted by title. https://github.com/zhyuanqi/OpenSearch-Dashboards/blob/19d4ba69c0ffde755022693da0d992f4bd8c1a0e/src/plugins/data_source_management/public/components/utils.ts#L38C22-L38C27 If my preferred data source starts with letter z, I may have to delete all other data sources to make it default which could be annoying.

We may need confirmation from product manager about this behavior.


await handleSetDefaultDatasourceAfterDeletion(savedObjects.client, uiSettings);
expect(uiSettings.set).toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: according to the behavior which set the first data source in the list as default, maybe it's nice to assert that uiSettings.set is called with the first data source id.

expect(uiSettings.set).toHaveBeenCalledWith('defaultDataSource', 'test');

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would do

});
});
describe('handleSetDefaultDatasourceDuringCreation', () => {
test('should set defaultDataSource if only one data source exists', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

For unit test of this function, I think it's worth to add a test to cover the case that when number of data source > 1 that uiSettings.set should not be called.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added!

@zhyuanqi
Copy link
Collaborator Author

zhyuanqi commented Mar 25, 2024

  1. There is one more case to consider: If my OSD is in previous version and has 3 data sources, there will not be default data source after upgrading to the version with your current change. Customers have to either delete or add a data source for your logic to trigger. Is this expected?
  2. Customers cannot use UI to update their default data source. The data sources are sorted by title. https://github.com/zhyuanqi/OpenSearch-Dashboards/blob/19d4ba69c0ffde755022693da0d992f4bd8c1a0e/src/plugins/data_source_management/public/components/utils.ts#L38C22-L38C27 If my preferred data source starts with letter z, I may have to delete all other data sources to make it default which could be annoying.

We may need confirmation from product manager about this behavior.

Thanks for pointing this out. Customer can set a default datasource in the edit page anytime after they created the datasource. For first question, after customer enables data_source, then he or she can adding datasource and the first created datasource would be default datasouce. This is the default behavior. I don't see a scenario customer can create the first datasource without setting it be default. I might miss something. Please point to me if I do.

For second one, I wil check with product manager for this.Thank you for pointing this out.

@ruanyl
Copy link
Member

ruanyl commented Mar 25, 2024

@zhyuanqi
One more question: it seems the current implementation only works when deleting default data source from UI(the data source table), perhaps there are other cases that the default data source get deleted?

@seraphjiang @xluo-aws @kgcreative
And also I'm curious how will the "default data source" behave after introducing workspace? Maybe this is something we need to discuss

@xluo-aws
Copy link
Member

Yes, user can view all saved objects they have access(including home workspace objects) in home workspace. But if a user create a saved object in this workspace, it's associated with this workspace.

@@ -49,6 +54,29 @@ export async function getDataSourcesWithFields(
return response?.savedObjects;
}

export async function handleSetDefaultDatasourceAfterDeletion(
savedObjects: SavedObjectsClientContract,
Copy link
Member

Choose a reason for hiding this comment

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

nit:
Based on the type "SavedObjectsClientContract", Looks like here we want to provide a savedObjectClient here.
What if we rename savedObjects to savedObjectsClient like we we did here: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6237/files#diff-fde383d0fdaaed3bb243ed36abd631c9c311596b2057f737253fc5ab11c4d5edR45?
What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed it!

Comment on lines 57 to 80
export async function handleSetDefaultDatasourceAfterDeletion(
savedObjects: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
uiSettings.remove('defaultDataSource');
const listOfDataSources: DataSourceTableItem[] = await getDataSources(savedObjects);
if (Array.isArray(listOfDataSources) && listOfDataSources.length >= 1) {
const datasourceId = listOfDataSources[0].id;
await uiSettings.set('defaultDataSource', datasourceId);
}
}

export async function handleSetDefaultDatasourceDuringCreation(
savedObjects: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
const listOfDataSources: DataSourceTableItem[] = await getDataSources(savedObjects);
if (Array.isArray(listOfDataSources) && listOfDataSources.length === 1) {
const datasourceId = listOfDataSources[0].id;
await uiSettings.set('defaultDataSource', datasourceId);
}
}

Copy link
Member

@xinruiba xinruiba Mar 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,

Maybe following scenario is out of scope:

Suppose we already have dataSource created before before we support default dataSource, this line will failed to set the first dataSource as default: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6237/files#diff-fde383d0fdaaed3bb243ed36abd631c9c311596b2057f737253fc5ab11c4d5edR74

Thus I'm thinking if we can handle that scenario and also keep one function to handle set default dataSource by updating it to:

Suggested change
export async function handleSetDefaultDatasourceAfterDeletion(
savedObjects: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
uiSettings.remove('defaultDataSource');
const listOfDataSources: DataSourceTableItem[] = await getDataSources(savedObjects);
if (Array.isArray(listOfDataSources) && listOfDataSources.length >= 1) {
const datasourceId = listOfDataSources[0].id;
await uiSettings.set('defaultDataSource', datasourceId);
}
}
export async function handleSetDefaultDatasourceDuringCreation(
savedObjects: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
const listOfDataSources: DataSourceTableItem[] = await getDataSources(savedObjects);
if (Array.isArray(listOfDataSources) && listOfDataSources.length === 1) {
const datasourceId = listOfDataSources[0].id;
await uiSettings.set('defaultDataSource', datasourceId);
}
}
export async function handleSetDefaultDatasource(
savedObjects: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
const currentDefaultDataSourceId = uiSettings.get('defaultDataSource');
if (currentDefaultDataSourceId) {
const targetDataSource = await getDataSourceById(currentDefaultDataSourceId, savedObjectsClient);
if (targetDataSource.id === currentDefaultDataSourceId) {
return;
}
}
setFirstDataSourceAsDefault(savedObjectsClient, uiSettings)
}
async function setFirstDataSourceAsDefault(
savedObjectsClient: SavedObjectsClientContract,
uiSettings: IUiSettingsClient
) {
uiSettings.remove('defaultDataSource');
const listOfDataSources: DataSourceTableItem[] = await getDataSources(savedObjects);
if (Array.isArray(listOfDataSources) && listOfDataSources.length >= 1) {
const datasourceId = listOfDataSources[0].id;
await uiSettings.set('defaultDataSource', datasourceId);
}
}

Just for suggestions, what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is a better approach. I will have a new CR on default with picker. Do you mind if i make the relative change in the new CR.

@zhyuanqi zhyuanqi force-pushed the default-behavior branch 3 times, most recently from fe3b323 to 2a97910 Compare March 25, 2024 18:40
xinruiba
xinruiba previously approved these changes Mar 26, 2024
xinruiba
xinruiba previously approved these changes Mar 26, 2024
}
}
} catch (e) {
setIsLoading(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens if error happens and we set isloading as false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will stop loading and show error as "Unable to set the Data Source to default. Please try it again."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should use setIsDeleting(false), let me rephrase this part

setIsLoading(false);
handleDisplayToastMessage({
id: 'dataSourcesManagement.editDataSource.setDefaultDataSourceFailMsg',
defaultMessage: 'Unable to set the Data Source to default. Please try it again.',
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does index pattern handle the error? How would user be able to retry if the data source is already deleted?

Copy link
Collaborator Author

@zhyuanqi zhyuanqi Mar 26, 2024

Choose a reason for hiding this comment

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

Let me change the default message to "Unable to find a default datasource. Please set a new default datasource."

@zhyuanqi zhyuanqi force-pushed the default-behavior branch 2 times, most recently from 18d64a4 to 0cd6a68 Compare March 26, 2024 16:15
Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
@ZilongX ZilongX merged commit 91a0530 into opensearch-project:main Mar 26, 2024
69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 27, 2024
* Make sure customer always have a default datasource

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

* Handle set as default

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

---------

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
Co-authored-by: Miki <[email protected]>
(cherry picked from commit 91a0530)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
ZilongX pushed a commit that referenced this pull request Mar 27, 2024
* Make sure customer always have a default datasource

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

* Handle set as default

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

---------

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
Co-authored-by: Miki <[email protected]>
(cherry picked from commit 91a0530)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.