-
Notifications
You must be signed in to change notification settings - Fork 116
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
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
@@ -159,3 +159,5 @@ require ( | |||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be removed before merging
internal/builder/packages.go
Outdated
@@ -180,7 +180,7 @@ func BuildPackage(options BuildOptions) (string, error) { | |||
return "", errors.Wrap(err, "resolving external fields failed") | |||
} | |||
|
|||
logger.Debug("Add dynamic mappings if needed") | |||
logger.Debug("Add dynamic mappings if needed (technical preview)") |
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.
Would it be interesting to add this ? Maybe changing to INFO instead ?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes necessary package-spec 2.3.0 to be published.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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.
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.
@@ -65,10 +73,28 @@ func TestValidate_WithNumericKeywordFields(t *testing.T) { | |||
require.Empty(t, errs) | |||
} | |||
|
|||
func TestValidate_WithEnabledImportAllECSSchema(t *testing.T) { | |||
finder := packageRootTestFinder{"../../test/packages/other/imported_mappings_tests"} |
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.
👍
/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.yml
in the package itself.ECS definitions are used instead of trying to convert the
ecs_mappings.json
to fields in elastic-package mainly because:ecs_mappings.json
usematch
,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_mappings
flag 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: