From 9da2853d12d400b2851568e61bda596ce936473f Mon Sep 17 00:00:00 2001 From: David Kyle Date: Fri, 31 Mar 2017 12:08:44 +0100 Subject: [PATCH] [ML] Hide AnalysisConfig.latency field if not set (elastic/x-pack-elasticsearch#895) Original commit: elastic/x-pack-elasticsearch@b2b3567820ed56c1d81bd65f3cb19649713c7aae --- .../xpack/ml/job/config/AnalysisConfig.java | 10 +++++++--- .../xpack/ml/job/process/DataStreamDiagnostics.java | 2 +- .../autodetect/writer/AbstractDataToProcessWriter.java | 2 +- .../org/elasticsearch/xpack/ml/MlMetadataTests.java | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfig.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfig.java index b126d9ba5e1..1295f0e8038 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfig.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfig.java @@ -380,7 +380,9 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable { if (categorizationFilters != null) { builder.field(CATEGORIZATION_FILTERS.getPreferredName(), categorizationFilters); } - builder.field(LATENCY.getPreferredName(), latency.getStringRep()); + if (latency != null) { + builder.field(LATENCY.getPreferredName(), latency.getStringRep()); + } if (period != null) { builder.field(PERIOD.getPreferredName(), period); } @@ -446,7 +448,7 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable { private List detectors; private TimeValue bucketSpan = DEFAULT_BUCKET_SPAN; private TimeValue batchSpan; - private TimeValue latency = TimeValue.ZERO; + private TimeValue latency; private Long period; private String categorizationFieldName; private List categorizationFilters; @@ -554,7 +556,9 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable { if (batchSpan != null) { TimeUtils.checkPositiveMultiple(batchSpan, TimeUnit.SECONDS, BATCH_SPAN); } - TimeUtils.checkNonNegativeMultiple(latency, TimeUnit.SECONDS, LATENCY); + if (latency != null) { + TimeUtils.checkNonNegativeMultiple(latency, TimeUnit.SECONDS, LATENCY); + } checkFieldIsNotNegativeIfSpecified(PERIOD.getPreferredName(), period); verifyDetectorAreDefined(detectors); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java index 479aaa44300..2ff9be9af77 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/DataStreamDiagnostics.java @@ -62,7 +62,7 @@ public class DataStreamDiagnostics { public DataStreamDiagnostics(Job job) { bucketSpan = job.getAnalysisConfig().getBucketSpan().seconds(); - latency = job.getAnalysisConfig().getLatency().seconds(); + latency = job.getAnalysisConfig().getLatency() == null ? 0 : job.getAnalysisConfig().getLatency().seconds(); } /** diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/AbstractDataToProcessWriter.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/AbstractDataToProcessWriter.java index ff98d42da4b..39f99cc3dc5 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/AbstractDataToProcessWriter.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/AbstractDataToProcessWriter.java @@ -58,7 +58,7 @@ public abstract class AbstractDataToProcessWriter implements DataToProcessWriter this.analysisConfig = Objects.requireNonNull(analysisConfig); this.dataCountsReporter = Objects.requireNonNull(dataCountsReporter); this.logger = Objects.requireNonNull(logger); - this.latencySeconds = analysisConfig.getLatency().seconds(); + this.latencySeconds = analysisConfig.getLatency() == null ? 0 : analysisConfig.getLatency().seconds(); Date date = dataCountsReporter.getLatestRecordTime(); latestEpochMsThisUpload = 0; diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java index a150ce30d97..565d18e4d20 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java @@ -51,7 +51,7 @@ public class MlMetadataTests extends AbstractSerializingTestCase { Job job = JobTests.createRandomizedJob(); if (randomBoolean()) { AnalysisConfig.Builder analysisConfig = new AnalysisConfig.Builder(job.getAnalysisConfig()); - analysisConfig.setLatency(TimeValue.ZERO); + analysisConfig.setLatency(null); DatafeedConfig datafeedConfig = DatafeedConfigTests.createRandomizedDatafeedConfig(job.getId()); if (datafeedConfig.hasAggregations()) { analysisConfig.setSummaryCountFieldName("doc_count");