Skip to content

Rename dimension mapping parameter to time_series_dimension #78012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ enable:
type: date
metricset:
type: keyword
dimension: true
time_series_dimension: true
k8s:
properties:
pod:
properties:
uid:
type: keyword
dimension: true
time_series_dimension: true
name:
type: keyword
ip:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ public Builder(String name, ScriptCompiler scriptCompiler, boolean ignoreMalform
= Parameter.boolParam("ignore_malformed", true, m -> toType(m).ignoreMalformed, ignoreMalformedByDefault);
this.script.precludesParameters(nullValue, ignoreMalformed);
addScriptValidation(script, indexed, hasDocValues);
this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false)
.addValidator(v -> {
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
throw new IllegalArgumentException(
"Field [dimension] requires that [" + indexed.name + "] and [" + hasDocValues.name + "] are true"
);
}
});
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
throw new IllegalArgumentException(
"Field ["
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
+ "] requires that ["
+ indexed.name
+ "] and ["
+ hasDocValues.name
+ "] are true"
);
}
});
}

Builder nullValue(String nullValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ public Builder(String name, IndexAnalyzers indexAnalyzers, ScriptCompiler script
this.script.precludesParameters(nullValue);
addScriptValidation(script, indexed, hasDocValues);

this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false).addValidator(v -> {
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
throw new IllegalArgumentException(
"Field [dimension] requires that [" + indexed.name + "] and [" + hasDocValues.name + "] are true"
"Field ["
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
+ "] requires that ["
+ indexed.name
+ "] and ["
+ hasDocValues.name
+ "] are true"
);
}
}).precludesParameters(normalizer, ignoreAbove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,24 @@ public Builder(String name, NumberType type, ScriptCompiler compiler, boolean ig
this.nullValue = new Parameter<>("null_value", false, () -> null,
(n, c, o) -> o == null ? null : type.parse(o, false), m -> toType(m).nullValue).acceptsNull();

this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false)
.addValidator(v -> {
if (v && EnumSet.of(NumberType.INTEGER, NumberType.LONG, NumberType.BYTE, NumberType.SHORT).contains(type) == false) {
throw new IllegalArgumentException("Parameter [dimension] cannot be set to numeric type [" + type.name + "]");
}
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
throw new IllegalArgumentException(
"Field [dimension] requires that [" + indexed.name + "] and [" + hasDocValues.name + "] are true"
);
}
});
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
if (v && EnumSet.of(NumberType.INTEGER, NumberType.LONG, NumberType.BYTE, NumberType.SHORT).contains(type) == false) {
throw new IllegalArgumentException(
"Parameter [" + TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + "] cannot be set to numeric type [" + type.name + "]"
);
}
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
throw new IllegalArgumentException(
"Field ["
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
+ "] requires that ["
+ indexed.name
+ "] and ["
+ hasDocValues.name
+ "] are true"
);
}
});

this.metric = TimeSeriesParams.metricParam(m -> toType(m).metricType, MetricType.gauge, MetricType.counter)
.addValidator(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
public final class TimeSeriesParams {

public static final String TIME_SERIES_METRIC_PARAM = "time_series_metric";
public static final String TIME_SERIES_DIMENSION_PARAM = "time_series_dimension";

private TimeSeriesParams() {}
private TimeSeriesParams() {
}

public enum MetricType {
gauge,
Expand All @@ -42,4 +44,8 @@ public static FieldMapper.Parameter<MetricType> metricParam(Function<FieldMapper
).acceptsNull();
}

public static FieldMapper.Parameter<Boolean> dimensionParam(Function<FieldMapper, Boolean> initializer) {
return FieldMapper.Parameter.boolParam(TIME_SERIES_DIMENSION_PARAM, false, initializer, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void testTooManyDimensionFields() {
for (int i = 0; i <= max; i++) {
b.startObject("field" + i)
.field("type", randomFrom("ip", "keyword", "long", "integer", "byte", "short"))
.field("dimension", true)
.field("time_series_dimension", true)
.endObject();
}
})));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,33 +219,39 @@ public void testDimensionIndexedAndDocvalues() {
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", false).field("doc_values", false);
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
assertThat(
e.getCause().getMessage(),
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
);
}
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", true).field("doc_values", false);
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
assertThat(
e.getCause().getMessage(),
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
);
}
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", false).field("doc_values", true);
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
assertThat(
e.getCause().getMessage(),
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
);
}
}

public void testDimensionMultiValuedField() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
}));

Exception e = expectThrows(MapperParsingException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,52 +314,52 @@ public void testDimension() throws IOException {
public void testDimensionAndIgnoreAbove() {
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("ignore_above", 2048);
b.field("time_series_dimension", true).field("ignore_above", 2048);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [ignore_above] cannot be set in conjunction with field [dimension]"));
containsString("Field [ignore_above] cannot be set in conjunction with field [time_series_dimension]"));
}

public void testDimensionAndNormalizer() {
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("normalizer", "my_normalizer");
b.field("time_series_dimension", true).field("normalizer", "my_normalizer");
})));
assertThat(e.getCause().getMessage(),
containsString("Field [normalizer] cannot be set in conjunction with field [dimension]"));
containsString("Field [normalizer] cannot be set in conjunction with field [time_series_dimension]"));
}

public void testDimensionIndexedAndDocvalues() {
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", false).field("doc_values", false);
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true"));
}
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", true).field("doc_values", false);
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true"));
}
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", false).field("doc_values", true);
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true"));
}
}

public void testDimensionMultiValuedField() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
}));

Exception e = expectThrows(MapperParsingException.class,
Expand All @@ -371,7 +371,7 @@ public void testDimensionMultiValuedField() throws IOException {
public void testDimensionExtraLongKeyword() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
}));

Exception e = expectThrows(MapperParsingException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ public void testDimension() throws IOException {
// dimension = true is not allowed
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
})));
assertThat(e.getCause().getMessage(), containsString("Parameter [dimension] cannot be set"));
assertThat(e.getCause().getMessage(), containsString("Parameter [time_series_dimension] cannot be set"));
}

public void testMetricType() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,39 @@ public void testDimensionIndexedAndDocvalues() {
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", false).field("doc_values", false);
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
assertThat(
e.getCause().getMessage(),
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
);
}
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", true).field("doc_values", false);
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
assertThat(
e.getCause().getMessage(),
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
);
}
{
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true).field("index", false).field("doc_values", true);
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
})));
assertThat(e.getCause().getMessage(),
containsString("Field [dimension] requires that [index] and [doc_values] are true"));
assertThat(
e.getCause().getMessage(),
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
);
}
}

public void testDimensionMultiValuedField() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
}));

Exception e = expectThrows(MapperParsingException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected static void assertNoDocValuesField(LuceneDocument doc, String field) {
protected <T> void assertDimension(boolean isDimension, Function<T, Boolean> checker) throws IOException {
MapperService mapperService = createMapperService(fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", isDimension);
b.field("time_series_dimension", isDimension);
}));

@SuppressWarnings("unchecked") // Syntactic sugar in tests
Expand Down Expand Up @@ -557,25 +557,25 @@ protected String randomFetchTestFormat() {
*/
protected void registerDimensionChecks(ParameterChecker checker) throws IOException {
// dimension cannot be updated
checker.registerConflictCheck("dimension", b -> b.field("dimension", true));
checker.registerConflictCheck("dimension", b -> b.field("dimension", false));
checker.registerConflictCheck("dimension",
checker.registerConflictCheck("time_series_dimension", b -> b.field("time_series_dimension", true));
checker.registerConflictCheck("time_series_dimension", b -> b.field("time_series_dimension", false));
checker.registerConflictCheck("time_series_dimension",
fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", false);
b.field("time_series_dimension", false);
}),
fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
}));
checker.registerConflictCheck("dimension",
checker.registerConflictCheck("time_series_dimension",
fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", true);
b.field("time_series_dimension", true);
}),
fieldMapping(b -> {
minimalMapping(b);
b.field("dimension", false);
b.field("time_series_dimension", false);
}));
}

Expand Down