Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions docs/changelog/136119.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 136119
summary: Fix logsdb settings provider mapping filters
area: Logs
type: bug
issues:
- 136107
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.logsdb.patterntext;

import org.elasticsearch.xpack.logsdb.DataStreamLicenseChangeTestCase;
import org.junit.Before;

import java.io.IOException;
import java.util.Map;

import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;

public class PatternTextBasicLicenseTests extends DataStreamLicenseChangeTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems orthogonal.. let's leave it outside, to simplify backporting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this test because the logic to gate pattern_text behind a basic license also depends on the mapping (to detect if pattern_text is in use), and so it was also suffering from this same bug. But I'll move the test into a follow-up PR.

@Before
public void checkClusterFeature() {
assumeTrue("[patterned_text] must be available", clusterHasFeature("mapper.patterned_text"));
}

private static final String patternTextMapping = """
{
"index_patterns": ["%name%"],
"priority": 500,
"data_stream": {},
"template": {
"mappings": {
"properties": {
"pattern_field": {
"type": "pattern_text"
}
}
}
}
}""";

@SuppressWarnings("unchecked")
public void testLicenseUpgrade() throws IOException {
final String dataStreamName = "test-foo";

final String doc = """
{"index": {}}
{"@timestamp": "2025-01-01T00:00:00.000Z", "pattern_field": "foo"}
""";

assertOK(putTemplate(client(), "logs@custom", patternTextMapping.replace("%name%", dataStreamName)));
assertOK(bulkIndex(client(), dataStreamName, () -> doc));

String backingIndex0 = getDataStreamBackingIndex(client(), dataStreamName, 0);
{
assertEquals("true", getSetting(client(), backingIndex0, "index.mapping.pattern_text.disable_templating"));
Map<String, Object> mapping = getMapping(client(), backingIndex0);
Map<String, Object> patternFieldMapping = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get(
"pattern_field"
);
assertThat(patternFieldMapping, hasEntry("disable_templating", true));
}

assertOK(rolloverDataStream(client(), dataStreamName));

String backingIndex1 = getDataStreamBackingIndex(client(), dataStreamName, 1);
{
assertEquals("true", getSetting(client(), backingIndex1, "index.mapping.pattern_text.disable_templating"));
Map<String, Object> mapping = getMapping(client(), backingIndex1);
Map<String, Object> patternFieldMapping = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get(
"pattern_field"
);
assertThat(patternFieldMapping, hasKey("disable_templating"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_PATH;
import static org.elasticsearch.xpack.logsdb.LogsDBPlugin.CLUSTER_LOGSDB_ENABLED;

final class LogsdbIndexModeSettingsProvider implements IndexSettingProvider {
private static final Logger LOGGER = LogManager.getLogger(LogsdbIndexModeSettingsProvider.class);
static final String LOGS_PATTERN = "logs-*-*";
private static final Set<String> MAPPING_INCLUDES = Set.of(
"_doc._source.*",
"_doc.properties.host**",
"_doc.properties.resource**",
"_doc.subobjects"
);
private static final Set<String> MAPPING_INCLUDES = Set.of("_source.*", "properties.host**", "properties.resource**", "subobjects")
.stream()
.flatMap(v -> Stream.of(v, "_doc." + v))
.collect(Collectors.toSet());

private final LogsdbLicenseService licenseService;
private final SetOnce<CheckedFunction<IndexMetadata, MapperService, IOException>> mapperServiceFactory = new SetOnce<>();
Expand Down Expand Up @@ -305,11 +305,11 @@ MappingHints getMappingHints(
@SuppressWarnings("unchecked")
private boolean checkMappingForPatternText(Map<String, Object> mapping) {
var docMapping = mapping.get("_doc");
if ((docMapping instanceof Map) == false) {
return false;
if (docMapping instanceof Map) {
mapping = (Map<String, Object>) docMapping;
}
boolean[] usesPatternText = { false };
MappingVisitor.visitMapping((Map<String, Object>) docMapping, (field, fieldMapping) -> {
MappingVisitor.visitMapping(mapping, (field, fieldMapping) -> {
if (Objects.equals(fieldMapping.get("type"), PatternTextFieldType.CONTENT_TYPE)) {
usesPatternText[0] = true;
}
Expand Down
Loading