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

Generate configuration from mage for all Beats #12618

Merged
merged 19 commits into from
Jun 25, 2019

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Jun 19, 2019

From now on all Beats use mage when generating configuration files. This comes with the following changes:

  • Heartbeat does not use post_process_config.py to modify processors, instead it is added using the templating
  • Functionbeat does not include unsupported outputs
  • All Beats can alter the common configuration coming from libbeat.

What does it mean for Community Beats?

When adopting this version of libbeat, you need to make sure that you have a target named Config in your magefile.go. An example target which generates a sample configuration, a reference configuration and a Docker configuration from {yourbeat}/_meta/beat.yml and the common configuration from libbeat is the following:

import devtools "github.com/elastic/beats/dev-tools/mage"

func Config() error {
    return devtools.Config(devtools.AllConfigTypes, devtools.ConfigFileParams{}, ".")
}

If the configuration of your Beat consists of multiple files, you can pass your own instance of ConfigFileParams:

func ConfigFileParams() devtools.ConfigFileParams {
    return devtools.ConfigFileParams{
        ShortParts: []string{
            devtools.OSSBeatDir("_meta/beat.yml"),
            devtools.OSSBeatDir("_meta/beat.custom.yml"),
            devtools.LibbeatDir("_meta/config.yml.tmpl"),
        },
        ReferenceParts: []string{
            devtools.OSSBeatDir("_meta/beat.reference.yml"),
            devtools.OSSBeatDir("_meta/beat.custom.referenceyml"),
            devtools.LibbeatDir("_meta/config.reference.yml.tmpl"),
        },
        DockerParts: []string{
            devtools.OSSBeatDir("_meta/beat.docker.yml"),
            devtools.LibbeatDir("_meta/config.docker.yml"),
        },
    }
}

It is also possible to pass variables to the templates using the ExtraVars attribute of ConfigFileParams struct.

@kvch kvch added the review label Jun 19, 2019
@kvch kvch requested review from a team as code owners June 19, 2019 17:44
libbeat/_meta/config.yml.tmpl Show resolved Hide resolved
libbeat/scripts/Makefile Show resolved Hide resolved
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 — tested that nothing broken from a Stack Monitoring metricsets/filesets config generation POV. Nice change!

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

LGTM, only a last small detail

libbeat/_meta/config.yml.tmpl Outdated Show resolved Hide resolved
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

Lovely 👍, no more cat + sed + bash + make magic.

libbeat/tests/system/input/libbeat.yml Outdated Show resolved Hide resolved
metricbeat/scripts/mage/config.go Outdated Show resolved Hide resolved
metricbeat/scripts/mage/config.go Outdated Show resolved Hide resolved
libbeat/_meta/config.yml.tmpl Outdated Show resolved Hide resolved
libbeat/_meta/config.reference.yml.tmpl Outdated Show resolved Hide resolved
@kvch kvch force-pushed the fix-functionbeat-exclude-invalid-outputs branch from b1205f1 to 61de1b5 Compare June 24, 2019 10:47
@kvch kvch force-pushed the fix-functionbeat-exclude-invalid-outputs branch from 61de1b5 to aaea913 Compare June 25, 2019 13:31
@kvch
Copy link
Contributor Author

kvch commented Jun 25, 2019

Failing tests are unrelated.

@kvch kvch merged commit 055dec8 into elastic:master Jun 25, 2019
@urso urso added the libbeat label Jul 4, 2019
DStape pushed a commit to DStape/beats that referenced this pull request Aug 20, 2019
From now on all Beats use `mage` when generating configuration files. This comes with the following changes:
* Heartbeat does not use `post_process_config.py` to modify processors, instead it is added using the templating
* Functionbeat does not include unsupported outputs
* All Beats can alter the common configuration coming from `libbeat`.

### What does it mean for Community Beats?
When adopting this version of `libbeat`, you need to make sure that you have a target named `Config` in your `magefile.go`. An example target which generates a sample configuration, a reference configuration and a Docker configuration from `{yourbeat}/_meta/beat.yml` and the common configuration from `libbeat` is the following:
```golang
import devtools "github.com/elastic/beats/dev-tools/mage"

func Config() error {
    return devtools.Config(devtools.AllConfigTypes, devtools.ConfigFileParams{}, ".")
}
```
If the configuration of your Beat consists of multiple files, you can pass your own instance of `ConfigFileParams`:
```golang
func ConfigFileParams() devtools.ConfigFileParams {
    return devtools.ConfigFileParams{
        ShortParts: []string{
            devtools.OSSBeatDir("_meta/beat.yml"),
            devtools.OSSBeatDir("_meta/beat.custom.yml"),
            devtools.LibbeatDir("_meta/config.yml.tmpl"),
        },
        ReferenceParts: []string{
            devtools.OSSBeatDir("_meta/beat.reference.yml"),
            devtools.OSSBeatDir("_meta/beat.custom.referenceyml"),
            devtools.LibbeatDir("_meta/config.reference.yml.tmpl"),
        },
        DockerParts: []string{
            devtools.OSSBeatDir("_meta/beat.docker.yml"),
            devtools.LibbeatDir("_meta/config.docker.yml"),
        },
    }
}
```
It is also possible to pass variables to the templates using the `ExtraVars` attribute of `ConfigFileParams` struct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants