Skip to content

Refactor schema reader to use intermediate schema structure#722

Merged
marshallmain merged 4 commits intoelastic:masterfrom
marshallmain:schema-nesting
Jan 21, 2020
Merged

Refactor schema reader to use intermediate schema structure#722
marshallmain merged 4 commits intoelastic:masterfrom
marshallmain:schema-nesting

Conversation

@marshallmain
Copy link
Copy Markdown
Contributor

This PR improves the ECS ability to nest reusable fields inside other reusable field sets. Currently there is at least one example of multiple reuse: "group" fields are reused in "user", and "user" is then reused by "client", "destination", "host", "server", and "source". However, the implementation in master depends on the "group" fields being copied to "user" before all of the "user" fields are copied to the final locations. This works because the "group" key comes before the "user" key when iterating over the keys in the schema dictionary, but this will not be the case for other places we might want to use multi-level nesting.

This PR adds an intermediate data structure representing the schema which contains references to reused field sets rather than immediately copying them. Using references removes the dependency on the order fieldsets are read in. The intermediate representation is then rendered into the same formats as before by recursively replacing the references with copies.

The output from the refactored version diverges from the original in a few ways. Most notably original_fieldset now refers to the closest reusable fieldset (previously client.user.group.domain would have original_fieldset: user instead of original_fieldset: group). original_fieldset is also populated in every reusable fieldset, even when the fieldset is not embedded. dashed_name now matches flat_name more closely.

Reopened version of #707 reapplying changes on top of master

Copy link
Copy Markdown
Contributor

@webmat webmat left a comment

Choose a reason for hiding this comment

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

Thanks for this, @marshallmain! This is looking great :-)

  • Could you add back a few tests? They don't need to cover all edge cases, but perhaps 1 or 2 tests exercising each of flatten_fields and cleanup_fields_recursive.
  • Please add a changelog entry to the "tooling" section

1.5.0-dev,true,client,client.as.number,long,extended,15169,Unique number allocated to the autonomous system. The autonomous system number (ASN) uniquely identifies each network on the Internet.
1.5.0-dev,true,client,client.as.organization.name,keyword,extended,Google LLC,Organization name.
1.5.0-dev,true,client,as.organization.name.text,text,extended,Google LLC,Organization name.
1.5.0-dev,true,client,client.as.organization.name.text,text,extended,Google LLC,Organization name.
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.

Hadn't noticed that before.

PRs that come with bugfixes are my favourites ;-)

@webmat
Copy link
Copy Markdown
Contributor

webmat commented Jan 20, 2020

Once we're done with this PR we should revisit #698

@marshallmain
Copy link
Copy Markdown
Contributor Author

Thanks for the review @webmat ! I'm planning to add the tests and changelog tomorrow so we can get this merged.

Copy link
Copy Markdown
Contributor

@webmat webmat left a comment

Choose a reason for hiding this comment

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

Looking great, thanks for adding the tests 👍

@marshallmain marshallmain merged commit 68afbb8 into elastic:master Jan 21, 2020
dcode pushed a commit to dcode/ecs that referenced this pull request Apr 15, 2020
)

* refactor schema reader to use intermediate schema structure

* remove logic for '.' notation in reusable field names

* update changelog.next.md

* Add tests for intermediate schema data structures
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.

2 participants