-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[test] Small enhancement to EcsDynamicTemplatesIT
#110740
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
31d3e17
Adjust ecs@mappings to latest ECS and tests to consider normalizer
eyalkoren 1705bf5
Update docs/changelog/110740.yaml
eyalkoren 5613d63
Adjusting the stack registry version
eyalkoren a240f84
Merge remote-tracking branch 'eyalkoren/ecs-tests-fix' into ecs-tests…
eyalkoren 8e4d18a
Improve PR summary
eyalkoren a552db7
Removing .caseless fields
eyalkoren 810d91a
Merge remote-tracking branch 'upstream/main' into ecs-tests-fix
eyalkoren 7d46885
Delete docs/changelog/110740.yaml
eyalkoren 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 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 |
---|---|---|
|
@@ -63,7 +63,7 @@ public class EcsDynamicTemplatesIT extends ESRestTestCase { | |
|
||
private static Map<String, Object> ecsDynamicTemplates; | ||
private static Map<String, Map<String, Object>> ecsFlatFieldDefinitions; | ||
private static Map<String, String> ecsFlatMultiFieldDefinitions; | ||
private static Map<String, Map<String, Object>> ecsFlatMultiFieldDefinitions; | ||
|
||
@BeforeClass | ||
public static void setupSuiteScopeCluster() throws Exception { | ||
|
@@ -142,12 +142,11 @@ private static void prepareEcsDefinitions() throws IOException { | |
iterator.remove(); | ||
} | ||
|
||
List<Map<String, String>> multiFields = (List<Map<String, String>>) definitions.get("multi_fields"); | ||
List<Map<String, Object>> multiFields = (List<Map<String, Object>>) definitions.get("multi_fields"); | ||
if (multiFields != null) { | ||
multiFields.forEach(multiFieldsDefinitions -> { | ||
String subfieldFlatName = Objects.requireNonNull(multiFieldsDefinitions.get("flat_name")); | ||
String subfieldType = Objects.requireNonNull(multiFieldsDefinitions.get("type")); | ||
ecsFlatMultiFieldDefinitions.put(subfieldFlatName, subfieldType); | ||
String subfieldFlatName = (String) Objects.requireNonNull(multiFieldsDefinitions.get("flat_name")); | ||
ecsFlatMultiFieldDefinitions.put(subfieldFlatName, multiFieldsDefinitions); | ||
}); | ||
} | ||
} | ||
|
@@ -191,7 +190,7 @@ public void testNumericMessage() throws IOException { | |
verifyEcsMappings(indexName); | ||
} | ||
|
||
private void assertType(String expectedType, Map<String, Object> actualMappings) throws IOException { | ||
private void assertType(String expectedType, Map<String, Object> actualMappings) { | ||
assertNotNull("expected to get non-null mappings for field", actualMappings); | ||
assertEquals(expectedType, actualMappings.get("type")); | ||
} | ||
|
@@ -411,32 +410,33 @@ private void verifyEcsMappings(String indexName) throws IOException { | |
if (expectedMappings == null) { | ||
nonEcsFields.add(fieldName); | ||
} else { | ||
String expectedType = (String) expectedMappings.get("type"); | ||
String actualMappingType = (String) actualMappings.get("type"); | ||
if (actualMappingType.equals(expectedType) == false) { | ||
fieldToWrongMappingType.put(fieldName, actualMappingType); | ||
} | ||
if (expectedMappings.get("index") != actualMappings.get("index")) { | ||
wronglyIndexedFields.add(fieldName); | ||
} | ||
if (expectedMappings.get("doc_values") != actualMappings.get("doc_values")) { | ||
wronglyDocValuedFields.add(fieldName); | ||
} | ||
compareExpectedToActualMappings( | ||
fieldName, | ||
actualMappings, | ||
expectedMappings, | ||
fieldToWrongMappingType, | ||
wronglyIndexedFields, | ||
wronglyDocValuedFields | ||
); | ||
} | ||
}); | ||
|
||
Map<String, String> shallowMultiFieldMapCopy = new HashMap<>(ecsFlatMultiFieldDefinitions); | ||
Map<String, Map<String, Object>> shallowMultiFieldMapCopy = new HashMap<>(ecsFlatMultiFieldDefinitions); | ||
logger.info("Testing mapping of {} ECS multi-fields", shallowMultiFieldMapCopy.size()); | ||
flatMultiFieldsMappings.forEach((fieldName, actualMappings) -> { | ||
String expectedType = shallowMultiFieldMapCopy.remove(fieldName); | ||
if (expectedType != null) { | ||
Map<String, Object> expectedMultiFieldMappings = shallowMultiFieldMapCopy.remove(fieldName); | ||
if (expectedMultiFieldMappings != null) { | ||
// not finding an entry in the expected multi-field mappings map is acceptable: our dynamic templates are required to | ||
// ensure multi-field mapping for all fields with such ECS definitions. However, the patterns in these templates may lead | ||
// to multi-field mapping for ECS fields for which such are not defined | ||
String actualMappingType = (String) actualMappings.get("type"); | ||
if (actualMappingType.equals(expectedType) == false) { | ||
fieldToWrongMappingType.put(fieldName, actualMappingType); | ||
} | ||
compareExpectedToActualMappings( | ||
fieldName, | ||
actualMappings, | ||
expectedMultiFieldMappings, | ||
fieldToWrongMappingType, | ||
wronglyIndexedFields, | ||
wronglyDocValuedFields | ||
); | ||
} | ||
}); | ||
|
||
|
@@ -460,7 +460,11 @@ private void verifyEcsMappings(String indexName) throws IOException { | |
); | ||
}); | ||
fieldToWrongMappingType.forEach((fieldName, actualMappingType) -> { | ||
String ecsExpectedType = (String) ecsFlatFieldDefinitions.get(fieldName).get("type"); | ||
Map<String, Object> fieldMappings = ecsFlatFieldDefinitions.get(fieldName); | ||
if (fieldMappings == null) { | ||
fieldMappings = ecsFlatMultiFieldDefinitions.get(fieldName); | ||
} | ||
Comment on lines
+464
to
+466
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. The field mappings are either in the top-level mappings or subfields map. We didn't look in the latter before thus error message for subfields was not as descriptive |
||
String ecsExpectedType = (String) fieldMappings.get("type"); | ||
logger.error( | ||
"ECS field '{}' should be mapped to type '{}' but is mapped to type '{}'. Update {} accordingly.", | ||
fieldName, | ||
|
@@ -493,4 +497,25 @@ private void verifyEcsMappings(String indexName) throws IOException { | |
wronglyDocValuedFields.isEmpty() | ||
); | ||
} | ||
|
||
private static void compareExpectedToActualMappings( | ||
String fieldName, | ||
Map<String, Object> actualMappings, | ||
Map<String, Object> expectedMappings, | ||
Map<String, String> fieldToWrongMappingType, | ||
List<String> wronglyIndexedFields, | ||
List<String> wronglyDocValuedFields | ||
) { | ||
String expectedType = (String) expectedMappings.get("type"); | ||
String actualMappingType = (String) actualMappings.get("type"); | ||
if (actualMappingType.equals(expectedType) == false) { | ||
fieldToWrongMappingType.put(fieldName, actualMappingType); | ||
} | ||
if (expectedMappings.get("index") != actualMappings.get("index")) { | ||
wronglyIndexedFields.add(fieldName); | ||
} | ||
if (expectedMappings.get("doc_values") != actualMappings.get("doc_values")) { | ||
wronglyDocValuedFields.add(fieldName); | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of kipping only the subfield's type, keeping all mappings so we can validate any of them