[Rollup] Disallow index patterns that match the rollup index (#30491)
We should not allow the user to configure index patterns that also match the index which stores the rollup index. For example, it is quite natural for a user to specify `metricbeat-*` as the index pattern, and then store the rollups in `metricbeat-rolled`. This will start throwing errors as soon as the rollup index is created because the indexer will try to search it. Note: this does not prevent the user from matching against existing rollup indices. That should be prevented by the field-level validation during job creation.
This commit is contained in:
parent
05ee0f8b6e
commit
a1c9def64e
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.io.stream.NamedWriteable;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -173,7 +174,7 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject {
|
|||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(id);
|
||||
|
@ -336,6 +337,17 @@ public class RollupJobConfig implements NamedWriteable, ToXContentObject {
|
|||
if (indexPattern == null || indexPattern.isEmpty()) {
|
||||
throw new IllegalArgumentException("An index pattern is mandatory.");
|
||||
}
|
||||
if (Regex.isMatchAllPattern(indexPattern)) {
|
||||
throw new IllegalArgumentException("Index pattern must not match all indices (as it would match it's own rollup index");
|
||||
}
|
||||
if (Regex.isSimpleMatchPattern(indexPattern)) {
|
||||
if (Regex.simpleMatch(indexPattern, rollupIndex)) {
|
||||
throw new IllegalArgumentException("Index pattern would match rollup index name which is not allowed.");
|
||||
}
|
||||
}
|
||||
if (indexPattern.equals(rollupIndex)) {
|
||||
throw new IllegalArgumentException("Rollup index may not be the same as the index pattern.");
|
||||
}
|
||||
if (rollupIndex == null || rollupIndex.isEmpty()) {
|
||||
throw new IllegalArgumentException("A rollup index name is mandatory.");
|
||||
}
|
||||
|
|
|
@ -27,8 +27,9 @@ public class ConfigTestHelpers {
|
|||
builder.setId(jobId);
|
||||
builder.setCron(getCronString());
|
||||
builder.setTimeout(new TimeValue(ESTestCase.randomIntBetween(1,100)));
|
||||
builder.setIndexPattern(ESTestCase.randomAlphaOfLengthBetween(1,10));
|
||||
builder.setRollupIndex(ESTestCase.randomAlphaOfLengthBetween(1,10));
|
||||
String indexPattern = ESTestCase.randomAlphaOfLengthBetween(1,10);
|
||||
builder.setIndexPattern(indexPattern);
|
||||
builder.setRollupIndex("rollup_" + indexPattern); // to ensure the index pattern != rollup index
|
||||
builder.setGroupConfig(ConfigTestHelpers.getGroupConfig().build());
|
||||
builder.setPageSize(ESTestCase.randomIntBetween(1,10));
|
||||
if (ESTestCase.randomBoolean()) {
|
||||
|
|
|
@ -95,8 +95,8 @@ public class TransportPutRollupJobAction extends TransportMasterNodeAction<PutRo
|
|||
XPackPlugin.checkReadyForXPackCustomMetadata(clusterState);
|
||||
|
||||
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
|
||||
|
|
|
@ -122,6 +122,37 @@ public class ConfigTests extends ESTestCase {
|
|||
assertThat(e.getMessage(), equalTo("An index pattern is mandatory."));
|
||||
}
|
||||
|
||||
public void testMatchAllIndexPattern() {
|
||||
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
|
||||
job.setIndexPattern("*");
|
||||
Exception e = expectThrows(IllegalArgumentException.class, job::build);
|
||||
assertThat(e.getMessage(), equalTo("Index pattern must not match all indices (as it would match it's own rollup index"));
|
||||
}
|
||||
|
||||
public void testMatchOwnRollupPatternPrefix() {
|
||||
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
|
||||
job.setIndexPattern("foo-*");
|
||||
job.setRollupIndex("foo-rollup");
|
||||
Exception e = expectThrows(IllegalArgumentException.class, job::build);
|
||||
assertThat(e.getMessage(), equalTo("Index pattern would match rollup index name which is not allowed."));
|
||||
}
|
||||
|
||||
public void testMatchOwnRollupPatternSuffix() {
|
||||
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
|
||||
job.setIndexPattern("*-rollup");
|
||||
job.setRollupIndex("foo-rollup");
|
||||
Exception e = expectThrows(IllegalArgumentException.class, job::build);
|
||||
assertThat(e.getMessage(), equalTo("Index pattern would match rollup index name which is not allowed."));
|
||||
}
|
||||
|
||||
public void testIndexPatternIdenticalToRollup() {
|
||||
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
|
||||
job.setIndexPattern("foo");
|
||||
job.setRollupIndex("foo");
|
||||
Exception e = expectThrows(IllegalArgumentException.class, job::build);
|
||||
assertThat(e.getMessage(), equalTo("Rollup index may not be the same as the index pattern."));
|
||||
}
|
||||
|
||||
public void testEmptyRollupIndex() {
|
||||
RollupJobConfig.Builder job = ConfigTestHelpers.getRollupJob("foo");
|
||||
job.setRollupIndex("");
|
||||
|
|
|
@ -188,4 +188,3 @@ setup:
|
|||
]
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue