Skip to content

Commit 2eede95

Browse files
committed
Fix warning when creating an OTel data stream
This was caused by LogsdbIndexModeSettingsProvider loading a filtered version of the mappings. It filters for `_doc.properties.host**` which contains host fields alias mappings from [email protected]. As the filtered mappings don't contain the alias target fields, this was causing an exception.
1 parent cc66490 commit 2eede95

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@
5151
final class LogsdbIndexModeSettingsProvider implements IndexSettingProvider {
5252
private static final Logger LOGGER = LogManager.getLogger(LogsdbIndexModeSettingsProvider.class);
5353
static final String LOGS_PATTERN = "logs-*-*";
54-
private static final Set<String> MAPPING_INCLUDES = Set.of("_doc._source.*", "_doc.properties.host**", "_doc.subobjects");
54+
private static final Set<String> MAPPING_INCLUDES = Set.of(
55+
"_doc._source.*",
56+
"_doc.properties.host**",
57+
"_doc.properties.resource**",
58+
"_doc.subobjects"
59+
);
5560

5661
private final LogsdbLicenseService licenseService;
5762
private final SetOnce<CheckedFunction<IndexMetadata, MapperService, IOException>> mapperServiceFactory = new SetOnce<>();

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,43 @@ public void testSortAndHostNameObject() throws Exception {
12211221
assertEquals(1, newMapperServiceCounter.get());
12221222
}
12231223

1224+
public void testSortAndHostNameAlias() throws Exception {
1225+
var settings = Settings.builder()
1226+
.put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB)
1227+
.put(IndexSettings.INDEX_FAST_REFRESH_SETTING.getKey(), true)
1228+
.build();
1229+
var mappings = """
1230+
{
1231+
"_doc": {
1232+
"properties": {
1233+
"@timestamp": {
1234+
"type": "date"
1235+
},
1236+
"resource": {
1237+
"properties": {
1238+
"attributes": {
1239+
"properties": {
1240+
"host.arch": {
1241+
"type": "keyword"
1242+
}
1243+
}
1244+
}
1245+
}
1246+
},
1247+
"host.architecture": {
1248+
"type": "alias",
1249+
"path": "resource.attributes.host.arch"
1250+
}
1251+
}
1252+
}
1253+
}
1254+
""";
1255+
Settings result = generateLogsdbSettings(settings, mappings);
1256+
assertTrue(IndexSettings.LOGSDB_SORT_ON_HOST_NAME.get(result));
1257+
assertTrue(IndexSettings.LOGSDB_ADD_HOST_NAME_FIELD.get(result));
1258+
assertEquals(1, newMapperServiceCounter.get());
1259+
}
1260+
12241261
public void testSortFastRefresh() throws Exception {
12251262
var settings = Settings.builder()
12261263
.put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB)

x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,31 @@ Metrics with different metric name hashes are not duplicates:
325325
bar: 42
326326
_metric_names_hash: 76b77d1a
327327
- is_false: errors
328+
---
329+
host.name pass-through:
330+
- do:
331+
bulk:
332+
index: metrics-generic.otel-default
333+
refresh: true
334+
body:
335+
- create: {"dynamic_templates":{"metrics.foo.bar":"counter_long"}}
336+
- "@timestamp": 2024-07-18T14:00:00Z
337+
scope:
338+
name: foo
339+
resource:
340+
attributes:
341+
host.name: localhost
342+
metrics:
343+
foo.bar: 42
344+
- is_false: errors
345+
- do:
346+
search:
347+
index: metrics-generic.otel-default
348+
body:
349+
query:
350+
term:
351+
host.name: localhost
352+
fields: [ "*" ]
353+
- length: { hits.hits: 1 }
354+
- match: { hits.hits.0.fields.resource\.attributes\.host\.name: [ "localhost" ] }
355+
- match: { hits.hits.0.fields.host\.name: [ "localhost" ] }

0 commit comments

Comments
 (0)