Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2c3f76e
Add dynamic templates as parameter
mrodm Dec 12, 2024
41d7b88
Add validation for each dynamic template depending on the parameters
mrodm Dec 16, 2024
ff5298e
Fixes for dynamic templates
mrodm Dec 16, 2024
af04d66
Compare fields with dynamic templates
mrodm Dec 17, 2024
f21c712
Remove multi_fields from flattened fields
mrodm Dec 17, 2024
aa28db6
Test without filtering dynamic templates
mrodm Dec 17, 2024
3767111
Ensure properties subfields are validated accordingly
mrodm Dec 18, 2024
9fb80b4
Restore filtering and add tests
mrodm Dec 18, 2024
2ad28ac
Disable unmatch_mapping_type and match_mapping_type and continue look…
mrodm Dec 19, 2024
8bdad65
Merge upstream/main into validate-dynamic-mappings
mrodm Dec 19, 2024
151e59e
Refactors and remove log statements
mrodm Dec 19, 2024
d0ff6b9
Fix function naming
mrodm Dec 19, 2024
b474b4b
Add test with match_pattern regex
mrodm Dec 19, 2024
066b5a0
Add comment in tests
mrodm Dec 19, 2024
a7eb191
Remove loading schema from create validator for mappings method
mrodm Jan 7, 2025
7666ac2
Separate parsing and validation of dynamic templates
mrodm Jan 7, 2025
a718796
Support match_pattern for the other settings
mrodm Jan 7, 2025
0a5e775
fix test
mrodm Jan 8, 2025
131cc9c
Update tests for multi-fields
mrodm Jan 8, 2025
38db8df
Review multi-fields logic
mrodm Jan 8, 2025
9ff3d0c
Revisit multi-fields logic in ECS
mrodm Jan 8, 2025
5165612
Report all errors related to multi-fields comparing with ECS
mrodm Jan 8, 2025
ce557c9
Ignored validation of multi-fields with ECS
mrodm Jan 8, 2025
ebda859
Fix multi-field test
mrodm Jan 8, 2025
019ffd4
Rephrase errors
mrodm Jan 9, 2025
8f36c18
Validate fully dynamic objects (preview) with dynamic templates
mrodm Jan 9, 2025
d96ffbf
Rephrase debug message
mrodm Jan 9, 2025
dbca4fe
Add logging - to be removed
mrodm Jan 9, 2025
8fce0ec
Merge remote-tracking branch 'upstream/main' into validate-dynamic-ma…
mrodm Jan 14, 2025
c333707
Revisited log messages
mrodm Jan 20, 2025
0569cfb
Remove comments
mrodm Jan 20, 2025
1aea303
Remove more debug statements
mrodm Jan 20, 2025
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
Prev Previous commit
Next Next commit
Fixes for dynamic templates
  • Loading branch information
mrodm committed Dec 16, 2024
commit ff5298ed2e123bf723020f0c37a15654c2363ed5
19 changes: 15 additions & 4 deletions internal/fields/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func (v *MappingValidator) validateMappingInECSSchema(currentPath string, defini
if found.Type == actualType {
return nil
}
// TODO: Compare all parameters and multifieds

// exceptions related to numbers
if isNumberTypeField(found.Type, actualType) {
Expand Down Expand Up @@ -695,6 +696,8 @@ func (v *MappingValidator) matchingWithDynamicTemplates(currentPath string, defi
} else {
r = strings.ReplaceAll(v, ".", "\\.")
r = strings.ReplaceAll(r, "*", ".*")
// Force to match beginning and ending
r = fmt.Sprintf("^%s$", r)
}

match, err := regexp.MatchString(r, elem)
Expand Down Expand Up @@ -746,8 +749,9 @@ func (v *MappingValidator) matchingWithDynamicTemplates(currentPath string, defi

// matches with the current definitions and path
// https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html
matched := true
allMatched := true
for setting, value := range contents {
matched := true
switch setting {
case "mapping":
// Skip
Expand Down Expand Up @@ -821,11 +825,12 @@ func (v *MappingValidator) matchingWithDynamicTemplates(currentPath string, defi
break
}
case "match_mapping_type":
logger.Debugf("> Check match_mapping_type: %q (type %s vs mapping type %q)", currentPath, definition, fieldType)
logger.Debugf("> Check match_mapping_type: %q (type %s)", currentPath, fieldType)
values, err := parseSetting(value)
if err != nil {
return false, fmt.Errorf("failed to check match_mapping_type setting: %w", err)
}
logger.Debugf(">> Comparing to values: %s", values)
if slices.Contains(values, "*") {
continue
}
Expand All @@ -835,11 +840,12 @@ func (v *MappingValidator) matchingWithDynamicTemplates(currentPath string, defi
break
}
case "unmatch_mapping_type":
logger.Debugf("> Check unmatch_mapping_type: %q (type %s vs mapping type %q)", currentPath, definition, fieldType)
logger.Debugf("> Check unmatch_mapping_type: %q (type %s)", currentPath, fieldType)
values, err := parseSetting(value)
if err != nil {
return false, fmt.Errorf("failed to check unmatch_mapping_type setting: %w", err)
}
logger.Debugf(">> Comparing to values: %s", values)
if slices.Contains(values, fieldType) {
logger.Debugf(">> Issue: matches")
matched = false
Expand All @@ -848,8 +854,13 @@ func (v *MappingValidator) matchingWithDynamicTemplates(currentPath string, defi
default:
return false, fmt.Errorf("unexpected setting found in dynamic template")
}
if !matched {
// If just one parameter does not match, this dynamic template can be skipped
allMatched = false
break
}
}
if matched {
if allMatched {
logger.Debugf("> Found dynamic template matched: %s", templateName)
return true, nil
}
Expand Down