From 41b254cdf45c591d4432bbf71b3005eea6845dfd Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Tue, 21 Nov 2017 11:47:34 +0100 Subject: [PATCH] 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@7598342712e33e967e9816f89524462d209da849 --- .../persistence/ElasticsearchMappings.java | 2 +- .../ml/job/results/ForecastRequestStats.java | 36 ++++++++++++------- .../ml/job/results/ReservedFieldNames.java | 2 +- .../results/ForecastRequestStatsTests.java | 10 ++++-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ElasticsearchMappings.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ElasticsearchMappings.java index 0473a69338d..70f22e355e1 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ElasticsearchMappings.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ElasticsearchMappings.java @@ -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()) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStats.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStats.java index a91ba9e892e..606c5fd81b7 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStats.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStats.java @@ -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 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 getMessages() { + return messages; } - public void setMessage(String message) { - this.message = message; + public void setMessages(List 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); } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNames.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNames.java index b6d8f55331c..64fb5c3230e 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNames.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/ReservedFieldNames.java @@ -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(), diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStatsTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStatsTests.java index 6ca8bead2df..0af6a9459b9 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStatsTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/ForecastRequestStatsTests.java @@ -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 { @@ -32,7 +34,12 @@ public class ForecastRequestStatsTests extends AbstractSerializingTestCase 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