Add ECS mappings during test runner executions#1090
Conversation
Review errors raised and their messages
In kibana versions < 8.6.0 the dot in the names caused that packages were not installed. It was interpreted that the string after the dot was an inner element of the map, causing validation errors.
This reverts commit a46de7b.
🌐 Coverage report
|
|
/test |
go.mod
Outdated
| sigs.k8s.io/yaml v1.3.0 // indirect | ||
| ) | ||
|
|
||
| replace github.com/elastic/package-spec/v2 => github.com/mrodm/package-spec/v2 v2.0.0-20221220145202-70d4563fbf33 |
There was a problem hiding this comment.
To be removed before merging
internal/builder/packages.go
Outdated
| } | ||
|
|
||
| logger.Debug("Add dynamic mappings if needed") | ||
| logger.Debug("Add dynamic mappings if needed (technical preview)") |
There was a problem hiding this comment.
Would it be interesting to add this ? Maybe changing to INFO instead ?
There was a problem hiding this comment.
Sounds good to add this. If changed to info it should probably appear only if the feature is used.
There was a problem hiding this comment.
Ok! I'll move this message as an INFO to be shown just when the feature is enabled/used.
| @@ -0,0 +1,20 @@ | |||
| format_version: 2.3.0 | |||
There was a problem hiding this comment.
This makes necessary package-spec 2.3.0 to be published.
jsoriano
left a comment
There was a problem hiding this comment.
Nice to see it working, added a possible improvement.
internal/fields/validate.go
Outdated
| ecsSchema, err := v.FieldDependencyManager.ImportAllFields(defaultExternal) | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
This will import ECS for each field, right?
Would it be possible to combine the v.Schema and the result of v.FieldDependencyManager.ImportAllFields(defaultExternal) in CreateValidatorForDirectory(...)? So we would only import ECS once and this logic here wouldn't be needed.
There was a problem hiding this comment.
I was worried in case all these ECS field definitions were added also for instance in the exported field documentation.
I've been checking again this, and when it is used to get the exported fields:
validator, err := fields.CreateValidatorForDirectory(fieldsParentDir)
if err != nil {
return "", errors.Wrapf(err, "can't create fields validator instance (path: %s)", fieldsParentDir)
}no spec version is used as a ValidatorOption parameter, so the default value (0.0.0) is taken. That makes sure that all these fields are not used at all in this stage since it must be at least 2.3.0. In any case, I've added fields.WithDisabledImportAllECSSChema() to ensure that feature is not used there.
I'll do the changes to move this logic directly in CreateValidatorForDirectory()
Thanks!
|
/test |
jsoriano
left a comment
There was a problem hiding this comment.
I am wondering now if we are correctly deciding when to import the schema for tests. It should be only imported for packages that include the ECS dynamic mappings.
This new datastream allows us to test the case where there is a field that is defined in both ECS and package fields.
| } | ||
|
|
||
| func TestValidate_WithEnabledImportAllECSSchema(t *testing.T) { | ||
| finder := packageRootTestFinder{"../../test/packages/other/imported_mappings_tests"} |
|
/test |
|
/test |
1 similar comment
|
/test |
Closes #1018
Follow-up of #1073
This PR adds all the ECS field definitions available in test executions to check whether or not a field in the sample event is defined. None of these field definitions are added in the built package.
The ECS version used for that regard is the version set at
_dev/build/build.ymlin the package itself.ECS definitions are used instead of trying to convert the
ecs_mappings.jsonto fields in elastic-package mainly because:ecs_mappings.jsonusematch,patch_unmatch, that do not have a relation 1 to 1 with the field definitions as managed in elastic-package.These mappings are going to be used just when that flag is enabled.
A new test package has been added with the
import_mappingsflag is enabled, and for that it requires package-spec 2.3.0 to be updated in elastic-package.This PR is based on the branch of #1073. To review just the commits from this PR, it should be checked from commit 26c8cfa (inclusive).
Requisites: