change forecast message into an array of messages (elastic/x-pack-elasticsearch#3070)

depends on elastic/machine-learning-cpp#419

Turns the forecast message into an array of messages.

Original commit: elastic/x-pack-elasticsearch@7598342712
This commit is contained in:
Hendrik Muhs 2017-11-21 11:47:34 +01:00 committed by GitHub
parent 941c0a5701
commit 41b254cdf4
4 changed files with 33 additions and 17 deletions

View File

@ -347,7 +347,7 @@ public class ElasticsearchMappings {
.startObject(ForecastRequestStats.END_TIME.getPreferredName()) .startObject(ForecastRequestStats.END_TIME.getPreferredName())
.field(TYPE, DATE) .field(TYPE, DATE)
.endObject() .endObject()
.startObject(ForecastRequestStats.MESSAGE.getPreferredName()) .startObject(ForecastRequestStats.MESSAGES.getPreferredName())
.field(TYPE, KEYWORD) .field(TYPE, KEYWORD)
.endObject() .endObject()
.startObject(ForecastRequestStats.PROGRESS.getPreferredName()) .startObject(ForecastRequestStats.PROGRESS.getPreferredName())

View File

@ -17,6 +17,7 @@ import org.elasticsearch.xpack.ml.job.config.Job;
import java.io.IOException; import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
@ -37,7 +38,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
public static final ParseField FORECAST_ID = new ParseField("forecast_id"); public static final ParseField FORECAST_ID = new ParseField("forecast_id");
public static final ParseField START_TIME = new ParseField("forecast_start_timestamp"); public static final ParseField START_TIME = new ParseField("forecast_start_timestamp");
public static final ParseField END_TIME = new ParseField("forecast_end_timestamp"); public static final ParseField END_TIME = new ParseField("forecast_end_timestamp");
public static final ParseField MESSAGE = new ParseField("forecast_message"); public static final ParseField MESSAGES = new ParseField("forecast_messages");
public static final ParseField PROCESSING_TIME_MS = new ParseField("processing_time_ms"); public static final ParseField PROCESSING_TIME_MS = new ParseField("processing_time_ms");
public static final ParseField PROGRESS = new ParseField("forecast_progress"); public static final ParseField PROGRESS = new ParseField("forecast_progress");
public static final ParseField PROCESSED_RECORD_COUNT = new ParseField("processed_record_count"); public static final ParseField PROCESSED_RECORD_COUNT = new ParseField("processed_record_count");
@ -53,7 +54,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
PARSER.declareString((modelForecastRequestStats, s) -> {}, Result.RESULT_TYPE); PARSER.declareString((modelForecastRequestStats, s) -> {}, Result.RESULT_TYPE);
PARSER.declareLong(ForecastRequestStats::setRecordCount, PROCESSED_RECORD_COUNT); PARSER.declareLong(ForecastRequestStats::setRecordCount, PROCESSED_RECORD_COUNT);
PARSER.declareString(ForecastRequestStats::setMessage, MESSAGE); PARSER.declareStringArray(ForecastRequestStats::setMessages, MESSAGES);
PARSER.declareField(ForecastRequestStats::setStartTimeStamp, PARSER.declareField(ForecastRequestStats::setStartTimeStamp,
p -> Instant.ofEpochMilli(p.longValue()), START_TIME, ValueType.LONG); p -> Instant.ofEpochMilli(p.longValue()), START_TIME, ValueType.LONG);
PARSER.declareField(ForecastRequestStats::setEndTimeStamp, PARSER.declareField(ForecastRequestStats::setEndTimeStamp,
@ -89,7 +90,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
private final String jobId; private final String jobId;
private final long forecastId; private final long forecastId;
private long recordCount; private long recordCount;
private String message; private List<String> messages;
private Instant dateStarted = Instant.EPOCH; private Instant dateStarted = Instant.EPOCH;
private Instant dateEnded = Instant.EPOCH; private Instant dateEnded = Instant.EPOCH;
private double progress; private double progress;
@ -106,7 +107,11 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
jobId = in.readString(); jobId = in.readString();
forecastId = in.readLong(); forecastId = in.readLong();
recordCount = in.readLong(); recordCount = in.readLong();
message = in.readOptionalString(); if (in.readBoolean()) {
messages = in.readList(StreamInput::readString);
} else {
messages = null;
}
dateStarted = Instant.ofEpochMilli(in.readVLong()); dateStarted = Instant.ofEpochMilli(in.readVLong());
dateEnded = Instant.ofEpochMilli(in.readVLong()); dateEnded = Instant.ofEpochMilli(in.readVLong());
progress = in.readDouble(); progress = in.readDouble();
@ -120,7 +125,12 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
out.writeString(jobId); out.writeString(jobId);
out.writeLong(forecastId); out.writeLong(forecastId);
out.writeLong(recordCount); out.writeLong(recordCount);
out.writeOptionalString(message); if (messages != null) {
out.writeBoolean(true);
out.writeStringList(messages);
} else {
out.writeBoolean(false);
}
out.writeVLong(dateStarted.toEpochMilli()); out.writeVLong(dateStarted.toEpochMilli());
out.writeVLong(dateEnded.toEpochMilli()); out.writeVLong(dateEnded.toEpochMilli());
out.writeDouble(progress); out.writeDouble(progress);
@ -136,8 +146,8 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
builder.field(Result.RESULT_TYPE.getPreferredName(), RESULT_TYPE_VALUE); builder.field(Result.RESULT_TYPE.getPreferredName(), RESULT_TYPE_VALUE);
builder.field(FORECAST_ID.getPreferredName(), forecastId); builder.field(FORECAST_ID.getPreferredName(), forecastId);
builder.field(PROCESSED_RECORD_COUNT.getPreferredName(), recordCount); builder.field(PROCESSED_RECORD_COUNT.getPreferredName(), recordCount);
if (message != null) { if (messages != null) {
builder.field(MESSAGE.getPreferredName(), message); builder.field(MESSAGES.getPreferredName(), messages);
} }
if (dateStarted.equals(Instant.EPOCH) == false) { if (dateStarted.equals(Instant.EPOCH) == false) {
builder.field(START_TIME.getPreferredName(), dateStarted.toEpochMilli()); builder.field(START_TIME.getPreferredName(), dateStarted.toEpochMilli());
@ -175,12 +185,12 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
return recordCount; return recordCount;
} }
public String getMessage() { public List<String> getMessages() {
return message; return messages;
} }
public void setMessage(String message) { public void setMessages(List<String> messages) {
this.message = message; this.messages = messages;
} }
public Instant getDateStarted() { public Instant getDateStarted() {
@ -250,7 +260,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
return Objects.equals(this.jobId, that.jobId) && return Objects.equals(this.jobId, that.jobId) &&
this.forecastId == that.forecastId && this.forecastId == that.forecastId &&
this.recordCount == that.recordCount && this.recordCount == that.recordCount &&
Objects.equals(this.message, that.message) && Objects.equals(this.messages, that.messages) &&
Objects.equals(this.dateStarted, that.dateStarted) && Objects.equals(this.dateStarted, that.dateStarted) &&
Objects.equals(this.dateEnded, that.dateEnded) && Objects.equals(this.dateEnded, that.dateEnded) &&
this.progress == that.progress && this.progress == that.progress &&
@ -261,7 +271,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(jobId, forecastId, recordCount, message, dateStarted, dateEnded, progress, return Objects.hash(jobId, forecastId, recordCount, messages, dateStarted, dateEnded, progress,
processingTime, memoryUsage, status); processingTime, memoryUsage, status);
} }
} }

View File

@ -133,7 +133,7 @@ public final class ReservedFieldNames {
ForecastRequestStats.START_TIME.getPreferredName(), ForecastRequestStats.START_TIME.getPreferredName(),
ForecastRequestStats.END_TIME.getPreferredName(), ForecastRequestStats.END_TIME.getPreferredName(),
ForecastRequestStats.MESSAGE.getPreferredName(), ForecastRequestStats.MESSAGES.getPreferredName(),
ForecastRequestStats.PROGRESS.getPreferredName(), ForecastRequestStats.PROGRESS.getPreferredName(),
ForecastRequestStats.STATUS.getPreferredName(), ForecastRequestStats.STATUS.getPreferredName(),

View File

@ -12,6 +12,8 @@ import org.elasticsearch.xpack.ml.job.results.ForecastRequestStats.ForecastReque
import java.io.IOException; import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
public class ForecastRequestStatsTests extends AbstractSerializingTestCase<ForecastRequestStats> { public class ForecastRequestStatsTests extends AbstractSerializingTestCase<ForecastRequestStats> {
@ -32,7 +34,12 @@ public class ForecastRequestStatsTests extends AbstractSerializingTestCase<Forec
forecastRequestStats.setRecordCount(randomLong()); forecastRequestStats.setRecordCount(randomLong());
} }
if (randomBoolean()) { if (randomBoolean()) {
forecastRequestStats.setMessage(randomAlphaOfLengthBetween(1, 20)); int size = scaledRandomIntBetween(1, 20);
List<String> list = new ArrayList<>();
for (int i = 0; i < size; i++) {
list.add(randomAlphaOfLength(40));
}
forecastRequestStats.setMessages(list);
} }
if (randomBoolean()) { if (randomBoolean()) {
forecastRequestStats.setStartTimeStamp(Instant.ofEpochMilli(randomNonNegativeLong())); forecastRequestStats.setStartTimeStamp(Instant.ofEpochMilli(randomNonNegativeLong()));
@ -65,5 +72,4 @@ public class ForecastRequestStatsTests extends AbstractSerializingTestCase<Forec
protected ForecastRequestStats doParseInstance(XContentParser parser) throws IOException { protected ForecastRequestStats doParseInstance(XContentParser parser) throws IOException {
return ForecastRequestStats.PARSER.apply(parser, null); return ForecastRequestStats.PARSER.apply(parser, null);
} }
} }