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

Integrating Validation API On Detector Creation Process #106

Merged
merged 11 commits into from
Nov 2, 2021

Conversation

amitgalitz
Copy link
Member

Signed-off-by: Amit Galitzky amgalitz@amazon.com

Description

This PR integrates the new Validation API (backend PR Link) that handles validation checks for detector settings. Currently the Validation API only includes “blocker/detector setting” level validation so the new API call will run “blocker” level validation on the detector settings as the user enters the last step of detector creation. The user will then be able to know if any of their detector settings will lead to issues that could cause detector creation to be blocked or to fail on initialization.

Changes include:

  • Calling the Validation API with ‘detector’ type parameter as the “Review and Create” gets rendered.
  • Validation API response will display call outs in both the detector settings and model configurations section of the “Review and Create” page. Call out will either indicate that the relative sections have been validated or display a message indicating what the error is.

Screenshots:

Validation API Response is empty, meanings all validation checks have passed:
Screen Shot 2021-10-27 at 1 16 21 PM

Issue found in model configurations:
Screen Shot 2021-10-27 at 1 19 07 PM

Parsing issue found in data filter query:
Screen Shot 2021-10-27 at 3 06 50 PM

Need to add testing still.

Check List

  • New functionality includes testing.
    • All tests pass
  • 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.

@ohltyler ohltyler added feature A new feature for the plugin v1.2.0 Version 1.2.0 labels Oct 28, 2021
Comment on lines +104 to +115
} else if (
!props.validDetectorSettings &&
props.validationResponse.hasOwnProperty('message')
) {
return (
<EuiCallOut
title="Issues found in the detector settings"
color="danger"
iconType="alert"
size="s"
style={{ marginBottom: '10px' }}
>
Copy link
Member

Choose a reason for hiding this comment

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

How would props.validDetectorSettings be false here, but it's under the if block where !props.validationError is true?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess naming is confusing but validationError is regarding any exception from validation API such as security exception is caught which should lead to no validation callout at all. So when !props.validationError is true it means props.validationError is false cause no exception was caught. props.validDetectorSettings refers to the actual ValidationAPI response and if detector settings are valid or not (data filter parsing issue and etc.) So basically if there is no exception from validate API call then validDetectorSettings can still be true or false depending on validation API response.

Copy link
Member

Choose a reason for hiding this comment

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

validationError is regarding any exception from validation API such as security exception is caught which should lead to no validation callout at all.

Is there a specific reason why not? Could be helpful to see any error here, since I'm assuming it would instantly fail when the user tries to click 'Create detector' anyways, if it is some security issue or something else.

I'm ok to leave as-is given the time, but can you add comments explaining the different names and what they mean? And/or rename the vars?

Copy link
Member Author

Choose a reason for hiding this comment

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

My main logic behind this was to only use the callouts for the purpose of what the validation API is meant for. For validating against the list of checks that are blocker issues. I didn't want there to be a weird callout that I wasn't prepared for incase there are other types of exceptions that occur that I didn't think of. However I think it also totally makes sense to display security issues or other exceptions as part of validation call out but as of now I left it as the same UI as other exceptions across AD plugin. It will show up as notification on bottom right like other exceptions show. I'll add comments to explain names better and revisit this for 1.3.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if done addressing comments, but can you add some comments like you've mentioned here? Or change the names?

Comment on lines 83 to 91
const [validDetectorSettings, setValidDetectorSettings] = useState(false);
const [validModelConfigurations, setValidModelConfigurations] =
useState(false);
const [validationError, setValidationError] = useState(false);
const [settingsResponse, setDetectorMessageResponse] =
useState<validationSettingResponse>({} as validationSettingResponse);
const [featureResponse, setFeatureResponse] =
useState<validationModelResponse>({} as validationModelResponse);
const [isCreatingDetector, setIsCreatingDetector] = useState(false);
Copy link
Member

Choose a reason for hiding this comment

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

nit: can you make these verbose types? e.g., useState<boolean>(false)?

Copy link
Member

@ohltyler ohltyler Oct 29, 2021

Choose a reason for hiding this comment

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

Another stylistic choice - I prefer to keep as few state variables as possible to prevent large amounts of vars to keep track of, especially to reduce the amount of vars needed to pass as props to child components. Can some of these be reduced, and then derived later when needed? Seems that most of these values could just be derived from the validation response.

Copy link
Member Author

Choose a reason for hiding this comment

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

Every single one of those variables could be potentially passed as props to child components. I could create some of them in validation response but I am not completely sure I understand what is the better style then on the frontend.

Copy link
Member

Choose a reason for hiding this comment

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

Understood they're all needed. I was suggesting passing fewer props to the child components, by passing the full response for example, and then in the child component, pulling out whatever info is needed (like settingsResponse, featureResponse, validDetectorSettings, validModelConfigurations, validationError, etc.).

This way there's much less states needed to keep track in here, and it simplifies the logic

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 ok to adjust now or later - if later can you open an issue to track simplifying this in the future?

yarn.lock Outdated
@@ -3494,6 +3494,11 @@ posix-character-classes@^0.1.0:
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=

prettier@^2.4.1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't match version in package.json: 2.1.1

Copy link
Member Author

Choose a reason for hiding this comment

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

ran yarn osd bootstrap again and yarn.lock is updated

Copy link
Member Author

Choose a reason for hiding this comment

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

after updating it looks like this:
first line changed to 2.1.1, not sure why line below still says version "2.4.1"

prettier@^2.1.1:
  version "2.4.1"
  resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.1.tgz#671e11c89c14a4cfc876ce564106c4a6726c9f5c"....

Copy link
Member

Choose a reason for hiding this comment

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

^ usually if yarn finds an existing dependency in yarn.lock and it is later upgraded, it will keep the existing alias if used by other dependencies. For example, some other dependency may need prettier@^2.1.1 (AKA some version of prettier >= v2.1.1). The underlying version 2.4.1 is what's actually referenced and used here, as you can see by the link to the prettier tarball in the yarn package registry

…step of detector creation

Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
…ing exceptions

Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
…ttier

Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
@amitgalitz amitgalitz force-pushed the validate-api-blocker branch from 8044baa to a92d7bb Compare November 1, 2021 22:42
// of the callout options.
// Callouts only displayed based on if validDetectorSettings is true or not, referring to
// to response content from validation API (empty body or response issue body).
// validationError reffers to if there was an exception from validation API which means no callout will
Copy link
Member

Choose a reason for hiding this comment

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

reffers -> refers. Also, can you add an example on what a possible exception could be? (security, failure reading the index, etc.).

Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
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!

@amitgalitz amitgalitz merged commit fab2af9 into opensearch-project:main Nov 2, 2021
ohltyler pushed a commit to ohltyler/anomaly-detection-dashboards-plugin-1 that referenced this pull request Nov 8, 2021
…roject#106)

* Integrated Validation API with Detector Creation Process

Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
ohltyler pushed a commit that referenced this pull request Nov 9, 2021
* Integrated Validation API with Detector Creation Process

Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature for the plugin v1.2.0 Version 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants