[7.x] Make ModelPlotConfig.annotations_enabled default to ModelPlotConfig.enabled if unset (#57808) (#57815)

This commit is contained in:
Przemysław Witek 2020-06-08 17:41:12 +02:00 committed by GitHub
parent 63e962c99a
commit 7a1300a09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 13 deletions

View File

@ -45,12 +45,12 @@ public class ModelPlotConfig implements ToXContentObject {
private final boolean enabled;
private final String terms;
private final boolean annotationsEnabled;
private final Boolean annotationsEnabled;
public ModelPlotConfig(boolean enabled, String terms, Boolean annotationsEnabled) {
this.enabled = enabled;
this.terms = terms;
this.annotationsEnabled = Boolean.TRUE.equals(annotationsEnabled);
this.annotationsEnabled = annotationsEnabled;
}
@Override
@ -60,7 +60,9 @@ public class ModelPlotConfig implements ToXContentObject {
if (terms != null) {
builder.field(TERMS_FIELD.getPreferredName(), terms);
}
builder.field(ANNOTATIONS_ENABLED_FIELD.getPreferredName(), annotationsEnabled);
if (annotationsEnabled != null) {
builder.field(ANNOTATIONS_ENABLED_FIELD.getPreferredName(), annotationsEnabled);
}
builder.endObject();
return builder;
}
@ -73,7 +75,7 @@ public class ModelPlotConfig implements ToXContentObject {
return this.terms;
}
public boolean annotationsEnabled() {
public Boolean annotationsEnabled() {
return annotationsEnabled;
}
@ -88,7 +90,9 @@ public class ModelPlotConfig implements ToXContentObject {
}
ModelPlotConfig that = (ModelPlotConfig) other;
return this.enabled == that.enabled && Objects.equals(this.terms, that.terms) && this.annotationsEnabled == that.annotationsEnabled;
return this.enabled == that.enabled
&& Objects.equals(this.terms, that.terms)
&& Objects.equals(this.annotationsEnabled, that.annotationsEnabled);
}
@Override

View File

@ -988,6 +988,11 @@ must be disabled if performance issues are experienced.
--
end::model-plot-config[]
tag::model-plot-config-annotations-enabled[]
If true, enables calculation and storage of the model change annotations
for each entity that is being analyzed. Defaults to `enabled`.
end::model-plot-config-annotations-enabled[]
tag::model-plot-config-enabled[]
If true, enables calculation and storage of the model bounds for each entity
that is being analyzed. By default, this is not enabled.
@ -1000,11 +1005,6 @@ applied. For example, "CPU,NetworkIn,DiskWrites". Wildcards are not supported.
Only the specified `terms` can be viewed when using the Single Metric Viewer.
end::model-plot-config-terms[]
tag::model-plot-config-annotations-enabled[]
If true, enables calculation and storage of the model change annotations
for each entity that is being analyzed. By default, this is not enabled.
end::model-plot-config-annotations-enabled[]
tag::model-snapshot-retention-days[]
Advanced configuration option, which affects the automatic removal of old model
snapshots for this job. It specifies the maximum period of time (in days) that

View File

@ -42,7 +42,8 @@ public class Annotation implements ToXContentObject, Writeable {
public enum Event {
USER,
DELAYED_DATA,
MODEL_SNAPSHOT_STORED;
MODEL_SNAPSHOT_STORED,
MODEL_CHANGE;
public static Event fromString(String value) {
return valueOf(value.toUpperCase(Locale.ROOT));

View File

@ -44,13 +44,13 @@ public class ModelPlotConfig implements ToXContentObject, Writeable {
private final boolean annotationsEnabled;
public ModelPlotConfig() {
this(true, null, true);
this(true, null, null);
}
public ModelPlotConfig(boolean enabled, String terms, Boolean annotationsEnabled) {
this.enabled = enabled;
this.terms = terms;
this.annotationsEnabled = Boolean.TRUE.equals(annotationsEnabled);
this.annotationsEnabled = annotationsEnabled != null ? annotationsEnabled : enabled;
}
public ModelPlotConfig(StreamInput in) throws IOException {

View File

@ -21,6 +21,14 @@ public class ModelPlotConfigTests extends AbstractSerializingTestCase<ModelPlotC
assertThat(modelPlotConfig.annotationsEnabled(), is(true));
}
public void testAnnotationEnabledDefaultsToEnabled() {
ModelPlotConfig modelPlotConfig = new ModelPlotConfig(false, null, null);
assertThat(modelPlotConfig.annotationsEnabled(), is(false));
modelPlotConfig = new ModelPlotConfig(true, null, null);
assertThat(modelPlotConfig.annotationsEnabled(), is(true));
}
@Override
protected ModelPlotConfig createTestInstance() {
return createRandomized();