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

Adding feature direction and moving suppression rules to each feature #960

Merged
merged 5 commits into from
Jan 27, 2025

Conversation

amitgalitz
Copy link
Member

@amitgalitz amitgalitz commented Dec 19, 2024

Description

  • Added feature direction capability to each feature so users can select if anomalies should only be considered if they actual values goes either above or below the expected value.
  • Moved suppressionRules into the feature creation and redesigned it,
  • Fixed a bug when we had multiple rules with negative values where the toast message was blank.
  • Additional slight wording changes on different form fields

Screenshot 2024-12-19 at 11 48 44 AM

Check List

  • New functionality includes testing.
    • All tests pass
  • [] New functionality has been documented.
  • 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.

@kaituo
Copy link
Collaborator

kaituo commented Dec 20, 2024

I manually tested your code and found two issues.

First, I tested bwc by creating a detector using cli. By default, every feature has two rules like

"rules": [
            {
                "action": "IGNORE_ANOMALY",
                "conditions": [
                    {
                        "feature_name": "deny max",
                        "threshold_type": "ACTUAL_OVER_EXPECTED_RATIO",
                        "operator": "LTE",
                        "value": 0.2
                    },
                    {
                        "feature_name": "deny max",
                        "threshold_type": "EXPECTED_OVER_ACTUAL_RATIO",
                        "operator": "LTE",
                        "value": 0.2
                    }
                ]
            }
        ]

But when I open the detector from UI, I can see only one rule:
Screenshot 2024-12-19 at 10 25 21 PM

Second, I am expecting that I cannot define a suppression rule from the opposite direction a user has selected. For example, when I select "Rise above expected value", I should not be able to see the "below the expected value" from the rule section. But I do see it:
Screenshot 2024-12-19 at 10 30 02 PM

@amitgalitz
Copy link
Member Author

I will address these issue, in addition, I missed on the part with the default rules, I will make sure we show them correctly in UI and also now for every detector with a feature direction we will have just that one default rule show along with the change on the UI so selection for only one shows.

@kaituo
Copy link
Collaborator

kaituo commented Dec 26, 2024

A few thoughts.

First, for every detector with a feature direction we will have just that two identical default rules show along with the change.
Screenshot 2024-12-26 at 9 55 13 AM

Second, current UX will overwrite my rules when I am playing around directions. For example, my double direction rules will not come back once I re-select "Deviation in any direction". Before cx click save, you have the original rules in record. You can restore them back, right?

Screenshot 2024-12-26 at 9 55 56 AM

Third, is it a good experience to change customers' rules when I change direction? For example, original rules are "above".

Screenshot 2024-12-26 at 9 58 47 AM

When I change to "below", both rules changed to "below":

Screenshot 2024-12-26 at 10 00 14 AM

Should we just hide the "above" rules?

Signed-off-by: Amit Galitzky <[email protected]>
Comment on lines 37 to 38
feature: any;
featureIndex: any;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add types instead of any?

Copy link
Member Author

Choose a reason for hiding this comment

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

added types

Comment on lines 425 to 432
const cleanedSuppressionRules =
form.values.suppressionRules.filter(
(_, i) => i === props.featureIndex
);
form.setFieldValue(
`suppressionRules.`,
cleanedSuppressionRules
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need these lines? Is arrayHelpers.remove enough? Also, should we use the following instead since you want to filter out any rule with props.featureIndex?

const cleanedSuppressionRules = form.values.suppressionRules.filter(
  (_, i) => i !== props.featureIndex
);
form.setFieldValue('suppressionRules', cleanedSuppressionRules);

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 previously had this to fix a bug where if there was only 1 suppression rule it wouldn't let me delete the last rule and fully clean up the array. I can remove this now though

@@ -101,7 +83,7 @@ export function SuppressionRules(props: SuppressionRulesProps) {
]}
hintLink={`${BASE_DOCS_LINK}/ad`}
isInvalid={isInvalid(field.name, form)}
error={extractArrayError(field.name, form)}
//error={extractArrayError(field.name, form)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you really want to hide error here?

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 was going to remove this completely as now I have errors seen before each field individually

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, can you add comment about this?

