Skip to content

Commit

Permalink
address Amit's comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kaituo Li <[email protected]>
  • Loading branch information
kaituo committed Oct 18, 2024
1 parent 4bc262c commit fa55f65
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/org/opensearch/ad/model/AnomalyDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public Integer getShingleSize(Integer customShingleSize) {
@Deprecated
public static final String DETECTION_DATE_RANGE_FIELD = "detection_date_range";
public static final String RULES_FIELD = "rules";
private static final String SUPPRESSION_RULE_ISSUE_PREFIX = "Suppression Rule Error: ";

protected String detectorType;

Expand Down Expand Up @@ -741,9 +742,9 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
}

// Null check for features
if (features == null) {
if (features == null || features.isEmpty()) {
// Cannot proceed with validation if features are null but rules are not null
this.errorMessage = "Suppression Rule Error: Features are not defined while suppression rules are provided.";
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX + "Features are not defined while suppression rules are provided.";
this.issueType = ValidationIssueType.RULE;
return;
}
Expand All @@ -760,7 +761,7 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
for (Rule rule : rules) {
if (rule == null || rule.getConditions() == null) {
// Invalid rule or conditions list is null
this.errorMessage = "Suppression Rule Error: A suppression rule or its conditions are not properly defined.";
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX + "A suppression rule or its conditions are not properly defined.";
this.issueType = ValidationIssueType.RULE;
return;
}
Expand All @@ -769,7 +770,7 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
for (Condition condition : rule.getConditions()) {
if (condition == null) {
// Invalid condition
this.errorMessage = "Suppression Rule Error: A condition within a suppression rule is not properly defined.";
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX + "A condition within a suppression rule is not properly defined.";
this.issueType = ValidationIssueType.RULE;
return;
}
Expand All @@ -779,15 +780,16 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
// Check if the feature name is null
if (featureName == null) {
// Feature name is required
this.errorMessage = "Suppression Rule Error: A condition is missing the feature name.";
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX + "A condition is missing the feature name.";
this.issueType = ValidationIssueType.RULE;
return;
}

// Check if the feature exists
if (!featureEnabledMap.containsKey(featureName)) {
// Feature does not exist
this.errorMessage = "Suppression Rule Error: Feature \""
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX
+ "Feature \""
+ featureName
+ "\" specified in a suppression rule does not exist.";
this.issueType = ValidationIssueType.RULE;
Expand All @@ -797,7 +799,8 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
// Check if the feature is enabled
if (!featureEnabledMap.get(featureName)) {
// Feature is not enabled
this.errorMessage = "Suppression Rule Error: Feature \""
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX
+ "Feature \""
+ featureName
+ "\" specified in a suppression rule is not enabled.";
this.issueType = ValidationIssueType.RULE;
Expand All @@ -814,7 +817,8 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
double value = condition.getValue();
if (Double.isNaN(value)) {
// Value is NaN
this.errorMessage = "Suppression Rule Error: The threshold value for feature \""
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX
+ "The threshold value for feature \""
+ featureName
+ "\" is not a valid number.";
this.issueType = ValidationIssueType.RULE;
Expand All @@ -824,7 +828,8 @@ private void validateRules(List<Feature> features, List<Rule> rules) {
// Check if the value is positive
if (value <= 0) {
// Value is not positive
this.errorMessage = "Suppression Rule Error: The threshold value for feature \""
this.errorMessage = SUPPRESSION_RULE_ISSUE_PREFIX
+ "The threshold value for feature \""
+ featureName
+ "\" must be a positive number.";
this.issueType = ValidationIssueType.RULE;
Expand Down

0 comments on commit fa55f65

Please sign in to comment.