Don’t write the usePerPartitionNormalization field unless it is set to true (elastic/x-pack-elasticsearch#873)

Original commit: elastic/x-pack-elasticsearch@db7cd6993d
This commit is contained in:
David Kyle 2017-03-29 15:09:14 +01:00 committed by GitHub
parent 2355338625
commit a85b18e70b
3 changed files with 12 additions and 37 deletions

View File

@ -402,7 +402,9 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable {
builder.field(MULTIPLE_BUCKET_SPANS.getPreferredName(),
multipleBucketSpans.stream().map(s -> s.getStringRep()).collect(Collectors.toList()));
}
builder.field(USER_PER_PARTITION_NORMALIZATION.getPreferredName(), usePerPartitionNormalization);
if (usePerPartitionNormalization) {
builder.field(USER_PER_PARTITION_NORMALIZATION.getPreferredName(), usePerPartitionNormalization);
}
builder.endObject();
return builder;
}

View File

@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
/**
* Reads the autodetect persisted state and writes the results via the {@linkplain JobResultsPersister} passed in the constructor.
* Reads the autodetect state and persists via a bulk request
*/
public class StateProcessor extends AbstractComponent {

View File

@ -31,7 +31,9 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
List<Detector> detectors = new ArrayList<>();
int numDetectors = randomIntBetween(1, 10);
for (int i = 0; i < numDetectors; i++) {
detectors.add(new Detector.Builder("count", null).build());
Detector.Builder builder = new Detector.Builder("count", null);
builder.setPartitionFieldName("part");
detectors.add(builder.build());
}
AnalysisConfig.Builder builder = new AnalysisConfig.Builder(detectors);
@ -47,9 +49,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
builder.setCategorizationFieldName(randomAsciiOfLength(10));
builder.setCategorizationFilters(Arrays.asList(generateRandomStringArray(10, 10, false)));
}
if (randomBoolean()) {
builder.setInfluencers(Arrays.asList(generateRandomStringArray(10, 10, false)));
}
if (randomBoolean()) {
builder.setLatency(TimeValue.timeValueSeconds(randomIntBetween(1, 1_000_000)));
}
@ -71,7 +70,11 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
builder.setResultFinalizationWindow(randomNonNegativeLong());
}
builder.setUsePerPartitionNormalization(false);
boolean usePerPartitionNormalisation = randomBoolean();
builder.setUsePerPartitionNormalization(usePerPartitionNormalisation);
if (!usePerPartitionNormalisation) { // influencers can't be used with per partition normalisation
builder.setInfluencers(Arrays.asList(generateRandomStringArray(10, 10, false)));
}
return builder;
}
@ -231,23 +234,19 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertTrue(ac.getMultipleBucketSpans().contains(TimeValue.timeValueSeconds(24000)));
}
public void testEquals_GivenSameReference() {
AnalysisConfig config = createFullyPopulatedConfig();
assertTrue(config.equals(config));
}
public void testEquals_GivenDifferentClass() {
assertFalse(createFullyPopulatedConfig().equals("a string"));
}
public void testEquals_GivenNull() {
assertFalse(createFullyPopulatedConfig().equals(null));
}
public void testEquals_GivenEqualConfig() {
AnalysisConfig config1 = createFullyPopulatedConfig();
AnalysisConfig config2 = createFullyPopulatedConfig();
@ -257,7 +256,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals(config1.hashCode(), config2.hashCode());
}
public void testEquals_GivenDifferentBatchSpan() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setBatchSpan(TimeValue.timeValueHours(3));
@ -271,7 +269,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenDifferentBucketSpan() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setBucketSpan(TimeValue.timeValueSeconds(1800));
@ -285,7 +282,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenCategorizationField() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setCategorizationFieldName("foo");
@ -299,7 +295,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenDifferentDetector() {
AnalysisConfig config1 = createConfigWithDetectors(Collections.singletonList(new Detector.Builder("min", "low_count").build()));
@ -309,7 +304,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenDifferentInfluencers() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setInfluencers(Arrays.asList("foo"));
@ -323,7 +317,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenDifferentLatency() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setLatency(TimeValue.timeValueSeconds(1800));
@ -337,7 +330,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenDifferentPeriod() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setPeriod(1800L);
@ -351,7 +343,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenSummaryCountField() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setSummaryCountFieldName("foo");
@ -365,7 +356,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenMultivariateByField() {
AnalysisConfig.Builder builder = createConfigBuilder();
builder.setMultivariateByFields(true);
@ -379,7 +369,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(config2.equals(config1));
}
public void testEquals_GivenDifferentCategorizationFilters() {
AnalysisConfig config1 = createFullyPopulatedConfig();
AnalysisConfig.Builder builder = createConfigBuilder();
@ -431,7 +420,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
}
public void testVerify_throws() {
// count works with no fields
Detector d = new Detector.Builder("count", null).build();
new AnalysisConfig.Builder(Collections.singletonList(d)).build();
@ -485,7 +473,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals("batch_span cannot be less or equal than 0. Value = -1", e.getMessage());
}
public void testVerify_GivenNegativeLatency() {
AnalysisConfig.Builder analysisConfig = createValidConfig();
analysisConfig.setLatency(TimeValue.timeValueSeconds(-1));
@ -495,7 +482,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals("latency cannot be less than 0. Value = -1", e.getMessage());
}
public void testVerify_GivenNegativePeriod() {
AnalysisConfig.Builder analysisConfig = createValidConfig();
analysisConfig.setPeriod(-1L);
@ -521,7 +507,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
analysisConfig.build();
}
public void testVerify_GivenValidConfigWithCategorizationFieldNameAndCategorizationFilters() {
AnalysisConfig.Builder analysisConfig = createValidConfig();
analysisConfig.setCategorizationFieldName("myCategory");
@ -530,7 +515,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
analysisConfig.build();
}
public void testVerify_OverlappingBuckets() {
List<Detector> detectors;
Detector detector;
@ -622,7 +606,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertFalse(ac.getOverlappingBuckets());
}
public void testMultipleBucketsConfig() {
AnalysisConfig.Builder ac = createValidConfig();
ac.setMultipleBucketSpans(Arrays.asList(
@ -675,9 +658,7 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_MULTIPLE_BUCKETSPANS_MUST_BE_MULTIPLE, -444, "3.7m"), e.getMessage());
}
public void testVerify_GivenCategorizationFiltersButNoCategorizationFieldName() {
AnalysisConfig.Builder config = createValidConfig();
config.setCategorizationFilters(Arrays.asList("foo"));
@ -686,9 +667,7 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_CATEGORIZATION_FILTERS_REQUIRE_CATEGORIZATION_FIELD_NAME), e.getMessage());
}
public void testVerify_GivenDuplicateCategorizationFilters() {
AnalysisConfig.Builder config = createValidConfig();
config.setCategorizationFieldName("myCategory");
config.setCategorizationFilters(Arrays.asList("foo", "bar", "foo"));
@ -698,9 +677,7 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_CATEGORIZATION_FILTERS_CONTAINS_DUPLICATES), e.getMessage());
}
public void testVerify_GivenEmptyCategorizationFilter() {
AnalysisConfig.Builder config = createValidConfig();
config.setCategorizationFieldName("myCategory");
config.setCategorizationFilters(Arrays.asList("foo", ""));
@ -712,7 +689,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
public void testCheckDetectorsHavePartitionFields() {
AnalysisConfig.Builder config = createValidConfig();
config.setUsePerPartitionNormalization(true);
@ -721,7 +697,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_PER_PARTITION_NORMALIZATION_REQUIRES_PARTITION_FIELD), e.getMessage());
}
public void testCheckDetectorsHavePartitionFields_doesntThrowWhenValid() {
AnalysisConfig.Builder config = createValidConfig();
Detector.Builder builder = new Detector.Builder(config.build().getDetectors().get(0));
@ -732,7 +707,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
config.build();
}
public void testCheckNoInfluencersAreSet() {
AnalysisConfig.Builder config = createValidConfig();
@ -747,7 +721,6 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
assertEquals(Messages.getMessage(Messages.JOB_CONFIG_PER_PARTITION_NORMALIZATION_CANNOT_USE_INFLUENCERS), e.getMessage());
}
public void testVerify_GivenCategorizationFiltersContainInvalidRegex() {
AnalysisConfig.Builder config = createValidConfig();