Skip to content

Commit e0196b4

Browse files
[ML] DeleteExpiredDataAction should use client with origin (#30646)
This is an admin action that should be allowed to operate on ML indices with full permissions.
1 parent aea4cd5 commit e0196b4

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.threadpool.ThreadPool;
1717
import org.elasticsearch.transport.TransportService;
18+
import org.elasticsearch.xpack.core.ClientHelper;
1819
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
1920
import org.elasticsearch.xpack.ml.MachineLearning;
2021
import org.elasticsearch.xpack.ml.job.retention.ExpiredForecastsRemover;
@@ -40,7 +41,7 @@ public TransportDeleteExpiredDataAction(Settings settings, ThreadPool threadPool
4041
Client client, ClusterService clusterService) {
4142
super(settings, DeleteExpiredDataAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
4243
DeleteExpiredDataAction.Request::new);
43-
this.client = client;
44+
this.client = ClientHelper.clientWithOrigin(client, ClientHelper.ML_ORIGIN);
4445
this.clusterService = clusterService;
4546
}
4647

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
* Removes up to {@link #MAX_FORECASTS} forecasts (stats + forecasts docs) that have expired.
4646
* A forecast is deleted if its expiration timestamp is earlier
4747
* than the start of the current day (local time-zone).
48+
*
49+
* This is expected to be used by actions requiring admin rights. Thus,
50+
* it is also expected that the provided client will be a client with the
51+
* ML origin so that permissions to manage ML indices are met.
4852
*/
4953
public class ExpiredForecastsRemover implements MlDataRemover {
5054

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemover.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
* of their respective job with the exception of the currently used snapshot.
3535
* A snapshot is deleted if its timestamp is earlier than the start of the
3636
* current day (local time-zone) minus the retention period.
37+
*
38+
* This is expected to be used by actions requiring admin rights. Thus,
39+
* it is also expected that the provided client will be a client with the
40+
* ML origin so that permissions to manage ML indices are met.
3741
*/
3842
public class ExpiredModelSnapshotsRemover extends AbstractExpiredJobDataRemover {
3943

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
import java.time.format.DateTimeFormatter;
3434
import java.util.Objects;
3535

36-
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
37-
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
38-
3936
/**
4037
* Removes all results that have expired the configured retention time
4138
* of their respective job. A result is deleted if its timestamp is earlier
4239
* than the start of the current day (local time-zone) minus the retention
4340
* period.
41+
*
42+
* This is expected to be used by actions requiring admin rights. Thus,
43+
* it is also expected that the provided client will be a client with the
44+
* ML origin so that permissions to manage ML indices are met.
4445
*/
4546
public class ExpiredResultsRemover extends AbstractExpiredJobDataRemover {
4647

@@ -65,7 +66,7 @@ protected void removeDataBefore(Job job, long cutoffEpochMs, ActionListener<Bool
6566
LOGGER.debug("Removing results of job [{}] that have a timestamp before [{}]", job.getId(), cutoffEpochMs);
6667
DeleteByQueryRequest request = createDBQRequest(job, cutoffEpochMs);
6768

68-
executeAsyncWithOrigin(client, ML_ORIGIN, DeleteByQueryAction.INSTANCE, request, new ActionListener<BulkByScrollResponse>() {
69+
client.execute(DeleteByQueryAction.INSTANCE, request, new ActionListener<BulkByScrollResponse>() {
6970
@Override
7071
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
7172
try {

0 commit comments

Comments
 (0)