Skip to content

Validate arrays of objects#1489

Merged
jsoriano merged 5 commits intoelastic:mainfrom
jsoriano:validate-arrays-of-objects
Oct 5, 2023
Merged

Validate arrays of objects#1489
jsoriano merged 5 commits intoelastic:mainfrom
jsoriano:validate-arrays-of-objects

Conversation

@jsoriano
Copy link
Copy Markdown
Member

@jsoriano jsoriano commented Oct 5, 2023

Add validation for arrays of objects, considering them as valid when they are inside nested or group.

When group is used, a filterable error is given, mentioning that nested should be used instead on this case.

Fix #1488

@jsoriano jsoriano requested a review from a team October 5, 2023 11:48
@jsoriano jsoriano self-assigned this Oct 5, 2023
)

// EPF - Elastic Package Fields [validation]
const ArrayOfObjectsErrorCode = "EPF00001"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrodm do we have a place where we are already defining Elastic Package errors?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, there is no definition of errors in Elastic Package. Until now, it was just getting the errors from package-spec validate method and return the errors filtered (if any).

Should this be added into a new internal/errors package ? Or maybe another naming to not have collisions with standard errors package (e.g. validationerrors? I don't like neither too much this).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed by now.

)

// EPF - Elastic Package Fields [validation]
const ArrayOfObjectsErrorCode = "EPF00001"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, there is no definition of errors in Elastic Package. Until now, it was just getting the errors from package-spec validate method and return the errors filtered (if any).

Should this be added into a new internal/errors package ? Or maybe another naming to not have collisions with standard errors package (e.g. validationerrors? I don't like neither too much this).

}
errs := v.validateMapElement(key, common.MapStr(val), doc)
if definition.Type == "group" {
errs = append(errs, arrayOfObjectsErr)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these errors could be filtered as it is the code.

The methods that get the errors and filter are just for the errors from package-spec. This is in internal/validation package. For instance

func ValidateAndFilterFromPath(rootPath string) (error, error) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this would need to be filtered at the moment of testing the package. This makes me wonder if this validation errors filtering fits here, or if this should be configured in tests. What do you think?

I could continue without making this filterable by now. It would only affect packages using spec v3.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed by now.

@jsoriano
Copy link
Copy Markdown
Member Author

jsoriano commented Oct 5, 2023

/test

@elasticmachine
Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

History

cc @jsoriano

@jsoriano jsoriano merged commit beabd87 into elastic:main Oct 5, 2023
@jsoriano jsoriano deleted the validate-arrays-of-objects branch October 5, 2023 16:48
jsoriano added a commit that referenced this pull request Sep 9, 2024
We added some additional validations for subobjects and arrays of objects
in #1498, #1489 and related PRs. These validations only apply to packages
with spec starting on 3.0.1.

These validations rely on the structure of documents. With the adoption of
features like `subobjects: false` or synthetic source the structure is lost, and
exceptions based on spec version are not working, so the tests fail for cases
where they should not for versions of the spec older than 3.0.1. This happens
for example in the `dns` data stream of the `network_traffic` package when
LogsDB is enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field validation failing for array of objects

3 participants