Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ public abstract class DotPrefixValidator<RequestType> implements MappedActionFil
* .ml-* is used by ML
* .slo-observability-* is used by Observability
*/
private static Set<String> IGNORED_INDEX_NAMES = Set.of(
".elastic-connectors-v1",
".elastic-connectors-sync-jobs-v1",
".ml-state",
".ml-anomalies-unrelated"
);
private static Set<String> IGNORED_INDEX_NAMES = Set.of(".elastic-connectors-v1", ".elastic-connectors-sync-jobs-v1", ".ml-state");
public static final Setting<List<String>> IGNORED_INDEX_PATTERNS_SETTING = Setting.stringListSetting(
"cluster.indices.validate_ignored_dot_patterns",
List.of(
"\\.ml-anomalies-.*",
"\\.ml-annotations-\\d+",
"\\.ml-state-\\d+",
"\\.ml-stats-\\d+",
"\\.slo-observability\\.sli-v\\d+.*",
"\\.slo-observability\\.summary-v\\d+.*",
"\\.entities\\.v\\d+\\..*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.BeforeClass;
Expand All @@ -27,8 +28,8 @@
import static org.mockito.Mockito.when;

public class DotPrefixValidatorTests extends ESTestCase {
private final OperatorValidator<?> opV = new OperatorValidator<>();
private final NonOperatorValidator<?> nonOpV = new NonOperatorValidator<>();
private final OperatorValidator<?> opV = new OperatorValidator<>(true);
private final NonOperatorValidator<?> nonOpV = new NonOperatorValidator<>(true);

private static ClusterService clusterService;

Expand Down Expand Up @@ -58,14 +59,19 @@ public void testValidation() {
opV.validateIndices(Set.of(".regular"));
assertFails(Set.of("first", ".second"));
assertFails(Set.of("<.regular-{MM-yy-dd}>"));
assertFails(Set.of(".this_index_contains_an_excepted_pattern.ml-annotations-1"));

// Test ignored names
nonOpV.validateIndices(Set.of(".elastic-connectors-v1"));
nonOpV.validateIndices(Set.of(".elastic-connectors-sync-jobs-v1"));
nonOpV.validateIndices(Set.of(".ml-state"));
nonOpV.validateIndices(Set.of(".ml-state-000001"));
nonOpV.validateIndices(Set.of(".ml-stats-000001"));
nonOpV.validateIndices(Set.of(".ml-anomalies-unrelated"));

// Test ignored patterns
nonOpV.validateIndices(Set.of(".ml-annotations-21309"));
nonOpV.validateIndices(Set.of(".ml-annotations-2"));
nonOpV.validateIndices(Set.of(".ml-state-21309"));
nonOpV.validateIndices(Set.of("<.ml-state-21309>"));
nonOpV.validateIndices(Set.of(".slo-observability.sli-v2"));
Expand Down Expand Up @@ -100,18 +106,22 @@ public void testValidation() {
}

private void assertFails(Set<String> indices) {
nonOpV.validateIndices(indices);
var validator = new NonOperatorValidator<>(false);
validator.validateIndices(indices);
assertWarnings(
"Index ["
+ indices.stream().filter(i -> i.startsWith(".") || i.startsWith("<.")).toList().get(0)
+ "] name begins with a dot (.), which is deprecated, and will not be allowed in a future Elasticsearch version."
);
}

private static class NonOperatorValidator<R> extends DotPrefixValidator<R> {
private class NonOperatorValidator<R> extends DotPrefixValidator<R> {

private NonOperatorValidator() {
private final boolean assertNoWarnings;

private NonOperatorValidator(boolean assertNoWarnings) {
super(new ThreadContext(Settings.EMPTY), clusterService);
this.assertNoWarnings = assertNoWarnings;
}

@Override
Expand All @@ -124,13 +134,25 @@ public String actionName() {
return "";
}

@Override
void validateIndices(@Nullable Set<String> indices) {
super.validateIndices(indices);
if (assertNoWarnings) {
assertWarnings();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserts that no warnings were created in the thread context

}
}

@Override
boolean isInternalRequest() {
return false;
}
}

private static class OperatorValidator<R> extends NonOperatorValidator<R> {
private class OperatorValidator<R> extends NonOperatorValidator<R> {
private OperatorValidator(boolean assertNoWarnings) {
super(assertNoWarnings);
}

@Override
boolean isInternalRequest() {
return true;
Expand Down
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ tests:
- class: org.elasticsearch.xpack.ml.integration.RevertModelSnapshotIT
method: testRevertModelSnapshot_DeleteInterveningResults
issue: https://github.com/elastic/elasticsearch/issues/132349
#- class: org.elasticsearch.xpack.ml.integration.TextEmbeddingQueryIT
# method: testHybridSearch
# issue: https://github.com/elastic/elasticsearch/issues/132703
- class: org.elasticsearch.xpack.ml.integration.RevertModelSnapshotIT
method: testRevertModelSnapshot
issue: https://github.com/elastic/elasticsearch/issues/132733
Expand Down Expand Up @@ -435,9 +432,6 @@ tests:
- class: org.elasticsearch.xpack.search.AsyncSearchErrorTraceIT
method: testAsyncSearchFailingQueryErrorTraceDefault
issue: https://github.com/elastic/elasticsearch/issues/133010
- class: org.elasticsearch.xpack.ml.integration.TextEmbeddingQueryIT
method: testModelWithPrefixStrings
issue: https://github.com/elastic/elasticsearch/issues/133138
- class: org.elasticsearch.xpack.security.authc.AuthenticationServiceTests
method: testInvalidToken
issue: https://github.com/elastic/elasticsearch/issues/133328
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/9.2.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
inference_api_openai_embeddings_headers,9169000
inference_api_openai_embeddings_headers,9169000
Loading