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" ));
@@ -96,18 +102,22 @@ public void testValidation() {
96
102
}
97
103
98
104
private void assertFails (Set <String > indices ) {
99
- nonOpV .validateIndices (indices );
105
+ var validator = new NonOperatorValidator <>(false );
106
+ validator .validateIndices (indices );
100
107
assertWarnings (
101
108
"Index ["
102
109
+ indices .stream ().filter (i -> i .startsWith ("." ) || i .startsWith ("<." )).toList ().get (0 )
103
110
+ "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
104
111
);
105
112
}
106
113
107
- private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
114
+ private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
108
115
109
- private NonOperatorValidator () {
116
+ private final boolean assertNoWarnings ;
117
+
118
+ private NonOperatorValidator (boolean assertNoWarnings ) {
110
119
super (new ThreadContext (Settings .EMPTY ), clusterService );
120
+ this .assertNoWarnings = assertNoWarnings ;
111
121
}
112
122
113
123
@ Override
@@ -120,13 +130,25 @@ public String actionName() {
120
130
return "" ;
121
131
}
122
132
133
+ @ Override
134
+ void validateIndices (@ Nullable Set <String > indices ) {
135
+ super .validateIndices (indices );
136
+ if (assertNoWarnings ) {
137
+ assertWarnings ();
138
+ }
139
+ }
140
+
123
141
@ Override
124
142
boolean isInternalRequest () {
125
143
return false ;
126
144
}
127
145
}
128
146
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
+
130
152
@ Override
131
153
boolean isInternalRequest () {
132
154
return true ;
0 commit comments