Skip to content

Commit

Permalink
Revert much of the newer config file parsing, fix tagdrop/tagpass
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Nov 26, 2015
1 parent 224a570 commit 8dde60e
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 293 deletions.
2 changes: 1 addition & 1 deletion accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ac *accumulator) AddFields(
}

if ac.plugin != nil {
if !ac.plugin.ShouldPass(measurement, tags) {
if !ac.plugin.ShouldPass(measurement) || !ac.plugin.ShouldTagsPass(tags) {
return
}
}
Expand Down
44 changes: 33 additions & 11 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type Agent struct {

Tags map[string]string

Config *Config

outputs []*runningOutput
plugins []*runningPlugin
}
Expand All @@ -74,6 +76,7 @@ type Agent struct {
func NewAgent(config *Config) (*Agent, error) {
agent := &Agent{
Tags: make(map[string]string),
Config: config,
Interval: internal.Duration{10 * time.Second},
RoundInterval: true,
FlushInterval: internal.Duration{10 * time.Second},
Expand All @@ -96,7 +99,11 @@ func NewAgent(config *Config) (*Agent, error) {
agent.Hostname = hostname
}

agent.Tags["host"] = agent.Hostname
if config.Tags == nil {
config.Tags = map[string]string{}
}

config.Tags["host"] = agent.Hostname

return agent, nil
}
Expand Down Expand Up @@ -146,18 +153,21 @@ func (a *Agent) Close() error {
}

// LoadOutputs loads the agent's outputs
func (a *Agent) LoadOutputs(filters []string, config *Config) ([]string, error) {
func (a *Agent) LoadOutputs(filters []string) ([]string, error) {
var names []string

for name, output := range config.OutputsDeclared() {
for _, name := range a.Config.OutputsDeclared() {
// Trim the ID off the output name for filtering
filtername := strings.TrimRight(name, "-0123456789")
creator, ok := outputs.Outputs[filtername]
if !ok {
return nil, fmt.Errorf("Undefined but requested output: %s", name)
}

if sliceContains(filtername, filters) || len(filters) == 0 {
if a.Debug {
log.Println("Output Enabled: ", name)
}
output := creator()

err := config.ApplyOutput(name, output)
err := a.Config.ApplyOutput(name, output)
if err != nil {
return nil, err
}
Expand All @@ -173,15 +183,27 @@ func (a *Agent) LoadOutputs(filters []string, config *Config) ([]string, error)
}

// LoadPlugins loads the agent's plugins
func (a *Agent) LoadPlugins(filters []string, config *Config) ([]string, error) {
func (a *Agent) LoadPlugins(filters []string) ([]string, error) {
var names []string

for name, plugin := range config.PluginsDeclared() {
for _, name := range a.Config.PluginsDeclared() {
// Trim the ID off the output name for filtering
filtername := strings.TrimRight(name, "-0123456789")
creator, ok := plugins.Plugins[filtername]
if !ok {
return nil, fmt.Errorf("Undefined but requested plugin: %s", name)
}

if sliceContains(filtername, filters) || len(filters) == 0 {
config := config.GetPluginConfig(name)
a.plugins = append(a.plugins, &runningPlugin{name, filtername, plugin, config})
plugin := creator()

config, err := a.Config.ApplyPlugin(name, plugin)
if err != nil {
return nil, err
}

a.plugins = append(a.plugins,
&runningPlugin{name, filtername, plugin, config})
names = append(names, name)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
ag.Debug = true
}

outputs, err := ag.LoadOutputs(outputFilters, config)
outputs, err := ag.LoadOutputs(outputFilters)
if err != nil {
log.Fatal(err)
}
Expand All @@ -111,7 +111,7 @@ func main() {
os.Exit(1)
}

plugins, err := ag.LoadPlugins(pluginFilters, config)
plugins, err := ag.LoadPlugins(pluginFilters)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit 8dde60e

Please sign in to comment.