Skip to content

Remove test usages of getDefaultBackingIndexName in CCR tests #127693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nielsbauman
Copy link
Contributor

We replace usages of time sensitive
DataStream#getDefaultBackingIndexName with the retrieval of the name via an API call. The problem with using the time sensitive method is that we can have test failures around midnight.

Relates #123376

We replace usages of time sensitive
`DataStream#getDefaultBackingIndexName` with the retrieval of the name
via an API call. The problem with using the time sensitive method is
that we can have test failures around midnight.

Relates elastic#123376
@elasticsearchmachine elasticsearchmachine added v9.1.0 needs:triage Requires assignment of a team area label labels May 5, 2025
Comment on lines -357 to -360
protected static boolean indexExists(String index) throws IOException {
Response response = adminClient().performRequest(new Request("HEAD", "/" + index));
return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method was already defined (with a better implementation) in ESRestTestCase.

Comment on lines -411 to -416
/**
* Fix point in time when data stream backing index is first time queried.
* This is required to avoid failures when running test at midnight.
* (index is created for day0, but assertions are executed for day1 assuming different time based index name that does not exist)
*/
private final LazyInitializable<Long, RuntimeException> time = new LazyInitializable<>(System::currentTimeMillis);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is nice, but it doesn't completely avoid any issues, as the cluster(s) don't use this time supplier.

Comment on lines -388 to +377
cleanUpFollower(
List.of(backingIndexName(dataStreamName, 1), backingIndexName(dataStreamName, 2), backingIndexName(dataStreamName, 3)),
List.of(dataStreamName),
List.of(autoFollowPatternName)
);
cleanUpLeader(
List.of(backingIndexName(dataStreamName, 1), backingIndexName(dataStreamName, 2), backingIndexName(dataStreamName, 3)),
List.of(dataStreamName),
List.of()
);
cleanUpFollower(List.of(), List.of(dataStreamName), List.of(autoFollowPatternName));
cleanUpLeader(List.of(), List.of(dataStreamName), List.of());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few more places like this. When a data stream is deleted, all its backing indices are deleted as well, of course. Theoretically it's possible that there are backing indices that have a name that matches a data stream name (e.g. manually created or taken out of an existing data stream) but are not in the data stream, but that doesn't seem to happen in these tests, so we don't need to explicitly delete the backing indices.

@nielsbauman nielsbauman added >test Issues or PRs that are addressing/adding tests :Distributed Indexing/CCR Issues around the Cross Cluster State Replication features :Data Management/Data streams Data streams and their lifecycles Team:Data Management Meta label for data/management team Team:Distributed Indexing Meta label for Distributed Indexing team and removed needs:triage Requires assignment of a team area label labels May 5, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-indexing (Team:Distributed Indexing)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@nielsbauman
Copy link
Contributor Author

I added the CCR label as well, as all of these changes are in CCR tests, so I'd like to ask if someone from the distributed team could have a quick scan as well.

@lukewhiting lukewhiting requested a review from Copilot May 6, 2025 09:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces the time‐sensitive usage of DataStream#getDefaultBackingIndexName in CCR tests with API calls that retrieve backing index information via integer generations. The changes include replacing string-based backing index name retrieval with integer parameters in verifyDataStream calls, updating index existence checks to use adminClient(), and slimming down cleanUp methods.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
x-pack/plugin/ccr/src/javaRestTest/java/org/elasticsearch/xpack/ccr/FollowIndexSecurityIT.java Updated index existence checks to use adminClient().
x-pack/plugin/ccr/src/javaRestTest/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java Replaced use of getDefaultBackingIndexName with integer-based verifyDataStream calls.
x-pack/plugin/ccr/src/javaRestTest/java/org/elasticsearch/xpack/ccr/DowngradeLicenseFollowIndexIT.java Updated index existence call with adminClient().
x-pack/plugin/ccr/src/javaRestTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java Revised verifyDataStream and cleanUp calls; introduced backingIndexNames variable usage.
x-pack/plugin/ccr/src/javaRestTest/java/org/elasticsearch/xpack/ccr/AbstractCCRRestTestCase.java Adjusted verifyDataStream implementation to use int... expectedBackingIndices.
test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java Modified indexExists and getDataStreamBackingIndexNames to work with RestClient parameter.
Comments suppressed due to low confidence (1)

x-pack/plugin/ccr/src/javaRestTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java:517

  • [nitpick] Consider using a consistent method to access the first element of backingIndexNames (for example, using get(0) if backingIndexNames is a standard List) to improve clarity and consistency with other element accesses.
followIndex(backingIndexNames.getFirst(), backingIndexNames.getFirst());

Copy link
Contributor

@lukewhiting lukewhiting left a comment

Choose a reason for hiding this comment

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

It's a tidy PR in general but it does fix the issue but I can't see a replacement of the functionality... Is it ok that we no longer verify the backing index names now in these tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Data streams Data streams and their lifecycles :Distributed Indexing/CCR Issues around the Cross Cluster State Replication features Team:Data Management Meta label for data/management team Team:Distributed Indexing Meta label for Distributed Indexing team >test Issues or PRs that are addressing/adding tests v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants