Skip to content

Commit

Permalink
chore: Fix linter findings for revive:enforce-slice-style in `plugi…
Browse files Browse the repository at this point in the history
…ns/inputs/[e-j]*` (influxdata#16088)
  • Loading branch information
zak-pawel authored and s-r-engineer committed Nov 11, 2024
1 parent 03af908 commit e49f171
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ var testEsAggregationData = []esAggregationQueryTest{
FilterQuery: "response: 200",
DateField: "@timestamp",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{},
},
nil,
Expand All @@ -357,7 +356,6 @@ var testEsAggregationData = []esAggregationQueryTest{
MetricFunction: "max",
DateField: "@timestamp",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{"size": "long"},
},
[]aggregationQueryData{
Expand Down Expand Up @@ -388,7 +386,6 @@ var testEsAggregationData = []esAggregationQueryTest{
MetricFunction: "average",
DateField: "@timestamp",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{"size": "long"},
},
nil,
Expand All @@ -405,7 +402,6 @@ var testEsAggregationData = []esAggregationQueryTest{
MetricFields: []string{"none"},
DateField: "@timestamp",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{},
},
nil,
Expand All @@ -421,7 +417,6 @@ var testEsAggregationData = []esAggregationQueryTest{
MeasurementName: "measurement11",
DateField: "@timestamp",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{},
},
nil,
Expand All @@ -439,7 +434,6 @@ var testEsAggregationData = []esAggregationQueryTest{
MetricFunction: "avg",
DateField: "@notatimestamp",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{"size": "long"},
},
[]aggregationQueryData{
Expand Down Expand Up @@ -496,7 +490,6 @@ var testEsAggregationData = []esAggregationQueryTest{
DateField: "@timestamp",
DateFieldFormat: "yyyy",
QueryPeriod: queryPeriod,
Tags: []string{},
mapMetricFields: map[string]string{},
},
nil,
Expand Down
6 changes: 1 addition & 5 deletions plugins/inputs/ethtool/ethtool_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,7 @@ func (c *commandEthtool) interfaces(includeNamespaces bool) ([]namespacedInterfa
func init() {
inputs.Add(pluginName, func() telegraf.Input {
return &Ethtool{
InterfaceInclude: []string{},
InterfaceExclude: []string{},
NamespaceInclude: []string{},
NamespaceExclude: []string{},
command: newCommandEthtool(),
command: newCommandEthtool(),
}
})
}
14 changes: 4 additions & 10 deletions plugins/inputs/ethtool/ethtool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,8 @@ func setup() {

c := &commandEthtoolMock{interfaceMap}
eth = &Ethtool{
InterfaceInclude: []string{},
InterfaceExclude: []string{},
DownInterfaces: "expose",
command: c,
DownInterfaces: "expose",
command: c,
}
}

Expand Down Expand Up @@ -932,7 +930,6 @@ func TestNormalizedKeys(t *testing.T) {
},
},
{
normalization: []string{},
stats: map[string]interface{}{
" Port RX ": uint64(1),
" Port_tx": uint64(0),
Expand All @@ -946,7 +943,6 @@ func TestNormalizedKeys(t *testing.T) {
},
},
{
normalization: []string{},
stats: map[string]interface{}{
" Port RX ": uint64(1),
" Port_tx": uint64(0),
Expand All @@ -972,10 +968,8 @@ func TestNormalizedKeys(t *testing.T) {

cmd := &commandEthtoolMock{interfaceMap}
eth = &Ethtool{
InterfaceInclude: []string{},
InterfaceExclude: []string{},
NormalizeKeys: c.normalization,
command: cmd,
NormalizeKeys: c.normalization,
command: cmd,
}

err := eth.Init()
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/eventhub_consumer/eventhub_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (e *EventHub) Init() (err error) {
}

// Set hub options
hubOpts := []eventhub.HubOption{}
hubOpts := make([]eventhub.HubOption, 0, 2)

if e.PersistenceDir != "" {
persister, err := persist.NewFilePersister(e.PersistenceDir)
Expand Down Expand Up @@ -162,7 +162,7 @@ func (e *EventHub) Stop() {
}

func (e *EventHub) configureReceiver() []eventhub.ReceiveOption {
receiveOpts := []eventhub.ReceiveOption{}
receiveOpts := make([]eventhub.ReceiveOption, 0, 4)

if e.ConsumerGroup != "" {
receiveOpts = append(receiveOpts, eventhub.ReceiveWithConsumerGroup(e.ConsumerGroup))
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/execd/shim/goshim.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ func getEnv(key string) string {
}

func loadConfigIntoInputs(md toml.MetaData, inputConfigs map[string][]toml.Primitive) ([]telegraf.Input, error) {
renderedInputs := []telegraf.Input{}

renderedInputs := make([]telegraf.Input, 0, len(inputConfigs))
for name, primitives := range inputConfigs {
inputCreator, ok := inputs.Inputs[name]
if !ok {
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/filecount/filecount.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ func (fc *FileCount) getDirs() []string {
}

func (fc *FileCount) initGlobPaths(acc telegraf.Accumulator) {
fc.globPaths = []globpath.GlobPath{}
for _, directory := range fc.getDirs() {
dirs := fc.getDirs()
fc.globPaths = make([]globpath.GlobPath, 0, len(dirs))
for _, directory := range dirs {
glob, err := globpath.Compile(directory)
if err != nil {
acc.AddError(err)
Expand All @@ -299,7 +300,6 @@ func (fc *FileCount) initGlobPaths(acc telegraf.Accumulator) {
func newFileCount() *FileCount {
return &FileCount{
Directory: "",
Directories: []string{},
Name: "*",
Recursive: true,
RegularOnly: true,
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/gnmi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ func guessPrefixFromUpdate(fields []updateField) string {
if len(fields) == 1 {
return fields[0].path.dir()
}
segments := make([]segment, 0, len(fields[0].path.segments))
commonPath := &pathInfo{
origin: fields[0].path.origin,
segments: append([]segment{}, fields[0].path.segments...),
segments: append(segments, fields[0].path.segments...),
}
for _, f := range fields[1:] {
commonPath.keepCommonPart(f.path)
Expand Down
6 changes: 4 additions & 2 deletions plugins/inputs/gnmi/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ func (pi *pathInfo) empty() bool {

func (pi *pathInfo) append(paths ...*gnmi.Path) *pathInfo {
// Copy the existing info
segments := make([]segment, 0, len(pi.segments))
path := &pathInfo{
origin: pi.origin,
target: pi.target,
segments: append([]segment{}, pi.segments...),
segments: append(segments, pi.segments...),
keyValues: make([]keySegment, 0, len(pi.keyValues)),
}
for _, elem := range pi.keyValues {
Expand Down Expand Up @@ -150,10 +151,11 @@ func (pi *pathInfo) append(paths ...*gnmi.Path) *pathInfo {

func (pi *pathInfo) appendSegments(segments ...string) *pathInfo {
// Copy the existing info
seg := make([]segment, 0, len(segments))
path := &pathInfo{
origin: pi.origin,
target: pi.target,
segments: append([]segment{}, pi.segments...),
segments: append(seg, pi.segments...),
keyValues: make([]keySegment, 0, len(pi.keyValues)),
}
for _, elem := range pi.keyValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func stateFullGCSServer(t *testing.T) *httptest.Server {
} else if pageToken == "page4" {
objListing["items"] = []interface{}{fourthElement}
} else if offset == "prefix/1604148850994" {
objListing["items"] = []interface{}{}
objListing["items"] = make([]interface{}, 0)
} else {
objListing["items"] = []interface{}{firstElement}
objListing["nextPageToken"] = "page2"
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/hugepages/hugepages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestInit(t *testing.T) {
})

t.Run("when empty hugepages types is provided then plugin should fail to initialize", func(t *testing.T) {
h := Hugepages{Types: []string{}}
h := Hugepages{Types: make([]string, 0)}
err := h.Init()

require.Error(t, err)
Expand Down
2 changes: 0 additions & 2 deletions plugins/inputs/icinga2/icinga2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func TestIcinga2Default(t *testing.T) {
func TestIcinga2DeprecatedHostConfig(t *testing.T) {
icinga2 := &Icinga2{
ObjectType: "hosts", // deprecated
Objects: []string{},
}
require.NoError(t, icinga2.Init())

Expand All @@ -40,7 +39,6 @@ func TestIcinga2DeprecatedHostConfig(t *testing.T) {
func TestIcinga2DeprecatedServicesConfig(t *testing.T) {
icinga2 := &Icinga2{
ObjectType: "services", // deprecated
Objects: []string{},
}
require.NoError(t, icinga2.Init())

Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/intel_dlb/intel_dlb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestDLB_writeReadSocketMessage(t *testing.T) {
connection: mockConn,
Log: testutil.Logger{},
}
mockConn.On("Write", []byte{}).Return(0, errors.New("write error")).Once().
mockConn.On("Write", make([]byte, 0)).Return(0, errors.New("write error")).Once().
On("Close").Return(nil).Once()

_, _, err := dlb.writeReadSocketMessage("")
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestDLB_writeReadSocketMessage(t *testing.T) {
connection: mockConn,
Log: testutil.Logger{},
}
mockConn.On("Write", []byte{}).Return(0, nil).Once().
mockConn.On("Write", make([]byte, 0)).Return(0, nil).Once().
On("Read", mock.Anything).Return(0, nil).
On("Close").Return(nil).Once()

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_pmt/intel_pmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestGather(t *testing.T) {
},
},
files: []testFile{
{guid: "test-guid", content: []byte{}},
{guid: "test-guid"},
},
wantErr: true,
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/intel_pmu/intel_pmu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestAddFiles(t *testing.T) {
mError := errors.New("mock error")

t.Run("no paths", func(t *testing.T) {
err := checkFiles([]string{}, mFileInfo)
err := checkFiles(nil, mFileInfo)
require.Error(t, err)
require.Contains(t, err.Error(), "no paths were given")
})
Expand Down
Loading

0 comments on commit e49f171

Please sign in to comment.