Skip to content

Commit

Permalink
Add Suppression Anomaly Rules in Advanced Settings (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#859)

This PR introduces suppression anomaly rules under the Advanced Settings section, enabling users to suppress anomalies based on the difference between expected and actual values, either as an absolute value or a relative percentage.

Testing:
* Added unit tests to verify the suppression rules functionality.
* Conducted manual end-to-end (e2e) tests to validate the implementation.

Signed-off-by: Kaituo Li <[email protected]>
  • Loading branch information
kaituo authored Sep 3, 2024
1 parent 3ed0058 commit 9874c48
Show file tree
Hide file tree
Showing 25 changed files with 3,901 additions and 920 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/remote-integ-tests-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ jobs:

- name: Run spec files from output
run: |
for i in $FILELIST; do
yarn cypress:run-without-security --browser electron --spec "${i}"
sleep 60
done
env CYPRESS_NO_COMMAND_LOG=1 yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/plugins/anomaly-detection-dashboards-plugin/*'
working-directory: opensearch-dashboards-functional-test

- name: Capture failure screenshots
Expand Down
6 changes: 5 additions & 1 deletion public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { DETECTOR_STATE } from '../../server/utils/constants';
import { Duration } from 'moment';
import moment from 'moment';
import { MDSQueryParams } from '../../server/models/types';
import { ImputationOption } from './types';
import {
ImputationOption,
Rule
} from './types';

export type FieldInfo = {
label: string;
Expand Down Expand Up @@ -212,6 +215,7 @@ export type Detector = {
taskProgress?: number;
taskError?: string;
imputationOption?: ImputationOption;
rules?: Rule[];
};

export type DetectorListItem = {
Expand Down
84 changes: 84 additions & 0 deletions public/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,87 @@ export enum ImputationMethod {
PREVIOUS = 'PREVIOUS',
}

// Constants for field names
export const RULES_FIELD = "rules";
export const ACTION_FIELD = "action";
export const CONDITIONS_FIELD = "conditions";
export const FEATURE_NAME_FIELD = "feature_name";
export const THRESHOLD_TYPE_FIELD = "threshold_type";
export const OPERATOR_FIELD = "operator";
export const VALUE_FIELD = "value";

// Enums
export enum Action {
IGNORE_ANOMALY = "IGNORE_ANOMALY", // ignore anomaly if found
}

export enum ThresholdType {
/**
* Specifies a threshold for ignoring anomalies where the actual value
* exceeds the expected value by a certain margin.
*
* Assume a represents the actual value and b signifies the expected value.
* IGNORE_SIMILAR_FROM_ABOVE implies the anomaly should be disregarded if a-b
* is less than or equal to ignoreSimilarFromAbove.
*/
ACTUAL_OVER_EXPECTED_MARGIN = "ACTUAL_OVER_EXPECTED_MARGIN",

/**
* Specifies a threshold for ignoring anomalies where the actual value
* is below the expected value by a certain margin.
*
* Assume a represents the actual value and b signifies the expected value.
* Likewise, IGNORE_SIMILAR_FROM_BELOW
* implies the anomaly should be disregarded if b-a is less than or equal to
* ignoreSimilarFromBelow.
*/
EXPECTED_OVER_ACTUAL_MARGIN = "EXPECTED_OVER_ACTUAL_MARGIN",

/**
* Specifies a threshold for ignoring anomalies based on the ratio of
* the difference to the actual value when the actual value exceeds
* the expected value.
*
* Assume a represents the actual value and b signifies the expected value.
* The variable IGNORE_NEAR_EXPECTED_FROM_ABOVE_BY_RATIO presumably implies the
* anomaly should be disregarded if the ratio of the deviation from the actual
* to the expected (a-b)/|a| is less than or equal to IGNORE_NEAR_EXPECTED_FROM_ABOVE_BY_RATIO.
*/
ACTUAL_OVER_EXPECTED_RATIO = "ACTUAL_OVER_EXPECTED_RATIO",

/**
* Specifies a threshold for ignoring anomalies based on the ratio of
* the difference to the actual value when the actual value is below
* the expected value.
*
* Assume a represents the actual value and b signifies the expected value.
* Likewise, IGNORE_NEAR_EXPECTED_FROM_BELOW_BY_RATIO appears to indicate that the anomaly
* should be ignored if the ratio of the deviation from the expected to the actual
* (b-a)/|a| is less than or equal to ignoreNearExpectedFromBelowByRatio.
*/
EXPECTED_OVER_ACTUAL_RATIO = "EXPECTED_OVER_ACTUAL_RATIO",
}

// Method to get the description of ThresholdType
export function getThresholdTypeDescription(thresholdType: ThresholdType): string {
return thresholdType; // In TypeScript, the enum itself holds the description.
}

// Enums for Operators
export enum Operator {
LTE = "LTE",
}

// Interfaces for Rule and Condition
export interface Rule {
action: Action;
conditions: Condition[];
}

export interface Condition {
featureName: string;
thresholdType: ThresholdType;
operator: Operator;
value: number;
}

Loading

0 comments on commit 9874c48

Please sign in to comment.