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 error that local cluster cannot get version #606

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

kamahuan
Copy link
Contributor

@kamahuan kamahuan commented Feb 7, 2025

Description

Currently in the new work flow page, when user click local data source, it shows a loading state and does not render any presets. This PR fix this issue by getting version from the datasource and render the presets based on the data source version.

Issues Resolved

None

UI changes after code change

for version 2.19

Xnip2025-02-07_00-07-07

for version 2.17

Xnip2025-02-07_00-16-27

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@ohltyler ohltyler left a comment

Choose a reason for hiding this comment

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

If adding a new API, make sure it is integrated into the rest of the redux store and our route service framework. For example, see #330 which onboards the search connectors API.

We don't want to make direct calls from client-side, as it can be unstable, cause issues with tests, doesn't integrate with our error handling propagation, and could lead to NPEs.

Comment on lines 46 to 56
router.get(
{
path: `${BASE_NODE_API_PATH}/version`,
validate: {
params: schema.object({
pattern: schema.string(),
}),
},
},
opensearchRoutesService.catIndices
);
Copy link
Member

Choose a reason for hiding this comment

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

This route is not being used. If adding a server-side call, let's properly integrate with the redux store for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this part is not used. Has removed the unused code.

Comment on lines 436 to 411
const response = await callWithRequest('cat.indices', {
index: pattern,
format: 'json',
});

// re-formatting the index results to match Index
const cleanedIndices = response.map((index: any) => ({
name: index.index,
health: index.health,
})) as Index[];

return res.ok({ body: cleanedIndices });
} catch (err: any) {
return generateCustomError(res, err);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused about this call - why is cat indices needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed this part.

@@ -71,7 +78,7 @@ const filterPresetsByVersion = async (
return workflows;
}

if (!dataSourceId) {
if (dataSourceId === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

I remember some discrepancy on how empty string vs. undefined is handled for data sources. @saimedhi please confirm if this change makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the scenario of local cluster, data source id would be an empty string ''. !dataSourceId would be true here so it will return empty presets for local cluster.

This is not the behavior we want so I changed the condition to only return empty if data source id is undefined.

Copy link
Collaborator

@saimedhi saimedhi Feb 10, 2025

Choose a reason for hiding this comment

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

@kamahuan , I agree with your change.

  • When local cluster is used, dataSourceId = ''
  • When no compatible datasource is used, dataSourceId is undefined. Implies dataSourceId not present in page Url.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for fixing the code added in "filter presets and processors based on backend version" PR.

Lets connect and test all the possible scenarios before merging this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we check the mds feature flag to determine if mds is enabled instead of checking if dataSourceId is present? Checking the feature flag should be the best practice and less error-prone

something like this - something like this - https://github.com/opensearch-project/anomaly-detection-dashboards-plugin/blob/main/public/pages/DetectorsList/containers/List/List.tsx#L147

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Jackie, I am not sure if I completely understand your comment. Line 76 and 77 checks if MDS is disabled, if so, we are showing all the presets assuming version >= 2.19. The other 2 cases checks 2 difference scenarios:

  1. if datasourceId === '', that means we are using local clusters
  2. if datasourceId === 'undefined', that means no compatible data source is used.
    Are you suggesting removing line 81 to check the scenario where datasource is enabled? I am unsure semantically, if enabling datasource consists of the 2 above scenarios. May I know if @ohltyler @saimedhi have any ideas about this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Line 76 and 77 checks if MDS is disabled

Don't use if(dataSourceId === undefined) to check if MDS is disabled, read the feature flag from config file and check the feature flag to determine if MDS is enabled. Something like this if(MDSEnabled) - https://github.com/opensearch-project/anomaly-detection-dashboards-plugin/blob/main/public/services.ts#L65

Comment on lines 51 to 57
if (dataSourceId === '') {
const response = await getCore().http.post('/api/console/proxy', {
query: { path: '/', method: 'GET', dataSourceId: '' },
});
return response.version.number;
}

Copy link
Member

Choose a reason for hiding this comment

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

Let's integrate this properly into redux and our server-side route services.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Add check local cluster version check into route.service file and redux into presetRedux file

// query: { path: '/', method: 'GET', dataSourceId: '' },
// });
// return response.version.number;
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kamahuan , could you remove this commented lines.

(state: AppState) => state.presets
);
const [allWorkflows, setAllWorkflows] = useState<WorkflowTemplate[]>([]);
const [filteredWorkflows, setFilteredWorkflows] = useState<
WorkflowTemplate[]
>([]);
const [isVersionLoading, setIsVersionLoading] = useState(false);
// const [isVersionLoading, setIsVersionLoading] = useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove commented lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@saimedhi saimedhi left a comment

Choose a reason for hiding this comment

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

@kamahuan, please clean up the commented code. Thank you for the fixes.

Copy link
Member

Choose a reason for hiding this comment

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

In general, I'm ok with the change, but it should go to a more logical reducer - suggest to move to opensearch_reducer. Also, after moving, suggest to reuse the existing loading state var there; a new one shouldn't be needed.

@kamahuan kamahuan force-pushed the feature1 branch 3 times, most recently from 17cac7e to 96dffc0 Compare February 10, 2025 19:56
Copy link
Member

@ohltyler ohltyler left a comment

Choose a reason for hiding this comment

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

LGTM - please resolve the merge conflicts, and work with Sai to ensure everything is tested and working as expected. Thanks!

Signed-off-by: Kama Huang <kamahuan@amazon.com>

refactor get local cluster version logic into service route and redux

Signed-off-by: Kama Huang <kamahuan@amazon.com>

refactor getVersion logic into opensearch reducer

Signed-off-by: Kama Huang <kamahuan@amazon.com>

adding loading state back to presetReducer

Signed-off-by: Kama Huang <kamahuan@amazon.com>

fixing unit tests

Signed-off-by: Kama Huang <kamahuan@amazon.com>
Signed-off-by: Kama Huang <kamahuan@amazon.com>
@ohltyler ohltyler merged commit 39ed7aa into opensearch-project:main Feb 17, 2025
7 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 17, 2025
Signed-off-by: Kama Huang <kamahuan@amazon.com>
(cherry picked from commit 39ed7aa)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ohltyler pushed a commit that referenced this pull request Feb 17, 2025
(cherry picked from commit 39ed7aa)

Signed-off-by: Kama Huang <kamahuan@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

4 participants