-
Notifications
You must be signed in to change notification settings - Fork 25.6k
OTLP: store units in mappings #134709
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
Merged
Merged
OTLP: store units in mappings #134709
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6b98987
OTLP: store units in mappings
felixbarny a091f7b
Update docs/changelog/134709.yaml
felixbarny d3da0f7
[CI] Auto commit changes from spotless
b56bb3e
Merge branch 'main' into bulk-meta
felixbarny ca07ebb
Use double braces for template values to avoid ambiguity
felixbarny 730082f
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny c779487
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny d540e7a
Fix issues after merge
felixbarny 7ab8702
Add transport version file
felixbarny 8664681
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny fa15fb4
Update transport version
felixbarny 5149afd
Bump OTel template version
felixbarny b6206a9
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny 2693bef
Bump transport version
felixbarny 343e92d
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny 535a874
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny eb4be7e
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny 2f55ef4
Fix high watermark indexing tests
felixbarny 5c065f8
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny cb4ca3a
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny d7c4d9e
Address review comments
felixbarny 588b7c5
Merge remote-tracking branch 'origin/main' into bulk-meta
felixbarny b3b7b6e
Fix replacement logic
felixbarny d967c35
Merge branch 'main' into bulk-meta
felixbarny c949f3e
Rename `dynamic_templates_params` to `dynamic_template_params`
felixbarny 3906494
Merge remote-tracking branch 'felixbarny/bulk-meta' into bulk-meta
felixbarny f315989
Update server/src/test/java/org/elasticsearch/action/index/IndexReque…
felixbarny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 134709 | ||
| summary: "OTLP: store units in mappings" | ||
| area: Mapping | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import java.util.Set; | ||
| import java.util.TreeMap; | ||
| import java.util.function.Predicate; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import java.util.regex.PatternSyntaxException; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -35,6 +36,9 @@ | |
|
|
||
| public class DynamicTemplate implements ToXContentObject { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @martijnvg do you know who owns this? Do we need another team to review dynamic template changes? |
||
|
|
||
| // Pattern to match {{param}} in dynamic template mappings | ||
| private static final Pattern DYNAMIC_TEMPLATE_PARAM = Pattern.compile("\\{\\{(.*?)}}"); | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public enum MatchType { | ||
| /** | ||
| * DEFAULT is set when the user did not explicitly set a match_pattern in their dynamic_templates entry. | ||
|
|
@@ -257,7 +261,7 @@ public final String toString() { | |
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| static DynamicTemplate parse(String name, Map<String, Object> conf) throws MapperParsingException { | ||
| static DynamicTemplate parse(String name, Map<String, ?> conf) throws MapperParsingException { | ||
| List<String> match = new ArrayList<>(4); // these pattern lists will typically be very small | ||
| List<String> pathMatch = new ArrayList<>(4); | ||
| List<String> unmatch = new ArrayList<>(4); | ||
|
|
@@ -268,7 +272,7 @@ static DynamicTemplate parse(String name, Map<String, Object> conf) throws Mappe | |
| List<String> unmatchMappingType = new ArrayList<>(4); | ||
| String matchPattern = MatchType.DEFAULT.toString(); | ||
|
|
||
| for (Map.Entry<String, Object> entry : conf.entrySet()) { | ||
| for (Map.Entry<String, ?> entry : conf.entrySet()) { | ||
| String propName = entry.getKey(); | ||
| if ("match".equals(propName)) { | ||
| addEntriesToPatternList(match, propName, entry); | ||
|
|
@@ -381,7 +385,7 @@ private static boolean matchPatternsAreDefined(final List<?>... matchLists) { | |
| return Stream.of(matchLists).anyMatch(Predicate.not(List::isEmpty)); | ||
| } | ||
|
|
||
| private static void addEntriesToPatternList(List<String> matchList, String propName, Map.Entry<String, Object> entry) { | ||
| private static void addEntriesToPatternList(List<String> matchList, String propName, Map.Entry<String, ?> entry) { | ||
| if (entry.getValue() instanceof List<?> ls) { | ||
| for (Object o : ls) { | ||
| if (o instanceof String s) { | ||
|
|
@@ -505,7 +509,9 @@ public String mappingType(String dynamicType) { | |
| String type; | ||
| if (mapping.containsKey("type")) { | ||
| type = mapping.get("type").toString(); | ||
| type = type.replace("{{dynamic_type}}", dynamicType); | ||
| type = type.replace("{dynamic_type}", dynamicType); | ||
| type = type.replace("{{dynamicType}}", dynamicType); | ||
| type = type.replace("{dynamicType}", dynamicType); | ||
| } else { | ||
| type = dynamicType; | ||
|
|
@@ -532,41 +538,68 @@ public boolean isRuntimeMapping() { | |
| } | ||
|
|
||
| public Map<String, Object> mappingForName(String name, String dynamicType) { | ||
| return processMap(mapping, name, dynamicType); | ||
| return mappingForName(name, dynamicType, Map.of()); | ||
| } | ||
|
|
||
| public Map<String, Object> mappingForName(String name, String dynamicType, Map<String, String> params) { | ||
| return processMap(mapping, name, dynamicType, params); | ||
| } | ||
|
|
||
| private static Map<String, Object> processMap(Map<String, Object> map, String name, String dynamicType) { | ||
| private static Map<String, Object> processMap(Map<String, Object> map, String name, String dynamicType, Map<String, String> params) { | ||
| Map<String, Object> processedMap = new HashMap<>(); | ||
| for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
| String key = entry.getKey() | ||
| .replace("{name}", name) | ||
| .replace("{dynamic_type}", dynamicType) | ||
| .replace("{dynamicType}", dynamicType); | ||
| processedMap.put(key, extractValue(entry.getValue(), name, dynamicType)); | ||
| String key = processString(entry.getKey(), name, dynamicType, params); | ||
| processedMap.put(key, extractValue(entry.getValue(), name, dynamicType, params)); | ||
| } | ||
| return processedMap; | ||
| } | ||
|
|
||
| private static List<?> processList(List<?> list, String name, String dynamicType) { | ||
| private static List<?> processList(List<?> list, String name, String dynamicType, Map<String, String> params) { | ||
| List<Object> processedList = new ArrayList<>(list.size()); | ||
| for (Object value : list) { | ||
| processedList.add(extractValue(value, name, dynamicType)); | ||
| processedList.add(extractValue(value, name, dynamicType, params)); | ||
| } | ||
| return processedList; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static Object extractValue(Object value, String name, String dynamicType) { | ||
| private static Object extractValue(Object value, String name, String dynamicType, Map<String, String> params) { | ||
| if (value instanceof Map) { | ||
| return processMap((Map<String, Object>) value, name, dynamicType); | ||
| return processMap((Map<String, Object>) value, name, dynamicType, params); | ||
| } else if (value instanceof List) { | ||
| return processList((List<?>) value, name, dynamicType); | ||
| } else if (value instanceof String) { | ||
| return value.toString().replace("{name}", name).replace("{dynamic_type}", dynamicType).replace("{dynamicType}", dynamicType); | ||
| return processList((List<?>) value, name, dynamicType, params); | ||
| } else if (value instanceof String valueString) { | ||
| valueString = processString(valueString, name, dynamicType, params); | ||
| return valueString; | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| private static String processString(String s, String name, String dynamicType, Map<String, String> params) { | ||
| s = s.replace("{{name}}", name) | ||
| .replace("{name}", name) | ||
| .replace("{{dynamic_type}}", dynamicType) | ||
| .replace("{dynamic_type}", dynamicType) | ||
| .replace("{{dynamicType}}", dynamicType) | ||
| .replace("{dynamicType}", dynamicType); | ||
|
|
||
| if (s.contains("{{") == false) { | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return s; | ||
| } | ||
|
|
||
| // Handle {{param}} replacements | ||
| Matcher matcher = DYNAMIC_TEMPLATE_PARAM.matcher(s); | ||
| StringBuilder sb = new StringBuilder(); | ||
| while (matcher.find()) { | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String key = matcher.group(1); | ||
| String replacement = params.getOrDefault(key, ""); | ||
kkrik-es marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement)); | ||
| } | ||
| matcher.appendTail(sb); | ||
|
|
||
| return sb.toString(); | ||
| } | ||
|
|
||
| String getName() { | ||
| return name; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.