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

chore(linters): Fix non-input/output plugin errcheck warnings #15472

Merged
merged 13 commits into from
Jun 12, 2024
Prev Previous commit
Next Next commit
address remaining reviews
  • Loading branch information
DStrand1 committed Jun 10, 2024
commit e493c8c59c0e311662339252287c517d1a118323
8 changes: 5 additions & 3 deletions plugins/aggregators/quantile/quantile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func (q *Quantile) Add(in telegraf.Metric) {
}
for k, field := range in.Fields() {
if v, isconvertible := convert(field); isconvertible {
//nolint:errcheck // This should never error out as we tested it in Init()
algo, _ := q.newAlgorithm(q.Compression)
err := algo.Add(v)
algo, err := q.newAlgorithm(q.Compression)
if err != nil {
q.Log.Errorf("generating algorithm %s: %v", k, err)
}
err = algo.Add(v)
if err != nil {
q.Log.Errorf("adding field %s: %v", k, err)
}
Expand Down
35 changes: 27 additions & 8 deletions plugins/parsers/dropwizard/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,26 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
return nil, err
}

metrics = p.readDWMetrics("counter", dwr["counters"], metrics, metricTime)
metrics = p.readDWMetrics("meter", dwr["meters"], metrics, metricTime)
metrics = p.readDWMetrics("gauge", dwr["gauges"], metrics, metricTime)
metrics = p.readDWMetrics("histogram", dwr["histograms"], metrics, metricTime)
metrics = p.readDWMetrics("timer", dwr["timers"], metrics, metricTime)
metrics, err = p.readDWMetrics("counter", dwr["counters"], metrics, metricTime)
if err != nil {
return nil, err
}
metrics, err = p.readDWMetrics("meter", dwr["meters"], metrics, metricTime)
if err != nil {
return nil, err
}
metrics, err = p.readDWMetrics("gauge", dwr["gauges"], metrics, metricTime)
if err != nil {
return nil, err
}
metrics, err = p.readDWMetrics("histogram", dwr["histograms"], metrics, metricTime)
if err != nil {
return nil, err
}
metrics, err = p.readDWMetrics("timer", dwr["timers"], metrics, metricTime)
if err != nil {
return nil, err
}

jsonTags := p.readTags(buf)

Expand Down Expand Up @@ -160,15 +175,19 @@ func (p *Parser) unmarshalMetrics(buf []byte) (map[string]interface{}, error) {
return jsonOut, nil
}

func (p *Parser) readDWMetrics(metricType string, dwms interface{}, metrics []telegraf.Metric, tm time.Time) []telegraf.Metric {
func (p *Parser) readDWMetrics(metricType string, dwms interface{}, metrics []telegraf.Metric, tm time.Time) ([]telegraf.Metric, error) {
if dwmsTyped, ok := dwms.(map[string]interface{}); ok {
for dwmName, dwmFields := range dwmsTyped {
measurementName := dwmName
tags := make(map[string]string)
fieldPrefix := ""
if p.templateEngine != nil {
//nolint:errcheck // Potential error not worth propagating
DStrand1 marked this conversation as resolved.
Show resolved Hide resolved
DStrand1 marked this conversation as resolved.
Show resolved Hide resolved
measurementName, tags, fieldPrefix, _ = p.templateEngine.Apply(dwmName)
var err error
measurementName, tags, fieldPrefix, err = p.templateEngine.Apply(dwmName)
if err != nil {
return nil, fmt.Errorf("failed to apply template for type %s: %w", metricType, err)
}
if len(fieldPrefix) > 0 {
fieldPrefix = fmt.Sprintf("%s%s", fieldPrefix, p.Separator)
}
Expand Down Expand Up @@ -203,7 +222,7 @@ func (p *Parser) readDWMetrics(metricType string, dwms interface{}, metrics []te
}
}

return metrics
return metrics, nil
}

func (p *Parser) Init() error {
Expand Down
6 changes: 5 additions & 1 deletion plugins/processors/dedup/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Dedup struct {
DedupInterval config.Duration `toml:"dedup_interval"`
FlushTime time.Time
Cache map[uint64]telegraf.Metric
Log telegraf.Logger `toml:"-"`
}

// Remove expired items from cache
Expand Down Expand Up @@ -127,7 +128,10 @@ func (d *Dedup) GetState() interface{} {
v = append(v, value)
}
//nolint:errcheck // no way to propagate the error
DStrand1 marked this conversation as resolved.
Show resolved Hide resolved
state, _ := s.SerializeBatch(v)
state, err := s.SerializeBatch(v)
if err != nil {
d.Log.Errorf("dedup processor failed to serialize metric batch: %v", err)
}
return state
}

Expand Down
9 changes: 7 additions & 2 deletions plugins/processors/filepath/filepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Options struct {
Clean []BaseOpts
Rel []RelOpts
ToSlash []BaseOpts `toml:"toslash"`

Log telegraf.Logger `toml:"-"`
}

type ProcessorFunc func(s string) string
Expand Down Expand Up @@ -82,8 +84,11 @@ func (o *Options) processMetric(metric telegraf.Metric) {
// Rel
for _, v := range o.Rel {
o.applyFunc(v.BaseOpts, func(s string) string {
//nolint:errcheck // no way to propagate the error
relPath, _ := filepath.Rel(v.BasePath, s)
relPath, err := filepath.Rel(v.BasePath, s)
if err != nil {
o.Log.Errorf("filepath processor failed to process relative filepath %s: %v", s, err)
return v.BasePath
}
return relPath
}, metric)
}
Expand Down
Loading