chore: Fix linter findings for errorlint (part4) (#12723)
Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
parent
100a27e823
commit
312fb04b68
|
|
@ -229,7 +229,7 @@ func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error {
|
||||||
queues := Queues{}
|
queues := Queues{}
|
||||||
err = xml.Unmarshal(dataQueues, &queues)
|
err = xml.Unmarshal(dataQueues, &queues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("queues XML unmarshal error: %v", err)
|
return fmt.Errorf("queues XML unmarshal error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataTopics, err := a.GetMetrics(a.TopicsURL())
|
dataTopics, err := a.GetMetrics(a.TopicsURL())
|
||||||
|
|
@ -239,7 +239,7 @@ func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error {
|
||||||
topics := Topics{}
|
topics := Topics{}
|
||||||
err = xml.Unmarshal(dataTopics, &topics)
|
err = xml.Unmarshal(dataTopics, &topics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("topics XML unmarshal error: %v", err)
|
return fmt.Errorf("topics XML unmarshal error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataSubscribers, err := a.GetMetrics(a.SubscribersURL())
|
dataSubscribers, err := a.GetMetrics(a.SubscribersURL())
|
||||||
|
|
@ -249,7 +249,7 @@ func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error {
|
||||||
subscribers := Subscribers{}
|
subscribers := Subscribers{}
|
||||||
err = xml.Unmarshal(dataSubscribers, &subscribers)
|
err = xml.Unmarshal(dataSubscribers, &subscribers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("subscribers XML unmarshal error: %v", err)
|
return fmt.Errorf("subscribers XML unmarshal error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.GatherQueuesMetrics(acc, queues)
|
a.GatherQueuesMetrics(acc, queues)
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
|
|
||||||
ch, err := a.conn.Channel()
|
ch, err := a.conn.Channel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open a channel: %s", err.Error())
|
return nil, fmt.Errorf("failed to open a channel: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Exchange != "" {
|
if a.Exchange != "" {
|
||||||
|
|
@ -250,7 +250,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to bind a queue: %s", err)
|
return nil, fmt.Errorf("failed to bind a queue: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -260,7 +260,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
false, // global
|
false, // global
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to set QoS: %s", err)
|
return nil, fmt.Errorf("failed to set QoS: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs, err := ch.Consume(
|
msgs, err := ch.Consume(
|
||||||
|
|
@ -273,7 +273,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
nil, // arguments
|
nil, // arguments
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed establishing connection to queue: %s", err)
|
return nil, fmt.Errorf("failed establishing connection to queue: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return msgs, err
|
return msgs, err
|
||||||
|
|
@ -307,7 +307,7 @@ func (a *AMQPConsumer) declareExchange(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error declaring exchange: %v", err)
|
return fmt.Errorf("error declaring exchange: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -341,7 +341,7 @@ func (a *AMQPConsumer) declareQueue(channel *amqp.Channel) (*amqp.Queue, error)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error declaring queue: %v", err)
|
return nil, fmt.Errorf("error declaring queue: %w", err)
|
||||||
}
|
}
|
||||||
return &queue, nil
|
return &queue, nil
|
||||||
}
|
}
|
||||||
|
|
@ -442,7 +442,7 @@ func (a *AMQPConsumer) Stop() {
|
||||||
a.cancel()
|
a.cancel()
|
||||||
a.wg.Wait()
|
a.wg.Wait()
|
||||||
err := a.conn.Close()
|
err := a.conn.Close()
|
||||||
if err != nil && err != amqp.ErrClosed {
|
if err != nil && !errors.Is(err, amqp.ErrClosed) {
|
||||||
a.Log.Errorf("Error closing AMQP connection: %s", err)
|
a.Log.Errorf("Error closing AMQP connection: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error {
|
||||||
for _, u := range n.Urls {
|
for _, u := range n.Urls {
|
||||||
addr, err := url.Parse(u)
|
addr, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("unable to parse address '%s': %s", u, err))
|
acc.AddError(fmt.Errorf("unable to parse address %q: %w", u, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ func (n *Apache) createHTTPClient() (*http.Client, error) {
|
||||||
func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
|
func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
req, err := http.NewRequest("GET", addr.String(), nil)
|
req, err := http.NewRequest("GET", addr.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error on new request to %s : %s", addr.String(), err)
|
return fmt.Errorf("error on new request to %q: %w", addr.String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(n.Username) != 0 && len(n.Password) != 0 {
|
if len(n.Username) != 0 && len(n.Password) != 0 {
|
||||||
|
|
@ -100,7 +100,7 @@ func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
resp, err := n.client.Do(req)
|
resp, err := n.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error on request to %s : %s", addr.String(), err)
|
return fmt.Errorf("error on request to %q: %w", addr.String(), err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ func (a *Aurora) Gather(acc telegraf.Accumulator) error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
role, err := a.gatherRole(ctx, u)
|
role, err := a.gatherRole(ctx, u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("%s: %v", u, err))
|
acc.AddError(fmt.Errorf("%s: %w", u, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ func (a *Aurora) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
err = a.gatherScheduler(ctx, u, role, acc)
|
err = a.gatherScheduler(ctx, u, role, acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("%s: %v", u, err))
|
acc.AddError(fmt.Errorf("%s: %w", u, err))
|
||||||
}
|
}
|
||||||
}(u)
|
}(u)
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +167,7 @@ func (a *Aurora) gatherRole(ctx context.Context, origin *url.URL) (RoleType, err
|
||||||
return Unknown, err
|
return Unknown, err
|
||||||
}
|
}
|
||||||
if err := resp.Body.Close(); err != nil {
|
if err := resp.Body.Close(); err != nil {
|
||||||
return Unknown, fmt.Errorf("closing body failed: %v", err)
|
return Unknown, fmt.Errorf("closing body failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
|
|
@ -212,7 +212,7 @@ func (a *Aurora) gatherScheduler(
|
||||||
decoder.UseNumber()
|
decoder.UseNumber()
|
||||||
err = decoder.Decode(&vars)
|
err = decoder.Decode(&vars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("decoding response: %v", err)
|
return fmt.Errorf("decoding response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fields = make(map[string]interface{}, len(vars))
|
var fields = make(map[string]interface{}, len(vars))
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func (b *Bcache) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := b.gatherBcache(bdev, acc); err != nil {
|
if err := b.gatherBcache(bdev, acc); err != nil {
|
||||||
return fmt.Errorf("gathering bcache failed: %v", err)
|
return fmt.Errorf("gathering bcache failed: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package beanstalkd_test
|
package beanstalkd_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
|
@ -121,7 +122,7 @@ func startTestServer(t *testing.T) (net.Listener, error) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
cmd, err := tp.ReadLine()
|
cmd, err := tp.ReadLine()
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
t.Log("Test server: failed read command. Error: ", err)
|
t.Log("Test server: failed read command. Error: ", err)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func (b *Bind) Gather(acc telegraf.Accumulator) error {
|
||||||
for _, u := range b.Urls {
|
for _, u := range b.Urls {
|
||||||
addr, err := url.Parse(u)
|
addr, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("unable to parse address '%s': %s", u, err))
|
acc.AddError(fmt.Errorf("unable to parse address %q: %w", u, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ func (b *Bind) readStatsJSON(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
||||||
return fmt.Errorf("unable to decode JSON blob: %s", err)
|
return fmt.Errorf("unable to decode JSON blob: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ func (b *Bind) readStatsXMLv2(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := xml.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
if err := xml.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
||||||
return fmt.Errorf("unable to decode XML document: %s", err)
|
return fmt.Errorf("unable to decode XML document: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := map[string]string{"url": addr.Host}
|
tags := map[string]string{"url": addr.Host}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (b *Bind) readStatsXMLv3(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := xml.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
if err := xml.NewDecoder(resp.Body).Decode(&stats); err != nil {
|
||||||
return fmt.Errorf("unable to decode XML document: %s", err)
|
return fmt.Errorf("unable to decode XML document: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,13 @@ func (bond *Bond) Gather(acc telegraf.Accumulator) error {
|
||||||
bondAbsPath := bond.HostProc + "/net/bonding/" + bondName
|
bondAbsPath := bond.HostProc + "/net/bonding/" + bondName
|
||||||
file, err := os.ReadFile(bondAbsPath)
|
file, err := os.ReadFile(bondAbsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("error inspecting %q interface: %v", bondAbsPath, err))
|
acc.AddError(fmt.Errorf("error inspecting %q interface: %w", bondAbsPath, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rawProcFile := strings.TrimSpace(string(file))
|
rawProcFile := strings.TrimSpace(string(file))
|
||||||
err = bond.gatherBondInterface(bondName, rawProcFile, acc)
|
err = bond.gatherBondInterface(bondName, rawProcFile, acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("error inspecting %q interface: %v", bondName, err))
|
acc.AddError(fmt.Errorf("error inspecting %q interface: %w", bondName, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -153,18 +153,18 @@ func (bond *Bond) readSysFiles(bondDir string) (sysFiles, error) {
|
||||||
|
|
||||||
file, err := os.ReadFile(bondDir + "/bonding/mode")
|
file, err := os.ReadFile(bondDir + "/bonding/mode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sysFiles{}, fmt.Errorf("error inspecting %q interface: %v", bondDir+"/bonding/mode", err)
|
return sysFiles{}, fmt.Errorf("error inspecting %q interface: %w", bondDir+"/bonding/mode", err)
|
||||||
}
|
}
|
||||||
output.ModeFile = strings.TrimSpace(string(file))
|
output.ModeFile = strings.TrimSpace(string(file))
|
||||||
file, err = os.ReadFile(bondDir + "/bonding/slaves")
|
file, err = os.ReadFile(bondDir + "/bonding/slaves")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sysFiles{}, fmt.Errorf("error inspecting %q interface: %v", bondDir+"/bonding/slaves", err)
|
return sysFiles{}, fmt.Errorf("error inspecting %q interface: %w", bondDir+"/bonding/slaves", err)
|
||||||
}
|
}
|
||||||
output.SlaveFile = strings.TrimSpace(string(file))
|
output.SlaveFile = strings.TrimSpace(string(file))
|
||||||
if bond.BondType == "IEEE 802.3ad Dynamic link aggregation" {
|
if bond.BondType == "IEEE 802.3ad Dynamic link aggregation" {
|
||||||
file, err = os.ReadFile(bondDir + "/bonding/ad_num_ports")
|
file, err = os.ReadFile(bondDir + "/bonding/ad_num_ports")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sysFiles{}, fmt.Errorf("error inspecting %q interface: %v", bondDir+"/bonding/ad_num_ports", err)
|
return sysFiles{}, fmt.Errorf("error inspecting %q interface: %w", bondDir+"/bonding/ad_num_ports", err)
|
||||||
}
|
}
|
||||||
output.ADPortsFile = strings.TrimSpace(string(file))
|
output.ADPortsFile = strings.TrimSpace(string(file))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ func (b *burrow) Gather(acc telegraf.Accumulator) error {
|
||||||
for _, addr := range b.Servers {
|
for _, addr := range b.Servers {
|
||||||
u, err := url.Parse(addr)
|
u, err := url.Parse(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("unable to parse address '%s': %s", addr, err))
|
acc.AddError(fmt.Errorf("unable to parse address %q: %w", addr, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if u.Path == "" {
|
if u.Path == "" {
|
||||||
|
|
|
||||||
|
|
@ -70,18 +70,18 @@ func (c *Ceph) Gather(acc telegraf.Accumulator) error {
|
||||||
func (c *Ceph) gatherAdminSocketStats(acc telegraf.Accumulator) error {
|
func (c *Ceph) gatherAdminSocketStats(acc telegraf.Accumulator) error {
|
||||||
sockets, err := findSockets(c)
|
sockets, err := findSockets(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find sockets at path '%s': %v", c.SocketDir, err)
|
return fmt.Errorf("failed to find sockets at path %q: %w", c.SocketDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range sockets {
|
for _, s := range sockets {
|
||||||
dump, err := perfDump(c.CephBinary, s)
|
dump, err := perfDump(c.CephBinary, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("error reading from socket '%s': %v", s.socket, err))
|
acc.AddError(fmt.Errorf("error reading from socket %q: %w", s.socket, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data, err := c.parseDump(dump)
|
data, err := c.parseDump(dump)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("error parsing dump from socket '%s': %v", s.socket, err))
|
acc.AddError(fmt.Errorf("error parsing dump from socket %q: %w", s.socket, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for tag, metrics := range data {
|
for tag, metrics := range data {
|
||||||
|
|
@ -107,11 +107,11 @@ func (c *Ceph) gatherClusterStats(acc telegraf.Accumulator) error {
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
output, err := c.execute(job.command)
|
output, err := c.execute(job.command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error executing command: %v", err)
|
return fmt.Errorf("error executing command: %w", err)
|
||||||
}
|
}
|
||||||
err = job.parser(acc, output)
|
err = job.parser(acc, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing output: %v", err)
|
return fmt.Errorf("error parsing output: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ var perfDump = func(binary string, socket *socket) (string, error) {
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error running ceph dump: %s", err)
|
return "", fmt.Errorf("error running ceph dump: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.String(), nil
|
return out.String(), nil
|
||||||
|
|
@ -166,7 +166,7 @@ var perfDump = func(binary string, socket *socket) (string, error) {
|
||||||
var findSockets = func(c *Ceph) ([]*socket, error) {
|
var findSockets = func(c *Ceph) ([]*socket, error) {
|
||||||
listing, err := os.ReadDir(c.SocketDir)
|
listing, err := os.ReadDir(c.SocketDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []*socket{}, fmt.Errorf("Failed to read socket directory '%s': %v", c.SocketDir, err)
|
return []*socket{}, fmt.Errorf("failed to read socket directory %q: %w", c.SocketDir, err)
|
||||||
}
|
}
|
||||||
sockets := make([]*socket, 0, len(listing))
|
sockets := make([]*socket, 0, len(listing))
|
||||||
for _, info := range listing {
|
for _, info := range listing {
|
||||||
|
|
@ -239,7 +239,7 @@ func (c *Ceph) parseDump(dump string) (taggedMetricMap, error) {
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
err := json.Unmarshal([]byte(dump), &data)
|
err := json.Unmarshal([]byte(dump), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse json: '%s': %v", dump, err)
|
return nil, fmt.Errorf("failed to parse json: %q: %w", dump, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.newTaggedMetricMap(data), nil
|
return c.newTaggedMetricMap(data), nil
|
||||||
|
|
@ -299,7 +299,7 @@ func (c *Ceph) execute(command string) (string, error) {
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error running ceph %v: %s", command, err)
|
return "", fmt.Errorf("error running ceph %q: %w", command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output := out.String()
|
output := out.String()
|
||||||
|
|
@ -378,7 +378,7 @@ type CephStatus struct {
|
||||||
func decodeStatus(acc telegraf.Accumulator, input string) error {
|
func decodeStatus(acc telegraf.Accumulator, input string) error {
|
||||||
data := &CephStatus{}
|
data := &CephStatus{}
|
||||||
if err := json.Unmarshal([]byte(input), data); err != nil {
|
if err := json.Unmarshal([]byte(input), data); err != nil {
|
||||||
return fmt.Errorf("failed to parse json: '%s': %v", input, err)
|
return fmt.Errorf("failed to parse json: %q: %w", input, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
decoders := []func(telegraf.Accumulator, *CephStatus) error{
|
decoders := []func(telegraf.Accumulator, *CephStatus) error{
|
||||||
|
|
@ -539,7 +539,7 @@ type CephDf struct {
|
||||||
func decodeDf(acc telegraf.Accumulator, input string) error {
|
func decodeDf(acc telegraf.Accumulator, input string) error {
|
||||||
data := &CephDf{}
|
data := &CephDf{}
|
||||||
if err := json.Unmarshal([]byte(input), data); err != nil {
|
if err := json.Unmarshal([]byte(input), data); err != nil {
|
||||||
return fmt.Errorf("failed to parse json: '%s': %v", input, err)
|
return fmt.Errorf("failed to parse json: %q: %w", input, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ceph.usage: records global utilization and number of objects
|
// ceph.usage: records global utilization and number of objects
|
||||||
|
|
@ -618,7 +618,7 @@ type CephOSDPoolStats []struct {
|
||||||
func decodeOsdPoolStats(acc telegraf.Accumulator, input string) error {
|
func decodeOsdPoolStats(acc telegraf.Accumulator, input string) error {
|
||||||
data := CephOSDPoolStats{}
|
data := CephOSDPoolStats{}
|
||||||
if err := json.Unmarshal([]byte(input), &data); err != nil {
|
if err := json.Unmarshal([]byte(input), &data); err != nil {
|
||||||
return fmt.Errorf("failed to parse json: '%s': %v", input, err)
|
return fmt.Errorf("failed to parse json: %q: %w", input, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ceph.pool.stats: records pre pool IO and recovery throughput
|
// ceph.pool.stats: records pre pool IO and recovery throughput
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func (c *Chrony) Gather(acc telegraf.Accumulator) error {
|
||||||
cmd := execCommand(c.path, flags...)
|
cmd := execCommand(c.path, flags...)
|
||||||
out, err := internal.CombinedOutputTimeout(cmd, time.Second*5)
|
out, err := internal.CombinedOutputTimeout(cmd, time.Second*5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out))
|
return fmt.Errorf("failed to run command %q: %w - %s", strings.Join(cmd.Args, " "), err, string(out))
|
||||||
}
|
}
|
||||||
fields, tags, err := processChronycOutput(string(out))
|
fields, tags, err := processChronycOutput(string(out))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
@ -224,7 +225,8 @@ func (c *CiscoTelemetryMDT) acceptTCPClients() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
conn, err := c.listener.Accept()
|
conn, err := c.listener.Accept()
|
||||||
if neterr, ok := err.(*net.OpError); ok && (neterr.Timeout() || neterr.Temporary()) {
|
var neterr *net.OpError
|
||||||
|
if errors.As(err, &neterr) && (neterr.Timeout() || neterr.Temporary()) {
|
||||||
continue
|
continue
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
break // Stop() will close the connection so Accept() will fail here
|
break // Stop() will close the connection so Accept() will fail here
|
||||||
|
|
@ -319,8 +321,8 @@ func (c *CiscoTelemetryMDT) MdtDialout(stream dialout.GRPCMdtDialout_MdtDialoutS
|
||||||
for {
|
for {
|
||||||
packet, err := stream.Recv()
|
packet, err := stream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != io.EOF {
|
if !errors.Is(err, io.EOF) {
|
||||||
c.acc.AddError(fmt.Errorf("GRPC dialout receive error: %v", err))
|
c.acc.AddError(fmt.Errorf("GRPC dialout receive error: %w", err))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -335,7 +337,7 @@ func (c *CiscoTelemetryMDT) MdtDialout(stream dialout.GRPCMdtDialout_MdtDialoutS
|
||||||
c.handleTelemetry(packet.Data)
|
c.handleTelemetry(packet.Data)
|
||||||
} else if int(packet.TotalSize) <= c.MaxMsgSize {
|
} else if int(packet.TotalSize) <= c.MaxMsgSize {
|
||||||
if _, err := chunkBuffer.Write(packet.Data); err != nil {
|
if _, err := chunkBuffer.Write(packet.Data); err != nil {
|
||||||
c.acc.AddError(fmt.Errorf("writing packet %q failed: %v", packet.Data, err))
|
c.acc.AddError(fmt.Errorf("writing packet %q failed: %w", packet.Data, err))
|
||||||
}
|
}
|
||||||
if chunkBuffer.Len() >= int(packet.TotalSize) {
|
if chunkBuffer.Len() >= int(packet.TotalSize) {
|
||||||
c.handleTelemetry(chunkBuffer.Bytes())
|
c.handleTelemetry(chunkBuffer.Bytes())
|
||||||
|
|
@ -358,7 +360,7 @@ func (c *CiscoTelemetryMDT) handleTelemetry(data []byte) {
|
||||||
msg := &telemetry.Telemetry{}
|
msg := &telemetry.Telemetry{}
|
||||||
err := proto.Unmarshal(data, msg)
|
err := proto.Unmarshal(data, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.acc.AddError(fmt.Errorf("failed to decode: %v", err))
|
c.acc.AddError(fmt.Errorf("failed to decode: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -756,7 +756,7 @@ func TestTCPDialoutOverflow(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, binary.Write(conn, binary.BigEndian, hdr))
|
require.NoError(t, binary.Write(conn, binary.BigEndian, hdr))
|
||||||
_, err = conn.Read([]byte{0})
|
_, err = conn.Read([]byte{0})
|
||||||
require.True(t, err == nil || err == io.EOF)
|
require.True(t, err == nil || errors.Is(err, io.EOF))
|
||||||
require.NoError(t, conn.Close())
|
require.NoError(t, conn.Close())
|
||||||
|
|
||||||
c.Stop()
|
c.Stop()
|
||||||
|
|
@ -838,7 +838,7 @@ func TestTCPDialoutMultiple(t *testing.T) {
|
||||||
_, err = conn2.Write([]byte{0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0})
|
_, err = conn2.Write([]byte{0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = conn2.Read([]byte{0})
|
_, err = conn2.Read([]byte{0})
|
||||||
require.True(t, err == nil || err == io.EOF)
|
require.True(t, err == nil || errors.Is(err, io.EOF))
|
||||||
require.NoError(t, conn2.Close())
|
require.NoError(t, conn2.Close())
|
||||||
|
|
||||||
telemetry.EncodingPath = "type:model/other/path"
|
telemetry.EncodingPath = "type:model/other/path"
|
||||||
|
|
@ -851,7 +851,7 @@ func TestTCPDialoutMultiple(t *testing.T) {
|
||||||
_, err = conn.Write([]byte{0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0})
|
_, err = conn.Write([]byte{0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = conn.Read([]byte{0})
|
_, err = conn.Read([]byte{0})
|
||||||
require.True(t, err == nil || err == io.EOF)
|
require.True(t, err == nil || errors.Is(err, io.EOF))
|
||||||
c.Stop()
|
c.Stop()
|
||||||
require.NoError(t, conn.Close())
|
require.NoError(t, conn.Close())
|
||||||
|
|
||||||
|
|
@ -889,7 +889,7 @@ func TestGRPCDialoutError(t *testing.T) {
|
||||||
|
|
||||||
// Wait for the server to close
|
// Wait for the server to close
|
||||||
_, err = stream.Recv()
|
_, err = stream.Recv()
|
||||||
require.True(t, err == nil || err == io.EOF)
|
require.True(t, err == nil || errors.Is(err, io.EOF))
|
||||||
c.Stop()
|
c.Stop()
|
||||||
|
|
||||||
require.Equal(t, acc.Errors, []error{errors.New("GRPC dialout error: foobar")})
|
require.Equal(t, acc.Errors, []error{errors.New("GRPC dialout error: foobar")})
|
||||||
|
|
@ -928,7 +928,7 @@ func TestGRPCDialoutMultiple(t *testing.T) {
|
||||||
require.NoError(t, stream2.Send(args))
|
require.NoError(t, stream2.Send(args))
|
||||||
require.NoError(t, stream2.Send(&dialout.MdtDialoutArgs{Errors: "testclose"}))
|
require.NoError(t, stream2.Send(&dialout.MdtDialoutArgs{Errors: "testclose"}))
|
||||||
_, err = stream2.Recv()
|
_, err = stream2.Recv()
|
||||||
require.True(t, err == nil || err == io.EOF)
|
require.True(t, err == nil || errors.Is(err, io.EOF))
|
||||||
require.NoError(t, conn2.Close())
|
require.NoError(t, conn2.Close())
|
||||||
|
|
||||||
telemetry.EncodingPath = "type:model/other/path"
|
telemetry.EncodingPath = "type:model/other/path"
|
||||||
|
|
@ -938,7 +938,7 @@ func TestGRPCDialoutMultiple(t *testing.T) {
|
||||||
require.NoError(t, stream.Send(args))
|
require.NoError(t, stream.Send(args))
|
||||||
require.NoError(t, stream.Send(&dialout.MdtDialoutArgs{Errors: "testclose"}))
|
require.NoError(t, stream.Send(&dialout.MdtDialoutArgs{Errors: "testclose"}))
|
||||||
_, err = stream.Recv()
|
_, err = stream.Recv()
|
||||||
require.True(t, err == nil || err == io.EOF)
|
require.True(t, err == nil || errors.Is(err, io.EOF))
|
||||||
|
|
||||||
c.Stop()
|
c.Stop()
|
||||||
require.NoError(t, conn.Close())
|
require.NoError(t, conn.Close())
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ func (ps *PubSub) Start(ac telegraf.Accumulator) error {
|
||||||
} else {
|
} else {
|
||||||
subRef, err := ps.getGCPSubscription(ps.Subscription)
|
subRef, err := ps.getGCPSubscription(ps.Subscription)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create subscription handle: %v", err)
|
return fmt.Errorf("unable to create subscription handle: %w", err)
|
||||||
}
|
}
|
||||||
ps.sub = subRef
|
ps.sub = subRef
|
||||||
}
|
}
|
||||||
|
|
@ -157,11 +157,11 @@ func (ps *PubSub) startReceiver(parentCtx context.Context) error {
|
||||||
cctx, ccancel := context.WithCancel(parentCtx)
|
cctx, ccancel := context.WithCancel(parentCtx)
|
||||||
err := ps.sub.Receive(cctx, func(ctx context.Context, msg message) {
|
err := ps.sub.Receive(cctx, func(ctx context.Context, msg message) {
|
||||||
if err := ps.onMessage(ctx, msg); err != nil {
|
if err := ps.onMessage(ctx, msg); err != nil {
|
||||||
ps.acc.AddError(fmt.Errorf("unable to add message from subscription %s: %v", ps.sub.ID(), err))
|
ps.acc.AddError(fmt.Errorf("unable to add message from subscription %s: %w", ps.sub.ID(), err))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ps.acc.AddError(fmt.Errorf("receiver for subscription %s exited: %v", ps.sub.ID(), err))
|
ps.acc.AddError(fmt.Errorf("receiver for subscription %s exited: %w", ps.sub.ID(), err))
|
||||||
} else {
|
} else {
|
||||||
ps.Log.Info("Subscription pull ended (no error, most likely stopped)")
|
ps.Log.Info("Subscription pull ended (no error, most likely stopped)")
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ func (ps *PubSub) onMessage(ctx context.Context, msg message) error {
|
||||||
if ps.Base64Data {
|
if ps.Base64Data {
|
||||||
strData, err := base64.StdEncoding.DecodeString(string(msg.Data()))
|
strData, err := base64.StdEncoding.DecodeString(string(msg.Data()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to base64 decode message: %v", err)
|
return fmt.Errorf("unable to base64 decode message: %w", err)
|
||||||
}
|
}
|
||||||
data = strData
|
data = strData
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -266,7 +266,7 @@ func (ps *PubSub) getPubSubClient() (*pubsub.Client, error) {
|
||||||
option.WithUserAgent(internal.ProductToken()),
|
option.WithUserAgent(internal.ProductToken()),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to generate PubSub client: %v", err)
|
return nil, fmt.Errorf("unable to generate PubSub client: %w", err)
|
||||||
}
|
}
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ func (c *CloudWatch) gatherMetrics(
|
||||||
for {
|
for {
|
||||||
resp, err := c.client.GetMetricData(context.Background(), params)
|
resp, err := c.client.GetMetricData(context.Background(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get metric data: %v", err)
|
return nil, fmt.Errorf("failed to get metric data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
results = append(results, resp.MetricDataResults...)
|
results = append(results, resp.MetricDataResults...)
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ func (c *Conntrack) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
contents, err := os.ReadFile(fName)
|
contents, err := os.ReadFile(fName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("failed to read file '%s': %v", fName, err))
|
acc.AddError(fmt.Errorf("failed to read file %q: %w", fName, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ func (c *Conntrack) Gather(acc telegraf.Accumulator) error {
|
||||||
perCPU := metric == "percpu"
|
perCPU := metric == "percpu"
|
||||||
stats, err := c.ps.NetConntrack(perCPU)
|
stats, err := c.ps.NetConntrack(perCPU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("failed to retrieve conntrack statistics: %v", err))
|
acc.AddError(fmt.Errorf("failed to retrieve conntrack statistics: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(stats) == 0 {
|
if len(stats) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -60,14 +60,14 @@ func (n *ConsulAgent) Init() error {
|
||||||
if n.TokenFile != "" {
|
if n.TokenFile != "" {
|
||||||
token, err := os.ReadFile(n.TokenFile)
|
token, err := os.ReadFile(n.TokenFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("reading file failed: %v", err)
|
return fmt.Errorf("reading file failed: %w", err)
|
||||||
}
|
}
|
||||||
n.Token = strings.TrimSpace(string(token))
|
n.Token = strings.TrimSpace(string(token))
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsCfg, err := n.ClientConfig.TLSConfig()
|
tlsCfg, err := n.ClientConfig.TLSConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("setting up TLS configuration failed: %v", err)
|
return fmt.Errorf("setting up TLS configuration failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.roundTripper = &http.Transport{
|
n.roundTripper = &http.Transport{
|
||||||
|
|
@ -100,7 +100,7 @@ func (n *ConsulAgent) loadJSON(url string) (*AgentInfo, error) {
|
||||||
|
|
||||||
resp, err := n.roundTripper.RoundTrip(req)
|
resp, err := n.roundTripper.RoundTrip(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error making HTTP request to %s: %s", url, err)
|
return nil, fmt.Errorf("error making HTTP request to %q: %w", url, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ func (n *ConsulAgent) loadJSON(url string) (*AgentInfo, error) {
|
||||||
var metrics AgentInfo
|
var metrics AgentInfo
|
||||||
err = json.NewDecoder(resp.Body).Decode(&metrics)
|
err = json.NewDecoder(resp.Body).Decode(&metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error parsing json response: %s", err)
|
return nil, fmt.Errorf("error parsing json response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &metrics, nil
|
return &metrics, nil
|
||||||
|
|
@ -121,7 +121,7 @@ func (n *ConsulAgent) loadJSON(url string) (*AgentInfo, error) {
|
||||||
func buildConsulAgent(acc telegraf.Accumulator, agentInfo *AgentInfo) error {
|
func buildConsulAgent(acc telegraf.Accumulator, agentInfo *AgentInfo) error {
|
||||||
t, err := time.Parse(timeLayout, agentInfo.Timestamp)
|
t, err := time.Parse(timeLayout, agentInfo.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing time: %s", err)
|
return fmt.Errorf("error parsing time: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, counters := range agentInfo.Counters {
|
for _, counters := range agentInfo.Counters {
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ func (c *CouchDB) Gather(accumulator telegraf.Accumulator) error {
|
||||||
go func(host string) {
|
go func(host string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := c.fetchAndInsertData(accumulator, host); err != nil {
|
if err := c.fetchAndInsertData(accumulator, host); err != nil {
|
||||||
accumulator.AddError(fmt.Errorf("[host=%s]: %s", host, err))
|
accumulator.AddError(fmt.Errorf("[host=%s]: %w", host, err))
|
||||||
}
|
}
|
||||||
}(u)
|
}(u)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func (*CPUStats) SampleConfig() string {
|
||||||
func (c *CPUStats) Gather(acc telegraf.Accumulator) error {
|
func (c *CPUStats) Gather(acc telegraf.Accumulator) error {
|
||||||
times, err := c.ps.CPUTimes(c.PerCPU, c.TotalCPU)
|
times, err := c.ps.CPUTimes(c.PerCPU, c.TotalCPU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting CPU info: %s", err)
|
return fmt.Errorf("error getting CPU info: %w", err)
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func (c *ServiceAccount) IsExpired() bool {
|
||||||
func (c *TokenCreds) Token(_ context.Context, _ Client) (string, error) {
|
func (c *TokenCreds) Token(_ context.Context, _ Client) (string, error) {
|
||||||
octets, err := os.ReadFile(c.Path)
|
octets, err := os.ReadFile(c.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error reading token file %q: %s", c.Path, err)
|
return "", fmt.Errorf("error reading token file %q: %w", c.Path, err)
|
||||||
}
|
}
|
||||||
if !utf8.Valid(octets) {
|
if !utf8.Valid(octets) {
|
||||||
return "", fmt.Errorf("token file does not contain utf-8 encoded text: %s", c.Path)
|
return "", fmt.Errorf("token file does not contain utf-8 encoded text: %s", c.Path)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package dcos
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -146,7 +147,8 @@ func (d *DCOS) GatherContainers(ctx context.Context, acc telegraf.Accumulator, c
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
m, err := d.client.GetContainerMetrics(ctx, node, container)
|
m, err := d.client.GetContainerMetrics(ctx, node, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err, ok := err.(APIError); ok && err.StatusCode == 404 {
|
var apiErr APIError
|
||||||
|
if errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
@ -162,7 +164,8 @@ func (d *DCOS) GatherContainers(ctx context.Context, acc telegraf.Accumulator, c
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
m, err := d.client.GetAppMetrics(ctx, node, container)
|
m, err := d.client.GetAppMetrics(ctx, node, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err, ok := err.(APIError); ok && err.StatusCode == 404 {
|
var apiErr APIError
|
||||||
|
if errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||||
return processFile(path)
|
return processFile(path)
|
||||||
})
|
})
|
||||||
// We've been cancelled via Stop().
|
// We've been cancelled via Stop().
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -123,7 +123,7 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||||
path := monitor.Directory + "/" + file.Name()
|
path := monitor.Directory + "/" + file.Name()
|
||||||
err := processFile(path)
|
err := processFile(path)
|
||||||
// We've been cancelled via Stop().
|
// We've been cancelled via Stop().
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +199,8 @@ func (monitor *DirectoryMonitor) processFile(path string) {
|
||||||
func (monitor *DirectoryMonitor) read(filePath string) {
|
func (monitor *DirectoryMonitor) read(filePath string) {
|
||||||
// Open, read, and parse the contents of the file.
|
// Open, read, and parse the contents of the file.
|
||||||
err := monitor.ingestFile(filePath)
|
err := monitor.ingestFile(filePath)
|
||||||
if _, isPathError := err.(*os.PathError); isPathError {
|
var pathErr *os.PathError
|
||||||
|
if errors.As(err, &pathErr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func (ds *DiskStats) Init() error {
|
||||||
func (ds *DiskStats) Gather(acc telegraf.Accumulator) error {
|
func (ds *DiskStats) Gather(acc telegraf.Accumulator) error {
|
||||||
disks, partitions, err := ds.ps.DiskUsage(ds.MountPoints, ds.IgnoreMountOpts, ds.IgnoreFS)
|
disks, partitions, err := ds.ps.DiskUsage(ds.MountPoints, ds.IgnoreMountOpts, ds.IgnoreFS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting disk usage info: %s", err)
|
return fmt.Errorf("error getting disk usage info: %w", err)
|
||||||
}
|
}
|
||||||
for i, du := range disks {
|
for i, du := range disks {
|
||||||
if du.Total == 0 {
|
if du.Total == 0 {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func (d *DiskIO) Init() error {
|
||||||
if hasMeta(device) {
|
if hasMeta(device) {
|
||||||
deviceFilter, err := filter.Compile(d.Devices)
|
deviceFilter, err := filter.Compile(d.Devices)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling device pattern: %s", err.Error())
|
return fmt.Errorf("error compiling device pattern: %w", err)
|
||||||
}
|
}
|
||||||
d.deviceFilter = deviceFilter
|
d.deviceFilter = deviceFilter
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ func (d *DiskIO) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
diskio, err := d.ps.DiskIO(devices)
|
diskio, err := d.ps.DiskIO(devices)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting disk io info: %s", err.Error())
|
return fmt.Errorf("error getting disk io info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, io := range diskio {
|
for _, io := range diskio {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func (d *Disque) Gather(acc telegraf.Accumulator) error {
|
||||||
for _, serv := range d.Servers {
|
for _, serv := range d.Servers {
|
||||||
u, err := url.Parse(serv)
|
u, err := url.Parse(serv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("unable to parse to address '%s': %s", serv, err))
|
acc.AddError(fmt.Errorf("unable to parse to address %q: %w", serv, err))
|
||||||
continue
|
continue
|
||||||
} else if u.Scheme == "" {
|
} else if u.Scheme == "" {
|
||||||
// fallback to simple string based address (i.e. "10.0.0.1:10000")
|
// fallback to simple string based address (i.e. "10.0.0.1:10000")
|
||||||
|
|
@ -100,7 +100,7 @@ func (d *Disque) gatherServer(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
c, err := net.DialTimeout("tcp", addr.Host, defaultTimeout)
|
c, err := net.DialTimeout("tcp", addr.Host, defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to connect to disque server '%s': %s", addr.Host, err)
|
return fmt.Errorf("unable to connect to disque server %q: %w", addr.Host, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if addr.User != nil {
|
if addr.User != nil {
|
||||||
|
|
@ -142,7 +142,7 @@ func (d *Disque) gatherServer(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if line[0] != '$' {
|
if line[0] != '$' {
|
||||||
return fmt.Errorf("bad line start: %s", ErrProtocolError)
|
return fmt.Errorf("bad line start: %w", ErrProtocolError)
|
||||||
}
|
}
|
||||||
|
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
|
|
@ -151,7 +151,7 @@ func (d *Disque) gatherServer(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
sz, err := strconv.Atoi(szStr)
|
sz, err := strconv.Atoi(szStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("bad size string <<%s>>: %s", szStr, ErrProtocolError)
|
return fmt.Errorf("bad size string <<%s>>: %w", szStr, ErrProtocolError)
|
||||||
}
|
}
|
||||||
|
|
||||||
var read int
|
var read int
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package dns_query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -87,7 +88,8 @@ func (d *DNSQuery) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
fields, tags, err := d.query(domain, server)
|
fields, tags, err := d.query(domain, server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if opErr, ok := err.(*net.OpError); !ok || !opErr.Timeout() {
|
var opErr *net.OpError
|
||||||
|
if !errors.As(err, &opErr) || !opErr.Timeout() {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +132,8 @@ func (d *DNSQuery) query(domain string, server string) (map[string]interface{},
|
||||||
addr := net.JoinHostPort(server, strconv.Itoa(d.Port))
|
addr := net.JoinHostPort(server, strconv.Itoa(d.Port))
|
||||||
r, rtt, err := c.Exchange(&msg, addr)
|
r, rtt, err := c.Exchange(&msg, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
|
var opErr *net.OpError
|
||||||
|
if errors.As(err, &opErr) && opErr.Timeout() {
|
||||||
tags["result"] = "timeout"
|
tags["result"] = "timeout"
|
||||||
fields["result_code"] = uint64(Timeout)
|
fields["result_code"] = uint64(Timeout)
|
||||||
return fields, tags, err
|
return fields, tags, err
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -95,12 +96,12 @@ func (*Docker) SampleConfig() string {
|
||||||
func (d *Docker) Init() error {
|
func (d *Docker) Init() error {
|
||||||
err := choice.CheckSlice(d.PerDeviceInclude, containerMetricClasses)
|
err := choice.CheckSlice(d.PerDeviceInclude, containerMetricClasses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error validating 'perdevice_include' setting : %v", err)
|
return fmt.Errorf("error validating 'perdevice_include' setting: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = choice.CheckSlice(d.TotalInclude, containerMetricClasses)
|
err = choice.CheckSlice(d.TotalInclude, containerMetricClasses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error validating 'total_include' setting : %v", err)
|
return fmt.Errorf("error validating 'total_include' setting: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary logic needed for backwards compatibility until 'perdevice' setting is removed.
|
// Temporary logic needed for backwards compatibility until 'perdevice' setting is removed.
|
||||||
|
|
@ -188,7 +189,7 @@ func (d *Docker) Gather(acc telegraf.Accumulator) error {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
containers, err := d.client.ContainerList(ctx, opts)
|
containers, err := d.client.ContainerList(ctx, opts)
|
||||||
if err == context.DeadlineExceeded {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
return errListTimeout
|
return errListTimeout
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -216,7 +217,7 @@ func (d *Docker) gatherSwarmInfo(acc telegraf.Accumulator) error {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
services, err := d.client.ServiceList(ctx, types.ServiceListOptions{})
|
services, err := d.client.ServiceList(ctx, types.ServiceListOptions{})
|
||||||
if err == context.DeadlineExceeded {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
return errServiceTimeout
|
return errServiceTimeout
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -293,7 +294,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
info, err := d.client.Info(ctx)
|
info, err := d.client.Info(ctx)
|
||||||
if err == context.DeadlineExceeded {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
return errInfoTimeout
|
return errInfoTimeout
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -453,20 +454,20 @@ func (d *Docker) gatherContainer(
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
r, err := d.client.ContainerStats(ctx, container.ID, false)
|
r, err := d.client.ContainerStats(ctx, container.ID, false)
|
||||||
if err == context.DeadlineExceeded {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
return errStatsTimeout
|
return errStatsTimeout
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting docker stats: %v", err)
|
return fmt.Errorf("error getting docker stats: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
dec := json.NewDecoder(r.Body)
|
dec := json.NewDecoder(r.Body)
|
||||||
if err = dec.Decode(&v); err != nil {
|
if err = dec.Decode(&v); err != nil {
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("error decoding: %v", err)
|
return fmt.Errorf("error decoding: %w", err)
|
||||||
}
|
}
|
||||||
daemonOSType := r.OSType
|
daemonOSType := r.OSType
|
||||||
|
|
||||||
|
|
@ -491,11 +492,11 @@ func (d *Docker) gatherContainerInspect(
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
info, err := d.client.ContainerInspect(ctx, container.ID)
|
info, err := d.client.ContainerInspect(ctx, container.ID)
|
||||||
if err == context.DeadlineExceeded {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
return errInspectTimeout
|
return errInspectTimeout
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error inspecting docker container: %v", err)
|
return fmt.Errorf("error inspecting docker container: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add whitelisted environment variables to tags
|
// Add whitelisted environment variables to tags
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -189,7 +190,7 @@ func (d *DockerLogs) Gather(acc telegraf.Accumulator) error {
|
||||||
defer d.removeFromContainerList(container.ID)
|
defer d.removeFromContainerList(container.ID)
|
||||||
|
|
||||||
err = d.tailContainerLogs(ctx, acc, container, containerName)
|
err = d.tailContainerLogs(ctx, acc, container, containerName)
|
||||||
if err != nil && err != context.Canceled {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
}(container)
|
}(container)
|
||||||
|
|
@ -284,7 +285,7 @@ func parseLine(line []byte) (time.Time, string, error) {
|
||||||
|
|
||||||
ts, err := time.Parse(time.RFC3339Nano, tsString)
|
ts, err := time.Parse(time.RFC3339Nano, tsString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, "", fmt.Errorf("error parsing timestamp %q: %v", tsString, err)
|
return time.Time{}, "", fmt.Errorf("error parsing timestamp %q: %w", tsString, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ts, string(message), nil
|
return ts, string(message), nil
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package dovecot
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
@ -74,19 +75,19 @@ func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype stri
|
||||||
|
|
||||||
_, _, err := net.SplitHostPort(addr)
|
_, _, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%q on url %s", err.Error(), addr)
|
return fmt.Errorf("%w on url %q", err, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := net.DialTimeout(proto, addr, defaultTimeout)
|
c, err := net.DialTimeout(proto, addr, defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to connect to dovecot server '%s': %s", addr, err)
|
return fmt.Errorf("unable to connect to dovecot server %q: %w", addr, err)
|
||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
// Extend connection
|
// Extend connection
|
||||||
if err := c.SetDeadline(time.Now().Add(defaultTimeout)); err != nil {
|
if err := c.SetDeadline(time.Now().Add(defaultTimeout)); err != nil {
|
||||||
return fmt.Errorf("setting deadline failed for dovecot server '%s': %s", addr, err)
|
return fmt.Errorf("setting deadline failed for dovecot server %q: %w", addr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := fmt.Sprintf("EXPORT\t%s", qtype)
|
msg := fmt.Sprintf("EXPORT\t%s", qtype)
|
||||||
|
|
@ -96,15 +97,16 @@ func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype stri
|
||||||
msg += "\n"
|
msg += "\n"
|
||||||
|
|
||||||
if _, err := c.Write([]byte(msg)); err != nil {
|
if _, err := c.Write([]byte(msg)); err != nil {
|
||||||
return fmt.Errorf("writing message %q failed for dovecot server '%s': %s", msg, addr, err)
|
return fmt.Errorf("writing message %q failed for dovecot server %q: %w", msg, addr, err)
|
||||||
}
|
}
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if _, err := io.Copy(&buf, c); err != nil {
|
if _, err := io.Copy(&buf, c); err != nil {
|
||||||
// We need to accept the timeout here as reading from the connection will only terminate on EOF
|
// We need to accept the timeout here as reading from the connection will only terminate on EOF
|
||||||
// or on a timeout to happen. As EOF for TCP connections will only be sent on connection closing,
|
// or on a timeout to happen. As EOF for TCP connections will only be sent on connection closing,
|
||||||
// the only way to get the whole message is to wait for the timeout to happen.
|
// the only way to get the whole message is to wait for the timeout to happen.
|
||||||
if nerr, ok := err.(net.Error); !ok || !nerr.Timeout() {
|
var nerr net.Error
|
||||||
return fmt.Errorf("copying message failed for dovecot server '%s': %s", addr, err)
|
if !errors.As(err, &nerr) || !nerr.Timeout() {
|
||||||
|
return fmt.Errorf("copying message failed for dovecot server %q: %w", addr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ func (dpdk *dpdk) Init() error {
|
||||||
|
|
||||||
dpdk.ethdevExcludedCommandsFilter, err = filter.Compile(dpdk.EthdevConfig.EthdevExcludeCommands)
|
dpdk.ethdevExcludedCommandsFilter, err = filter.Compile(dpdk.EthdevConfig.EthdevExcludeCommands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error occurred during filter prepation for ethdev excluded commands - %v", err)
|
return fmt.Errorf("error occurred during filter prepation for ethdev excluded commands: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dpdk.connector = newDpdkConnector(dpdk.SocketPath, dpdk.AccessTimeout)
|
dpdk.connector = newDpdkConnector(dpdk.SocketPath, dpdk.AccessTimeout)
|
||||||
|
|
@ -118,15 +118,15 @@ func (dpdk *dpdk) validateCommands() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if commandWithParams[0] != '/' {
|
if commandWithParams[0] != '/' {
|
||||||
return fmt.Errorf("'%v' command should start with '/'", commandWithParams)
|
return fmt.Errorf("%q command should start with '/'", commandWithParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
if commandWithoutParams := stripParams(commandWithParams); len(commandWithoutParams) >= maxCommandLength {
|
if commandWithoutParams := stripParams(commandWithParams); len(commandWithoutParams) >= maxCommandLength {
|
||||||
return fmt.Errorf("'%v' command is too long. It shall be less than %v characters", commandWithoutParams, maxCommandLength)
|
return fmt.Errorf("%q command is too long. It shall be less than %v characters", commandWithoutParams, maxCommandLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(commandWithParams) >= maxCommandLengthWithParams {
|
if len(commandWithParams) >= maxCommandLengthWithParams {
|
||||||
return fmt.Errorf("command with parameters '%v' shall be less than %v characters", commandWithParams, maxCommandLengthWithParams)
|
return fmt.Errorf("command with parameters %q shall be less than %v characters", commandWithParams, maxCommandLengthWithParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ func (dpdk *dpdk) gatherCommands(acc telegraf.Accumulator) []string {
|
||||||
ethdevCommands := removeSubset(dpdk.ethdevCommands, dpdk.ethdevExcludedCommandsFilter)
|
ethdevCommands := removeSubset(dpdk.ethdevCommands, dpdk.ethdevExcludedCommandsFilter)
|
||||||
ethdevCommands, err := dpdk.appendCommandsWithParamsFromList(ethdevListCommand, ethdevCommands)
|
ethdevCommands, err := dpdk.appendCommandsWithParamsFromList(ethdevListCommand, ethdevCommands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("error occurred during fetching of %v params - %v", ethdevListCommand, err))
|
acc.AddError(fmt.Errorf("error occurred during fetching of %q params: %w", ethdevListCommand, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
commands = append(commands, ethdevCommands...)
|
commands = append(commands, ethdevCommands...)
|
||||||
|
|
@ -163,7 +163,7 @@ func (dpdk *dpdk) gatherCommands(acc telegraf.Accumulator) []string {
|
||||||
if choice.Contains("rawdev", dpdk.DeviceTypes) {
|
if choice.Contains("rawdev", dpdk.DeviceTypes) {
|
||||||
rawdevCommands, err := dpdk.appendCommandsWithParamsFromList(rawdevListCommand, dpdk.rawdevCommands)
|
rawdevCommands, err := dpdk.appendCommandsWithParamsFromList(rawdevListCommand, dpdk.rawdevCommands)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("error occurred during fetching of %v params - %v", rawdevListCommand, err))
|
acc.AddError(fmt.Errorf("error occurred during fetching of %q params: %w", rawdevListCommand, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
commands = append(commands, rawdevCommands...)
|
commands = append(commands, rawdevCommands...)
|
||||||
|
|
@ -206,21 +206,21 @@ func (dpdk *dpdk) processCommand(acc telegraf.Accumulator, commandWithParams str
|
||||||
var parsedResponse map[string]interface{}
|
var parsedResponse map[string]interface{}
|
||||||
err = json.Unmarshal(buf, &parsedResponse)
|
err = json.Unmarshal(buf, &parsedResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("failed to unmarshall json response from %v command - %v", commandWithParams, err))
|
acc.AddError(fmt.Errorf("failed to unmarshall json response from %q command: %w", commandWithParams, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
command := stripParams(commandWithParams)
|
command := stripParams(commandWithParams)
|
||||||
value := parsedResponse[command]
|
value := parsedResponse[command]
|
||||||
if isEmpty(value) {
|
if isEmpty(value) {
|
||||||
acc.AddError(fmt.Errorf("got empty json on '%v' command", commandWithParams))
|
acc.AddError(fmt.Errorf("got empty json on %q command", commandWithParams))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jf := jsonparser.JSONFlattener{}
|
jf := jsonparser.JSONFlattener{}
|
||||||
err = jf.FullFlattenJSON("", value, true, true)
|
err = jf.FullFlattenJSON("", value, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("failed to flatten response - %v", err))
|
acc.AddError(fmt.Errorf("failed to flatten response: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,14 @@ func newDpdkConnector(pathToSocket string, accessTimeout config.Duration) *dpdkC
|
||||||
func (conn *dpdkConnector) connect() (*initMessage, error) {
|
func (conn *dpdkConnector) connect() (*initMessage, error) {
|
||||||
connection, err := net.Dial("unixpacket", conn.pathToSocket)
|
connection, err := net.Dial("unixpacket", conn.pathToSocket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to connect to the socket - %v", err)
|
return nil, fmt.Errorf("failed to connect to the socket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.connection = connection
|
conn.connection = connection
|
||||||
result, err := conn.readMaxOutputLen()
|
result, err := conn.readMaxOutputLen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if closeErr := conn.tryClose(); closeErr != nil {
|
if closeErr := conn.tryClose(); closeErr != nil {
|
||||||
return nil, fmt.Errorf("%v and failed to close connection - %v", err, closeErr)
|
return nil, fmt.Errorf("%w and failed to close connection: %w", err, closeErr)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -61,35 +61,33 @@ func (conn *dpdkConnector) connect() (*initMessage, error) {
|
||||||
func (conn *dpdkConnector) getCommandResponse(fullCommand string) ([]byte, error) {
|
func (conn *dpdkConnector) getCommandResponse(fullCommand string) ([]byte, error) {
|
||||||
connection, err := conn.getConnection()
|
connection, err := conn.getConnection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get connection to execute %v command - %v", fullCommand, err)
|
return nil, fmt.Errorf("failed to get connection to execute %q command: %w", fullCommand, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.setTimeout()
|
err = conn.setTimeout()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to set timeout for %v command - %v", fullCommand, err)
|
return nil, fmt.Errorf("failed to set timeout for %q command: %w", fullCommand, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = connection.Write([]byte(fullCommand))
|
_, err = connection.Write([]byte(fullCommand))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if closeErr := conn.tryClose(); closeErr != nil {
|
if closeErr := conn.tryClose(); closeErr != nil {
|
||||||
return nil, fmt.Errorf("failed to send '%v' command - %v and failed to close connection - %v",
|
return nil, fmt.Errorf("failed to send %q command: %w and failed to close connection: %w", fullCommand, err, closeErr)
|
||||||
fullCommand, err, closeErr)
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to send '%v' command - %v", fullCommand, err)
|
return nil, fmt.Errorf("failed to send %q command: %w", fullCommand, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, conn.maxOutputLen)
|
buf := make([]byte, conn.maxOutputLen)
|
||||||
messageLength, err := connection.Read(buf)
|
messageLength, err := connection.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if closeErr := conn.tryClose(); closeErr != nil {
|
if closeErr := conn.tryClose(); closeErr != nil {
|
||||||
return nil, fmt.Errorf("failed read response of '%v' command - %v and failed to close connection - %v",
|
return nil, fmt.Errorf("failed read response of %q command: %w and failed to close connection: %w", fullCommand, err, closeErr)
|
||||||
fullCommand, err, closeErr)
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to read response of '%v' command - %v", fullCommand, err)
|
return nil, fmt.Errorf("failed to read response of %q command: %w", fullCommand, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if messageLength == 0 {
|
if messageLength == 0 {
|
||||||
return nil, fmt.Errorf("got empty response during execution of '%v' command", fullCommand)
|
return nil, fmt.Errorf("got empty response during execution of %q command", fullCommand)
|
||||||
}
|
}
|
||||||
return buf[:messageLength], nil
|
return buf[:messageLength], nil
|
||||||
}
|
}
|
||||||
|
|
@ -134,18 +132,18 @@ func (conn *dpdkConnector) readMaxOutputLen() (*initMessage, error) {
|
||||||
buf := make([]byte, maxInitMessageLength)
|
buf := make([]byte, maxInitMessageLength)
|
||||||
err := conn.setTimeout()
|
err := conn.setTimeout()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to set timeout - %v", err)
|
return nil, fmt.Errorf("failed to set timeout: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
messageLength, err := conn.connection.Read(buf)
|
messageLength, err := conn.connection.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read InitMessage - %v", err)
|
return nil, fmt.Errorf("failed to read InitMessage: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var initMessage initMessage
|
var initMessage initMessage
|
||||||
err = json.Unmarshal(buf[:messageLength], &initMessage)
|
err = json.Unmarshal(buf[:messageLength], &initMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response - %v", err)
|
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if initMessage.MaxOutputLen == 0 {
|
if initMessage.MaxOutputLen == 0 {
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ func Test_getCommandResponse(t *testing.T) {
|
||||||
buf, err := dpdk.connector.getCommandResponse(command)
|
buf, err := dpdk.connector.getCommandResponse(command)
|
||||||
|
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Contains(t, err.Error(), "failed to get connection to execute / command")
|
require.Contains(t, err.Error(), "failed to get connection to execute \"/\" command")
|
||||||
require.Equal(t, 0, len(buf))
|
require.Equal(t, 0, len(buf))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,15 @@ func getParams(command string) string {
|
||||||
func isSocket(path string) error {
|
func isSocket(path string) error {
|
||||||
pathInfo, err := os.Lstat(path)
|
pathInfo, err := os.Lstat(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return fmt.Errorf("provided path does not exist: '%v'", path)
|
return fmt.Errorf("provided path does not exist: %q", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot get system information of '%v' file: %v", path, err)
|
return fmt.Errorf("cannot get system information of %q file: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pathInfo.Mode()&os.ModeSocket != os.ModeSocket {
|
if pathInfo.Mode()&os.ModeSocket != os.ModeSocket {
|
||||||
return fmt.Errorf("provided path does not point to a socket file: '%v'", path)
|
return fmt.Errorf("provided path does not point to a socket file: %q", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -72,7 +72,7 @@ func jsonToArray(input []byte, command string) ([]string, error) {
|
||||||
var intArray []int64
|
var intArray []int64
|
||||||
err = json.Unmarshal(rawMessage[command], &intArray)
|
err = json.Unmarshal(rawMessage[command], &intArray)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshall json response - %v", err)
|
return nil, fmt.Errorf("failed to unmarshall json response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stringArray := make([]string, 0, len(intArray))
|
stringArray := make([]string, 0, len(intArray))
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,11 @@ func (e *ElasticsearchQuery) runAggregationQuery(ctx context.Context, aggregatio
|
||||||
|
|
||||||
src, err := query.Source()
|
src, err := query.Source()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get query source - %v", err)
|
return nil, fmt.Errorf("failed to get query source: %w", err)
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(src)
|
data, err := json.Marshal(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal response - %v", err)
|
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
|
||||||
}
|
}
|
||||||
e.Log.Debugf("{\"query\": %s}", string(data))
|
e.Log.Debugf("{\"query\": %s}", string(data))
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@ func (e *ElasticsearchQuery) getMetricFields(ctx context.Context, aggregation es
|
||||||
for _, metricField := range aggregation.MetricFields {
|
for _, metricField := range aggregation.MetricFields {
|
||||||
resp, err := e.esClient.GetFieldMapping().Index(aggregation.Index).Field(metricField).Do(ctx)
|
resp, err := e.esClient.GetFieldMapping().Index(aggregation.Index).Field(metricField).Do(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mapMetricFields, fmt.Errorf("error retrieving field mappings for %s: %s", aggregation.Index, err.Error())
|
return mapMetricFields, fmt.Errorf("error retrieving field mappings for %s: %w", aggregation.Index, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, index := range resp {
|
for _, index := range resp {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (e *ElasticsearchQuery) initAggregation(ctx context.Context, agg esAggregat
|
||||||
// retrieve field mapping and build queries only once
|
// retrieve field mapping and build queries only once
|
||||||
agg.mapMetricFields, err = e.getMetricFields(ctx, agg)
|
agg.mapMetricFields, err = e.getMetricFields(ctx, agg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("not possible to retrieve fields: %v", err.Error())
|
return fmt.Errorf("not possible to retrieve fields: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metricField := range agg.MetricFields {
|
for _, metricField := range agg.MetricFields {
|
||||||
|
|
@ -153,7 +153,7 @@ func (e *ElasticsearchQuery) connectToES() error {
|
||||||
// check for ES version on first node
|
// check for ES version on first node
|
||||||
esVersion, err := client.ElasticsearchVersion(e.URLs[0])
|
esVersion, err := client.ElasticsearchVersion(e.URLs[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("elasticsearch version check failed: %s", err)
|
return fmt.Errorf("elasticsearch version check failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
esVersionSplit := strings.Split(esVersion, ".")
|
esVersionSplit := strings.Split(esVersion, ".")
|
||||||
|
|
@ -187,7 +187,7 @@ func (e *ElasticsearchQuery) Gather(acc telegraf.Accumulator) error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
err := e.esAggregationQuery(acc, agg, i)
|
err := e.esAggregationQuery(acc, agg, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("elasticsearch query aggregation %s: %s ", agg.MeasurementName, err.Error()))
|
acc.AddError(fmt.Errorf("elasticsearch query aggregation %s: %w", agg.MeasurementName, err))
|
||||||
}
|
}
|
||||||
}(agg, i)
|
}(agg, i)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ func (e *EventHub) Start(acc telegraf.Accumulator) error {
|
||||||
for _, partitionID := range partitions {
|
for _, partitionID := range partitions {
|
||||||
_, err := e.hub.Receive(ctx, partitionID, e.onMessage, receiveOpts...)
|
_, err := e.hub.Receive(ctx, partitionID, e.onMessage, receiveOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating receiver for partition %q: %v", partitionID, err)
|
return fmt.Errorf("creating receiver for partition %q: %w", partitionID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package exec
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -68,7 +69,7 @@ func (c CommandRunner) Run(
|
||||||
) ([]byte, []byte, error) {
|
) ([]byte, []byte, error) {
|
||||||
splitCmd, err := shellquote.Split(command)
|
splitCmd, err := shellquote.Split(command)
|
||||||
if err != nil || len(splitCmd) == 0 {
|
if err != nil || len(splitCmd) == 0 {
|
||||||
return nil, nil, fmt.Errorf("exec: unable to parse command, %s", err)
|
return nil, nil, fmt.Errorf("exec: unable to parse command: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := osExec.Command(splitCmd[0], splitCmd[1:]...)
|
cmd := osExec.Command(splitCmd[0], splitCmd[1:]...)
|
||||||
|
|
@ -126,7 +127,7 @@ func removeWindowsCarriageReturns(b bytes.Buffer) bytes.Buffer {
|
||||||
if len(byt) > 0 {
|
if len(byt) > 0 {
|
||||||
_, _ = buf.Write(byt)
|
_, _ = buf.Write(byt)
|
||||||
}
|
}
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +144,7 @@ func (e *Exec) ProcessCommand(command string, acc telegraf.Accumulator, wg *sync
|
||||||
|
|
||||||
out, errBuf, runErr := e.runner.Run(command, e.Environment, time.Duration(e.Timeout))
|
out, errBuf, runErr := e.runner.Run(command, e.Environment, time.Duration(e.Timeout))
|
||||||
if !e.parseDespiteError && runErr != nil {
|
if !e.parseDespiteError && runErr != nil {
|
||||||
err := fmt.Errorf("exec: %s for command '%s': %s", runErr, command, string(errBuf))
|
err := fmt.Errorf("exec: %w for command %q: %s", runErr, command, string(errBuf))
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,10 +107,11 @@ func (e *Execd) cmdReadOutStream(out io.Reader) {
|
||||||
for {
|
for {
|
||||||
metric, err := parser.Next()
|
metric, err := parser.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == influx.EOF {
|
if errors.Is(err, influx.EOF) {
|
||||||
break // stream ended
|
break // stream ended
|
||||||
}
|
}
|
||||||
if parseErr, isParseError := err.(*influx.ParseError); isParseError {
|
var parseErr *influx.ParseError
|
||||||
|
if errors.As(err, &parseErr) {
|
||||||
// parse error.
|
// parse error.
|
||||||
e.acc.AddError(parseErr)
|
e.acc.AddError(parseErr)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@ func (e *Execd) Gather(_ telegraf.Accumulator) error {
|
||||||
case "STDIN":
|
case "STDIN":
|
||||||
if osStdin, ok := e.process.Stdin.(*os.File); ok {
|
if osStdin, ok := e.process.Stdin.(*os.File); ok {
|
||||||
if err := osStdin.SetWriteDeadline(time.Now().Add(1 * time.Second)); err != nil {
|
if err := osStdin.SetWriteDeadline(time.Now().Add(1 * time.Second)); err != nil {
|
||||||
return fmt.Errorf("setting write deadline failed: %s", err)
|
return fmt.Errorf("setting write deadline failed: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := io.WriteString(e.process.Stdin, "\n"); err != nil {
|
if _, err := io.WriteString(e.process.Stdin, "\n"); err != nil {
|
||||||
return fmt.Errorf("writing to stdin failed: %s", err)
|
return fmt.Errorf("writing to stdin failed: %w", err)
|
||||||
}
|
}
|
||||||
case "none":
|
case "none":
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue