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: Linter fixes for plugins/inputs/p* #10066

Merged
merged 8 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-hostpool v0.1.0 // indirect
github.com/bmatcuk/doublestar/v3 v3.0.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/caio/go-tdigest v3.1.0+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
Expand Down Expand Up @@ -172,8 +171,6 @@ require (
github.com/karrick/godirwalk v1.16.1
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/klauspost/compress v1.13.6 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leodido/ragel-machinery v0.0.0-20181214104525-299bdde78165 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down Expand Up @@ -345,7 +342,6 @@ require (
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/pierrec/lz4/v4 v4.1.8 // indirect
github.com/rogpeppe/go-internal v1.6.2 // indirect
go.opentelemetry.io/otel v1.0.0-RC3 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.23.0 // indirect
go.opentelemetry.io/otel/internal/metric v0.23.0 // indirect
Expand Down
7 changes: 3 additions & 4 deletions plugins/inputs/passenger/passenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/testutil"
Expand Down Expand Up @@ -49,7 +48,7 @@ func Test_Invalid_Passenger_Status_Cli(t *testing.T) {

err := r.Gather(&acc)
require.Error(t, err)
assert.Contains(t, err.Error(), `exec: "an-invalid-command": executable file not found in `)
require.Contains(t, err.Error(), `exec: "an-invalid-command": executable file not found in `)
}

func Test_Invalid_Xml(t *testing.T) {
Expand All @@ -65,7 +64,7 @@ func Test_Invalid_Xml(t *testing.T) {

err = r.Gather(&acc)
require.Error(t, err)
assert.Equal(t, "cannot parse input with error: EOF", err.Error())
require.Equal(t, "cannot parse input with error: EOF", err.Error())
}

// We test this by ensure that the error message match the path of default cli
Expand All @@ -80,7 +79,7 @@ func Test_Default_Config_Load_Default_Command(t *testing.T) {

err = r.Gather(&acc)
require.Error(t, err)
assert.Contains(t, err.Error(), "exec: \"passenger-status\": executable file not found in ")
require.Contains(t, err.Error(), "exec: \"passenger-status\": executable file not found in ")
}

func TestPassengerGenerateMetric(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions plugins/inputs/pgbouncer/pgbouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/plugins/inputs/postgresql"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPgBouncerGeneratesMetricsIntegration(t *testing.T) {
Expand Down Expand Up @@ -55,20 +55,20 @@ func TestPgBouncerGeneratesMetricsIntegration(t *testing.T) {
metricsCounted := 0

for _, metric := range intMetricsPgBouncer {
assert.True(t, acc.HasInt64Field("pgbouncer", metric))
require.True(t, acc.HasInt64Field("pgbouncer", metric))
metricsCounted++
}

for _, metric := range intMetricsPgBouncerPools {
assert.True(t, acc.HasInt64Field("pgbouncer_pools", metric))
require.True(t, acc.HasInt64Field("pgbouncer_pools", metric))
metricsCounted++
}

for _, metric := range int32Metrics {
assert.True(t, acc.HasInt32Field("pgbouncer", metric))
require.True(t, acc.HasInt32Field("pgbouncer", metric))
metricsCounted++
}

assert.True(t, metricsCounted > 0)
assert.Equal(t, len(intMetricsPgBouncer)+len(intMetricsPgBouncerPools)+len(int32Metrics), metricsCounted)
require.True(t, metricsCounted > 0)
require.Equal(t, len(intMetricsPgBouncer)+len(intMetricsPgBouncerPools)+len(int32Metrics), metricsCounted)
}
13 changes: 5 additions & 8 deletions plugins/inputs/phpfpm/fcgi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,23 @@ func newFcgiClient(h string, args ...interface{}) (*conn, error) {
return fcgi, err
}

func (c *conn) Request(
env map[string]string,
requestData string,
) (retout []byte, reterr []byte, err error) {
func (c *conn) Request(env map[string]string, requestData string) (retout []byte, reterr []byte, err error) {
defer c.rwc.Close()
var reqID uint16 = 1

err = c.writeBeginRequest(reqID, uint16(roleResponder), 0)
if err != nil {
return
return nil, nil, err
}

err = c.writePairs(typeParams, reqID, env)
if err != nil {
return
return nil, nil, err
}

if len(requestData) > 0 {
if err = c.writeRecord(typeStdin, reqID, []byte(requestData)); err != nil {
return
return nil, nil, err
}
}

Expand Down Expand Up @@ -82,5 +79,5 @@ READ_LOOP:
}
}

return
return retout, reterr, err
}
16 changes: 7 additions & 9 deletions plugins/inputs/phpfpm/phpfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ func importMetric(r io.Reader, acc telegraf.Accumulator, addr string) {

func expandUrls(urls []string) ([]string, error) {
addrs := make([]string, 0, len(urls))
for _, url := range urls {
if isNetworkURL(url) {
addrs = append(addrs, url)
for _, address := range urls {
if isNetworkURL(address) {
addrs = append(addrs, address)
continue
}
paths, err := globUnixSocket(url)
paths, err := globUnixSocket(address)
if err != nil {
return nil, err
}
Expand All @@ -290,8 +290,8 @@ func expandUrls(urls []string) ([]string, error) {
return addrs, nil
}

func globUnixSocket(url string) ([]string, error) {
pattern, status := unixSocketPaths(url)
func globUnixSocket(address string) ([]string, error) {
pattern, status := unixSocketPaths(address)
glob, err := globpath.Compile(pattern)
if err != nil {
return nil, fmt.Errorf("could not compile glob %q: %v", pattern, err)
Expand All @@ -312,9 +312,7 @@ func globUnixSocket(url string) ([]string, error) {
return addresses, nil
}

func unixSocketPaths(addr string) (string, string) {
var socketPath, statusPath string

func unixSocketPaths(addr string) (socketPath string, statusPath string) {
socketAddr := strings.Split(addr, ":")
if len(socketAddr) >= 2 {
socketPath = socketAddr[0]
Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/phpfpm/phpfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"net/http/httptest"
"testing"

"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/testutil"
)

type statServer struct{}
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestPhpFpmDefaultGetFromLocalhost(t *testing.T) {

err := acc.GatherError(r.Gather)
require.Error(t, err)
assert.Contains(t, err.Error(), "/status")
require.Contains(t, err.Error(), "/status")
}

func TestPhpFpmGeneratesMetrics_Throw_Error_When_Fpm_Status_Is_Not_Responding(t *testing.T) {
Expand All @@ -297,8 +297,8 @@ func TestPhpFpmGeneratesMetrics_Throw_Error_When_Fpm_Status_Is_Not_Responding(t

err := acc.GatherError(r.Gather)
require.Error(t, err)
assert.Contains(t, err.Error(), `unable to connect to phpfpm status page 'http://aninvalidone'`)
assert.Contains(t, err.Error(), `lookup aninvalidone`)
require.Contains(t, err.Error(), `unable to connect to phpfpm status page 'http://aninvalidone'`)
require.Contains(t, err.Error(), `lookup aninvalidone`)
}

func TestPhpFpmGeneratesMetrics_Throw_Error_When_Socket_Path_Is_Invalid(t *testing.T) {
Expand All @@ -312,7 +312,7 @@ func TestPhpFpmGeneratesMetrics_Throw_Error_When_Socket_Path_Is_Invalid(t *testi

err := acc.GatherError(r.Gather)
require.Error(t, err)
assert.Equal(t, `socket doesn't exist "/tmp/invalid.sock"`, err.Error())
require.Equal(t, `socket doesn't exist "/tmp/invalid.sock"`, err.Error())
}

const outputSample = `
Expand Down
18 changes: 17 additions & 1 deletion plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/go-ping/ping"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
Expand Down Expand Up @@ -82,6 +83,20 @@ type Ping struct {
Size *int
}

type roundTripTimeStats struct {
min float64
avg float64
max float64
stddev float64
}

type stats struct {
trans int
recv int
ttl int
roundTripTimeStats
powersj marked this conversation as resolved.
Show resolved Hide resolved
}

func (*Ping) Description() string {
return "Ping given url(s) and return statistics"
}
Expand Down Expand Up @@ -262,7 +277,7 @@ func (p *Ping) pingToURLNative(destination string, acc telegraf.Accumulator) {

sort.Sort(durationSlice(stats.Rtts))
for _, perc := range p.Percentiles {
var value = percentile(durationSlice(stats.Rtts), perc)
var value = percentile(stats.Rtts, perc)
powersj marked this conversation as resolved.
Show resolved Hide resolved
var field = fmt.Sprintf("percentile%v_ms", perc)
fields[field] = float64(value.Nanoseconds()) / float64(time.Millisecond)
}
Expand All @@ -273,6 +288,7 @@ func (p *Ping) pingToURLNative(destination string, acc telegraf.Accumulator) {
fields["ttl"] = stats.ttl
}

//nolint:unconvert // Conversion may be needed for float64 https://github.com/mdempsky/unconvert/issues/40
fields["percent_packet_loss"] = float64(stats.PacketLoss)
fields["minimum_response_ms"] = float64(stats.MinRtt) / float64(time.Millisecond)
fields["average_response_ms"] = float64(stats.AvgRtt) / float64(time.Millisecond)
Expand Down
Loading