|
@@ -14,10 +14,11 @@ import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;
|
|
|
import org.elasticsearch.xpack.core.rollup.RollupField;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import static java.util.Collections.singletonList;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
@@ -49,11 +50,11 @@ public class MetricConfigSerializingTests extends AbstractSerializingTestCase<Me
|
|
|
|
|
|
MetricConfig config = new MetricConfig("my_field", singletonList("max"));
|
|
|
config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().get(0), equalTo("Could not find a [numeric] or [date] field with name [my_field] in any" +
|
|
|
- " of the indices matching the index pattern."));
|
|
|
+ assertThat(e.validationErrors().get(0), equalTo("Could not find a [numeric] or [date,date_nanos] field with name [my_field] " +
|
|
|
+ "in any of the indices matching the index pattern."));
|
|
|
}
|
|
|
|
|
|
- public void testValidateNomatchingField() {
|
|
|
+ public void testValidateNoMatchingField() {
|
|
|
ActionRequestValidationException e = new ActionRequestValidationException();
|
|
|
Map<String, Map<String, FieldCapabilities>> responseMap = new HashMap<>();
|
|
|
|
|
@@ -63,8 +64,8 @@ public class MetricConfigSerializingTests extends AbstractSerializingTestCase<Me
|
|
|
|
|
|
MetricConfig config = new MetricConfig("my_field", singletonList("max"));
|
|
|
config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().get(0), equalTo("Could not find a [numeric] or [date] field with name [my_field] in any" +
|
|
|
- " of the indices matching the index pattern."));
|
|
|
+ assertThat(e.validationErrors().get(0), equalTo("Could not find a [numeric] or [date,date_nanos] field with name [my_field] " +
|
|
|
+ "in any of the indices matching the index pattern."));
|
|
|
}
|
|
|
|
|
|
public void testValidateFieldWrongType() {
|
|
@@ -77,7 +78,7 @@ public class MetricConfigSerializingTests extends AbstractSerializingTestCase<Me
|
|
|
|
|
|
MetricConfig config = new MetricConfig("my_field", singletonList("max"));
|
|
|
config.validateMappings(responseMap, e);
|
|
|
- assertThat("The field referenced by a metric group must be a [numeric] or [date] type," +
|
|
|
+ assertThat("The field referenced by a metric group must be a [numeric] or [date,date_nanos] type," +
|
|
|
" but found [keyword] for field [my_field]", is(in(e.validationErrors())));
|
|
|
}
|
|
|
|
|
@@ -95,90 +96,54 @@ public class MetricConfigSerializingTests extends AbstractSerializingTestCase<Me
|
|
|
assertThat(e.validationErrors().get(0), equalTo("The field [my_field] must be aggregatable across all indices, but is not."));
|
|
|
}
|
|
|
|
|
|
- public void testValidateDateFieldUnsupportedMetric() {
|
|
|
- ActionRequestValidationException e = new ActionRequestValidationException();
|
|
|
+ public void testValidateDateFieldsUnsupportedMetric() {
|
|
|
Map<String, Map<String, FieldCapabilities>> responseMap = new HashMap<>();
|
|
|
|
|
|
- // Have to mock fieldcaps because the ctor's aren't public...
|
|
|
- FieldCapabilities fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("date", fieldCaps));
|
|
|
+ for (String mappingType : RollupField.DATE_FIELD_MAPPER_TYPES) {
|
|
|
+ // Have to mock fieldcaps because the ctor's aren't public...
|
|
|
+ FieldCapabilities fieldCaps = mock(FieldCapabilities.class);
|
|
|
+ when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
+ responseMap.put("my_field", Collections.singletonMap(mappingType, fieldCaps));
|
|
|
+
|
|
|
+ Set<String> unsupportedMetrics = new HashSet<>(RollupField.SUPPORTED_METRICS);
|
|
|
+ unsupportedMetrics.removeAll(RollupField.SUPPORTED_DATE_METRICS);
|
|
|
+ for (String unsupportedMetric : unsupportedMetrics) {
|
|
|
+ MetricConfig config = new MetricConfig("my_field", Collections.singletonList(unsupportedMetric));
|
|
|
+ ActionRequestValidationException e = new ActionRequestValidationException();
|
|
|
+ config.validateMappings(responseMap, e);
|
|
|
+ assertThat(e.validationErrors().get(0), equalTo("Only the metrics " + RollupField.SUPPORTED_DATE_METRICS.toString() +
|
|
|
+ " are supported for [" + mappingType + "] types, but unsupported metrics [" + unsupportedMetric +
|
|
|
+ "] supplied for field [my_field]"));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- MetricConfig config = new MetricConfig("my_field", Arrays.asList("avg", "max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().get(0), equalTo("Only the metrics " + RollupField.SUPPORTED_DATE_METRICS.toString() +
|
|
|
- " are supported for [date] types, but unsupported metrics [avg] supplied for field [my_field]"));
|
|
|
}
|
|
|
|
|
|
public void testValidateMatchingField() {
|
|
|
ActionRequestValidationException e = new ActionRequestValidationException();
|
|
|
Map<String, Map<String, FieldCapabilities>> responseMap = new HashMap<>();
|
|
|
|
|
|
- // Have to mock fieldcaps because the ctor's aren't public...
|
|
|
- FieldCapabilities fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("long", fieldCaps));
|
|
|
-
|
|
|
- MetricConfig config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("double", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("float", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("short", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("byte", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("half_float", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("scaled_float", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("integer", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
-
|
|
|
- fieldCaps = mock(FieldCapabilities.class);
|
|
|
- when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
- responseMap.put("my_field", Collections.singletonMap("date", fieldCaps));
|
|
|
- config = new MetricConfig("my_field", singletonList("max"));
|
|
|
- config.validateMappings(responseMap, e);
|
|
|
- assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
+ for (String numericType : RollupField.NUMERIC_FIELD_MAPPER_TYPES) {
|
|
|
+ // Have to mock fieldcaps because the ctor's aren't public...
|
|
|
+ FieldCapabilities fieldCaps = mock(FieldCapabilities.class);
|
|
|
+ when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
+ responseMap.put("my_field", Collections.singletonMap(numericType, fieldCaps));
|
|
|
+ MetricConfig config = ConfigTestHelpers
|
|
|
+ .randomMetricConfigWithFieldAndMetrics(random(), "my_field", RollupField.SUPPORTED_NUMERIC_METRICS);
|
|
|
+ config.validateMappings(responseMap, e);
|
|
|
+ assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String dateType : RollupField.DATE_FIELD_MAPPER_TYPES) {
|
|
|
+ // Have to mock fieldcaps because the ctor's aren't public...
|
|
|
+ FieldCapabilities fieldCaps = mock(FieldCapabilities.class);
|
|
|
+ when(fieldCaps.isAggregatable()).thenReturn(true);
|
|
|
+ responseMap.put("my_field", Collections.singletonMap(dateType, fieldCaps));
|
|
|
+ MetricConfig config = ConfigTestHelpers
|
|
|
+ .randomMetricConfigWithFieldAndMetrics(random(), "my_field", RollupField.SUPPORTED_DATE_METRICS);
|
|
|
+ config.validateMappings(responseMap, e);
|
|
|
+ assertThat(e.validationErrors().size(), equalTo(0));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|