15
15
import org .elasticsearch .common .settings .Settings ;
16
16
import org .elasticsearch .common .util .concurrent .ThreadContext ;
17
17
import org .elasticsearch .common .util .set .Sets ;
18
+ import org .elasticsearch .core .Nullable ;
18
19
import org .elasticsearch .test .ESTestCase ;
19
20
import org .elasticsearch .threadpool .ThreadPool ;
20
21
import org .junit .BeforeClass ;
27
28
import static org .mockito .Mockito .when ;
28
29
29
30
public 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 );
32
33
33
34
private static ClusterService clusterService ;
34
35
@@ -58,14 +59,19 @@ public void testValidation() {
58
59
opV .validateIndices (Set .of (".regular" ));
59
60
assertFails (Set .of ("first" , ".second" ));
60
61
assertFails (Set .of ("<.regular-{MM-yy-dd}>" ));
62
+ assertFails (Set .of (".this_index_contains_an_excepted_pattern.ml-annotations-1" ));
61
63
62
64
// Test ignored names
63
65
nonOpV .validateIndices (Set .of (".elastic-connectors-v1" ));
64
66
nonOpV .validateIndices (Set .of (".elastic-connectors-sync-jobs-v1" ));
65
67
nonOpV .validateIndices (Set .of (".ml-state" ));
68
+ nonOpV .validateIndices (Set .of (".ml-state-000001" ));
69
+ nonOpV .validateIndices (Set .of (".ml-stats-000001" ));
66
70
nonOpV .validateIndices (Set .of (".ml-anomalies-unrelated" ));
67
71
68
72
// Test ignored patterns
73
+ nonOpV .validateIndices (Set .of (".ml-annotations-21309" ));
74
+ nonOpV .validateIndices (Set .of (".ml-annotations-2" ));
69
75
nonOpV .validateIndices (Set .of (".ml-state-21309" ));
70
76
nonOpV .validateIndices (Set .of (">.ml-state-21309>" ));
71
77
nonOpV .validateIndices (Set .of (".slo-observability.sli-v2" ));
@@ -86,18 +92,22 @@ public void testValidation() {
86
92
}
87
93
88
94
private void assertFails (Set <String > indices ) {
89
- nonOpV .validateIndices (indices );
95
+ var validator = new NonOperatorValidator <>(false );
96
+ validator .validateIndices (indices );
90
97
assertWarnings (
91
98
"Index ["
92
99
+ indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().get (0 )
93
100
+ "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
94
101
);
95
102
}
96
103
97
- private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
104
+ private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
98
105
99
- private NonOperatorValidator () {
106
+ private final boolean assertNoWarnings ;
107
+
108
+ private NonOperatorValidator (boolean assertNoWarnings ) {
100
109
super (new ThreadContext (Settings .EMPTY ), clusterService );
110
+ this .assertNoWarnings = assertNoWarnings ;
101
111
}
102
112
103
113
@ Override
@@ -110,13 +120,25 @@ public String actionName() {
110
120
return "" ;
111
121
}
112
122
123
+ @ Override
124
+ void validateIndices (@ Nullable Set <String > indices ) {
125
+ super .validateIndices (indices );
126
+ if (assertNoWarnings ) {
127
+ assertWarnings ();
128
+ }
129
+ }
130
+
113
131
@ Override
114
132
boolean isInternalRequest () {
115
133
return false ;
116
134
}
117
135
}
118
136
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
+
120
142
@ Override
121
143
boolean isInternalRequest () {
122
144
return true ;
0 commit comments