|
@@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.ClusterSettings;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
|
|
import org.elasticsearch.common.util.set.Sets;
|
|
|
+import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import org.junit.BeforeClass;
|
|
@@ -27,8 +28,8 @@ import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
public class DotPrefixValidatorTests extends ESTestCase {
|
|
|
- private final OperatorValidator<?> opV = new OperatorValidator<>();
|
|
|
- private final NonOperatorValidator<?> nonOpV = new NonOperatorValidator<>();
|
|
|
+ private final OperatorValidator<?> opV = new OperatorValidator<>(true);
|
|
|
+ private final NonOperatorValidator<?> nonOpV = new NonOperatorValidator<>(true);
|
|
|
|
|
|
private static ClusterService clusterService;
|
|
|
|
|
@@ -58,14 +59,19 @@ public class DotPrefixValidatorTests extends ESTestCase {
|
|
|
opV.validateIndices(Set.of(".regular"));
|
|
|
assertFails(Set.of("first", ".second"));
|
|
|
assertFails(Set.of("<.regular-{MM-yy-dd}>"));
|
|
|
+ assertFails(Set.of(".this_index_contains_an_excepted_pattern.ml-annotations-1"));
|
|
|
|
|
|
// Test ignored names
|
|
|
nonOpV.validateIndices(Set.of(".elastic-connectors-v1"));
|
|
|
nonOpV.validateIndices(Set.of(".elastic-connectors-sync-jobs-v1"));
|
|
|
nonOpV.validateIndices(Set.of(".ml-state"));
|
|
|
+ nonOpV.validateIndices(Set.of(".ml-state-000001"));
|
|
|
+ nonOpV.validateIndices(Set.of(".ml-stats-000001"));
|
|
|
nonOpV.validateIndices(Set.of(".ml-anomalies-unrelated"));
|
|
|
|
|
|
// Test ignored patterns
|
|
|
+ nonOpV.validateIndices(Set.of(".ml-annotations-21309"));
|
|
|
+ nonOpV.validateIndices(Set.of(".ml-annotations-2"));
|
|
|
nonOpV.validateIndices(Set.of(".ml-state-21309"));
|
|
|
nonOpV.validateIndices(Set.of("<.ml-state-21309>"));
|
|
|
nonOpV.validateIndices(Set.of(".slo-observability.sli-v2"));
|
|
@@ -100,7 +106,8 @@ public class DotPrefixValidatorTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
private void assertFails(Set<String> indices) {
|
|
|
- nonOpV.validateIndices(indices);
|
|
|
+ var validator = new NonOperatorValidator<>(false);
|
|
|
+ validator.validateIndices(indices);
|
|
|
assertWarnings(
|
|
|
"Index ["
|
|
|
+ indices.stream().filter(i -> i.startsWith(".") || i.startsWith("<.")).toList().get(0)
|
|
@@ -108,10 +115,13 @@ public class DotPrefixValidatorTests extends ESTestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- private static class NonOperatorValidator<R> extends DotPrefixValidator<R> {
|
|
|
+ private class NonOperatorValidator<R> extends DotPrefixValidator<R> {
|
|
|
|
|
|
- private NonOperatorValidator() {
|
|
|
+ private final boolean assertNoWarnings;
|
|
|
+
|
|
|
+ private NonOperatorValidator(boolean assertNoWarnings) {
|
|
|
super(new ThreadContext(Settings.EMPTY), clusterService);
|
|
|
+ this.assertNoWarnings = assertNoWarnings;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -124,13 +134,25 @@ public class DotPrefixValidatorTests extends ESTestCase {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ void validateIndices(@Nullable Set<String> indices) {
|
|
|
+ super.validateIndices(indices);
|
|
|
+ if (assertNoWarnings) {
|
|
|
+ assertWarnings();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
boolean isInternalRequest() {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static class OperatorValidator<R> extends NonOperatorValidator<R> {
|
|
|
+ private class OperatorValidator<R> extends NonOperatorValidator<R> {
|
|
|
+ private OperatorValidator(boolean assertNoWarnings) {
|
|
|
+ super(assertNoWarnings);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
boolean isInternalRequest() {
|
|
|
return true;
|