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

fix: parallelism fix for ifname processor #10007

Merged
merged 8 commits into from
Dec 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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