Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel committed Oct 8, 2024
1 parent 347a7fa commit 8ae82b5
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion internal/snmp/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (t *Table) Init(tr Translator) error {
// makes sure oid or name is set in config file
// otherwise snmp will produce metrics with an empty name
if t.Oid == "" && t.Name == "" {
return errors.New("snmp table in config file is not named: one or both of the oid and name settings must be set")
return errors.New("unnamed SNMP table in config file: one or both of the oid and name settings must be set")
}

if t.initialized {
Expand Down
6 changes: 3 additions & 3 deletions plugins/common/shim/goshim.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ func (s *Shim) Run(pollInterval time.Duration) error {
if s.Input != nil {
err := s.RunInput(pollInterval)
if err != nil {
return fmt.Errorf("error during RunInput: %w", err)
return fmt.Errorf("running input failed: %w", err)
}
} else if s.Processor != nil {
err := s.RunProcessor()
if err != nil {
return fmt.Errorf("error during RunProcessor: %w", err)
return fmt.Errorf("running processor failed: %w", err)
}
} else if s.Output != nil {
err := s.RunOutput()
if err != nil {
return fmt.Errorf("error during RunOutput: %w", err)
return fmt.Errorf("running output failed: %w", err)
}
} else {
return errors.New("nothing to run")
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/influxdb_listener/influxdb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"net"
"net/http"
"time"
Expand Down Expand Up @@ -449,7 +450,7 @@ func (h *InfluxDBListener) handleWriteUpstreamParser(res http.ResponseWriter, re

h.acc.AddMetric(m)
}
if !errors.Is(err, influx_upstream.ErrEOF) {
if !errors.Is(err, io.EOF) {
h.Log.Debugf("Error parsing the request body: %v", err.Error())
if err := badRequest(res, err.Error()); err != nil {
h.Log.Debugf("error in bad-request: %v", err)
Expand Down
8 changes: 3 additions & 5 deletions plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const (
defaultWriteTimeout = 10 * time.Second
)

var ErrEOF = io.EOF

// The BadRequestCode constants keep standard error messages
// see: https://v2.docs.influxdata.com/v2.0/api/#operation/PostWrite
type BadRequestCode string
Expand Down Expand Up @@ -309,7 +307,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc {
if h.ParserType == "upstream" {
parser := influx_upstream.Parser{}
err = parser.Init()
if !errors.Is(err, ErrEOF) && err != nil {
if !errors.Is(err, io.EOF) && err != nil {
h.Log.Debugf("Error initializing parser: %v", err.Error())
return
}
Expand All @@ -327,7 +325,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc {
} else {
parser := influx.Parser{}
err = parser.Init()
if !errors.Is(err, ErrEOF) && err != nil {
if !errors.Is(err, io.EOF) && err != nil {
h.Log.Debugf("Error initializing parser: %v", err.Error())
return
}
Expand All @@ -341,7 +339,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc {
metrics, err = parser.Parse(bytes)
}

if !errors.Is(err, ErrEOF) && err != nil {
if !errors.Is(err, io.EOF) && err != nil {
h.Log.Debugf("Error parsing the request body: %v", err.Error())
if err := badRequest(res, Invalid, err.Error()); err != nil {
h.Log.Debugf("error in bad-request: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/kafka_consumer/kafka_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (k *KafkaConsumer) Init() error {
}

if err := k.SetConfig(cfg, k.Log); err != nil {
return fmt.Errorf("failed to SetConfig: %w", err)
return fmt.Errorf("setting config failed: %w", err)
}

switch strings.ToLower(k.Offset) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/opcua/read_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (o *ReadClient) read() error {
resp, err := o.Client.Read(o.ctx, req)
if err != nil {
o.ReadError.Incr(1)
return fmt.Errorf("failed to read RegisterNodes: %w", err)
return fmt.Errorf("reading registered nodes failed: %w", err)
}
o.ReadSuccess.Incr(1)
for i, d := range resp.Results {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/zipkin/codec/jsonV1/jsonV1.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TraceIDFromString(s string) (string, error) {
var hi, lo uint64
var err error
if len(s) > 32 {
return "", fmt.Errorf("length of TraceID cannot be greater than 16 hex characters: %s", s)
return "", fmt.Errorf("length of TraceID cannot be greater than 32 hex characters: %s", s)
} else if len(s) > 16 {
hiLen := len(s) - 16
if hi, err = strconv.ParseUint(s[0:hiLen], 16, 64); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/zipkin/zipkin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func postThriftData(datafile, address, contentType string) error {
endpoint := fmt.Sprintf("http://%s/api/v1/spans", address)
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(dat))
if err != nil {
return fmt.Errorf("unable to create new POST request for: %q", endpoint)
return fmt.Errorf("unable to create new POST request for %q: %w", endpoint, err)
}

req.Header.Set("Content-Type", contentType)
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/timestream/timestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ func (*Timestream) SampleConfig() string {

func (t *Timestream) Connect() error {
if t.DatabaseName == "" {
return errors.New("`database_name` key is required")
return errors.New("'database_name' key is required")
}

if t.MappingMode == "" {
return errors.New("`mapping_mode` key is required")
return errors.New("'mapping_mode' key is required")
}

if t.MappingMode != MappingModeSingleTable && t.MappingMode != MappingModeMultiTable {
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/timestream/timestream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func TestConnectValidatesConfigParameters(t *testing.T) {
}
// checking base arguments
noDatabaseName := Timestream{Log: testutil.Logger{}}
require.ErrorContains(t, noDatabaseName.Connect(), "`database_name` key is required")
require.ErrorContains(t, noDatabaseName.Connect(), "'database_name' key is required")

noMappingMode := Timestream{
DatabaseName: tsDbName,
Log: testutil.Logger{},
}
require.ErrorContains(t, noMappingMode.Connect(), "`mapping_mode` key is required")
require.ErrorContains(t, noMappingMode.Connect(), "'mapping_mode' key is required")

incorrectMappingMode := Timestream{
DatabaseName: tsDbName,
Expand Down
3 changes: 1 addition & 2 deletions plugins/parsers/influx/influx_upstream/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (

var (
ErrNoMetric = errors.New("no metric in line")
ErrEOF = io.EOF
)

type TimeFunc func() time.Time
Expand Down Expand Up @@ -259,7 +258,7 @@ func (sp *StreamParser) Next() (telegraf.Metric, error) {
return nil, err
}

return nil, ErrEOF
return nil, io.EOF
}

m, err := nextMetric(sp.decoder, sp.precision, sp.defaultTime, false)
Expand Down
6 changes: 3 additions & 3 deletions plugins/parsers/influx/influx_upstream/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func TestStreamParser(t *testing.T) {
for {
m, err := parser.Next()
if err != nil {
if errors.Is(err, ErrEOF) {
if errors.Is(err, io.EOF) {
break
}
require.Equal(t, tt.err.Error(), err.Error())
Expand Down Expand Up @@ -958,7 +958,7 @@ func TestStreamParserErrorString(t *testing.T) {
var errs []error
for i := 0; i < 20; i++ {
_, err := parser.Next()
if errors.Is(err, ErrEOF) {
if errors.Is(err, io.EOF) {
break
}

Expand Down Expand Up @@ -997,7 +997,7 @@ func TestStreamParserReaderError(t *testing.T) {
require.Equal(t, err, readerErr)

_, err = parser.Next()
require.Equal(t, err, ErrEOF)
require.Equal(t, err, io.EOF)
}

func TestStreamParserProducesAllAvailableMetrics(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions plugins/parsers/wavefront/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

var (
errEOF = io.EOF
errInvalidTimestamp = errors.New("invalid timestamp")
)

Expand Down Expand Up @@ -131,7 +130,7 @@ func (ep *loopedParser) parse(p *PointParser, pt *Point) error {
return err
}
err = ep.wsParser.parse(p, pt)
if errors.Is(err, errEOF) {
if errors.Is(err, io.EOF) {
break
}
}
Expand Down Expand Up @@ -171,7 +170,7 @@ func (ep *whiteSpaceParser) parse(p *PointParser, _ *Point) error {

if tok == EOF {
if !ep.nextOptional {
return errEOF
return io.EOF
}
return nil
}
Expand Down

0 comments on commit 8ae82b5

Please sign in to comment.