Skip to content

Commit e4e7da5

Browse files
nielsbaumanDonalEvans
authored andcommitted
Manually roll over in SearchableSnapshotActionIT (elastic#135098)
If we let ILM take care of the rollover, the test sometimes takes a few seconds longer due to ILM's partially periodic design. By doing the rollover manually, we have more control over the test without sacrificing much relevant coverage. Additionally, we configure the log level of the `ILMHistoryStore` to `INFO`, as its logs can be incredibly verbose and are not relevant with the rest of the package already emitting `TRACE` logs. Fixes elastic#135060
1 parent 91f2f30 commit e4e7da5

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

x-pack/plugin/ilm/qa/multi-node/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ testClusters.configureEach {
3535
setting 'indices.lifecycle.poll_interval', '1000ms'
3636
setting 'logger.org.elasticsearch.xpack.core.ilm', 'TRACE'
3737
setting 'logger.org.elasticsearch.xpack.ilm', 'TRACE'
38+
// The TRACE logs of the history store are too verbose and not useful, so we set it to INFO
39+
setting 'logger.org.elasticsearch.xpack.ilm.history.ILMHistoryStore', 'INFO'
3840
/*
3941
* In TimeSeriesLifecycleActionsIT.testWaitForSnapshotSlmExecutedBefore() we create a snapshot, then associate an ILM policy with an index, and
4042
* then that policy checks if a snapshot has been started at the same millisecond or later than the policy's action's date. Since both the

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.apache.http.entity.ContentType;
1111
import org.apache.http.entity.StringEntity;
12+
import org.elasticsearch.action.admin.indices.rollover.RolloverConditions;
1213
import org.elasticsearch.client.Request;
1314
import org.elasticsearch.client.Response;
1415
import org.elasticsearch.client.ResponseException;
@@ -295,7 +296,10 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
295296
TimeValue.ZERO,
296297
Map.of(
297298
RolloverAction.NAME,
298-
new RolloverAction(null, null, null, 1L, null, null, null, null, null, null),
299+
// We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
300+
// snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
301+
// to improve reliability and speed of the test.
302+
new RolloverAction(RolloverConditions.newBuilder().addMaxIndexDocsCondition(2L).build()),
299303
SearchableSnapshotAction.NAME,
300304
new SearchableSnapshotAction(snapshotRepo)
301305
)
@@ -319,8 +323,11 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
319323

320324
// rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
321325
indexDocument(client(), dataStream, true);
326+
rolloverMaxOneDocCondition(client(), dataStream);
327+
List<String> backingIndices = getDataStreamBackingIndexNames(dataStream);
328+
assertThat(backingIndices.size(), equalTo(2));
322329

323-
String backingIndexName = getDataStreamBackingIndexNames(dataStream).getFirst();
330+
String backingIndexName = backingIndices.getFirst();
324331
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
325332
awaitIndexExists(restoredIndexName);
326333
TimeSeriesRestDriver.awaitStepKey(client(), restoredIndexName, "hot", null, PhaseCompleteStep.NAME);
@@ -357,7 +364,10 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
357364
TimeValue.ZERO,
358365
Map.of(
359366
RolloverAction.NAME,
360-
new RolloverAction(null, null, null, 1L, null, null, null, null, null, null),
367+
// We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
368+
// snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
369+
// to improve reliability and speed of the test.
370+
new RolloverAction(RolloverConditions.newBuilder().addMaxIndexDocsCondition(2L).build()),
361371
SearchableSnapshotAction.NAME,
362372
new SearchableSnapshotAction(snapshotRepo)
363373
)
@@ -383,8 +393,11 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
383393
// rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
384394
// indexing only one document as we want only one rollover to be triggered
385395
indexDocument(client(), dataStream, true);
396+
rolloverMaxOneDocCondition(client(), dataStream);
397+
List<String> backingIndices = getDataStreamBackingIndexNames(dataStream);
398+
assertThat(backingIndices.size(), equalTo(2));
386399

387-
String backingIndexName = getDataStreamBackingIndexNames(dataStream).getFirst();
400+
String backingIndexName = backingIndices.getFirst();
388401
String searchableSnapMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
389402
awaitIndexExists(searchableSnapMountedIndexName);
390403
TimeSeriesRestDriver.awaitStepKey(client(), searchableSnapMountedIndexName, "hot", null, PhaseCompleteStep.NAME);
@@ -453,15 +466,24 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
453466
public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
454467
String index = "myindex-" + randomAlphaOfLength(4).toLowerCase(Locale.ROOT) + "-000001";
455468
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
456-
Map<String, LifecycleAction> hotActions = new HashMap<>();
457-
hotActions.put(RolloverAction.NAME, new RolloverAction(null, null, null, 1L, null, null, null, null, null, null));
458-
hotActions.put(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(snapshotRepo, randomBoolean()));
459469
createPolicy(
460470
client(),
461471
policy,
462472
null,
463473
null,
464-
new Phase("hot", TimeValue.ZERO, hotActions),
474+
new Phase(
475+
"hot",
476+
TimeValue.ZERO,
477+
Map.of(
478+
RolloverAction.NAME,
479+
// We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
480+
// snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
481+
// to improve reliability and speed of the test.
482+
new RolloverAction(RolloverConditions.newBuilder().addMaxIndexDocsCondition(2L).build()),
483+
SearchableSnapshotAction.NAME,
484+
new SearchableSnapshotAction(snapshotRepo, randomBoolean())
485+
)
486+
),
465487
new Phase(
466488
"cold",
467489
TimeValue.ZERO,
@@ -472,16 +494,13 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
472494

473495
createIndex(
474496
index,
475-
Settings.builder().put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias").build(),
497+
Settings.builder().put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias").put(LifecycleSettings.LIFECYCLE_NAME, policy).build(),
476498
null,
477499
"\"alias\": {\"is_write_index\": true}"
478500
);
479501
ensureGreen(index);
480502
indexDocument(client(), index, true);
481-
482-
// enable ILM after we indexed a document as otherwise ILM might sometimes run so fast the indexDocument call will fail with
483-
// `index_not_found_exception`
484-
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
503+
rolloverMaxOneDocCondition(client(), "alias");
485504

486505
final String searchableSnapMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index;
487506

@@ -772,7 +791,10 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
772791
TimeValue.ZERO,
773792
Map.of(
774793
RolloverAction.NAME,
775-
new RolloverAction(null, null, null, 1L, null, null, null, null, null, null),
794+
// We create the policy with maxDocs 2 since we're required to have a rollover action if we're creating a searchable
795+
// snapshot in the hot phase. But we will only index one document and trigger the rollover manually,
796+
// to improve reliability and speed of the test.
797+
new RolloverAction(RolloverConditions.newBuilder().addMaxIndexDocsCondition(2L).build()),
776798
SearchableSnapshotAction.NAME,
777799
new SearchableSnapshotAction(snapshotRepo, randomBoolean())
778800
)
@@ -804,6 +826,7 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
804826

805827
// rollover the data stream so searchable_snapshot can complete
806828
indexDocument(client(), dataStream, true);
829+
rolloverMaxOneDocCondition(client(), dataStream);
807830

808831
final String restoredIndex = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + firstGenIndex;
809832
logger.info("--> waiting for [{}] to exist...", restoredIndex);

0 commit comments

Comments
 (0)