1515import org .elasticsearch .common .settings .Settings ;
1616import org .elasticsearch .common .util .concurrent .ThreadContext ;
1717import org .elasticsearch .common .util .set .Sets ;
18+ import org .elasticsearch .core .Nullable ;
1819import org .elasticsearch .test .ESTestCase ;
1920import org .elasticsearch .threadpool .ThreadPool ;
2021import org .junit .BeforeClass ;
2728import static org .mockito .Mockito .when ;
2829
2930public class DotPrefixValidatorTests extends ESTestCase {
30- private final OperatorValidator <?> opV = new OperatorValidator <>();
31- private final NonOperatorValidator <?> nonOpV = new NonOperatorValidator <>();
31+ private final OperatorValidator <?> opV = new OperatorValidator <>(true );
32+ private final NonOperatorValidator <?> nonOpV = new NonOperatorValidator <>(true );
3233
3334 private static ClusterService clusterService ;
3435
@@ -58,14 +59,19 @@ public void testValidation() {
5859 opV .validateIndices (Set .of (".regular" ));
5960 assertFails (Set .of ("first" , ".second" ));
6061 assertFails (Set .of ("<.regular-{MM-yy-dd}>" ));
62+ assertFails (Set .of (".this_index_contains_an_excepted_pattern.ml-annotations-1" ));
6163
6264 // Test ignored names
6365 nonOpV .validateIndices (Set .of (".elastic-connectors-v1" ));
6466 nonOpV .validateIndices (Set .of (".elastic-connectors-sync-jobs-v1" ));
6567 nonOpV .validateIndices (Set .of (".ml-state" ));
68+ nonOpV .validateIndices (Set .of (".ml-state-000001" ));
69+ nonOpV .validateIndices (Set .of (".ml-stats-000001" ));
6670 nonOpV .validateIndices (Set .of (".ml-anomalies-unrelated" ));
6771
6872 // Test ignored patterns
73+ nonOpV .validateIndices (Set .of (".ml-annotations-21309" ));
74+ nonOpV .validateIndices (Set .of (".ml-annotations-2" ));
6975 nonOpV .validateIndices (Set .of (".ml-state-21309" ));
7076 nonOpV .validateIndices (Set .of (">.ml-state-21309>" ));
7177 nonOpV .validateIndices (Set .of (".slo-observability.sli-v2" ));
@@ -86,18 +92,22 @@ public void testValidation() {
8692 }
8793
8894 private void assertFails (Set <String > indices ) {
89- nonOpV .validateIndices (indices );
95+ var validator = new NonOperatorValidator <>(false );
96+ validator .validateIndices (indices );
9097 assertWarnings (
9198 "Index ["
9299 + indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().get (0 )
93100 + "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
94101 );
95102 }
96103
97- private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
104+ private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
98105
99- private NonOperatorValidator () {
106+ private final boolean assertNoWarnings ;
107+
108+ private NonOperatorValidator (boolean assertNoWarnings ) {
100109 super (new ThreadContext (Settings .EMPTY ), clusterService );
110+ this .assertNoWarnings = assertNoWarnings ;
101111 }
102112
103113 @ Override
@@ -110,13 +120,25 @@ public String actionName() {
110120 return "" ;
111121 }
112122
123+ @ Override
124+ void validateIndices (@ Nullable Set <String > indices ) {
125+ super .validateIndices (indices );
126+ if (assertNoWarnings ) {
127+ assertWarnings ();
128+ }
129+ }
130+
113131 @ Override
114132 boolean isInternalRequest () {
115133 return false ;
116134 }
117135 }
118136
119- private static class OperatorValidator <R > extends NonOperatorValidator <R > {
137+ private class OperatorValidator <R > extends NonOperatorValidator <R > {
138+ private OperatorValidator (boolean assertNoWarnings ) {
139+ super (assertNoWarnings );
140+ }
141+
120142 @ Override
121143 boolean isInternalRequest () {
122144 return true ;
0 commit comments