Skip to content

Commit 1aed889

Browse files
No longer require logs@settings component template to enable logsdb by default. (#114501) (#114525)
This change also opts out apm logs from logsdb. Co-authored-by: Elastic Machine <[email protected]>
1 parent 638d3c2 commit 1aed889

File tree

4 files changed

+22
-59
lines changed

4 files changed

+22
-59
lines changed

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsIndexModeRollingUpgradeIT.java

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public class LogsIndexModeRollingUpgradeIT extends AbstractRollingUpgradeTestCas
4545
.module("x-pack-stack")
4646
.setting("xpack.security.enabled", "false")
4747
.setting("xpack.license.self_generated.type", "trial")
48-
.setting("cluster.logsdb.enabled", "true")
48+
// We upgrade from standard to logsdb, so we need to start with logsdb disabled,
49+
// then later cluster.logsdb.enabled gets set to true and next rollover data stream is in logsdb mode.
50+
.setting("cluster.logsdb.enabled", "false")
4951
.setting("stack.templates.enabled", "false")
5052
.build();
5153

@@ -91,39 +93,6 @@ protected String getTestRestCluster() {
9193
}
9294
}""";
9395

94-
private static final String LOGS_TEMPLATE = """
95-
{
96-
"index_patterns": [ "logs-*-*" ],
97-
"data_stream": {},
98-
"priority": 500,
99-
"template": {
100-
"settings": {
101-
"index": {
102-
"mode": "logsdb"
103-
}
104-
},
105-
"mappings": {
106-
"properties": {
107-
"@timestamp" : {
108-
"type": "date"
109-
},
110-
"host.name": {
111-
"type": "keyword"
112-
},
113-
"method": {
114-
"type": "keyword"
115-
},
116-
"message": {
117-
"type": "text"
118-
},
119-
"ip.address": {
120-
"type": "ip"
121-
}
122-
}
123-
}
124-
}
125-
}""";
126-
12796
public void testLogsIndexing() throws IOException {
12897
if (isOldCluster()) {
12998
assertOK(client().performRequest(putTemplate(client(), "logs-template", STANDARD_TEMPLATE)));
@@ -169,7 +138,7 @@ public void testLogsIndexing() throws IOException {
169138
assertOK(bulkIndexResponse);
170139
assertThat(entityAsMap(bulkIndexResponse).get("errors"), Matchers.is(false));
171140
} else if (isUpgradedCluster()) {
172-
assertOK(client().performRequest(putTemplate(client(), "logs-template", LOGS_TEMPLATE)));
141+
enableLogsdbByDefault();
173142
assertOK(client().performRequest(rolloverDataStream(client(), "logs-apache-production")));
174143
final Response bulkIndexResponse = client().performRequest(bulkIndex("logs-apache-production", () -> {
175144
final StringBuilder sb = new StringBuilder();
@@ -202,6 +171,18 @@ public void testLogsIndexing() throws IOException {
202171
}
203172
}
204173

174+
private static void enableLogsdbByDefault() throws IOException {
175+
var request = new Request("PUT", "/_cluster/settings");
176+
request.setJsonEntity("""
177+
{
178+
"persistent": {
179+
"cluster.logsdb.enabled": true
180+
}
181+
}
182+
""");
183+
assertOK(client().performRequest(request));
184+
}
185+
205186
private void assertIndexMappingsAndSettings(int backingIndex, final Matcher<Object> indexModeMatcher, final MapMatcher mappingsMatcher)
206187
throws IOException {
207188
assertThat(

x-pack/plugin/apm-data/src/main/resources/component-templates/[email protected]

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ _meta:
66
template:
77
settings:
88
codec: best_compression
9+
mode: standard

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
package org.elasticsearch.xpack.logsdb;
99

10-
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
1110
import org.elasticsearch.cluster.metadata.Metadata;
12-
import org.elasticsearch.cluster.metadata.MetadataIndexTemplateService;
1311
import org.elasticsearch.common.compress.CompressedXContent;
1412
import org.elasticsearch.common.regex.Regex;
1513
import org.elasticsearch.common.settings.Settings;
@@ -54,7 +52,7 @@ public Settings getAdditionalIndexSettings(
5452
return Settings.EMPTY;
5553
}
5654

57-
if (usesLogsAtSettingsComponentTemplate(metadata, dataStreamName) && matchesLogsPattern(dataStreamName)) {
55+
if (matchesLogsPattern(dataStreamName)) {
5856
return Settings.builder().put("index.mode", IndexMode.LOGSDB.getName()).build();
5957
}
6058

@@ -69,21 +67,4 @@ private IndexMode resolveIndexMode(final String mode) {
6967
return mode != null ? Enum.valueOf(IndexMode.class, mode.toUpperCase(Locale.ROOT)) : null;
7068
}
7169

72-
private boolean usesLogsAtSettingsComponentTemplate(final Metadata metadata, final String name) {
73-
final String template = MetadataIndexTemplateService.findV2Template(metadata, name, false);
74-
if (template == null) {
75-
return false;
76-
}
77-
final ComposableIndexTemplate composableIndexTemplate = metadata.templatesV2().get(template);
78-
if (composableIndexTemplate == null) {
79-
return false;
80-
}
81-
for (final String componentTemplate : composableIndexTemplate.composedOf()) {
82-
if ("logs@settings".equals(componentTemplate)) {
83-
return true;
84-
}
85-
}
86-
return false;
87-
}
88-
8970
}

x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProviderTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void testWithoutLogsComponentTemplate() throws IOException {
148148
List.of(new CompressedXContent(DEFAULT_MAPPING))
149149
);
150150

151-
assertTrue(additionalIndexSettings.isEmpty());
151+
assertIndexMode(additionalIndexSettings, IndexMode.LOGSDB.getName());
152152
}
153153

154154
public void testWithLogsComponentTemplate() throws IOException {
@@ -202,7 +202,7 @@ public void testWithCustomComponentTemplatesOnly() throws IOException {
202202
List.of(new CompressedXContent(DEFAULT_MAPPING))
203203
);
204204

205-
assertTrue(additionalIndexSettings.isEmpty());
205+
assertIndexMode(additionalIndexSettings, IndexMode.LOGSDB.getName());
206206
}
207207

208208
public void testNonMatchingTemplateIndexPattern() throws IOException {
@@ -220,7 +220,7 @@ public void testNonMatchingTemplateIndexPattern() throws IOException {
220220
List.of(new CompressedXContent(DEFAULT_MAPPING))
221221
);
222222

223-
assertTrue(additionalIndexSettings.isEmpty());
223+
assertIndexMode(additionalIndexSettings, IndexMode.LOGSDB.getName());
224224
}
225225

226226
public void testCaseSensitivity() throws IOException {
@@ -256,7 +256,7 @@ public void testMultipleHyphensInDataStreamName() throws IOException {
256256
List.of(new CompressedXContent(DEFAULT_MAPPING))
257257
);
258258

259-
assertTrue(additionalIndexSettings.isEmpty());
259+
assertIndexMode(additionalIndexSettings, IndexMode.LOGSDB.getName());
260260
}
261261

262262
public void testBeforeAndAFterSettingUpdate() throws IOException {

0 commit comments

Comments
 (0)