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" ));
@@ -96,18 +102,22 @@ public void testValidation() {
96102 }
97103
98104 private void assertFails (Set <String > indices ) {
99- nonOpV .validateIndices (indices );
105+ var validator = new NonOperatorValidator <>(false );
106+ validator .validateIndices (indices );
100107 assertWarnings (
101108 "Index ["
102109 + indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().get (0 )
103110 + "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
104111 );
105112 }
106113
107- private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
114+ private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
108115
109- private NonOperatorValidator () {
116+ private final boolean assertNoWarnings ;
117+
118+ private NonOperatorValidator (boolean assertNoWarnings ) {
110119 super (new ThreadContext (Settings .EMPTY ), clusterService );
120+ this .assertNoWarnings = assertNoWarnings ;
111121 }
112122
113123 @ Override
@@ -120,13 +130,25 @@ public String actionName() {
120130 return "" ;
121131 }
122132
133+ @ Override
134+ void validateIndices (@ Nullable Set <String > indices ) {
135+ super .validateIndices (indices );
136+ if (assertNoWarnings ) {
137+ assertWarnings ();
138+ }
139+ }
140+
123141 @ Override
124142 boolean isInternalRequest () {
125143 return false ;
126144 }
127145 }
128146
129- private static class OperatorValidator <R > extends NonOperatorValidator <R > {
147+ private class OperatorValidator <R > extends NonOperatorValidator <R > {
148+ private OperatorValidator (boolean assertNoWarnings ) {
149+ super (assertNoWarnings );
150+ }
151+
130152 @ Override
131153 boolean isInternalRequest () {
132154 return true ;
0 commit comments