mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 06:46:10 +00:00
[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.
This commit is contained in:
parent
f0da3da6b0
commit
01bdfcde6f
@ -15,6 +15,7 @@ import org.elasticsearch.common.inject.Inject;
|
|||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
import org.elasticsearch.xpack.core.ClientHelper;
|
||||||
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
|
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
|
||||||
import org.elasticsearch.xpack.ml.MachineLearning;
|
import org.elasticsearch.xpack.ml.MachineLearning;
|
||||||
import org.elasticsearch.xpack.ml.job.retention.ExpiredForecastsRemover;
|
import org.elasticsearch.xpack.ml.job.retention.ExpiredForecastsRemover;
|
||||||
@ -40,7 +41,7 @@ public class TransportDeleteExpiredDataAction extends HandledTransportAction<Del
|
|||||||
Client client, ClusterService clusterService) {
|
Client client, ClusterService clusterService) {
|
||||||
super(settings, DeleteExpiredDataAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
|
super(settings, DeleteExpiredDataAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
|
||||||
DeleteExpiredDataAction.Request::new);
|
DeleteExpiredDataAction.Request::new);
|
||||||
this.client = client;
|
this.client = ClientHelper.clientWithOrigin(client, ClientHelper.ML_ORIGIN);
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,10 @@ import java.util.Objects;
|
|||||||
* Removes up to {@link #MAX_FORECASTS} forecasts (stats + forecasts docs) that have expired.
|
* Removes up to {@link #MAX_FORECASTS} forecasts (stats + forecasts docs) that have expired.
|
||||||
* A forecast is deleted if its expiration timestamp is earlier
|
* A forecast is deleted if its expiration timestamp is earlier
|
||||||
* than the start of the current day (local time-zone).
|
* than the start of the current day (local time-zone).
|
||||||
|
*
|
||||||
|
* This is expected to be used by actions requiring admin rights. Thus,
|
||||||
|
* it is also expected that the provided client will be a client with the
|
||||||
|
* ML origin so that permissions to manage ML indices are met.
|
||||||
*/
|
*/
|
||||||
public class ExpiredForecastsRemover implements MlDataRemover {
|
public class ExpiredForecastsRemover implements MlDataRemover {
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ import java.util.Objects;
|
|||||||
* of their respective job with the exception of the currently used snapshot.
|
* of their respective job with the exception of the currently used snapshot.
|
||||||
* A snapshot is deleted if its timestamp is earlier than the start of the
|
* A snapshot is deleted if its timestamp is earlier than the start of the
|
||||||
* current day (local time-zone) minus the retention period.
|
* current day (local time-zone) minus the retention period.
|
||||||
|
*
|
||||||
|
* This is expected to be used by actions requiring admin rights. Thus,
|
||||||
|
* it is also expected that the provided client will be a client with the
|
||||||
|
* ML origin so that permissions to manage ML indices are met.
|
||||||
*/
|
*/
|
||||||
public class ExpiredModelSnapshotsRemover extends AbstractExpiredJobDataRemover {
|
public class ExpiredModelSnapshotsRemover extends AbstractExpiredJobDataRemover {
|
||||||
|
|
||||||
|
@ -33,14 +33,15 @@ import java.time.ZonedDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
|
|
||||||
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all results that have expired the configured retention time
|
* Removes all results that have expired the configured retention time
|
||||||
* of their respective job. A result is deleted if its timestamp is earlier
|
* of their respective job. A result is deleted if its timestamp is earlier
|
||||||
* than the start of the current day (local time-zone) minus the retention
|
* than the start of the current day (local time-zone) minus the retention
|
||||||
* period.
|
* period.
|
||||||
|
*
|
||||||
|
* This is expected to be used by actions requiring admin rights. Thus,
|
||||||
|
* it is also expected that the provided client will be a client with the
|
||||||
|
* ML origin so that permissions to manage ML indices are met.
|
||||||
*/
|
*/
|
||||||
public class ExpiredResultsRemover extends AbstractExpiredJobDataRemover {
|
public class ExpiredResultsRemover extends AbstractExpiredJobDataRemover {
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ public class ExpiredResultsRemover extends AbstractExpiredJobDataRemover {
|
|||||||
LOGGER.debug("Removing results of job [{}] that have a timestamp before [{}]", job.getId(), cutoffEpochMs);
|
LOGGER.debug("Removing results of job [{}] that have a timestamp before [{}]", job.getId(), cutoffEpochMs);
|
||||||
DeleteByQueryRequest request = createDBQRequest(job, cutoffEpochMs);
|
DeleteByQueryRequest request = createDBQRequest(job, cutoffEpochMs);
|
||||||
|
|
||||||
executeAsyncWithOrigin(client, ML_ORIGIN, DeleteByQueryAction.INSTANCE, request, new ActionListener<BulkByScrollResponse>() {
|
client.execute(DeleteByQueryAction.INSTANCE, request, new ActionListener<BulkByScrollResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
|
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user