From cc397279f544200a5ec4c7a015d24ca57c5cc027 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Fri, 3 Dec 2021 21:44:41 +0100 Subject: [PATCH] fix: parallelism fix for ifname processor (#10007) --- plugins/processors/ifname/ifname.go | 38 ++++++++++++----------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/plugins/processors/ifname/ifname.go b/plugins/processors/ifname/ifname.go index 228124e7b9b83..fab4eb401eb7a 100644 --- a/plugins/processors/ifname/ifname.go +++ b/plugins/processors/ifname/ifname.go @@ -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 @@ -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 } @@ -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) @@ -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 }