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

Add option to support moved filebeat modules #9432

Merged
merged 7 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha1...master[Check the HEAD d
- Added `detect_null_bytes` selector to detect null bytes from a io.reader. {pull}9210[9210]
- Added `syslog_host` variable to HAProxy module to allow syslog listener to bind to configured host. {pull}9366[9366]
- Added support on Traefik for Common Log Format and Combined Log Format mixed which is the default Traefik format {issue}8015[8015] {issue}6111[6111] {pull}8768[8768].
- Add option to modules.yml file to indicate that a module has been moved {pull}9432[9432].

*Heartbeat*

Expand Down
26 changes: 26 additions & 0 deletions filebeat/fileset/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/kibana"
Expand Down Expand Up @@ -57,6 +58,12 @@ func newModuleRegistry(modulesPath string,
continue
}

// Look for moved modules
if module, moved := getCurrentModuleName(modulesPath, mcfg.Module); moved {
logp.Warn("Using old name '%s' for module '%s', please update your configuration", mcfg.Module, module)
mcfg.Module = module
}

reg.registry[mcfg.Module] = map[string]*Fileset{}
moduleFilesets, err := getModuleFilesets(modulesPath, mcfg.Module)
if err != nil {
Expand Down Expand Up @@ -180,7 +187,26 @@ func mcfgFromConfig(cfg *common.Config) (*ModuleConfig, error) {
return &mcfg, nil
}

func getCurrentModuleName(modulePath, module string) (string, bool) {
moduleConfigPath := filepath.Join(modulePath, module, "module.yml")
d, err := ioutil.ReadFile(moduleConfigPath)
if err != nil {
return module, false
}

var moduleConfig struct {
MovedTo string `yaml:"movedTo"`
}
err = yaml.Unmarshal(d, &moduleConfig)
if err == nil && moduleConfig.MovedTo != "" {
return moduleConfig.MovedTo, true
}

return module, false
}

func getModuleFilesets(modulePath, module string) ([]string, error) {
module, _ = getCurrentModuleName(modulePath, module)
fileInfos, err := ioutil.ReadDir(filepath.Join(modulePath, module))
if err != nil {
return []string{}, err
Expand Down
18 changes: 18 additions & 0 deletions filebeat/fileset/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ func TestNewModuleRegistryConfig(t *testing.T) {
assert.NotContains(t, reg.registry["nginx"], "error")
}

func TestMovedModule(t *testing.T) {
modulesPath, err := filepath.Abs("./test/moved_module")
assert.NoError(t, err)

configs := []*ModuleConfig{
&ModuleConfig{
Module: "old",
Filesets: map[string]*FilesetConfig{
"test": {},
},
},
}

reg, err := newModuleRegistry(modulesPath, configs, nil, "5.2.0")
assert.NoError(t, err)
assert.NotNil(t, reg)
}

func TestApplyOverrides(t *testing.T) {
falseVar := false
trueVar := true
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions filebeat/fileset/test/moved_module/old/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
movedTo: new