Skip to content

Commit

Permalink
Fix rebase fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed Jul 30, 2024
1 parent b3f6323 commit 41f5256
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
52 changes: 27 additions & 25 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,26 +971,30 @@ func (c *Config) probeParser(parentcategory string, parentname string, table *as
}

func (c *Config) addParser(parentcategory, parentname string, table *ast.Table) (*models.RunningParser, error) {
var dataformat string
c.getFieldString(table, "data_format", &dataformat)
if dataformat == "" {
dataformat = setDefaultParser(parentcategory, parentname)
conf := &models.ParserConfig{
Parent: parentname,
}

var influxParserType string
c.getFieldString(table, "influx_parser_type", &influxParserType)
if dataformat == "influx" && influxParserType == "upstream" {
dataformat = "influx_upstream"
c.getFieldString(table, "data_format", &conf.DataFormat)
if conf.DataFormat == "" {
conf.DataFormat = setDefaultParser(parentcategory, parentname)
} else if conf.DataFormat == "influx" {
var influxParserType string
c.getFieldString(table, "influx_parser_type", &influxParserType)
if influxParserType == "upstream" {
conf.DataFormat = "influx_upstream"
}
}
c.getFieldString(table, "log_level", &conf.LogLevel)

creator, ok := parsers.Parsers[dataformat]
creator, ok := parsers.Parsers[conf.DataFormat]
if !ok {
return nil, fmt.Errorf("undefined but requested parser: %s", dataformat)
return nil, fmt.Errorf("undefined but requested parser: %s", conf.DataFormat)
}
parser := creator(parentname)

// Handle reset-mode of CSV parsers to stay backward compatible (see issue #12022)
if dataformat == "csv" && parentcategory == "inputs" {
if conf.DataFormat == "csv" && parentcategory == "inputs" {
if parentname == "exec" {
csvParser := parser.(*csv.Parser)
csvParser.ResetMode = "always"
Expand All @@ -1001,36 +1005,31 @@ func (c *Config) addParser(parentcategory, parentname string, table *ast.Table)
return nil, err
}

conf := &models.ParserConfig{
Parent: parentname,
DataFormat: dataformat,
}
running := models.NewRunningParser(parser, conf)
err := running.Init()
return running, err
}

func (c *Config) addSerializer(parentname string, table *ast.Table) (*models.RunningSerializer, error) {
var dataformat string
c.getFieldString(table, "data_format", &dataformat)
if dataformat == "" {
dataformat = "influx"
conf := &models.SerializerConfig{
Parent: parentname,
}
c.getFieldString(table, "data_format", &conf.DataFormat)
if conf.DataFormat == "" {
conf.DataFormat = "influx"
}
c.getFieldString(table, "log_level", &conf.LogLevel)

creator, ok := serializers.Serializers[dataformat]
creator, ok := serializers.Serializers[conf.DataFormat]
if !ok {
return nil, fmt.Errorf("undefined but requested serializer: %s", dataformat)
return nil, fmt.Errorf("undefined but requested serializer: %s", conf.DataFormat)
}
serializer := creator()

if err := c.toml.UnmarshalTable(table, serializer); err != nil {
return nil, err
}

conf := &models.SerializerConfig{
Parent: parentname,
DataFormat: dataformat,
}
running := models.NewRunningSerializer(serializer, conf)
err := running.Init()
return running, err
Expand Down Expand Up @@ -1336,6 +1335,7 @@ func (c *Config) buildAggregator(name string, tbl *ast.Table) (*models.Aggregato
c.getFieldString(tbl, "name_suffix", &conf.MeasurementSuffix)
c.getFieldString(tbl, "name_override", &conf.NameOverride)
c.getFieldString(tbl, "alias", &conf.Alias)
c.getFieldString(tbl, "log_level", &conf.LogLevel)

conf.Tags = make(map[string]string)
if node, ok := tbl.Fields["tags"]; ok {
Expand Down Expand Up @@ -1369,6 +1369,7 @@ func (c *Config) buildProcessor(category, name string, tbl *ast.Table) (*models.

c.getFieldInt64(tbl, "order", &conf.Order)
c.getFieldString(tbl, "alias", &conf.Alias)
c.getFieldString(tbl, "log_level", &conf.LogLevel)

if c.hasErrs() {
return nil, c.firstErr()
Expand Down Expand Up @@ -1478,6 +1479,7 @@ func (c *Config) buildInput(name string, tbl *ast.Table) (*models.InputConfig, e
c.getFieldString(tbl, "name_suffix", &cp.MeasurementSuffix)
c.getFieldString(tbl, "name_override", &cp.NameOverride)
c.getFieldString(tbl, "alias", &cp.Alias)
c.getFieldString(tbl, "log_level", &cp.LogLevel)

cp.Tags = make(map[string]string)
if node, ok := tbl.Fields["tags"]; ok {
Expand Down
5 changes: 4 additions & 1 deletion models/running_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func NewRunningAggregator(aggregator telegraf.Aggregator, config *AggregatorConf
logger.RegisterErrorCallback(func() {
aggErrorsRegister.Incr(1)
})

if err := logger.SetLogLevel(config.LogLevel); err != nil {
logger.Error(err)
}
SetLoggerOnPlugin(aggregator, logger)

return &RunningAggregator{
Expand Down Expand Up @@ -74,6 +76,7 @@ type AggregatorConfig struct {
Period time.Duration
Delay time.Duration
Grace time.Duration
LogLevel string

NameOverride string
MeasurementPrefix string
Expand Down

0 comments on commit 41f5256

Please sign in to comment.