[ML] Hide AnalysisConfig.latency field if not set (elastic/x-pack-elasticsearch#895)

Original commit: elastic/x-pack-elasticsearch@b2b3567820
This commit is contained in:
David Kyle 2017-03-31 12:08:44 +01:00 committed by GitHub
parent d7f3a260fd
commit 9da2853d12
4 changed files with 10 additions and 6 deletions

View File

@ -380,7 +380,9 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable {
if (categorizationFilters != null) { if (categorizationFilters != null) {
builder.field(CATEGORIZATION_FILTERS.getPreferredName(), categorizationFilters); builder.field(CATEGORIZATION_FILTERS.getPreferredName(), categorizationFilters);
} }
if (latency != null) {
builder.field(LATENCY.getPreferredName(), latency.getStringRep()); builder.field(LATENCY.getPreferredName(), latency.getStringRep());
}
if (period != null) { if (period != null) {
builder.field(PERIOD.getPreferredName(), period); builder.field(PERIOD.getPreferredName(), period);
} }
@ -446,7 +448,7 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable {
private List<Detector> detectors; private List<Detector> detectors;
private TimeValue bucketSpan = DEFAULT_BUCKET_SPAN; private TimeValue bucketSpan = DEFAULT_BUCKET_SPAN;
private TimeValue batchSpan; private TimeValue batchSpan;
private TimeValue latency = TimeValue.ZERO; private TimeValue latency;
private Long period; private Long period;
private String categorizationFieldName; private String categorizationFieldName;
private List<String> categorizationFilters; private List<String> categorizationFilters;
@ -554,7 +556,9 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable {
if (batchSpan != null) { if (batchSpan != null) {
TimeUtils.checkPositiveMultiple(batchSpan, TimeUnit.SECONDS, BATCH_SPAN); TimeUtils.checkPositiveMultiple(batchSpan, TimeUnit.SECONDS, BATCH_SPAN);
} }
if (latency != null) {
TimeUtils.checkNonNegativeMultiple(latency, TimeUnit.SECONDS, LATENCY); TimeUtils.checkNonNegativeMultiple(latency, TimeUnit.SECONDS, LATENCY);
}
checkFieldIsNotNegativeIfSpecified(PERIOD.getPreferredName(), period); checkFieldIsNotNegativeIfSpecified(PERIOD.getPreferredName(), period);
verifyDetectorAreDefined(detectors); verifyDetectorAreDefined(detectors);

View File

@ -62,7 +62,7 @@ public class DataStreamDiagnostics {
public DataStreamDiagnostics(Job job) { public DataStreamDiagnostics(Job job) {
bucketSpan = job.getAnalysisConfig().getBucketSpan().seconds(); bucketSpan = job.getAnalysisConfig().getBucketSpan().seconds();
latency = job.getAnalysisConfig().getLatency().seconds(); latency = job.getAnalysisConfig().getLatency() == null ? 0 : job.getAnalysisConfig().getLatency().seconds();
} }
/** /**

View File

@ -58,7 +58,7 @@ public abstract class AbstractDataToProcessWriter implements DataToProcessWriter
this.analysisConfig = Objects.requireNonNull(analysisConfig); this.analysisConfig = Objects.requireNonNull(analysisConfig);
this.dataCountsReporter = Objects.requireNonNull(dataCountsReporter); this.dataCountsReporter = Objects.requireNonNull(dataCountsReporter);
this.logger = Objects.requireNonNull(logger); this.logger = Objects.requireNonNull(logger);
this.latencySeconds = analysisConfig.getLatency().seconds(); this.latencySeconds = analysisConfig.getLatency() == null ? 0 : analysisConfig.getLatency().seconds();
Date date = dataCountsReporter.getLatestRecordTime(); Date date = dataCountsReporter.getLatestRecordTime();
latestEpochMsThisUpload = 0; latestEpochMsThisUpload = 0;

View File

@ -51,7 +51,7 @@ public class MlMetadataTests extends AbstractSerializingTestCase<MlMetadata> {
Job job = JobTests.createRandomizedJob(); Job job = JobTests.createRandomizedJob();
if (randomBoolean()) { if (randomBoolean()) {
AnalysisConfig.Builder analysisConfig = new AnalysisConfig.Builder(job.getAnalysisConfig()); AnalysisConfig.Builder analysisConfig = new AnalysisConfig.Builder(job.getAnalysisConfig());
analysisConfig.setLatency(TimeValue.ZERO); analysisConfig.setLatency(null);
DatafeedConfig datafeedConfig = DatafeedConfigTests.createRandomizedDatafeedConfig(job.getId()); DatafeedConfig datafeedConfig = DatafeedConfigTests.createRandomizedDatafeedConfig(job.getId());
if (datafeedConfig.hasAggregations()) { if (datafeedConfig.hasAggregations()) {
analysisConfig.setSummaryCountFieldName("doc_count"); analysisConfig.setSummaryCountFieldName("doc_count");