1010package org .elasticsearch .validation ;
1111
1212import org .elasticsearch .cluster .service .ClusterService ;
13+ import org .elasticsearch .common .Strings ;
1314import org .elasticsearch .common .settings .ClusterSettings ;
14- import org .elasticsearch .common .settings .Setting ;
1515import org .elasticsearch .common .settings .Settings ;
1616import org .elasticsearch .common .util .concurrent .ThreadContext ;
1717import org .elasticsearch .common .util .set .Sets ;
1818import org .elasticsearch .test .ESTestCase ;
1919import org .elasticsearch .threadpool .ThreadPool ;
2020import org .junit .BeforeClass ;
2121
22- import java .util .HashSet ;
22+ import java .util .ArrayList ;
23+ import java .util .List ;
2324import java .util .Set ;
2425
2526import static org .mockito .Mockito .mock ;
2829public class DotPrefixValidatorTests extends ESTestCase {
2930 private final OperatorValidator <?> opV = new OperatorValidator <>();
3031 private final NonOperatorValidator <?> nonOpV = new NonOperatorValidator <>();
31- private static final Set <Setting <?>> settings ;
3232
3333 private static ClusterService clusterService ;
34- private static ClusterSettings clusterSettings ;
35-
36- static {
37- Set <Setting <?>> cSettings = new HashSet <>(ClusterSettings .BUILT_IN_CLUSTER_SETTINGS );
38- cSettings .add (DotPrefixValidator .VALIDATE_DOT_PREFIXES );
39- settings = cSettings ;
40- }
4134
4235 @ BeforeClass
4336 public static void beforeClass () {
37+ List <String > allowed = new ArrayList <>(DotPrefixValidator .IGNORED_INDEX_PATTERNS_SETTING .getDefault (Settings .EMPTY ));
38+ // Add a new allowed pattern for testing
39+ allowed .add ("\\ .potato\\ d+" );
40+ Settings settings = Settings .builder ()
41+ .put (DotPrefixValidator .IGNORED_INDEX_PATTERNS_SETTING .getKey (), Strings .collectionToCommaDelimitedString (allowed ))
42+ .build ();
4443 clusterService = mock (ClusterService .class );
45- clusterSettings = new ClusterSettings (Settings .EMPTY , Sets .newHashSet (DotPrefixValidator .VALIDATE_DOT_PREFIXES ));
44+ ClusterSettings clusterSettings = new ClusterSettings (
45+ settings ,
46+ Sets .newHashSet (DotPrefixValidator .VALIDATE_DOT_PREFIXES , DotPrefixValidator .IGNORED_INDEX_PATTERNS_SETTING )
47+ );
4648 when (clusterService .getClusterSettings ()).thenReturn (clusterSettings );
47- when (clusterService .getSettings ()).thenReturn (Settings . EMPTY );
49+ when (clusterService .getSettings ()).thenReturn (settings );
4850 when (clusterService .threadPool ()).thenReturn (mock (ThreadPool .class ));
4951 }
5052
@@ -74,18 +76,25 @@ public void testValidation() {
7476 nonOpV .validateIndices (Set .of (".slo-observability.summary-v2.3" ));
7577 nonOpV .validateIndices (Set .of (".slo-observability.summary-v2.3-2024-01-01" ));
7678 nonOpV .validateIndices (Set .of ("<.slo-observability.summary-v3.3.{2024-10-16||/M{yyyy-MM-dd|UTC}}>" ));
79+ nonOpV .validateIndices (Set .of (".entities.v1.latest.builtin_services_from_ecs_data" ));
80+ nonOpV .validateIndices (Set .of (".entities.v92.latest.eggplant.potato" ));
81+ nonOpV .validateIndices (Set .of ("<.entities.v12.latest.eggplant-{M{yyyy-MM-dd|UTC}}>" ));
82+
83+ // Test pattern added to the settings
84+ nonOpV .validateIndices (Set .of (".potato5" ));
85+ nonOpV .validateIndices (Set .of ("<.potato5>" ));
7786 }
7887
7988 private void assertFails (Set <String > indices ) {
8089 nonOpV .validateIndices (indices );
8190 assertWarnings (
8291 "Index ["
83- + indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().getFirst ( )
92+ + indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().get ( 0 )
8493 + "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
8594 );
8695 }
8796
88- private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
97+ private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
8998
9099 private NonOperatorValidator () {
91100 super (new ThreadContext (Settings .EMPTY ), clusterService );
@@ -107,7 +116,7 @@ boolean isInternalRequest() {
107116 }
108117 }
109118
110- private class OperatorValidator <R > extends NonOperatorValidator <R > {
119+ private static class OperatorValidator <R > extends NonOperatorValidator <R > {
111120 @ Override
112121 boolean isInternalRequest () {
113122 return true ;
0 commit comments