Skip to content

Commit

Permalink
Remove unnecessary deprecation warning in Get Alias API (#82773) (#83090
Browse files Browse the repository at this point in the history
)

The check removed by this commit checks specifically for requests for
aliases that *would* be system aliases, if they existed. I'm not sure
why we were doing this, as we don't try to do this anywhere else. The
only test that this seems to make fail is the test explicitly checking
that behavior, which I don't think is really what we want. So I'm just
removing it.

Relates #81589
  • Loading branch information
gwbrown authored Jan 25, 2022
1 parent 8615ba8 commit 6d541d9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,49 +194,5 @@ private static void checkSystemIndexAccess(
if (netNewSystemIndices.isEmpty() == false) {
throw systemIndices.netNewSystemIndexAccessException(threadContext, netNewSystemIndices);
}
checkSystemAliasAccess(request, systemIndices, systemIndexAccessLevel, threadContext);
}

private static void checkSystemAliasAccess(
GetAliasesRequest request,
SystemIndices systemIndices,
SystemIndexAccessLevel systemIndexAccessLevel,
ThreadContext threadContext
) {
final Predicate<String> systemIndexAccessAllowPredicate;
if (systemIndexAccessLevel == SystemIndexAccessLevel.NONE) {
systemIndexAccessAllowPredicate = name -> true;
} else if (systemIndexAccessLevel == SystemIndexAccessLevel.RESTRICTED) {
systemIndexAccessAllowPredicate = systemIndices.getProductSystemIndexNamePredicate(threadContext).negate();
} else {
throw new IllegalArgumentException("Unexpected system index access level: " + systemIndexAccessLevel);
}

final List<String> systemAliases = new ArrayList<>();
final List<String> netNewSystemAliases = new ArrayList<>();
for (String alias : request.aliases()) {
if (systemIndices.isSystemName(alias)) {
if (systemIndexAccessAllowPredicate.test(alias)) {
if (systemIndices.isNetNewSystemIndex(alias)) {
netNewSystemAliases.add(alias);
} else {
systemAliases.add(alias);
}
}
}
}

if (systemAliases.isEmpty() == false) {
deprecationLogger.warn(
DeprecationCategory.API,
"open_system_alias_access",
"this request accesses aliases with names reserved for system indices: {}, but in a future major version, direct "
+ "access to system indices and their aliases will not be allowed",
systemAliases
);
}
if (netNewSystemAliases.isEmpty() == false) {
throw systemIndices.netNewSystemIndexAccessException(threadContext, netNewSystemAliases);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,40 +241,6 @@ public void testDeprecationWarningNotEmittedWhenOnlyNonsystemIndexRequested() {
assertThat(result.get("c").size(), equalTo(1));
}

public void testDeprecationWarningEmittedWhenRequestingNonExistingAliasInSystemPattern() {
ClusterState state = systemIndexTestClusterState();
SystemIndices systemIndices = new SystemIndices(
Collections.singletonMap(
this.getTestName(),
new SystemIndices.Feature(
this.getTestName(),
"test feature",
Collections.singletonList(new SystemIndexDescriptor(".y*", "an index that doesn't exist"))
)
)
);

GetAliasesRequest request = new GetAliasesRequest(".y");
ImmutableOpenMap<String, List<AliasMetadata>> aliases = ImmutableOpenMap.<String, List<AliasMetadata>>builder().build();
final String[] concreteIndices = {};
assertEquals(state.metadata().findAliases(request, concreteIndices), aliases);
ImmutableOpenMap<String, List<AliasMetadata>> result = TransportGetAliasesAction.postProcess(
request,
concreteIndices,
aliases,
state,
SystemIndexAccessLevel.NONE,
null,
systemIndices
);
assertThat(result.size(), equalTo(0));
assertWarnings(
Level.WARN,
"this request accesses aliases with names reserved for system indices: [.y], but in a future major version, direct"
+ " access to system indices and their aliases will not be allowed"
);
}

public void testPostProcessDataStreamAliases() {
IndexNameExpressionResolver resolver = TestIndexNameExpressionResolver.newInstance();
List<Tuple<String, Integer>> tuples = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ private void assertGetAliasAPIBehavesAsExpected(String regularIndex, String regu
.setWarningsHandler(
warnings -> org.elasticsearch.core.List.of(
"this request accesses system indices: [.fleet-artifacts-7], but "
+ "in a future major version, direct access to system indices will be prevented by default",
"this request accesses aliases with names reserved for system indices: [.fleet-artifacts], but in a future major "
+ "version, direct access to system indices and their aliases will not be allowed"
+ "in a future major version, direct access to system indices will be prevented by default"
).equals(warnings) == false
)
.build();
Expand Down

0 comments on commit 6d541d9

Please sign in to comment.