Skip to content
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

Fix validation of multi-fields of external fields #1335

Merged
merged 17 commits into from
Jul 10, 2023

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Jun 29, 2023

Refactor validator so it preloads external fields instead of loading them on demand when requested. This allows to have a single implementation of external fields resolution.

Regarding multi-fields in external fields, it was not possible to validate them before because it was not possible to differentiate them from undefined fields without previously resolving the parent. This would require to resolve the parent for all unknown fields that were potential children of external fields. Now they are preloaded, so they can be directly validated.

There was also an error in dependency management that was being ignored to help on testing. This error is reported now, and tests depending on this explicitly disable dependency management to avoid it.

The status data stream of the mongodb package from elastic/integrations#6692 is included here as a test case for time series and multi-fields. This is required because enabling synthetic source is the only way we have now to find multi-fields in test documents.

Fix #1334.

@jsoriano jsoriano requested a review from a team June 29, 2023 18:30
@jsoriano jsoriano self-assigned this Jun 29, 2023
@jsoriano
Copy link
Member Author

test integrations

@elasticmachine
Copy link
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6756

@jsoriano
Copy link
Member Author

test integrations

@elasticmachine
Copy link
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6756

injectOptions := fields.InjectFieldsOptions{
// Keep External parameter when rendering fields, so we can render
// documentation for empty groups imported from ECS, for backwards compatibility.
KeepExternal: true,
Copy link
Member Author

@jsoriano jsoriano Jun 30, 2023

Choose a reason for hiding this comment

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

This parameter for fields injection can be a bit difficult to follow. Its only purpose is to mimic a collateral behaviour we had with lazy resolution of external fields: In some places we were skipping group fields when they were empty. But this was not happening with external fields, because on these checks the field was still unresolved.

We may argue that this behaviour is unexpected and we should fix it instead, because it treats fields on different ways depending if they are external or not. But fixing this would break CI builds of packages, because it changes what fields are rendered.

This flag helps keeping the old behaviour for rendered documentation:

  • When rendering documentation, we keep external, so we can keep the old behaviour.
  • In other cases, such as when resolving external fields in package builds, we remove the "external" parameter once the field is injected, so it is not written to fields files. On these cases we may be removing empty groups from built fields files, but this is actually good because they don't generate any meaningful mapping.

@jsoriano
Copy link
Member Author

test integrations

@jsoriano
Copy link
Member Author

Something is happening with buildkite 🤔

@mrodm
Copy link
Contributor

mrodm commented Jul 3, 2023

buildkite test this

@mrodm
Copy link
Contributor

mrodm commented Jul 3, 2023

test integrations

@elasticmachine
Copy link
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6756

@jsoriano
Copy link
Member Author

jsoriano commented Jul 3, 2023

/test

@jsoriano
Copy link
Member Author

jsoriano commented Jul 3, 2023

test integrations

@elasticmachine
Copy link
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6756

@jsoriano
Copy link
Member Author

jsoriano commented Jul 3, 2023

test integrations

@elasticmachine
Copy link
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6756

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @jsoriano

@jsoriano
Copy link
Member Author

jsoriano commented Jul 4, 2023

test integrations

@elasticmachine
Copy link
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6756

Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

Great job fixing this and supporting backwards compatibility! 💪

internal/fields/validate.go Show resolved Hide resolved
@jlind23
Copy link
Collaborator

jlind23 commented Jul 10, 2023

@mrodm as @jsoriano is out for now, can we please make this land?

@mrodm
Copy link
Contributor

mrodm commented Jul 10, 2023

@mrodm as @jsoriano is out for now, can we please make this land?

@jlind23 sure, I'll merge this PR since all these changes look good to me.
To release a new elastic-package version, I would wait for @jsoriano last check, in case it is better to test or add something else first.

@jlind23
Copy link
Collaborator

jlind23 commented Jul 10, 2023

@mrodm sounds good to me, thanks.

@mrodm mrodm merged commit 744a033 into elastic:main Jul 10, 2023
6 checks passed
jsoriano added a commit that referenced this pull request Sep 18, 2023
We inject fields from ECS on different scenarios: when generating documentation,
when building packages, or when validating documents in tests.

On #1335 we did a refactor around this, to fix some validation issues, in a way that
more code is reused between all these uses. After this change, validation used field
definitions that include the already resolved external fields, but we weren't including
there information that was used by validators, what included validation of expected
and allowed values.

So these validations haven't been executed since then.

Tests have been included to try to avoid regressions related to this in the future.
bhapas pushed a commit to bhapas/elastic-package that referenced this pull request Sep 21, 2023
We inject fields from ECS on different scenarios: when generating documentation,
when building packages, or when validating documents in tests.

On elastic#1335 we did a refactor around this, to fix some validation issues, in a way that
more code is reused between all these uses. After this change, validation used field
definitions that include the already resolved external fields, but we weren't including
there information that was used by validators, what included validation of expected
and allowed values.

So these validations haven't been executed since then.

Tests have been included to try to avoid regressions related to this in the future.
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.

Error: undefined field for ECS multi-field mapping
4 participants