Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

swith direct index query to api call #312

Conversation

ylwu-amzn
Copy link
Contributor

@ylwu-amzn ylwu-amzn commented Oct 15, 2020

Issues opendistro-for-elasticsearch/anomaly-detection#195

Description of changes:

Change direct index query to API call for FGAC(Fine-Grained Access Control).

Skip flaky test now, will fix it later.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines +89 to +99
[SEARCH_ALERTS]: {
REQUEST: (state: Monitors): Monitors => ({
...state
}),
SUCCESS: (state: Monitors, action: APIResponseAction): Monitors => ({
...state
}),
FAILURE: (state: Monitors, action: APIResponseAction): Monitors => ({
...state
}),
},
Copy link
Contributor

@ohltyler ohltyler Oct 15, 2020

Choose a reason for hiding this comment

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

Maybe don't need to store alert info in redux store, but can you at least update the requesting and errorMessage fields here, similar to others? Can be helpful later on when determining loading states and propagating errors

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, not sure if this will impact other components using requesting and errorMessage. Will add todo here and add it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, not a blocker. If anything, adding requesting and errorMessage wouldn't hurt, as it would just make the frontend more accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added toto here, if any client components using these search APIs needs requesting and errorMessage, feel free to resolve this todo..

Comment on lines +65 to +75
[SEARCH_ANOMALY_RESULTS]: {
REQUEST: (state: Anomalies): Anomalies => ({
...state
}),
SUCCESS: (state: Anomalies, action: APIResponseAction): Anomalies => ({
...state
}),
FAILURE: (state: Anomalies): Anomalies => ({
...state
}),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

same thing here

const result = await dispatch(
searchES(
getBucketizedAnomalyResultsQuery(
searchResults(getBucketizedAnomalyResultsQuery(
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I see this was already like this before, but I feel that overall we should try to avoid making direct calls and using the results directly, since it may cause errors to use those results/responses in downstream functions, etc. This is where redux store can help here in storing data and error messages. Not a blocker obviously

Copy link
Contributor

Choose a reason for hiding this comment

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

we have to use direct calls because we are calling same API in multiple places of same component, but current redux store does not support. We have an issue #23 for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for clarifying. Another solution may be making reducer functions more fine-grained and/or storing more fine-grained results in the redux store. Will add suggestion to the issue.

} catch (err) {
console.log('Anomaly detector - Unable to search anomaly result', err);
if (isIndexNotFoundError(err)) {
return { ok: true, response: { totalDetectors: 0, detectors: [] } };
Copy link
Contributor

@ohltyler ohltyler Oct 16, 2020

Choose a reason for hiding this comment

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

minor: this response doesn't matter since the reducer isn't using the responses right now to parse anything, but this response doesn't make a lot of sense. Maybe just return empty for now, or at least add TODO to change when we store results in the reducer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, will fix this in next PR.

Copy link
Contributor

@saratvemulapalli saratvemulapalli left a comment

Choose a reason for hiding this comment

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

Overall the changes look good to me.

Copy link
Contributor

@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.

Thanks for adding! Just left a few other minor comments.

@yizheliu-amazon yizheliu-amazon merged commit 2f6184e into opendistro-for-elasticsearch:master Oct 16, 2020
@ohltyler ohltyler added the enhancement Enhance current feature for better performance, user experience, etc label Oct 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Enhance current feature for better performance, user experience, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants