Skip to content
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

Remove index_mode property from index templates #85985

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ public void testIndexDocsWithCustomRoutingAllowed() throws Exception {
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, true, null)
new ComposableIndexTemplate.DataStreamTemplate(false, true)
);
client().execute(
PutComposableIndexTemplateAction.INSTANCE,
Expand Down Expand Up @@ -1804,7 +1804,7 @@ public void testPartitionedTemplate() throws IOException {
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, true, null)
new ComposableIndexTemplate.DataStreamTemplate(false, true)
);
ComposableIndexTemplate finalTemplate = template;
client().execute(
Expand All @@ -1830,7 +1830,7 @@ public void testPartitionedTemplate() throws IOException {
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, true, null)
new ComposableIndexTemplate.DataStreamTemplate(false, true)
);
client().execute(
PutComposableIndexTemplateAction.INSTANCE,
Expand All @@ -1856,7 +1856,7 @@ public void testPartitionedTemplate() throws IOException {
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, false, null)
new ComposableIndexTemplate.DataStreamTemplate(false, false)
);
ComposableIndexTemplate finalTemplate1 = template;
Exception e = expectThrows(
Expand Down Expand Up @@ -1898,7 +1898,7 @@ public void testSearchWithRouting() throws IOException, ExecutionException, Inte
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, true, null)
new ComposableIndexTemplate.DataStreamTemplate(false, true)
);
client().execute(
PutComposableIndexTemplateAction.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.action.admin.indices.template.put.PutComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.cluster.metadata.ComponentTemplate;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.FormatNames;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void testTimeRanges() throws Exception {
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, false, IndexMode.TIME_SERIES),
new ComposableIndexTemplate.DataStreamTemplate(false, false),
null
)
);
Expand Down Expand Up @@ -167,6 +168,122 @@ public void testTimeRanges() throws Exception {
}
}

public void testTsdbTemplatesWithComponentTemplate() throws Exception {
var mappingTemplate = """
{
"_doc":{
"properties": {
"metricset": {
"type": "keyword",
"time_series_dimension": true
}
}
}
}""";
var putComponentTemplateRequest = new PutComponentTemplateAction.Request("id");
putComponentTemplateRequest.componentTemplate(
new ComponentTemplate(
new Template(
Settings.builder().put("index.routing_path", "metricset").build(),
new CompressedXContent(mappingTemplate),
null
),
null,
null
)
);
Exception e = expectThrows(
IllegalArgumentException.class,
() -> client().execute(PutComponentTemplateAction.INSTANCE, putComponentTemplateRequest).actionGet()
);
// We can't know whether the index template that uses this component template has data streams enabled:
// (The generation of certain settings index.mode, index.time_series_start_time etc. only doesn't happen)
assertThat(e.getMessage(), equalTo("[index.routing_path] requires [index.mode=time_series]"));
}

public void testInvalidTsdbTemplatesNoTimeSeriesDimensionAttribute() throws Exception {
var mappingTemplate = """
{
"_doc":{
"properties": {
"metricset": {
"type": "keyword"
}
}
}
}""";
var request = new PutComposableIndexTemplateAction.Request("id");
request.indexTemplate(
new ComposableIndexTemplate(
List.of("k8s*"),
new Template(
Settings.builder().put("index.routing_path", "metricset").build(),
new CompressedXContent(mappingTemplate),
null
),
null,
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, false),
null
)
);
Exception e = expectThrows(
IllegalArgumentException.class,
() -> client().execute(PutComposableIndexTemplateAction.INSTANCE, request).actionGet()
);
assertThat(
e.getCause().getCause().getMessage(),
equalTo(
"All fields that match routing_path must be keywords with [time_series_dimension: true] and "
+ "without the [script] parameter. [metricset] was not [time_series_dimension: true]."
)
);
}

public void testInvalidTsdbTemplatesNoKeywordFieldType() throws Exception {
var mappingTemplate = """
{
"_doc":{
"properties": {
"metricset": {
"type": "long",
"time_series_dimension": true
}
}
}
}""";
var request = new PutComposableIndexTemplateAction.Request("id");
request.indexTemplate(
new ComposableIndexTemplate(
List.of("k8s*"),
new Template(
Settings.builder().put("index.routing_path", "metricset").build(),
new CompressedXContent(mappingTemplate),
null
),
null,
null,
null,
null,
new ComposableIndexTemplate.DataStreamTemplate(false, false),
null
)
);
Exception e = expectThrows(
IllegalArgumentException.class,
() -> client().execute(PutComposableIndexTemplateAction.INSTANCE, request).actionGet()
);
assertThat(
e.getCause().getCause().getMessage(),
equalTo(
"All fields that match routing_path must be keywords with [time_series_dimension: true] and "
+ "without the [script] parameter. [metricset] was [long]."
)
);
}

static String formatInstant(Instant instant) {
return DateFormatter.forPattern(FormatNames.STRICT_DATE_OPTIONAL_TIME.getName()).format(instant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public class TsdbDataStreamRestIT extends ESRestTestCase {
}
},
"data_stream": {
"index_mode": "time_series"
}
}""";

Expand Down Expand Up @@ -463,7 +462,7 @@ public void testChangeTemplateIndexMode() throws Exception {
e.getMessage(),
containsString(
"composable template [1] with index patterns [k8s*], priority [null],"
+ " index_mode [null] would cause tsdb data streams [k8s] to no longer match a data stream template"
+ " index.routing_path [] would cause tsdb data streams [k8s] to no longer match a data stream template"
+ " with a time_series index_mode"
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ public class DataStreamIndexSettingsProvider implements IndexSettingProvider {
public Settings getAdditionalIndexSettings(
String indexName,
String dataStreamName,
IndexMode templateIndexMode,
boolean isTsdbTemplate,
Metadata metadata,
Instant resolvedAt,
Settings allSettings
) {
if (dataStreamName != null) {
DataStream dataStream = metadata.dataStreams().get(dataStreamName);
// First backing index is created and then data stream is rolled over (in a single cluster state update).
// So at this point we can't check index_mode==time_series,
// so checking that index_mode==null|standard and templateIndexMode == TIME_SERIES
boolean migrating = dataStream != null
&& (dataStream.getIndexMode() == null || dataStream.getIndexMode() == IndexMode.STANDARD)
&& templateIndexMode == IndexMode.TIME_SERIES;
// So at this point we can't check timeSeries=true,
// so checking that timeSeries=false and template is tsdb
boolean migrating = dataStream != null && dataStream.isTimeSeries() == false && isTsdbTemplate;
IndexMode indexMode;
if (migrating) {
indexMode = IndexMode.TIME_SERIES;
} else if (dataStream != null) {
indexMode = dataStream.getIndexMode();
} else if (dataStream != null && dataStream.isTimeSeries()) {
indexMode = IndexMode.TIME_SERIES;
} else if (isTsdbTemplate) {
indexMode = IndexMode.TIME_SERIES;
} else {
indexMode = templateIndexMode;
indexMode = null;
}
if (indexMode != null) {
Settings.Builder builder = Settings.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.threadpool.Scheduler;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -109,7 +108,7 @@ void setPollInterval(TimeValue newValue) {
ClusterState updateTimeSeriesTemporalRange(ClusterState current, Instant now) {
Metadata.Builder mBuilder = null;
for (DataStream dataStream : current.metadata().dataStreams().values()) {
if (dataStream.getIndexMode() != IndexMode.TIME_SERIES) {
if (dataStream.isTimeSeries() == false) {
continue;
}
if (dataStream.isReplicated()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettingProviders;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.MapperBuilderContext;
Expand Down Expand Up @@ -287,7 +286,7 @@ public void cleanup() {
private ClusterState createInitialState() {
ComposableIndexTemplate template = new ComposableIndexTemplate.Builder().indexPatterns(List.of("logs-*"))
.template(new Template(Settings.builder().put("index.routing_path", "uid").build(), null, null))
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate(false, false, IndexMode.TIME_SERIES))
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate(false, false))
.build();
Metadata.Builder builder = Metadata.builder();
builder.put("template", template);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testGetAdditionalIndexSettings() {
Settings result = provider.getAdditionalIndexSettings(
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
dataStreamName,
IndexMode.TIME_SERIES,
true,
metadata,
now,
settings
Expand All @@ -61,7 +61,7 @@ public void testGetAdditionalIndexSettingsLookAheadTime() {
Settings result = provider.getAdditionalIndexSettings(
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
dataStreamName,
IndexMode.TIME_SERIES,
true,
metadata,
now,
settings
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreated() {
var result = provider.getAdditionalIndexSettings(
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
dataStreamName,
IndexMode.TIME_SERIES,
true,
metadata,
now,
settings
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreatedTimeSettingsMi
ds.isReplicated(),
ds.isSystem(),
ds.isAllowCustomRouting(),
IndexMode.TIME_SERIES
true
)
);
Metadata metadata = mb.build();
Expand All @@ -139,7 +139,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreatedTimeSettingsMi
() -> provider.getAdditionalIndexSettings(
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
dataStreamName,
IndexMode.TIME_SERIES,
true,
metadata,
now,
settings
Expand All @@ -155,7 +155,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreatedTimeSettingsMi
);
}

public void testGetAdditionalIndexSettingsIndexModeNotSpecified() {
public void testGetAdditionalIndexSettingsNonTsdbTemplate() {
Metadata metadata = Metadata.EMPTY_METADATA;
String dataStreamName = "logs-app1";

Expand All @@ -164,30 +164,12 @@ public void testGetAdditionalIndexSettingsIndexModeNotSpecified() {
Settings result = provider.getAdditionalIndexSettings(
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
dataStreamName,
null,
false,
metadata,
Instant.ofEpochMilli(1L),
settings
);
assertThat(result.size(), equalTo(0));
}

public void testGetAdditionalIndexSettingsIndexModeStandardSpecified() {
Metadata metadata = Metadata.EMPTY_METADATA;
String dataStreamName = "logs-app1";

Settings settings = Settings.EMPTY;
var provider = new DataStreamIndexSettingsProvider();
Settings result = provider.getAdditionalIndexSettings(
DataStream.getDefaultBackingIndexName(dataStreamName, 1),
dataStreamName,
IndexMode.STANDARD,
metadata,
Instant.ofEpochMilli(1L),
settings
);
assertThat(result.size(), equalTo(1));
assertThat(result.get(IndexSettings.MODE.getKey()), equalTo(IndexMode.STANDARD.name().toLowerCase(Locale.ROOT)));
}

}
Loading