Skip to content

Commit

Permalink
fix: parallelism fix for ifname processor (#10007)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska authored Dec 3, 2021
1 parent 1143a50 commit cc39727
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions plugins/processors/ifname/ifname.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,13 @@ type IfName struct {
ifTable *si.Table
ifXTable *si.Table

lock sync.Mutex
cache *TTLCache

cache *TTLCache
lock sync.Mutex
parallel parallel.Parallel
acc telegraf.Accumulator
sigs sigMap

getMapRemote mapFunc
makeTable makeTableFunc

gsBase snmp.GosnmpWrapper

sigs sigMap
}

const minRetry = 5 * time.Minute
Expand All @@ -132,6 +127,10 @@ func (d *IfName) Init() error {

d.sigs = make(sigMap)

if _, err := snmp.NewWrapper(d.ClientConfig); err != nil {
return fmt.Errorf("parsing SNMP client config: %w", err)
}

return nil
}

Expand Down Expand Up @@ -192,14 +191,7 @@ func (d *IfName) invalidate(agent string) {
}

func (d *IfName) Start(acc telegraf.Accumulator) error {
d.acc = acc

var err error
d.gsBase, err = snmp.NewWrapper(d.ClientConfig)
if err != nil {
return fmt.Errorf("parsing SNMP client config: %w", err)
}

d.ifTable, err = d.makeTable("IF-MIB::ifDescr")
if err != nil {
return fmt.Errorf("looking up ifDescr in local MIB: %w", err)
Expand Down Expand Up @@ -299,27 +291,27 @@ func (d *IfName) getMap(agent string) (entry nameMap, age time.Duration, err err
}

func (d *IfName) getMapRemoteNoMock(agent string) (nameMap, error) {
gs := d.gsBase
err := gs.SetAgent(agent)
gs, err := snmp.NewWrapper(d.ClientConfig)
if err != nil {
return nil, fmt.Errorf("parsing SNMP client config: %w", err)
}

if err = gs.SetAgent(agent); err != nil {
return nil, fmt.Errorf("parsing agent tag: %w", err)
}

err = gs.Connect()
if err != nil {
if err = gs.Connect(); err != nil {
return nil, fmt.Errorf("connecting when fetching interface names: %w", err)
}

//try ifXtable and ifName first. if that fails, fall back to
//ifTable and ifDescr
var m nameMap
m, err = buildMap(gs, d.ifXTable, "ifName")
if err == nil {
if m, err = buildMap(gs, d.ifXTable, "ifName"); err == nil {
return m, nil
}

m, err = buildMap(gs, d.ifTable, "ifDescr")
if err == nil {
if m, err = buildMap(gs, d.ifTable, "ifDescr"); err == nil {
return m, nil
}

Expand Down

0 comments on commit cc39727

Please sign in to comment.