Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -202,9 +202,6 @@ private static void maybeThrowOnUnsupportedResource(String resource) {
if (resource.startsWith(EXCLUSION)) {
throw new IllegalArgumentException("Exclusions are not currently supported but was found in the expression [" + resource + "]");
}
if (resource.startsWith(DATE_MATH)) {
throw new IllegalArgumentException("Date math are not currently supported but was found in the expression [" + resource + "]");
}
Comment on lines -205 to -207
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to be the only necessary production code change.

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

if (IndexNameExpressionResolver.hasSelectorSuffix(resource)) {
throw new IllegalArgumentException("Selectors are not currently supported but was found in the expression [" + resource + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ public void testFlatOnlyRewrite() {
createRandomProjectWithAlias("P2"),
createRandomProjectWithAlias("P3")
);
String[] requestedResources = new String[] { "logs*", "metrics*" };
String[] requestedResources = new String[] { "logs*", "metrics*", "<traces-{now/d}>" };

var actual = CrossProjectIndexExpressionsRewriter.rewriteIndexExpressions(origin, linked, requestedResources);

assertThat(actual.keySet(), containsInAnyOrder("logs*", "metrics*"));
assertThat(actual.keySet(), containsInAnyOrder("logs*", "metrics*", "<traces-{now/d}>"));
assertIndexRewriteResultsContains(actual.get("logs*"), containsInAnyOrder("logs*", "P1:logs*", "P2:logs*", "P3:logs*"));
assertIndexRewriteResultsContains(
actual.get("metrics*"),
containsInAnyOrder("metrics*", "P1:metrics*", "P2:metrics*", "P3:metrics*")
);
assertIndexRewriteResultsContains(
actual.get("<traces-{now/d}>"),
containsInAnyOrder("<traces-{now/d}>", "P1:<traces-{now/d}>", "P2:<traces-{now/d}>", "P3:<traces-{now/d}>")
);
}

public void testFlatAndQualifiedRewrite() {
Expand All @@ -48,16 +52,17 @@ public void testFlatAndQualifiedRewrite() {
createRandomProjectWithAlias("P2"),
createRandomProjectWithAlias("P3")
);
String[] requestedResources = new String[] { "P1:logs*", "metrics*" };
String[] requestedResources = new String[] { "P1:logs*", "metrics*", "P2:<traces-{now/d}>" };

var actual = CrossProjectIndexExpressionsRewriter.rewriteIndexExpressions(origin, linked, requestedResources);

assertThat(actual.keySet(), containsInAnyOrder("P1:logs*", "metrics*"));
assertThat(actual.keySet(), containsInAnyOrder("P1:logs*", "metrics*", "P2:<traces-{now/d}>"));
assertIndexRewriteResultsContains(actual.get("P1:logs*"), containsInAnyOrder("P1:logs*"));
assertIndexRewriteResultsContains(
actual.get("metrics*"),
containsInAnyOrder("metrics*", "P1:metrics*", "P2:metrics*", "P3:metrics*")
);
assertIndexRewriteResultsContains(actual.get("P2:<traces-{now/d}>"), containsInAnyOrder("P2:<traces-{now/d}>"));
}

public void testQualifiedOnlyRewrite() {
Expand All @@ -67,13 +72,14 @@ public void testQualifiedOnlyRewrite() {
createRandomProjectWithAlias("P2"),
createRandomProjectWithAlias("P3")
);
String[] requestedResources = new String[] { "P1:logs*", "P2:metrics*" };
String[] requestedResources = new String[] { "P1:logs*", "P2:metrics*", "P3:<traces-{now/d}>" };

var actual = CrossProjectIndexExpressionsRewriter.rewriteIndexExpressions(origin, linked, requestedResources);

assertThat(actual.keySet(), containsInAnyOrder("P1:logs*", "P2:metrics*"));
assertThat(actual.keySet(), containsInAnyOrder("P1:logs*", "P2:metrics*", "P3:<traces-{now/d}>"));
assertIndexRewriteResultsContains(actual.get("P1:logs*"), containsInAnyOrder("P1:logs*"));
assertIndexRewriteResultsContains(actual.get("P2:metrics*"), containsInAnyOrder("P2:metrics*"));
assertIndexRewriteResultsContains(actual.get("P3:<traces-{now/d}>"), containsInAnyOrder("P3:<traces-{now/d}>"));
}

public void testOriginQualifiedOnlyRewrite() {
Expand All @@ -83,13 +89,14 @@ public void testOriginQualifiedOnlyRewrite() {
createRandomProjectWithAlias("P2"),
createRandomProjectWithAlias("P3")
);
String[] requestedResources = new String[] { "_origin:logs*", "_origin:metrics*" };
String[] requestedResources = new String[] { "_origin:logs*", "_origin:metrics*", "_origin:<traces-{now/d}>" };

var actual = CrossProjectIndexExpressionsRewriter.rewriteIndexExpressions(origin, linked, requestedResources);

assertThat(actual.keySet(), containsInAnyOrder("_origin:logs*", "_origin:metrics*"));
assertThat(actual.keySet(), containsInAnyOrder("_origin:logs*", "_origin:metrics*", "_origin:<traces-{now/d}>"));
assertIndexRewriteResultsContains(actual.get("_origin:logs*"), containsInAnyOrder("logs*"));
assertIndexRewriteResultsContains(actual.get("_origin:metrics*"), containsInAnyOrder("metrics*"));
assertIndexRewriteResultsContains(actual.get("_origin:<traces-{now/d}>"), containsInAnyOrder("<traces-{now/d}>"));
}

public void testOriginQualifiedOnlyRewriteWithNoLikedProjects() {
Expand Down Expand Up @@ -149,12 +156,16 @@ public void testQualifiedStartsWithProjectWildcardRewrite() {
createRandomProjectWithAlias("Q1"),
createRandomProjectWithAlias("Q2")
);
String[] requestedResources = new String[] { "Q*:metrics*" };
String[] requestedResources = new String[] { "Q*:metrics*", "P*:<traces-{now/d}>" };

var actual = CrossProjectIndexExpressionsRewriter.rewriteIndexExpressions(origin, linked, requestedResources);

assertThat(actual.keySet(), containsInAnyOrder("Q*:metrics*"));
assertThat(actual.keySet(), containsInAnyOrder("Q*:metrics*", "P*:<traces-{now/d}>"));
assertIndexRewriteResultsContains(actual.get("Q*:metrics*"), containsInAnyOrder("Q1:metrics*", "Q2:metrics*"));
assertIndexRewriteResultsContains(
actual.get("P*:<traces-{now/d}>"),
containsInAnyOrder("<traces-{now/d}>", "P1:<traces-{now/d}>", "P2:<traces-{now/d}>")
);
}

public void testQualifiedEndsWithProjectWildcardRewrite() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,10 @@ protected static void wipeAllIndices() throws IOException {
}

protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOException {
wipeAllIndices(preserveSecurityIndices, cleanupClient());
}

protected static void wipeAllIndices(boolean preserveSecurityIndices, RestClient cleanupClient) throws IOException {
try {
// remove all indices except some history indices which can pop up after deleting all data streams but shouldn't interfere
final List<String> indexPatterns = new ArrayList<>(
Expand All @@ -1248,7 +1252,7 @@ protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOE
RequestOptions.DEFAULT.toBuilder().setWarningsHandler(ESRestTestCase::ignoreSystemIndexAccessWarnings)
);

final Response response = cleanupClient().performRequest(deleteRequest);
final Response response = cleanupClient.performRequest(deleteRequest);
try (InputStream is = response.getEntity().getContent()) {
assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));
}
Expand Down