Skip to content

Commit

Permalink
Generate configuration from mage for all Beats (elastic#12618)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kvch authored Jun 25, 2019
1 parent 9a18874 commit 5a16af8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
52 changes: 52 additions & 0 deletions _meta/beat.reference.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
###################### Journalbeat Configuration Example #########################

# This file is an example configuration file highlighting only the most common
# options. The journalbeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/journalbeat/index.html

# For more available modules and options, please see the journalbeat.reference.yml sample
# configuration file.

#=========================== Journalbeat inputs =============================

journalbeat.inputs:
# Paths that should be crawled and fetched. Possible values files and directories.
# When setting a directory, all journals under it are merged.
# When empty starts to read from local journal.
- paths: []

# The number of seconds to wait before trying to read again from journals.
#backoff: 1s
# The maximum number of seconds to wait before attempting to read again from journals.
#max_backoff: 20s

# Position to start reading from journal. Valid values: head, tail, cursor
seek: cursor
# Fallback position if no cursor data is available.
#cursor_seek_fallback: head

# Exact matching for field values of events.
# Matching for nginx entries: "systemd.unit=nginx"
#include_matches: []

# Optional fields that you can specify to add additional information to the
# output. Fields can be scalar values, arrays, dictionaries, or any nested
# combination of these.
#fields:
# env: staging


#========================= Journalbeat global options ============================
#journalbeat:
# Name of the registry file. If a relative path is used, it is considered relative to the
# data path.
#registry_file: registry

#==================== Elasticsearch template setting ==========================
setup.template.settings:
index.number_of_shards: 1
#index.codec: best_compression
#_source.enabled: false
22 changes: 10 additions & 12 deletions journalbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ setup.template.settings:

#============================= Elastic Cloud ==================================

# These settings simplify using journalbeat with the Elastic Cloud (https://cloud.elastic.co/).
# These settings simplify using Journalbeat with the Elastic Cloud (https://cloud.elastic.co/).

# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
Expand Down Expand Up @@ -434,7 +434,6 @@ output.elasticsearch:
# never, once, and freely. Default is never.
#ssl.renegotiation: never


#----------------------------- Logstash output ---------------------------------
#output.logstash:
# Boolean flag to enable or disable the output module.
Expand Down Expand Up @@ -578,7 +577,7 @@ output.elasticsearch:
#username: ''
#password: ''

# Kafka version journalbeat is assumed to run against. Defaults to the "1.0.0".
# Kafka version Journalbeat is assumed to run against. Defaults to the "1.0.0".
#version: '1.0.0'

# Configure JSON encoding
Expand Down Expand Up @@ -835,7 +834,7 @@ output.elasticsearch:
#filename: journalbeat

# Maximum size in kilobytes of each file. When this size is reached, and on
# every journalbeat restart, the files are rotated. The default value is 10240
# every Journalbeat restart, the files are rotated. The default value is 10240
# kB.
#rotate_every_kb: 10000

Expand All @@ -847,7 +846,6 @@ output.elasticsearch:
# Permissions to use for file creation. The default is 0600.
#permissions: 0600


#----------------------------- Console output ---------------------------------
#output.console:
# Boolean flag to enable or disable the output module.
Expand All @@ -863,26 +861,26 @@ output.elasticsearch:

#================================= Paths ======================================

# The home path for the journalbeat installation. This is the default base path
# The home path for the Journalbeat installation. This is the default base path
# for all other path settings and for miscellaneous files that come with the
# distribution (for example, the sample dashboards).
# If not set by a CLI flag or in the configuration file, the default for the
# home path is the location of the binary.
#path.home:

# The configuration path for the journalbeat installation. This is the default
# The configuration path for the Journalbeat installation. This is the default
# base path for configuration files, including the main YAML configuration file
# and the Elasticsearch template file. If not set by a CLI flag or in the
# configuration file, the default for the configuration path is the home path.
#path.config: ${path.home}

# The data path for the journalbeat installation. This is the default base path
# for all the files in which journalbeat needs to store its data. If not set by a
# The data path for the Journalbeat installation. This is the default base path
# for all the files in which Journalbeat needs to store its data. If not set by a
# CLI flag or in the configuration file, the default for the data path is a data
# subdirectory inside the home path.
#path.data: ${path.home}/data

# The logs path for a journalbeat installation. This is the default location for
# The logs path for a Journalbeat installation. This is the default location for
# the Beat's log files. If not set by a CLI flag or in the configuration file,
# the default for the logs path is a logs subdirectory inside the home path.
#path.logs: ${path.home}/logs
Expand Down Expand Up @@ -1087,7 +1085,7 @@ setup.kibana:
# Send all logging output to Windows Event Logs. The default is false.
#logging.to_eventlog: false

# If enabled, journalbeat periodically logs its internal metrics that have changed
# If enabled, Journalbeat periodically logs its internal metrics that have changed
# in the last period. For each metric that changed, the delta from the value at
# the beginning of the period is logged. Also, the total values for
# all non-zero internal metrics are logged on shutdown. The default is true.
Expand Down Expand Up @@ -1134,7 +1132,7 @@ logging.files:


#============================== Xpack Monitoring ===============================
# journalbeat can export internal metrics to a central Elasticsearch monitoring
# Journalbeat can export internal metrics to a central Elasticsearch monitoring
# cluster. This requires xpack monitoring to be enabled in Elasticsearch. The
# reporting is disabled by default.

Expand Down
2 changes: 1 addition & 1 deletion journalbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ setup.kibana:

#============================= Elastic Cloud ==================================

# These settings simplify using journalbeat with the Elastic Cloud (https://cloud.elastic.co/).
# These settings simplify using Journalbeat with the Elastic Cloud (https://cloud.elastic.co/).

# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
Expand Down
5 changes: 5 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,8 @@ func selectImage(platform string) (string, error) {

return devtools.BeatsCrossBuildImage + ":" + goVersion + "-" + tagSuffix, nil
}

// Config generates both the short/reference/docker configs.
func Config() error {
return devtools.Config(devtools.AllConfigTypes, devtools.ConfigFileParams{}, ".")
}

0 comments on commit 5a16af8

Please sign in to comment.