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

Semantic validations #160

Merged
merged 18 commits into from
Apr 22, 2021
Merged

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Apr 20, 2021

What does this PR do?

This PR introduces semantic validations to the Package Spec. Semantic validations are validations of the package spec that cannot be achieved simply by adding declarative rules to the package spec, but instead may require some amount of programming to express the rules.

To demonstrate how semantic validations can be written, this PR implements the following semantic validation rule:

Validate that the id fields inside Kibana object files have the same value as the object filename (minus the .json extension, of course)

A follow up PR will implement a second semantic validation rule:

Validate that there are no dangling references to Kibana objects in any Kibana object files within the scope of a package. That is, if a Kibana object file in package P references another Kibana object with ID i, then there must exist a Kibana object file for id i in package P

Why is it important?

To enforce semantic constraints on package elements.

Checklist

Related issues

@elasticmachine
Copy link

elasticmachine commented Apr 20, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #160 updated

  • Start Time: 2021-04-21T20:12:10.513+0000

  • Duration: 7 min 2 sec

  • Commit: 63a6d6d

Trends 🧪

Image of Build Times

@ycombinator ycombinator marked this pull request as ready for review April 20, 2021 19:48
@ycombinator ycombinator requested a review from mtojek April 20, 2021 19:48
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I left a couple of questions/ideas in comments. The idea is great as it's much simpler than building a dedicated AST.

We need to remember that it will produce additional technical debt on porting the validator to other languages (but it's acceptable).

As this PR changes interfaces for package-spec, which approach is better:

  1. Push this PR to master, then to elastic-package, and integrations (I assume you'll have to fix some packages) and then iterate on new rules.
  2. Push this PR to master, add more rules (at least the TODO one) and then push everything further.

code/go/internal/validator/spec.go Outdated Show resolved Hide resolved
code/go/pkg/validator/errors.go Show resolved Hide resolved
@ycombinator
Copy link
Contributor Author

We need to remember that it will produce additional technical debt on porting the validator to other languages (but it's acceptable).

Agreed. This is why I created a new Golang package, semantic, which is where we should keep all these semantic validation implementations. That way, at least it's easy to find all the semantic validations in a single place when porting them over to another language.

BTW, I think we have a similar issue with the format checkers implementation. Maybe we should move all format checker code into this semantic package as well? WDYT?

@ycombinator
Copy link
Contributor Author

ycombinator commented Apr 21, 2021

As this PR changes interfaces for package-spec, which approach is better:

  1. Push this PR to master, then to elastic-package, and integrations (I assume you'll have to fix some packages) and then iterate on new rules.
  2. Push this PR to master, add more rules (at least the TODO one) and then push everything further.

I think option 1 is better, especially since there may be fixes to some integrations packages as a result. That way the PR to integrations can not only update the elastic-package dependency but also have these fixes, but also remain relatively small in size. Plus this way we can rollout at least one semantic validation out sooner.

Later we can similarly make a second set of PRs for the second semantic validation rule (the one marked as TODO in this PR).

@ycombinator ycombinator requested a review from mtojek April 21, 2021 19:38
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

BTW, I think we have a similar issue with the format checkers implementation. Maybe we should move all format checker code into this semantic package as well? WDYT?

SGTM, you can open an issue to refactor them too or modify in one next PRs (up to you).

@ycombinator
Copy link
Contributor Author

SGTM, you can open an issue to refactor them too or modify in one next PRs (up to you).

Okay, I will do this in a follow up PR soon after this one is merged.

@ycombinator
Copy link
Contributor Author

@mtojek I made a non-trivial change to make CI green again on this PR: 4230c1a. Please re-review. Thanks!

@ycombinator ycombinator requested a review from mtojek April 21, 2021 20:06
@ycombinator ycombinator mentioned this pull request Apr 21, 2021
2 tasks
@ycombinator ycombinator merged commit 92ee6e4 into elastic:master Apr 22, 2021
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.

3 participants