Copy link
Member Author

Choose a reason for hiding this comment

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

added comment about new extractError

Comment on lines 156 to 177
isInvalid={
!!extractError(
`suppressionRules.${
props.featureIndex
}[${index}].${
isPercentage === false
? 'absoluteThreshold'
: 'relativeThreshold'
}`,
form
)
}
error={extractError(
`suppressionRules.${
props.featureIndex
}[${index}].${
isPercentage === false
? 'absoluteThreshold'
: 'relativeThreshold'
}`,
form
)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it better to call the function extractError only once like

const thresholdFieldName = `suppressionRules.${props.featureIndex}[${index}].${
  isPercentage === false ? 'absoluteThreshold' : 'relativeThreshold'
}`;

const thresholdError = extractError(thresholdFieldName, form);

<FormattedFormRow
  isInvalid={!!thresholdError}
  error={thresholdError}
  fullWidth
>
  {/* … */}
</FormattedFormRow>

Copy link
Member Author

@amitgalitz amitgalitz Jan 27, 2025

Choose a reason for hiding this comment

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

Yes I just have to put inside an inline expression and do something like this:

 {(() => {
      const thresholdFieldName = `suppressionRules.${props.featureIndex}[${index}].${
        isPercentage === false ? 'absoluteThreshold' : 'relativeThreshold'
      }`;
      const thresholdError = extractError(thresholdFieldName, form);

      return (
        <FormattedFormRow
          isInvalid={!!thresholdError}
          error={thresholdError}
          fullWidth
        >

but need to make sure I have correct access to all the constants

Copy link
Member Author

Choose a reason for hiding this comment

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

made the change

@@ -63,6 +63,8 @@ export function Features(props: FeaturesProps) {
<EuiFlexGroup direction="column" style={{ margin: '0px' }}>
<FieldArray name="featureList" validateOnChange={true}>
{({ push, remove, form: { values } }: FieldArrayRenderProps) => {
console.log("values.featureList: " + JSON.stringify(values.featureList))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you want to keep this log line? Looks like debug message.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed, added it when I was checking the types I added

Signed-off-by: Amit Galitzky <[email protected]>
@kaituo kaituo merged commit e60e4e9 into opensearch-project:main Jan 27, 2025
9 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 27, 2025
…#960)

* adding feature direction and moving suppression rules to each feature

Signed-off-by: Amit Galitzky <[email protected]>

* fixing bug where two conditions didn't display

Signed-off-by: Amit Galitzky <[email protected]>

* improve error handling

Signed-off-by: Amit Galitzky <[email protected]>

* style changes and removing extra errors

Signed-off-by: Amit Galitzky <[email protected]>

* remove console log

Signed-off-by: Amit Galitzky <[email protected]>

---------

Signed-off-by: Amit Galitzky <[email protected]>
(cherry picked from commit e60e4e9)
amitgalitz added a commit to amitgalitz/anomaly-detection-dashboards-plugin that referenced this pull request Jan 28, 2025
…opensearch-project#960)

* adding feature direction and moving suppression rules to each feature

Signed-off-by: Amit Galitzky <[email protected]>

* fixing bug where two conditions didn't display

Signed-off-by: Amit Galitzky <[email protected]>

* improve error handling

Signed-off-by: Amit Galitzky <[email protected]>

* style changes and removing extra errors

Signed-off-by: Amit Galitzky <[email protected]>

* remove console log

Signed-off-by: Amit Galitzky <[email protected]>

---------

Signed-off-by: Amit Galitzky <[email protected]>
amitgalitz added a commit that referenced this pull request Jan 28, 2025
…#960) (#966)

* adding feature direction and moving suppression rules to each feature



* fixing bug where two conditions didn't display



* improve error handling



* style changes and removing extra errors



* remove console log



---------

Signed-off-by: Amit Galitzky <[email protected]>
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.

2 participants