-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[Rollup] Disallow index patterns that match rollup indices #30491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c660ebe
733e12d
98a47f8
2c3185c
275b594
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; | ||
| import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; | ||
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.IndicesOptions; | ||
| import org.elasticsearch.action.support.master.TransportMasterNodeAction; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
|
|
@@ -44,10 +45,12 @@ | |
| import org.elasticsearch.xpack.core.XPackField; | ||
| import org.elasticsearch.xpack.core.rollup.RollupField; | ||
| import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; | ||
| import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; | ||
| import org.elasticsearch.xpack.core.rollup.job.RollupJob; | ||
| import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; | ||
| import org.elasticsearch.xpack.rollup.Rollup; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -91,9 +94,16 @@ protected void masterOperation(PutRollupJobAction.Request request, ClusterState | |
| return; | ||
| } | ||
|
|
||
| // Check to see if the index pattern matches any existing rollup indices | ||
| ActionRequestValidationException validationException = validateIndexPattern(request, clusterState); | ||
| if (validationException != null) { | ||
| listener.onFailure(validationException); | ||
| return; | ||
| } | ||
|
|
||
| FieldCapabilitiesRequest fieldCapsRequest = new FieldCapabilitiesRequest() | ||
| .indices(request.getConfig().getIndexPattern()) | ||
| .fields(request.getConfig().getAllFields().toArray(new String[0])); | ||
| .indices(request.getConfig().getIndexPattern()) | ||
| .fields(request.getConfig().getAllFields().toArray(new String[0])); | ||
|
|
||
| client.fieldCaps(fieldCapsRequest, new ActionListener<FieldCapabilitiesResponse>() { | ||
| @Override | ||
|
|
@@ -115,6 +125,26 @@ public void onFailure(Exception e) { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Ensure that the index pattern doesn't match any pre-existing rollup indices. We don't need to check | ||
| * if the pattern would match it's own rollup index because the request already validated that. | ||
| */ | ||
|
||
| private static ActionRequestValidationException validateIndexPattern(PutRollupJobAction.Request request, ClusterState clusterState) { | ||
| IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(Settings.EMPTY); | ||
| String[] indices = resolver.concreteIndexNames(clusterState, IndicesOptions.strictExpandOpenAndForbidClosed(), | ||
| request.getConfig().getIndexPattern()); | ||
|
|
||
| ActionRequestValidationException validationException = new ActionRequestValidationException(); | ||
|
|
||
| Arrays.stream(indices) | ||
| .forEach(index -> TransportGetRollupCapsAction.findRollupIndexCaps(index, clusterState.getMetaData().index(index)) | ||
| .ifPresent(c -> validationException | ||
| .addValidationError("Index pattern [" + request.getConfig().getIndexPattern() + "] matches existing rollup index [" | ||
| + index + "] from jobs " + c.getJobCaps().stream().map(RollupJobCaps::getJobID).collect(Collectors.toList())))); | ||
|
|
||
| return validationException.validationErrors().size() > 0 ? validationException : null; | ||
| } | ||
|
|
||
| private static RollupJob createRollupJob(RollupJobConfig config, ThreadPool threadPool) { | ||
| // ensure we only filter for the allowed headers | ||
| Map<String, String> filteredHeaders = threadPool.getThreadContext().getHeaders().entrySet().stream() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch !