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" ));
@@ -100,18 +106,22 @@ public void testValidation() {
100106 }
101107
102108 private void assertFails (Set <String > indices ) {
103- nonOpV .validateIndices (indices );
109+ var validator = new NonOperatorValidator <>(false );
110+ validator .validateIndices (indices );
104111 assertWarnings (
105112 "Index ["
106113 + indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().get (0 )
107114 + "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
108115 );
109116 }
110117
111- private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
118+ private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
112119
113- private NonOperatorValidator () {
120+ private final boolean assertNoWarnings ;
121+
122+ private NonOperatorValidator (boolean assertNoWarnings ) {
114123 super (new ThreadContext (Settings .EMPTY ), clusterService );
124+ this .assertNoWarnings = assertNoWarnings ;
115125 }
116126
117127 @ Override
@@ -124,13 +134,25 @@ public String actionName() {
124134 return "" ;
125135 }
126136
137+ @ Override
138+ void validateIndices (@ Nullable Set <String > indices ) {
139+ super .validateIndices (indices );
140+ if (assertNoWarnings ) {
141+ assertWarnings ();
142+ }
143+ }
144+
127145 @ Override
128146 boolean isInternalRequest () {
129147 return false ;
130148 }
131149 }
132150
133- private static class OperatorValidator <R > extends NonOperatorValidator <R > {
151+ private class OperatorValidator <R > extends NonOperatorValidator <R > {
152+ private OperatorValidator (boolean assertNoWarnings ) {
153+ super (assertNoWarnings );
154+ }
155+
134156 @ Override
135157 boolean isInternalRequest () {
136158 return true ;
0 commit comments