-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Generator] Fix metricbeat-style custom beats #13293
Changes from all commits
46bc736
3512651
bf67014
1448fe6
b11269a
7e5f211
b9f5611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{{.BeatName}}.config.modules: | ||
path: ${path.config}/modules.d/*.yml | ||
reload.enabled: false | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be good if metricbeat would use the same files, so we remember to maintain them. Maybe a way to do it is to generate a custom beat called "metricbeat", and check that these files are the same as the ones for the real Metricbeat. But let's forget about this by now. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
########################## {{.BeatName}} Configuration ########################### | ||
|
||
# This file is a full configuration example documenting all non-deprecated | ||
# options in comments. For a shorter configuration example, that contains only | ||
# the most common options, please see metricbeat.yml in the same directory. | ||
# | ||
# You can find the full configuration reference here: | ||
# https://www.elastic.co/guide/en/beats/metricbeat/index.html | ||
|
||
#============================ Config Reloading =============================== | ||
|
||
# Config reloading allows to dynamically load modules. Each file which is | ||
# monitored must contain one or multiple modules as a list. | ||
{{.BeatName}}.config.modules: | ||
|
||
# Glob pattern for configuration reloading | ||
path: ${path.config}/modules.d/*.yml | ||
|
||
# Period on which files under path should be checked for changes | ||
reload.period: 10s | ||
|
||
# Set to true to enable config reloading | ||
reload.enabled: false | ||
|
||
# Maximum amount of time to randomly delay the start of a metricset. Use 0 to | ||
# disable startup delay. | ||
{{.BeatName}}.max_start_delay: 10s | ||
|
||
#============================== Autodiscover =================================== | ||
|
||
# Autodiscover allows you to detect changes in the system and spawn new modules | ||
# as they happen. | ||
|
||
#{{.BeatName}}.autodiscover: | ||
# List of enabled autodiscover providers | ||
# providers: | ||
# - type: docker | ||
# templates: | ||
# - condition: | ||
# equals.docker.container.image: etcd | ||
# config: | ||
# - module: etcd | ||
# metricsets: ["leader", "self", "store"] | ||
# period: 10s | ||
# hosts: ["${host}:2379"] | ||
|
||
#=========================== Timeseries instance =============================== | ||
|
||
# Enabling this will add a `timeseries.instance` keyword field to all metric | ||
# events. For a given metricset, this field will be unique for every single item | ||
# being monitored. | ||
# This setting is experimental. | ||
|
||
#timeseries.enabled: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
#========================== Modules configuration ============================ | ||
|
||
{{.BeatName}}.config.modules: | ||
# Glob pattern for configuration loading | ||
path: ${path.config}/modules.d/*.yml | ||
|
||
# Set to true to enable config reloading | ||
reload.enabled: false | ||
|
||
# Period on which files under path should be checked for changes | ||
#reload.period: 10s | ||
|
||
#==================== Elasticsearch template setting ========================== | ||
|
||
setup.template.settings: | ||
index.number_of_shards: 1 | ||
index.codec: best_compression | ||
#_source.enabled: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/cfgfile" | ||
"github.com/elastic/beats/libbeat/cmd" | ||
) | ||
|
||
// BuildModulesManager adds support for modules management to a beat | ||
func BuildModulesManager(beat *beat.Beat) (cmd.ModulesManager, error) { | ||
config := beat.BeatConfig | ||
|
||
glob, err := config.String("config.modules.path", -1) | ||
if err != nil { | ||
return nil, errors.Errorf("modules management requires '%s.config.modules.path' setting", Name) | ||
} | ||
|
||
if !strings.HasSuffix(glob, "*.yml") { | ||
return nil, errors.Errorf("wrong settings for config.modules.path, it is expected to end with *.yml. Got: %s", glob) | ||
} | ||
|
||
modulesManager, err := cfgfile.NewGlobManager(glob, ".yml", ".disabled") | ||
if err != nil { | ||
return nil, errors.Wrap(err, "initialization error") | ||
} | ||
return modulesManager, nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should move the one in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I can try that. Might not be a bad idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this. We'd need to separate out the ModulesManager and root code in metricbeat, since both the user beats and metricbeat share an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is what I meant with moving to some reusable place 😬 But ok, we can leave this for a future change dedicated only to this. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
cmd "github.com/elastic/beats/libbeat/cmd" | ||
"github.com/elastic/beats/libbeat/cmd/instance" | ||
"github.com/elastic/beats/metricbeat/beater" | ||
"github.com/elastic/beats/metricbeat/cmd/test" | ||
"github.com/elastic/beats/metricbeat/mb/module" | ||
) | ||
|
||
// Name of this beat | ||
var Name = "{beat}" | ||
|
||
// RootCmd to handle beats cli | ||
var RootCmd *cmd.BeatsRootCmd | ||
|
||
var ( | ||
// Use a customized instance of Metricbeat where startup delay has | ||
// been disabled to workaround the fact that Modules() will return | ||
// the static modules (not the dynamic ones) with a start delay. | ||
testModulesCreator = beater.Creator( | ||
beater.WithModuleOptions( | ||
module.WithMetricSetInfo(), | ||
module.WithMaxStartDelay(0), | ||
), | ||
) | ||
) | ||
|
||
func init() { | ||
RootCmd = cmd.GenRootCmdWithSettings(beater.DefaultCreator(), instance.Settings{Name: Name}) | ||
RootCmd.AddCommand(cmd.GenModulesCmd(Name, "", BuildModulesManager)) | ||
RootCmd.TestCmd.AddCommand(test.GenTestModulesCmd(Name, "", testModulesCreator)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!