diff --git a/internal/config/config.go b/internal/config/config.go index 64338cded..a38af7924 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -53,8 +53,9 @@ type Config struct { Agent *AgentConfig Inputs []*models.RunningInput Outputs []*models.RunningOutput - Processors []*models.RunningProcessor Aggregators []*models.RunningAggregator + // Processors have a slice wrapper type because they need to be sorted + Processors models.RunningProcessors } func NewConfig() *Config { @@ -654,6 +655,10 @@ func (c *Config) LoadConfig(path string) error { } } } + + if len(c.Processors) > 1 { + sort.Sort(c.Processors) + } return nil } @@ -911,13 +916,26 @@ func buildAggregator(name string, tbl *ast.Table) (*models.AggregatorConfig, err // buildProcessor TODO doc func buildProcessor(name string, tbl *ast.Table) (*models.ProcessorConfig, error) { conf := &models.ProcessorConfig{Name: name} - unsupportedFields := []string{"tagexclude", "taginclude"} + unsupportedFields := []string{"tagexclude", "taginclude", "fielddrop", "fieldpass"} for _, field := range unsupportedFields { if _, ok := tbl.Fields[field]; ok { // TODO raise error because field is not supported } } + if node, ok := tbl.Fields["order"]; ok { + if kv, ok := node.(*ast.KeyValue); ok { + if b, ok := kv.Value.(*ast.Integer); ok { + var err error + conf.Order, err = strconv.ParseInt(b.Value, 10, 64) + if err != nil { + log.Printf("Error parsing int value for %s: %s\n", name, err) + } + } + } + } + + delete(tbl.Fields, "order") var err error conf.Filter, err = buildFilter(tbl) if err != nil { diff --git a/internal/models/running_processor.go b/internal/models/running_processor.go index f4f483f6d..600b61928 100644 --- a/internal/models/running_processor.go +++ b/internal/models/running_processor.go @@ -10,9 +10,16 @@ type RunningProcessor struct { Config *ProcessorConfig } +type RunningProcessors []*RunningProcessor + +func (rp RunningProcessors) Len() int { return len(rp) } +func (rp RunningProcessors) Swap(i, j int) { rp[i], rp[j] = rp[j], rp[i] } +func (rp RunningProcessors) Less(i, j int) bool { return rp[i].Config.Order < rp[j].Config.Order } + // FilterConfig containing a name and filter type ProcessorConfig struct { Name string + Order int64 Filter Filter }