Skip to content

Commit

Permalink
Add flatten_result_index_mapping field to Config (#1276) (#1277)
Browse files Browse the repository at this point in the history
* Add flatten_result_index_mapping field into Config



* apply spotless check



---------


(cherry picked from commit 34b350e)

Signed-off-by: Jackie Han <jkhanjob@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent faee8ab commit d3bd162
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/opensearch/ad/model/ADTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ public static ADTask parse(XContentParser parser, String taskId) throws IOExcept
detector.getRules(),
detector.getCustomResultIndexMinSize(),
detector.getCustomResultIndexMinAge(),
detector.getCustomResultIndexTTL()
detector.getCustomResultIndexTTL(),
detector.getFlattenResultIndexMapping()
);
return new Builder()
.taskId(parsedTaskId)
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/opensearch/ad/model/AnomalyDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public Integer getShingleSize(Integer customShingleSize) {
* @param customResultIndexMinSize custom result index lifecycle management min size condition
* @param customResultIndexMinAge custom result index lifecycle management min age condition
* @param customResultIndexTTL custom result index lifecycle management ttl
* @param flattenResultIndexMapping flag to indicate whether to flatten result index mapping or not
*/
public AnomalyDetector(
String detectorId,
Expand All @@ -176,7 +177,8 @@ public AnomalyDetector(
List<Rule> rules,
Integer customResultIndexMinSize,
Integer customResultIndexMinAge,
Integer customResultIndexTTL
Integer customResultIndexTTL,
Boolean flattenResultIndexMapping
) {
super(
detectorId,
Expand All @@ -203,7 +205,8 @@ public AnomalyDetector(
historyIntervals,
customResultIndexMinSize,
customResultIndexMinAge,
customResultIndexTTL
customResultIndexTTL,
flattenResultIndexMapping
);

checkAndThrowValidationErrors(ValidationAspect.DETECTOR);
Expand Down Expand Up @@ -280,6 +283,7 @@ public AnomalyDetector(StreamInput input) throws IOException {
this.customResultIndexMinSize = input.readOptionalInt();
this.customResultIndexMinAge = input.readOptionalInt();
this.customResultIndexTTL = input.readOptionalInt();
this.flattenResultIndexMapping = input.readOptionalBoolean();
}

public XContentBuilder toXContent(XContentBuilder builder) throws IOException {
Expand Down Expand Up @@ -345,6 +349,7 @@ public void writeTo(StreamOutput output) throws IOException {
output.writeOptionalInt(customResultIndexMinSize);
output.writeOptionalInt(customResultIndexMinAge);
output.writeOptionalInt(customResultIndexTTL);
output.writeOptionalBoolean(flattenResultIndexMapping);
}

@Override
Expand Down Expand Up @@ -441,6 +446,7 @@ public static AnomalyDetector parse(
Integer customResultIndexMinSize = null;
Integer customResultIndexMinAge = null;
Integer customResultIndexTTL = null;
Boolean flattenResultIndexMapping = null;

ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -575,6 +581,9 @@ public static AnomalyDetector parse(
case RESULT_INDEX_FIELD_TTL:
customResultIndexTTL = onlyParseNumberValue(parser);
break;
case FLATTEN_RESULT_INDEX_MAPPING:
flattenResultIndexMapping = onlyParseBooleanValue(parser);
break;
default:
parser.skipChildren();
break;
Expand Down Expand Up @@ -605,7 +614,8 @@ public static AnomalyDetector parse(
rules,
customResultIndexMinSize,
customResultIndexMinAge,
customResultIndexTTL
customResultIndexTTL,
flattenResultIndexMapping
);
detector.setDetectionDateRange(detectionDateRange);
return detector;
Expand Down Expand Up @@ -692,4 +702,11 @@ private static Integer onlyParseNumberValue(XContentParser parser) throws IOExce
}
return null;
}

private static Boolean onlyParseBooleanValue(XContentParser parser) throws IOException {
if (parser.currentToken() == XContentParser.Token.VALUE_BOOLEAN) {
return parser.booleanValue();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ protected AnomalyDetector copyConfig(User user, Config config) {
detector.getRules(),
config.getCustomResultIndexMinSize(),
config.getCustomResultIndexMinAge(),
config.getCustomResultIndexTTL()
config.getCustomResultIndexTTL(),
config.getFlattenResultIndexMapping()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ public static ForecastTask parse(XContentParser parser, String taskId) throws IO
forecaster.getHistoryIntervals(),
forecaster.getCustomResultIndexMinSize(),
forecaster.getCustomResultIndexMinAge(),
forecaster.getCustomResultIndexTTL()
forecaster.getCustomResultIndexTTL(),
forecaster.getFlattenResultIndexMapping()
);
return new Builder()
.taskId(parsedTaskId)
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/opensearch/forecast/model/Forecaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public Forecaster(
Integer historyIntervals,
Integer customResultIndexMinSize,
Integer customResultIndexMinAge,
Integer customResultIndexTTL
Integer customResultIndexTTL,
Boolean flattenResultIndexMapping
) {
super(
forecasterId,
Expand All @@ -161,7 +162,8 @@ public Forecaster(
historyIntervals,
customResultIndexMinSize,
customResultIndexMinAge,
customResultIndexTTL
customResultIndexTTL,
flattenResultIndexMapping
);

checkAndThrowValidationErrors(ValidationAspect.FORECASTER);
Expand Down Expand Up @@ -303,6 +305,7 @@ public static Forecaster parse(
Integer customResultIndexMinSize = null;
Integer customResultIndexMinAge = null;
Integer customResultIndexTTL = null;
Boolean flattenResultIndexMapping = null;

ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -431,6 +434,9 @@ public static Forecaster parse(
case RESULT_INDEX_FIELD_TTL:
customResultIndexTTL = parser.intValue();
break;
case FLATTEN_RESULT_INDEX_MAPPING:
flattenResultIndexMapping = parser.booleanValue();
break;
default:
parser.skipChildren();
break;
Expand Down Expand Up @@ -461,7 +467,8 @@ public static Forecaster parse(
historyIntervals,
customResultIndexMinSize,
customResultIndexMinAge,
customResultIndexTTL
customResultIndexTTL,
flattenResultIndexMapping
);
return forecaster;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ protected Config copyConfig(User user, Config config) {
config.getHistoryIntervals(),
config.getCustomResultIndexMinSize(),
config.getCustomResultIndexMinAge(),
config.getCustomResultIndexTTL()
config.getCustomResultIndexTTL(),
config.getFlattenResultIndexMapping()
);
}

Expand Down
22 changes: 19 additions & 3 deletions src/main/java/org/opensearch/timeseries/model/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public abstract class Config implements Writeable, ToXContentObject {
public static final String RESULT_INDEX_FIELD_MIN_SIZE = "result_index_min_size";
public static final String RESULT_INDEX_FIELD_MIN_AGE = "result_index_min_age";
public static final String RESULT_INDEX_FIELD_TTL = "result_index_ttl";
public static final String FLATTEN_RESULT_INDEX_MAPPING = "flatten_result_index_mapping";

protected String id;
protected Long version;
Expand Down Expand Up @@ -118,6 +119,7 @@ public abstract class Config implements Writeable, ToXContentObject {
protected Integer customResultIndexMinSize;
protected Integer customResultIndexMinAge;
protected Integer customResultIndexTTL;
protected Boolean flattenResultIndexMapping;

public static String INVALID_RESULT_INDEX_NAME_SIZE = "Result index name size must contains less than "
+ MAX_RESULT_INDEX_NAME_SIZE
Expand Down Expand Up @@ -148,7 +150,8 @@ protected Config(
Integer historyIntervals,
Integer customResultIndexMinSize,
Integer customResultIndexMinAge,
Integer customResultIndexTTL
Integer customResultIndexTTL,
Boolean flattenResultIndexMapping
) {
if (Strings.isBlank(name)) {
errorMessage = CommonMessages.EMPTY_NAME;
Expand Down Expand Up @@ -267,6 +270,7 @@ protected Config(
this.customResultIndexMinSize = Strings.trimToNull(resultIndex) == null ? null : customResultIndexMinSize;
this.customResultIndexMinAge = Strings.trimToNull(resultIndex) == null ? null : customResultIndexMinAge;
this.customResultIndexTTL = Strings.trimToNull(resultIndex) == null ? null : customResultIndexTTL;
this.flattenResultIndexMapping = Strings.trimToNull(resultIndex) == null ? null : flattenResultIndexMapping;
}

public int suggestHistory() {
Expand Down Expand Up @@ -310,6 +314,7 @@ public Config(StreamInput input) throws IOException {
this.customResultIndexMinSize = input.readOptionalInt();
this.customResultIndexMinAge = input.readOptionalInt();
this.customResultIndexTTL = input.readOptionalInt();
this.flattenResultIndexMapping = input.readOptionalBoolean();
}

/*
Expand Down Expand Up @@ -362,6 +367,7 @@ public void writeTo(StreamOutput output) throws IOException {
output.writeOptionalInt(customResultIndexMinSize);
output.writeOptionalInt(customResultIndexMinAge);
output.writeOptionalInt(customResultIndexTTL);
output.writeOptionalBoolean(flattenResultIndexMapping);
}

public boolean invalidShingleSizeRange(Integer shingleSizeToTest) {
Expand Down Expand Up @@ -418,7 +424,8 @@ public boolean equals(Object o) {
&& Objects.equal(historyIntervals, config.historyIntervals)
&& Objects.equal(customResultIndexMinSize, config.customResultIndexMinSize)
&& Objects.equal(customResultIndexMinAge, config.customResultIndexMinAge)
&& Objects.equal(customResultIndexTTL, config.customResultIndexTTL);
&& Objects.equal(customResultIndexTTL, config.customResultIndexTTL)
&& Objects.equal(flattenResultIndexMapping, config.flattenResultIndexMapping);
}

@Generated
Expand All @@ -445,7 +452,8 @@ public int hashCode() {
historyIntervals,
customResultIndexMinSize,
customResultIndexMinAge,
customResultIndexTTL
customResultIndexTTL,
flattenResultIndexMapping
);
}

Expand Down Expand Up @@ -494,6 +502,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (customResultIndexTTL != null) {
builder.field(RESULT_INDEX_FIELD_TTL, customResultIndexTTL);
}
if (flattenResultIndexMapping != null) {
builder.field(FLATTEN_RESULT_INDEX_MAPPING, flattenResultIndexMapping);
}
return builder;
}

Expand Down Expand Up @@ -702,6 +713,10 @@ public Integer getCustomResultIndexTTL() {
return customResultIndexTTL;
}

public Boolean getFlattenResultIndexMapping() {
return flattenResultIndexMapping;
}

/**
* Identifies redundant feature names.
*
Expand Down Expand Up @@ -756,6 +771,7 @@ public String toString() {
.append("customResultIndexMinSize", customResultIndexMinSize)
.append("customResultIndexMinAge", customResultIndexMinAge)
.append("customResultIndexTTL", customResultIndexTTL)
.append("flattenResultIndexMapping", flattenResultIndexMapping)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ public ToXContentObject[] getConfig(String detectorId, BasicHeader header, boole
null,
detector.getCustomResultIndexMinSize(),
detector.getCustomResultIndexMinAge(),
detector.getCustomResultIndexTTL()
detector.getCustomResultIndexTTL(),
detector.getFlattenResultIndexMapping()
),
detectorJob,
historicalAdTask,
Expand Down Expand Up @@ -640,7 +641,8 @@ protected AnomalyDetector cloneDetector(AnomalyDetector anomalyDetector, String
null,
anomalyDetector.getCustomResultIndexMinSize(),
anomalyDetector.getCustomResultIndexMinAge(),
anomalyDetector.getCustomResultIndexTTL()
anomalyDetector.getCustomResultIndexTTL(),
anomalyDetector.getFlattenResultIndexMapping()
);
return detector;
}
Expand Down
Loading

0 comments on commit d3bd162

Please sign in to comment.