Skip to content

Commit

Permalink
Add option to support moved filebeat modules
Browse files Browse the repository at this point in the history
If a module needs to be moved, existing configuration will stop working,
this change adds an option to mark an old module as moved to other name.

This is being considered for the movement of apache2 module to apache to
be coherent with metricbeat module (#9402).
  • Loading branch information
jsoriano committed Dec 7, 2018
1 parent 0248d78 commit 30bc249
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 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,27 @@ func mcfgFromConfig(cfg *common.Config) (*ModuleConfig, error) {
return &mcfg, nil
}

func getCurrentModuleName(modulePath, module string) (string, bool) {
moduleConfigPath := filepath.Join(modulePath, module, "module.yml")
logp.Info("path: %s, module: %s, path: %s", modulePath, module, moduleConfigPath)
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

0 comments on commit 30bc249

Please sign in to comment.