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

Move existing Filebeat generator logic to package generator #7506

Closed

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Jul 4, 2018

I am splitting up #6912 to make rebasing it a bit easier.
This PR moves the current generator logic, including module, fileset and fields.yml generators, to a different package.

Blocks #6912

@kvch kvch added review refactoring Filebeat Filebeat :Generator Related to code generators for building custom Beats or modules. labels Jul 4, 2018

replace := map[string]string{"module": module}
templatesPath := path.Join(beatsPath, "scripts", "module")
filesToCopy := []string{
Copy link
Member

Choose a reason for hiding this comment

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

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 calls generator.CopyTemplates which not only copies the files, but substitutes the template strings in copied files. I think apart from copying, there is not so much to share.

I could move Copy from the package mage to libbeat/utils or libbeat/common/utils and use it from there. It would be a bit bigger undertaking, as right now files are copied one-by-one and after each file is copied, the substitution is done. If I use this, I need to change the algorithm to substitute template strings after the file is copied. It would also mean that each file would need to be opened, read and written twice, once to copy it and once to substitute strings.

However, if I do so, I would rather refactor all generators and other possible places where files are copied. So I would rather address this in a follow up PR. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

return fmt.Errorf("module already exists: %s", module)
}

err := generator.CreateDirectories(modulePath, []string{path.Join("_meta", "kibana", "6")})
Copy link
Member

Choose a reason for hiding this comment

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

I'm asking myself what version should it be here. And if we have the module generator as part of the beat, should we directly create the dashboard directory. Some users could also use 5.x or in the future 7.x with this beat version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we make it configurable? Maybe passing a param using a flag e.g. --kibana-version? It could be 6 by default until we release version 7.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of having the module generator creating the correct directory, it perhaps should be the kibana exporting command that takes care of the directory creation. So we don't create the directories here but they are only add when someone actually exports dashboards. It would be mean we have to add some knowledge about modules and Kibana directories to the exported but I think that would make sense.

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 it's a good idea.
I am wondering if there are use cases when a users would need directories without calling export. But I don't see any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When would you create the directory? The exporter AFAIK prints the exported dashboard to stdout. Do you want it to change it to saving it to a file?

Copy link
Member

Choose a reason for hiding this comment

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

yes, I think we should change the exported. Either to have default to file with the correct file structure or having a config option.

Copy link
Member

Choose a reason for hiding this comment

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

Note: I would not change the exporter in this PR.

@kvch kvch force-pushed the refactor/filebeat/move-fields-yml-generator branch from e6ebaf7 to bb163fe Compare July 17, 2018 08:32
@ruflin
Copy link
Member

ruflin commented Jul 18, 2018

How does this PR conflict with #7533 ?

@kvch
Copy link
Contributor Author

kvch commented Jul 18, 2018

I am moving the code I edit in the other PR to a different package in this one.

@ruflin
Copy link
Member

ruflin commented Jul 18, 2018

I'm ok with moving the refactoring to an other PR and merge this one. The reason I think it does not fit well into #7506 is because there a large part of the code is also moved around which will make it very hard to follow the diff. So my preferred option would be to have a follow up PR of this that takes care of the refactoring and then #7506 is rebase on top of it.

#7506 is the reason for me the refactoring becomes more important as the code is moved from dev only usage to production usage.

@kvch
Copy link
Contributor Author

kvch commented Jul 18, 2018

Works for me.

@ruflin
Copy link
Member

ruflin commented Jul 18, 2018

Ups, my comment above was intended to be on #7533. That is why I referenced this PR. Let's sync up offline on the order and cleanup of the PR's.

@kvch
Copy link
Contributor Author

kvch commented Nov 19, 2018

Closing in favour of a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Filebeat Filebeat :Generator Related to code generators for building custom Beats or modules. refactoring review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants