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

chore: Fix linter findings for revive:enforce-slice-style in plugins/inputs/[p-z]* #16043

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/inputs/p4runtime/p4runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func TestSingleEntitiesMultipleCounterRead(t *testing.T) {

func TestNoCountersAvailable(t *testing.T) {
forwardingPipelineConfig := &p4.ForwardingPipelineConfig{
P4Info: &p4_config.P4Info{Counters: []*p4_config.Counter{}},
P4Info: &p4_config.P4Info{Counters: make([]*p4_config.Counter, 0)},
}

p4RtClient := &fakeP4RuntimeClient{
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ func init() {
Deadline: 10,
Method: "exec",
Binary: "ping",
Arguments: []string{},
Percentiles: []int{},
Arguments: make([]string, 0),
Percentiles: make([]int, 0),
}
p.nativePingFunc = p.nativePing
return p
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestPostgresqlGeneratesMetricsIntegration(t *testing.T) {
"sessions_abandoned",
}

int32Metrics := []string{}
var int32Metrics []string

floatMetrics := []string{
"blk_read_time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestPostgresqlGeneratesMetricsIntegration(t *testing.T) {
"datid",
}

int32Metrics := []string{}
var int32Metrics []string

floatMetrics := []string{
"blk_read_time",
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestPostgresqlFieldOutputIntegration(t *testing.T) {
"datid",
}

int32Metrics := []string{}
var int32Metrics []string

floatMetrics := []string{
"blk_read_time",
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/procstat/pgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (pg *Pgrep) find(args []string) ([]PID, error) {
out := string(buf)

// Parse the command output to extract the PIDs
pids := []PID{}
fields := strings.Fields(out)
pids := make([]PID, 0, len(fields))
for _, field := range fields {
pid, err := strconv.ParseInt(field, 10, 32)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions plugins/inputs/procstat/procstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestMockExecCommand(_ *testing.T) {
var cmd []string //nolint:prealloc // Pre-allocated this slice would break the algorithm
for _, arg := range os.Args {
if arg == "--" {
cmd = []string{}
cmd = make([]string, 0)
continue
}
if cmd == nil {
Expand Down Expand Up @@ -139,7 +139,8 @@ func (p *testProc) SetTag(k, v string) {
}

func (p *testProc) MemoryMaps(bool) (*[]process.MemoryMapsStat, error) {
return &[]process.MemoryMapsStat{}, nil
stats := make([]process.MemoryMapsStat, 0)
return &stats, nil
}

func (p *testProc) Metrics(prefix string, cfg *collectionConfig, t time.Time) ([]telegraf.Metric, error) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/sflow/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestIPv4SW(t *testing.T) {
packet, err := hex.DecodeString(str)
require.NoError(t, err)

actual := []telegraf.Metric{}
actual := make([]telegraf.Metric, 0)
dc := newDecoder()
dc.OnPacket(func(p *v5Format) {
metrics := makeMetrics(p)
Expand Down Expand Up @@ -835,6 +835,6 @@ func TestFlowExpandCounter(t *testing.T) {
actual := makeMetrics(p)

// we don't do anything with samples yet
expected := []telegraf.Metric{}
expected := make([]telegraf.Metric, 0)
testutil.RequireMetricsEqual(t, expected, actual, testutil.IgnoreTime())
}
2 changes: 1 addition & 1 deletion plugins/inputs/sflow/metricencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func makeMetrics(p *v5Format) []telegraf.Metric {
now := time.Now()
metrics := []telegraf.Metric{}
metrics := make([]telegraf.Metric, 0)
tags := map[string]string{
"agent_address": p.AgentAddress.String(),
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/sflow/packetdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (d *packetDecoder) DecodeOnePacket(r io.Reader) (*v5Format, error) {
}

func (d *packetDecoder) decodeSamples(r io.Reader) ([]sample, error) {
result := []sample{}
// # of samples
var numOfSamples uint32
if err := read(r, &numOfSamples, "sample count"); err != nil {
return nil, err
}

result := make([]sample, 0, numOfSamples)
for i := 0; i < int(numOfSamples); i++ {
sam, err := d.decodeSample(r)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func distinguishNVMeDevices(userDevices, availableNVMeDevices []string) []string
func (m *Smart) scanDevices(ignoreExcludes bool, scanArgs ...string) ([]string, error) {
out, err := runCmd(m.Timeout, m.UseSudo, m.PathSmartctl, scanArgs...)
if err != nil {
return []string{}, fmt.Errorf("failed to run command '%s %s': %w - %s", m.PathSmartctl, scanArgs, err, string(out))
return nil, fmt.Errorf("failed to run command '%s %s': %w - %s", m.PathSmartctl, scanArgs, err, string(out))
}
var devices []string
for _, line := range strings.Split(string(out), "\n") {
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/smart/smart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestGatherInParallelMode(t *testing.T) {
require.NoError(t, err)

result := acc.GetTelegrafMetrics()
testutil.RequireMetricsEqual(t, []telegraf.Metric{}, result)
testutil.RequireMetricsEqual(t, make([]telegraf.Metric, 0), result)
})
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func TestGatherNoAttributes(t *testing.T) {

func TestExcludedDev(t *testing.T) {
require.True(t, excludedDev([]string{"/dev/pass6"}, "/dev/pass6 -d atacam"), "Should be excluded.")
require.False(t, excludedDev([]string{}, "/dev/pass6 -d atacam"), "Shouldn't be excluded.")
require.False(t, excludedDev(make([]string, 0), "/dev/pass6 -d atacam"), "Shouldn't be excluded.")
require.False(t, excludedDev([]string{"/dev/pass6"}, "/dev/pass1 -d atacam"), "Shouldn't be excluded.")
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ func TestSnmpInit_noTranslateGosmi(t *testing.T) {
}},
},
ClientConfig: snmp.ClientConfig{
Path: []string{},
Path: make([]string, 0),
Translator: "gosmi",
},
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/inputs/snmp_trap/snmp_trap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ func TestReceiveTrap(t *testing.T) {
},
},
},
entries: []entry{}, // nothing in cache
metrics: []telegraf.Metric{},
},
// v1 enterprise specific trap
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/sqlserver/sqlserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestSqlServer_QueriesInclusionExclusion(t *testing.T) {
cases := []map[string]interface{}{
{
"IncludeQuery": []string{},
"IncludeQuery": make([]string, 0),
"ExcludeQuery": []string{"WaitStatsCategorized", "DatabaseIO", "ServerProperties", "MemoryClerk", "Schedulers", "VolumeSpace", "Cpu"},
"queries": []string{"PerformanceCounters", "SqlRequests"},
"queriesTotal": 2,
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (s *stackdriver) generatetimeSeriesConfs(
return s.timeSeriesConfCache.TimeSeriesConfs, nil
}

ret := []*timeSeriesConf{}
ret := make([]*timeSeriesConf, 0)
req := &monitoringpb.ListMetricDescriptorsRequest{
Name: "projects/" + s.Project,
}
Expand Down Expand Up @@ -718,7 +718,7 @@ func init() {
RateLimit: defaultRateLimit,
Delay: defaultDelay,
GatherRawDistributionBuckets: true,
DistributionAggregationAligners: []string{},
DistributionAggregationAligners: make([]string, 0),
}
})
}
8 changes: 4 additions & 4 deletions plugins/inputs/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *MockStackdriverClient) ListTimeSeries(
}

func (m *MockStackdriverClient) Close() error {
call := &Call{name: "Close", args: []interface{}{}}
call := &Call{name: "Close", args: make([]interface{}, 0)}
m.Lock()
m.calls = append(m.calls, call)
m.Unlock()
Expand All @@ -68,7 +68,7 @@ func TestInitAndRegister(t *testing.T) {
RateLimit: defaultRateLimit,
Delay: defaultDelay,
GatherRawDistributionBuckets: true,
DistributionAggregationAligners: []string{},
DistributionAggregationAligners: make([]string, 0),
}
require.Equal(t, expected, inputs.Inputs["stackdriver"]())
}
Expand Down Expand Up @@ -751,7 +751,7 @@ func TestGather(t *testing.T) {
require.Equalf(t, tt.wantAccErr, len(acc.Errors) > 0,
"Accumulator errors. got=%v, want=%t", acc.Errors, tt.wantAccErr)

actual := []telegraf.Metric{}
actual := make([]telegraf.Metric, 0, len(acc.Metrics))
for _, m := range acc.Metrics {
actual = append(actual, testutil.FromTestMetric(m))
}
Expand Down Expand Up @@ -874,7 +874,7 @@ func TestGatherAlign(t *testing.T) {
err := s.Gather(&acc)
require.NoError(t, err)

actual := []telegraf.Metric{}
actual := make([]telegraf.Metric, 0, len(acc.Metrics))
for _, m := range acc.Metrics {
actual = append(actual, testutil.FromTestMetric(m))
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ func TestParse_TimingsMultipleFieldsWithTemplate(t *testing.T) {
// In this case the behaviour should be the same as normal behaviour
func TestParse_TimingsMultipleFieldsWithoutTemplate(t *testing.T) {
s := NewTestStatsd()
s.Templates = []string{}
s.Templates = make([]string, 0)
s.Percentiles = []Number{90.0}
acc := &testutil.Accumulator{}

Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func TestShort_SampleData(t *testing.T) {
t.Run(tC.desc, func(t *testing.T) {
s := &Supervisor{
Server: "http://example.org:9001/RPC2",
MetricsInc: []string{},
MetricsExc: []string{},
MetricsInc: make([]string, 0),
MetricsExc: make([]string, 0),
}
status := supervisorInfo{
StateCode: tC.supervisorData.StateCode,
Expand Down Expand Up @@ -153,8 +153,8 @@ func TestIntegration_BasicGathering(t *testing.T) {
defer ctr.Terminate()
s := &Supervisor{
Server: "http://login:pass@" + testutil.GetLocalHost() + ":" + ctr.Ports[supervisorPort] + "/RPC2",
MetricsInc: []string{},
MetricsExc: []string{},
MetricsInc: make([]string, 0),
MetricsExc: make([]string, 0),
}
err = s.Init()
require.NoError(t, err, "failed to run Init function")
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/sysstat/sysstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *Sysstat) Gather(acc telegraf.Accumulator) error {
// The above command collects system metrics during <collectInterval> and
// saves it in binary form to tmpFile.
func (s *Sysstat) collect(tempfile string) error {
options := []string{}
options := make([]string, 0, len(s.Activities))
for _, act := range s.Activities {
options = append(options, "-S", act)
}
Expand Down
1 change: 0 additions & 1 deletion plugins/inputs/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestUniqueUsers(t *testing.T) {
{
name: "empty entry",
expected: 0,
data: []host.UserStat{},
},
{
name: "all duplicates",
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/varnish/varnish.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func init() {
UseSudo: false,
InstanceName: "",
Timeout: defaultTimeout,
Regexps: []string{},
Regexps: make([]string, 0),
}
})
}
2 changes: 1 addition & 1 deletion plugins/inputs/vsphere/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func NewClient(ctx context.Context, vSphereURL *url.URL, vs *VSphere) (*Client,
c.Timeout = time.Duration(vs.Timeout)
m := view.NewManager(c.Client)

v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{}, true)
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, make([]string, 0), true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/vsphere/vsan.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (e *Endpoint) queryResyncSummary(ctx context.Context, vsanClient *soap.Clie
includeSummary := true
request := vsantypes.VsanQuerySyncingVsanObjects{
This: vsanSystemEx,
Uuids: []string{}, // We only need summary information.
Uuids: make([]string, 0), // We only need summary information.
Start: 0,
IncludeSummary: &includeSummary,
}
Expand Down
22 changes: 11 additions & 11 deletions plugins/inputs/vsphere/vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ func TestFinder(t *testing.T) {
require.Len(t, host, 1)
require.Equal(t, "DC0_H0", host[0].Name)

host = []mo.HostSystem{}
host = make([]mo.HostSystem, 0)
err = f.Find(ctx, "HostSystem", "/DC0/host/DC0_C0/DC0_C0_H0", &host)
require.NoError(t, err)
require.Len(t, host, 1)
require.Equal(t, "DC0_C0_H0", host[0].Name)

var resourcepool = []mo.ResourcePool{}
resourcepool := make([]mo.ResourcePool, 0)
err = f.Find(ctx, "ResourcePool", "/DC0/host/DC0_C0/Resources/DC0_C0_RP0", &resourcepool)
require.NoError(t, err)
require.Len(t, host, 1)
require.Equal(t, "DC0_C0_H0", host[0].Name)

host = []mo.HostSystem{}
host = make([]mo.HostSystem, 0)
err = f.Find(ctx, "HostSystem", "/DC0/host/DC0_C0/*", &host)
require.NoError(t, err)
require.Len(t, host, 3)
Expand All @@ -322,8 +322,8 @@ func TestFinder(t *testing.T) {
testLookupVM(ctx, t, &f, "/*/host/**/*DC*VM*", 8, "")
testLookupVM(ctx, t, &f, "/*/host/**/*DC*/*/*DC*", 4, "")

vm = []mo.VirtualMachine{}
err = f.FindAll(ctx, "VirtualMachine", []string{"/DC0/vm/DC0_H0*", "/DC0/vm/DC0_C0*"}, []string{}, &vm)
vm = make([]mo.VirtualMachine, 0)
err = f.FindAll(ctx, "VirtualMachine", []string{"/DC0/vm/DC0_H0*", "/DC0/vm/DC0_C0*"}, nil, &vm)
require.NoError(t, err)
require.Len(t, vm, 4)

Expand All @@ -333,7 +333,7 @@ func TestFinder(t *testing.T) {
excludePaths: []string{"/DC0/vm/DC0_H0_VM0"},
resType: "VirtualMachine",
}
vm = []mo.VirtualMachine{}
vm = make([]mo.VirtualMachine, 0)
require.NoError(t, rf.FindAll(ctx, &vm))
require.Len(t, vm, 3)

Expand All @@ -343,7 +343,7 @@ func TestFinder(t *testing.T) {
excludePaths: []string{"/**"},
resType: "VirtualMachine",
}
vm = []mo.VirtualMachine{}
vm = make([]mo.VirtualMachine, 0)
require.NoError(t, rf.FindAll(ctx, &vm))
require.Empty(t, vm)

Expand All @@ -353,7 +353,7 @@ func TestFinder(t *testing.T) {
excludePaths: []string{"/**"},
resType: "VirtualMachine",
}
vm = []mo.VirtualMachine{}
vm = make([]mo.VirtualMachine, 0)
require.NoError(t, rf.FindAll(ctx, &vm))
require.Empty(t, vm)

Expand All @@ -363,7 +363,7 @@ func TestFinder(t *testing.T) {
excludePaths: []string{"/this won't match anything"},
resType: "VirtualMachine",
}
vm = []mo.VirtualMachine{}
vm = make([]mo.VirtualMachine, 0)
require.NoError(t, rf.FindAll(ctx, &vm))
require.Len(t, vm, 8)

Expand All @@ -373,7 +373,7 @@ func TestFinder(t *testing.T) {
excludePaths: []string{"/**/*VM0"},
resType: "VirtualMachine",
}
vm = []mo.VirtualMachine{}
vm = make([]mo.VirtualMachine, 0)
require.NoError(t, rf.FindAll(ctx, &vm))
require.Len(t, vm, 4)
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestVsanCmmds(t *testing.T) {

f := Finder{c}
var clusters []mo.ClusterComputeResource
err = f.FindAll(ctx, "ClusterComputeResource", []string{"/**"}, []string{}, &clusters)
err = f.FindAll(ctx, "ClusterComputeResource", []string{"/**"}, nil, &clusters)
require.NoError(t, err)

clusterObj := object.NewClusterComputeResource(c.Client.Client, clusters[0].Reference())
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (wg *Wireguard) gatherDevicePeerMetrics(acc telegraf.Accumulator, device *w
}

if len(peer.AllowedIPs) > 0 {
cidrs := []string{}
cidrs := make([]string, 0, len(peer.AllowedIPs))
for _, ip := range peer.AllowedIPs {
cidrs = append(cidrs, ip.String())
}
Expand Down
Loading
Loading