diff --git a/docs/changelog/135484.yaml b/docs/changelog/135484.yaml new file mode 100644 index 0000000000000..cac2793ead10a --- /dev/null +++ b/docs/changelog/135484.yaml @@ -0,0 +1,5 @@ +pr: 135484 +summary: Add origin to client in SLM task +area: ILM+SLM +type: bug +issues: [] diff --git a/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java b/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java index f75eed517dbdb..7e71c04f06391 100644 --- a/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java +++ b/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java @@ -16,6 +16,7 @@ import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; import org.elasticsearch.action.admin.cluster.snapshots.get.TransportGetSnapshotsAction; import org.elasticsearch.client.internal.Client; +import org.elasticsearch.client.internal.OriginSettingClient; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.ProjectState; @@ -79,7 +80,7 @@ public SnapshotLifecycleTask( final SnapshotHistoryStore historyStore ) { this.projectId = projectId; - this.client = client; + this.client = new OriginSettingClient(client, ClientHelper.INDEX_LIFECYCLE_ORIGIN); this.clusterService = clusterService; this.historyStore = historyStore; } diff --git a/x-pack/plugin/slm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleServiceTests.java b/x-pack/plugin/slm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleServiceTests.java index e170fa4dd6961..d328b4621d237 100644 --- a/x-pack/plugin/slm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleServiceTests.java +++ b/x-pack/plugin/slm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleServiceTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.slm; import org.apache.lucene.util.SetOnce; +import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -31,6 +32,7 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.client.NoOpClient; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; @@ -129,7 +131,7 @@ public void testNothingScheduledWhenNotRunning() throws InterruptedException { ClusterService clusterService = ClusterServiceUtils.createClusterService(initialState, threadPool); SnapshotLifecycleService sls = new SnapshotLifecycleService( Settings.EMPTY, - (projectId) -> new FakeSnapshotTask(e -> logger.info("triggered")), + (projectId) -> new FakeSnapshotTask(e -> logger.info("triggered"), new NoOpClient(threadPool)), clusterService, clock ) @@ -198,7 +200,7 @@ public void testPolicyCRUD() throws Exception { ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); SnapshotLifecycleService sls = new SnapshotLifecycleService( Settings.EMPTY, - (projectId) -> new FakeSnapshotTask(e -> trigger.get().accept(e)), + (projectId) -> new FakeSnapshotTask(e -> trigger.get().accept(e), new NoOpClient(threadPool)), clusterService, clock ) @@ -329,7 +331,7 @@ public void testPolicyNamesEndingInNumbers() throws Exception { ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); SnapshotLifecycleService sls = new SnapshotLifecycleService( Settings.EMPTY, - (projectId) -> new FakeSnapshotTask(e -> trigger.get().accept(e)), + (projectId) -> new FakeSnapshotTask(e -> trigger.get().accept(e), new NoOpClient(threadPool)), clusterService, clock ) @@ -509,7 +511,7 @@ public void submitUnbatchedStateUpdateTask(String source, ClusterStateUpdateTask SnapshotLifecycleService service = new SnapshotLifecycleService( Settings.EMPTY, - (projectId) -> new SnapshotLifecycleTask(projectId, null, null, null), + (projectId) -> new SnapshotLifecycleTask(projectId, new NoOpClient(threadPool), null, null), fakeService, clock ); @@ -529,8 +531,8 @@ public void submitUnbatchedStateUpdateTask(String source, ClusterStateUpdateTask class FakeSnapshotTask extends SnapshotLifecycleTask { private final Consumer onTriggered; - FakeSnapshotTask(Consumer onTriggered) { - super(projectId, null, null, null); + FakeSnapshotTask(Consumer onTriggered, Client client) { + super(projectId, client, null, null); this.onTriggered = onTriggered; }