Skip to content

Conversation

@nielsbauman
Copy link
Contributor

These usages had the potential of causing test failures when a data stream was created before midnight and the backing index name generation ran the next day - which would be millisecconds apart. To avoid these failures, we update the tests to be robust to these time differences.

Resolves #123376

These usages had the potential of causing test failures when a data
stream was created before midnight and the backing index name generation
ran the next day - which would be millisecconds apart. To avoid these
failures, we update the tests to be robust to these time differences.

Resolves elastic#123376
@nielsbauman nielsbauman added >non-issue :Data Management/Data streams Data streams and their lifecycles labels Jun 16, 2025
@elasticsearchmachine elasticsearchmachine added v9.1.0 Team:Data Management Meta label for data/management team labels Jun 16, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@lukewhiting lukewhiting requested a review from Copilot June 16, 2025 10:02
Copy link
Contributor

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 updates test code to remove direct usages of DataStream#getDefaultBackingIndexName in favor of more robust index name resolution methods, reducing the risk of test failures caused by time differences. Key changes include replacing direct calls with projectMetadata.dataStreams() lookups, using DataStreamTestHelper for assertions, and passing explicit time parameters where needed.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java Replaced default backing index name call with data stream lookup
x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowActionTests.java Switched to DataStreamTestHelper assertions for backing index names
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataTests.java Updated error messages to use index name from Index object
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataDeleteIndexServiceTests.java Updated index deletion logic with decreased index lookup via data stream
server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamServiceTests.java Replaced usages of getDefaultBackingIndexName with write index lookup
server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java Updated index lookups to use getIndices() calls
server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTests.java Updated test assertions with backing index objects
server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceTests.java Injected explicit time parameter to backing index name resolution
server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceAutoShardingTests.java Updated source & rollover index name assertions
modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/downsampling/DeleteSourceAndAddDownsampleToDSTests.java Swapped legacy index name calls with data stream index lookups
modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleServiceTests.java Replaced legacy index name resolution with DataStreamTestHelper comparisons
modules/data-streams/src/test/java/org/elasticsearch/datastreams/MetadataDataStreamRolloverServiceTests.java Updated rollover tests with explicit time providers and time parameters

@nielsbauman nielsbauman requested a review from lukewhiting June 17, 2025 10:44
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.

One question more than comment but otherwise looks good 👍🏻

dataStreamName,
List.of(new Index(DataStream.getDefaultBackingIndexName(dataStreamName, 1, now.toEpochMilli()), "uuid"))
).setIndexMode(IndexMode.TIME_SERIES).build();
).setIndexMode(IndexMode.TIME_SERIES).setTimeProvider(now::toEpochMilli).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Bit of a nitpick not specifically about this PR but I'm interested in why we went for this TimeProvider pattern Vs using the Clock interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid I have no idea... This time provider predates my time at Elastic

@nielsbauman nielsbauman merged commit 9f78d11 into elastic:main Jun 17, 2025
27 checks passed
@nielsbauman nielsbauman deleted the ds-default-index branch June 17, 2025 14:02
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 >non-issue Team:Data Management Meta label for data/management team v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove test usages of DataStream#getDefaultBackingIndexName

3 participants