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

Support flat and extended manifest files #130

Merged
merged 12 commits into from
Oct 13, 2020

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented Oct 7, 2020

Issue: elastic/package-spec#55

Changes introduced in the PR:

  • use ucfg to support both flat and extended manifest files
  • fix visibility of manifest related structures (all visible)
  • replace VarValue (scalar/list) with interface{}
  • fix comments in multiple places (mainly: dataStream)

@mtojek mtojek requested a review from ycombinator October 7, 2020 12:14
@mtojek mtojek self-assigned this Oct 7, 2020
@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 7, 2020

💚 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 #130 updated]

  • Start Time: 2020-10-13T10:51:02.284+0000

  • Duration: 11 min 50 sec

@mtojek mtojek marked this pull request as ready for review October 7, 2020 13:03
// manifest file.
type VarValue struct {
scalar string
list []string
Copy link
Contributor

@ycombinator ycombinator Oct 8, 2020

Choose a reason for hiding this comment

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

I'm curious why you removed VarValue and replaced it with the broader interface{} type. AFAICT the only types of values allowed for input configuration variables are scalars (int, string, boolean, etc.) or lists of scalars. We don't support maps/dicts. That was the intent behind creating a stricter VarValue type that codified these rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because of ucfg which (I suppose) doesn't support UnmarshalYAML and MarshalJSON methods. It seemed to me that the codebase would be smaller, although I'm aware of the risk you brought here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you keep VarValue and make it implement https://godoc.org/github.com/elastic/go-ucfg#ConfigUnpacker somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can try to do this, although I'm not convinced it will work (didn't see this earlier).

I see the benefits of having stricter VarValue type, so if you prefer I can switch back from ucfg to our implementation and extend it with same trick for expanding config map keys as in package-spec.

Copy link
Contributor

@ycombinator ycombinator Oct 8, 2020

Choose a reason for hiding this comment

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

Thanks, I appreciate you giving it a try. There are a few examples of implementing ConfigUnpacker in the Beats repo. You can find them in your IDE with this regex: func \(.* Unpack\(.*Config.

If you succeed, it would allow us to preserve the strictness of what a variable value can be, which is very nice.

If it doesn't work, let's stick with ucfg and reduce the strictness of what a variable value can be by replacing VarValue with interface{}. I think that's the better tradeoff than implementing some trick to parse flat values with the yaml package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got it fixed. Let's see what CI will say.

type Variable struct {
Name string `config:"name" json:"name" yaml:"name"`
Type string `config:"type" json:"type" yaml:"type"`
Default interface{} `config:"default" json:"default" yaml:"default"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we're introducing the config struct tags for ucfg's benefit, do we still need to keep the yaml struct tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right, although I have to check whether we don't call yaml.Marshal somewhere...

type policyTemplate struct {
Inputs []input `json:"inputs"`
// PolicyTemplate is a configuration of inputs responsible for collecting log or metric data.
type PolicyTemplate struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the visibility change needed for ucfg to work correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's due to consistency. If somebody wants to use Manifest structure and extract policy templates to a separate variable, it wouldn't be possible (can't use a package visible field). In general exposed fields should use public structures.

@mtojek
Copy link
Contributor Author

mtojek commented Oct 12, 2020

/test

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM. WFG.

@mtojek
Copy link
Contributor Author

mtojek commented Oct 12, 2020

Something didn't work here:

[2020-10-12T17:03:59.994Z] 2020/10/12 17:03:59 DEBUG found 0 hits in logs-apache.access-ep data stream
[2020-10-12T17:04:00.940Z] 2020/10/12 17:04:00 DEBUG found 0 hits in logs-apache.access-ep data stream
[2020-10-12T17:04:01.885Z] 2020/10/12 17:04:01 DEBUG found 0 hits in logs-apache.access-ep data stream
[2020-10-12T17:04:02.829Z] 2020/10/12 17:04:02 DEBUG found 0 hits in logs-apache.access-ep data stream
[2020-10-12T17:04:03.777Z] System test for apache/access data stream failed

I will investigate it tomorrow.

@mtojek
Copy link
Contributor Author

mtojek commented Oct 13, 2020

Ok, I approached the next issue:

[2020-10-13T09:42:07.328Z] Error: error running package system tests: locating data stream root failed: verifying manifest file failed (path: /var/lib/jenkins/workspace/Beats_elastic-package_PR-130/src/github.com/elastic/elastic-package/test/packages/apache/data_stream/status/manifest.yml): reading package manifest failed (path: /var/lib/jenkins/workspace/Beats_elastic-package_PR-130/src/github.com/elastic/elastic-package/test/packages/apache/data_stream/status/manifest.yml): unpacking data stream manifest failed (path: /var/lib/jenkins/workspace/Beats_elastic-package_PR-130/src/github.com/elastic/elastic-package/test/packages/apache/data_stream/status/manifest.yml): type mismatch accessing 'streams.0.vars.0.default' (source:'/var/lib/jenkins/workspace/Beats_elastic-package_PR-130/src/github.com/elastic/elastic-package/test/packages/apache/data_stream/status/manifest.yml')

@mtojek
Copy link
Contributor Author

mtojek commented Oct 13, 2020

Ok, it looks that I fixed it finally. VarVariable can be either interface{} or []interface{}. Initially we forgot that's not just string (array of strings).

@mtojek mtojek merged commit 392c5dc into elastic:master Oct 13, 2020
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