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

New subcommand: generate #6912

Closed

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Apr 20, 2018

A new subcommand is added named generate to all Beats. This command has a few more subcommands in case of Filebeat.

Motivation

This is the next baby step to removing Python from make update and making it possible for all users without development envs to generate files, if they edited something locally (including generating FB module).

Subcommands in case of all Beats (e.g. Metricbeat):

$ ./metricbeat generate -h
Generate files for Metricbeat

Usage:
  metricbeat generate [command]

Available Commands:
  global-fields        Generate global fields.yml for Metricbeat
  kibana-index-pattern Generate Kibana index pattern for Metricbeat

Flags:
      --beats_path string    (default "..")
  -h, --help                help for generate

Subcommands of generate:

  1. global-fields: The existing fields.yml collector is ported to Golang and is unified for all Beats. The behaviour is not changed. The collected fields.yml files are concatenated into one global fields.yml and placed under _meta.
  2. kibana-index-pattern: The existing Golang script is exposed as a subcommand.

Subcommands of Filebeat:

$ ./filebeat generate -h
Generate files for Filebeat

Usage:
  filebeat generate [command]

Available Commands:
  fields               Generate fields.yml for a fileset
  fileset              Generate a new Filebeat fileset
  global-fields        Generate global fields.yml for Filebeat
  kibana-index-pattern Generate Kibana index pattern for Filebeat
  module               Generate a new Filebeat module

Flags:
      --beats_path string    (default "..")
  -h, --help                help for generate

Special subcommands of Filebeat:

  1. fields: Existing script is exposed.
  2. fileset: Existing script is exposed.
  3. module: Existing script is exposed.

Misc additions

  • Main logic of Filebeat generators is moved to filebeat/generator from filebeat/scripts/generator
  • Remove an unnecessary param from subcommands of keystore
  • Fix tyop in Kibana index pattern

TODO

  • refactor Kibana index pattern generator
  • more verbose help

Depends on: #6911

@kvch kvch added in progress Pull request is currently in progress. review Filebeat Filebeat libbeat labels Apr 20, 2018
return bytes.Join([][]byte{newline, content}, empty)
}

func Generate(beatsPath, beatName string, files []*YmlFile) error {

Choose a reason for hiding this comment

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

exported function Generate should have comment or be unexported

libbeatFields = "libbeat/processors/*/_meta/fields.yml"
)

type YmlFile struct {

Choose a reason for hiding this comment

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

exported type YmlFile should have comment or be unexported

@@ -418,6 +419,38 @@ func (b *Beat) Setup(bt beat.Creator, template, dashboards, machineLearning, pip
}())
}

// Setup registers ES index template and kibana dashboards

Choose a reason for hiding this comment

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

comment on exported method Beat.GenerateGlobalFields should be of the form "GenerateGlobalFields ..."

)

var (
BeatsPath = flag.String("beats_path", "..", "")

Choose a reason for hiding this comment

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

exported var BeatsPath should have comment or be unexported


err = writeFieldsYml(beatsPath, moduleName, filesetName, d)
if err != nil {
return fmt.Errorf("cannot write field.yml of fileset: %v\n", err)

Choose a reason for hiding this comment

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

error strings should not be capitalized or end with punctuation or a newline

var d []byte
d, err = p.toFieldsYml(noDoc)
if err != nil {
return fmt.Errorf("cannot generate fields.yml for fileset: %v\n", err)

Choose a reason for hiding this comment

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

error strings should not be capitalized or end with punctuation or a newline

func Generate(moduleName, filesetName, beatsPath string, noDoc bool) error {
p, err := readPipeline(beatsPath, moduleName, filesetName)
if err != nil {
return fmt.Errorf("cannot read pipeline.yml of fileset: %v\n", err)

Choose a reason for hiding this comment

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

error strings should not be capitalized or end with punctuation or a newline

return nil
}

func Generate(moduleName, filesetName, beatsPath string, noDoc bool) error {

Choose a reason for hiding this comment

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

exported function Generate should have comment or be unexported


modulePath := path.Join(modulesPath, "module", moduleName)
if !generator.DirExists(modulePath) {
return fmt.Errorf("cannot generate fileset: module not exists, please create module first by create-module command\n")

Choose a reason for hiding this comment

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

error strings should not be capitalized or end with punctuation or a newline

@kvch kvch removed the review label May 14, 2018
@kvch kvch force-pushed the feature/libbeat/new-subcommand-generate branch from 16b848e to 74dd3ea Compare July 3, 2018 15:36
@kvch kvch force-pushed the feature/libbeat/new-subcommand-generate branch from 619b9e8 to 789170a Compare July 3, 2018 16:03
@kvch
Copy link
Contributor Author

kvch commented Jul 3, 2018

I rebased the PR. But it still has a few minor problems, before it becomes ready to review.

@kvch
Copy link
Contributor Author

kvch commented Jan 16, 2019

Closing in favour of #9314

@kvch kvch closed this Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Filebeat Filebeat in progress Pull request is currently in progress. libbeat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants