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:
parent
941c0a5701
commit
41b254cdf4
|
@ -347,7 +347,7 @@ public class ElasticsearchMappings {
|
|||
.startObject(ForecastRequestStats.END_TIME.getPreferredName())
|
||||
.field(TYPE, DATE)
|
||||
.endObject()
|
||||
.startObject(ForecastRequestStats.MESSAGE.getPreferredName())
|
||||
.startObject(ForecastRequestStats.MESSAGES.getPreferredName())
|
||||
.field(TYPE, KEYWORD)
|
||||
.endObject()
|
||||
.startObject(ForecastRequestStats.PROGRESS.getPreferredName())
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.xpack.ml.job.config.Job;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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 START_TIME = new ParseField("forecast_start_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 PROGRESS = new ParseField("forecast_progress");
|
||||
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.declareLong(ForecastRequestStats::setRecordCount, PROCESSED_RECORD_COUNT);
|
||||
PARSER.declareString(ForecastRequestStats::setMessage, MESSAGE);
|
||||
PARSER.declareStringArray(ForecastRequestStats::setMessages, MESSAGES);
|
||||
PARSER.declareField(ForecastRequestStats::setStartTimeStamp,
|
||||
p -> Instant.ofEpochMilli(p.longValue()), START_TIME, ValueType.LONG);
|
||||
PARSER.declareField(ForecastRequestStats::setEndTimeStamp,
|
||||
|
@ -89,7 +90,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
private final String jobId;
|
||||
private final long forecastId;
|
||||
private long recordCount;
|
||||
private String message;
|
||||
private List<String> messages;
|
||||
private Instant dateStarted = Instant.EPOCH;
|
||||
private Instant dateEnded = Instant.EPOCH;
|
||||
private double progress;
|
||||
|
@ -106,7 +107,11 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
jobId = in.readString();
|
||||
forecastId = in.readLong();
|
||||
recordCount = in.readLong();
|
||||
message = in.readOptionalString();
|
||||
if (in.readBoolean()) {
|
||||
messages = in.readList(StreamInput::readString);
|
||||
} else {
|
||||
messages = null;
|
||||
}
|
||||
dateStarted = Instant.ofEpochMilli(in.readVLong());
|
||||
dateEnded = Instant.ofEpochMilli(in.readVLong());
|
||||
progress = in.readDouble();
|
||||
|
@ -120,7 +125,12 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
out.writeString(jobId);
|
||||
out.writeLong(forecastId);
|
||||
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(dateEnded.toEpochMilli());
|
||||
out.writeDouble(progress);
|
||||
|
@ -136,8 +146,8 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
builder.field(Result.RESULT_TYPE.getPreferredName(), RESULT_TYPE_VALUE);
|
||||
builder.field(FORECAST_ID.getPreferredName(), forecastId);
|
||||
builder.field(PROCESSED_RECORD_COUNT.getPreferredName(), recordCount);
|
||||
if (message != null) {
|
||||
builder.field(MESSAGE.getPreferredName(), message);
|
||||
if (messages != null) {
|
||||
builder.field(MESSAGES.getPreferredName(), messages);
|
||||
}
|
||||
if (dateStarted.equals(Instant.EPOCH) == false) {
|
||||
builder.field(START_TIME.getPreferredName(), dateStarted.toEpochMilli());
|
||||
|
@ -175,12 +185,12 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
return recordCount;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
public List<String> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
public void setMessages(List<String> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public Instant getDateStarted() {
|
||||
|
@ -250,7 +260,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
return Objects.equals(this.jobId, that.jobId) &&
|
||||
this.forecastId == that.forecastId &&
|
||||
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.dateEnded, that.dateEnded) &&
|
||||
this.progress == that.progress &&
|
||||
|
@ -261,7 +271,7 @@ public class ForecastRequestStats implements ToXContentObject, Writeable {
|
|||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public final class ReservedFieldNames {
|
|||
|
||||
ForecastRequestStats.START_TIME.getPreferredName(),
|
||||
ForecastRequestStats.END_TIME.getPreferredName(),
|
||||
ForecastRequestStats.MESSAGE.getPreferredName(),
|
||||
ForecastRequestStats.MESSAGES.getPreferredName(),
|
||||
ForecastRequestStats.PROGRESS.getPreferredName(),
|
||||
ForecastRequestStats.STATUS.getPreferredName(),
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.elasticsearch.xpack.ml.job.results.ForecastRequestStats.ForecastReque
|
|||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForecastRequestStatsTests extends AbstractSerializingTestCase<ForecastRequestStats> {
|
||||
|
||||
|
@ -32,7 +34,12 @@ public class ForecastRequestStatsTests extends AbstractSerializingTestCase<Forec
|
|||
forecastRequestStats.setRecordCount(randomLong());
|
||||
}
|
||||
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()) {
|
||||
forecastRequestStats.setStartTimeStamp(Instant.ofEpochMilli(randomNonNegativeLong()));
|
||||
|
@ -65,5 +72,4 @@ public class ForecastRequestStatsTests extends AbstractSerializingTestCase<Forec
|
|||
protected ForecastRequestStats doParseInstance(XContentParser parser) throws IOException {
|
||||
return ForecastRequestStats.PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue