Skip to content

Commit

Permalink
chore: Enable revive:enforce-repeated-arg-type-style rule (influxda…
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Nov 14, 2024
1 parent 13a29cb commit fe4246f
Show file tree
Hide file tree
Showing 36 changed files with 86 additions and 145 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ linters-settings:
- name: enforce-map-style
arguments: ["make"]
exclude: [ "TEST" ]
- name: enforce-repeated-arg-type-style
arguments: ["short"]
- name: enforce-slice-style
arguments: ["make"]
- name: error-naming
Expand Down
6 changes: 1 addition & 5 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,7 @@ func (a *Agent) runProcessors(
}

// startAggregators sets up the aggregator unit and returns the source channel.
func (a *Agent) startAggregators(
aggC chan<- telegraf.Metric,
outputC chan<- telegraf.Metric,
aggregators []*models.RunningAggregator,
) (chan<- telegraf.Metric, *aggregatorUnit) {
func (a *Agent) startAggregators(aggC, outputC chan<- telegraf.Metric, aggregators []*models.RunningAggregator) (chan<- telegraf.Metric, *aggregatorUnit) {
src := make(chan telegraf.Metric, 100)
unit := &aggregatorUnit{
src: src,
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,10 @@ func (c *Config) LinkSecrets() error {
return nil
}

func (c *Config) probeParser(parentcategory string, parentname string, table *ast.Table) bool {
func (c *Config) probeParser(parentCategory, parentName string, table *ast.Table) bool {
dataFormat := c.getFieldString(table, "data_format")
if dataFormat == "" {
dataFormat = setDefaultParser(parentcategory, parentname)
dataFormat = setDefaultParser(parentCategory, parentName)
}

creator, ok := parsers.Parsers[dataFormat]
Expand Down Expand Up @@ -1812,7 +1812,7 @@ func keys(m map[string]bool) []string {
return result
}

func setDefaultParser(category string, name string) string {
func setDefaultParser(category, name string) string {
// Legacy support, exec plugin originally parsed JSON by default.
if category == "inputs" && name == "exec" {
return "json"
Expand Down
2 changes: 1 addition & 1 deletion config/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func resolve(secret []byte, resolvers map[string]telegraf.ResolveFunc) ([]byte,
return newsecret, remaining, replaceErrs
}

func splitLink(s string) (storeid string, key string) {
func splitLink(s string) (storeID, key string) {
// There should _ALWAYS_ be two parts due to the regular expression match
parts := strings.SplitN(s[2:len(s)-1], ":", 2)
return parts[0], parts[1]
Expand Down
12 changes: 2 additions & 10 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,11 @@ type IncludeExcludeFilter struct {
excludeDefault bool
}

func NewIncludeExcludeFilter(
include []string,
exclude []string,
) (Filter, error) {
func NewIncludeExcludeFilter(include, exclude []string) (Filter, error) {
return NewIncludeExcludeFilterDefaults(include, exclude, true, false)
}

func NewIncludeExcludeFilterDefaults(
include []string,
exclude []string,
includeDefault bool,
excludeDefault bool,
) (Filter, error) {
func NewIncludeExcludeFilterDefaults(include, exclude []string, includeDefault, excludeDefault bool) (Filter, error) {
in, err := Compile(include)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "strings"

// ParseImage Adapts some of the logic from the actual Docker library's image parsing routines:
// https://github.com/docker/distribution/blob/release/2.7/reference/normalize.go
func ParseImage(image string) (imageName string, imageVersion string) {
func ParseImage(image string) (imageName, imageVersion string) {
domain := ""
remainder := ""

Expand Down
2 changes: 1 addition & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func sanitizeTimestamp(timestamp string, decimalSeparator []string) string {
}

// parseTime parses a string timestamp according to the format string.
func parseTime(format string, timestamp string, location *time.Location) (time.Time, error) {
func parseTime(format, timestamp string, location *time.Location) (time.Time, error) {
loc := location
if loc == nil {
loc = time.UTC
Expand Down
2 changes: 1 addition & 1 deletion internal/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Process struct {
}

// New creates a new process wrapper
func New(command []string, envs []string) (*Process, error) {
func New(command, envs []string) (*Process, error) {
if len(command) == 0 {
return nil, errors.New("no command")
}
Expand Down
5 changes: 2 additions & 3 deletions internal/templating/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ func NewDefaultTemplateWithPattern(pattern string) (*Template, error) {
return NewTemplate(DefaultSeparator, pattern, nil)
}

// NewTemplate returns a new template ensuring it has a measurement
// specified.
func NewTemplate(separator string, pattern string, defaultTags map[string]string) (*Template, error) {
// NewTemplate returns a new template ensuring it has a measurement specified.
func NewTemplate(separator, pattern string, defaultTags map[string]string) (*Template, error) {
parts := strings.Split(pattern, separator)
hasMeasurement := false
template := &Template{
Expand Down
2 changes: 1 addition & 1 deletion models/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewBuffer(name, id, alias string, capacity int, strategy, path string) (Buf
return nil, fmt.Errorf("invalid buffer strategy %q", strategy)
}

func NewBufferStats(name string, alias string, capacity int) BufferStats {
func NewBufferStats(name, alias string, capacity int) BufferStats {
tags := map[string]string{"output": name}
if alias != "" {
tags["alias"] = alias
Expand Down
4 changes: 2 additions & 2 deletions models/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (f *Filter) compileMetricFilter() error {
return err
}

func ShouldPassFilters(include filter.Filter, exclude filter.Filter, key string) bool {
func ShouldPassFilters(include, exclude filter.Filter, key string) bool {
if include != nil && exclude != nil {
return include.Match(key) && !exclude.Match(key)
} else if include != nil {
Expand All @@ -295,7 +295,7 @@ func ShouldPassFilters(include filter.Filter, exclude filter.Filter, key string)
return true
}

func ShouldTagsPass(passFilters []TagFilter, dropFilters []TagFilter, tags []*telegraf.Tag) bool {
func ShouldTagsPass(passFilters, dropFilters []TagFilter, tags []*telegraf.Tag) bool {
pass := func(tpf []TagFilter) bool {
for _, pat := range tpf {
if pat.filter == nil {
Expand Down
12 changes: 2 additions & 10 deletions models/makemetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ import (
"github.com/influxdata/telegraf"
)

// makemetric applies new metric plugin and agent measurement and tag
// settings.
func makemetric(
metric telegraf.Metric,
nameOverride string,
namePrefix string,
nameSuffix string,
tags map[string]string,
globalTags map[string]string,
) telegraf.Metric {
// makeMetric applies new metric plugin and agent measurement and tag settings.
func makeMetric(metric telegraf.Metric, nameOverride, namePrefix, nameSuffix string, tags, globalTags map[string]string) telegraf.Metric {
if len(nameOverride) != 0 {
metric.SetName(nameOverride)
}
Expand Down
2 changes: 1 addition & 1 deletion models/running_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (r *RunningAggregator) UpdateWindow(start, until time.Time) {
}

func (r *RunningAggregator) MakeMetric(telegrafMetric telegraf.Metric) telegraf.Metric {
m := makemetric(
m := makeMetric(
telegrafMetric,
r.Config.NameOverride,
r.Config.MeasurementPrefix,
Expand Down
4 changes: 2 additions & 2 deletions models/running_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (r *RunningInput) MakeMetric(metric telegraf.Metric) telegraf.Metric {
return nil
}

makemetric(
makeMetric(
metric,
r.Config.NameOverride,
r.Config.MeasurementPrefix,
Expand All @@ -214,7 +214,7 @@ func (r *RunningInput) MakeMetric(metric telegraf.Metric) telegraf.Metric {
if r.Config.AlwaysIncludeGlobalTags {
global = r.defaultTags
}
makemetric(metric, "", "", "", local, global)
makeMetric(metric, "", "", "", local, global)
}

switch r.Config.TimeSource {
Expand Down
7 changes: 1 addition & 6 deletions models/running_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ type RunningOutput struct {
aggMutex sync.Mutex
}

func NewRunningOutput(
output telegraf.Output,
config *OutputConfig,
batchSize int,
bufferLimit int,
) *RunningOutput {
func NewRunningOutput(output telegraf.Output, config *OutputConfig, batchSize, bufferLimit int) *RunningOutput {
tags := map[string]string{"output": config.Name}
if config.Alias != "" {
tags["alias"] = config.Alias
Expand Down
16 changes: 3 additions & 13 deletions plugins/aggregators/histogram/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ func (h *HistogramAggregator) Push(acc telegraf.Accumulator) {

// groupFieldsByBuckets groups fields by metric buckets which are represented as tags
func (h *HistogramAggregator) groupFieldsByBuckets(
metricsWithGroupedFields *[]groupedByCountFields,
name string,
field string,
tags map[string]string,
counts []int64,
metricsWithGroupedFields *[]groupedByCountFields, name, field string, tags map[string]string, counts []int64,
) {
sum := int64(0)
buckets := h.getBuckets(name, field) // note that len(buckets) + 1 == len(counts)
Expand All @@ -193,13 +189,7 @@ func (h *HistogramAggregator) groupFieldsByBuckets(
}

// groupField groups field by count value
func (h *HistogramAggregator) groupField(
metricsWithGroupedFields *[]groupedByCountFields,
name string,
field string,
count int64,
tags map[string]string,
) {
func (h *HistogramAggregator) groupField(metricsWithGroupedFields *[]groupedByCountFields, name, field string, count int64, tags map[string]string) {
for key, metric := range *metricsWithGroupedFields {
if name == metric.name && isTagsIdentical(tags, metric.tags) {
(*metricsWithGroupedFields)[key].fieldsWithCount[field] = count
Expand Down Expand Up @@ -233,7 +223,7 @@ func (h *HistogramAggregator) resetCache() {
}

// getBuckets finds buckets and returns them
func (h *HistogramAggregator) getBuckets(metric string, field string) []float64 {
func (h *HistogramAggregator) getBuckets(metric, field string) []float64 {
if buckets, ok := h.buckets[metric][field]; ok {
return buckets
}
Expand Down
8 changes: 2 additions & 6 deletions plugins/aggregators/histogram/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ type fields map[string]interface{}
type tags map[string]string

// NewTestHistogram creates new test histogram aggregation with specified config
func NewTestHistogram(cfg []bucketConfig, reset bool, cumulative bool, pushOnlyOnUpdate bool) telegraf.Aggregator {
func NewTestHistogram(cfg []bucketConfig, reset, cumulative, pushOnlyOnUpdate bool) telegraf.Aggregator {
return NewTestHistogramWithExpirationInterval(cfg, reset, cumulative, pushOnlyOnUpdate, 0)
}

func NewTestHistogramWithExpirationInterval(
cfg []bucketConfig,
reset bool,
cumulative bool,
pushOnlyOnUpdate bool,
expirationInterval config.Duration,
cfg []bucketConfig, reset, cumulative, pushOnlyOnUpdate bool, expirationInterval config.Duration,
) telegraf.Aggregator {
htm := NewHistogramAggregator()
htm.Configs = cfg
Expand Down
4 changes: 2 additions & 2 deletions plugins/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func testPluginDirectory(t *testing.T, directory string) {
require.NoError(t, err)
}

func parseSourceFile(t *testing.T, goPluginFile string, pluginCategory string) {
func parseSourceFile(t *testing.T, goPluginFile, pluginCategory string) {
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, goPluginFile, nil, parser.ParseComments)
require.NoError(t, err)
Expand Down Expand Up @@ -80,7 +80,7 @@ func resolvePluginFromImports(t *testing.T, imports []*ast.ImportSpec) string {
return filepath.Base(importPath)
}

func testBuildTags(t *testing.T, buildComment string, pluginCategory string, plugin string) {
func testBuildTags(t *testing.T, buildComment, pluginCategory, plugin string) {
tags := strings.Split(buildComment, "||")
// tags might contain spaces and hence trim
tags = stringMap(tags, strings.TrimSpace)
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/opcua/opcua_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newTempDir() (string, error) {
return dir, err
}

func generateCert(host string, rsaBits int, certFile, keyFile string, dur time.Duration) (cert string, key string, err error) {
func generateCert(host string, rsaBits int, certFile, keyFile string, dur time.Duration) (cert, key string, err error) {
dir, err := newTempDir()
if err != nil {
return "", "", fmt.Errorf("failed to create certificate: %w", err)
Expand Down
7 changes: 1 addition & 6 deletions plugins/common/parallel/ordered.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ type Ordered struct {
queue chan futureMetric
}

func NewOrdered(
acc telegraf.Accumulator,
fn func(telegraf.Metric) []telegraf.Metric,
orderedQueueSize int,
workerCount int,
) *Ordered {
func NewOrdered(acc telegraf.Accumulator, fn func(telegraf.Metric) []telegraf.Metric, orderedQueueSize, workerCount int) *Ordered {
p := &Ordered{
fn: fn,
workerQueue: make(chan job, workerCount),
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/shim/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestProcessorShimWithLargerThanDefaultScannerBufferSize(t *testing.T) {
testSendAndReceive(t, "f1", string(b))
}

func testSendAndReceive(t *testing.T, fieldKey string, fieldValue string) {
func testSendAndReceive(t *testing.T, fieldKey, fieldValue string) {
p := &testProcessor{"hi", "mom"}

stdinReader, stdinWriter := io.Pipe()
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/kinesis_consumer/kinesis_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ func (t *telegrafLoggerWrapper) Logf(classification logging.Classification, form
// noopStore implements the storage interface with discard
type noopStore struct{}

func (n noopStore) SetCheckpoint(string, string, string) error { return nil }
func (n noopStore) GetCheckpoint(string, string) (string, error) { return "", nil }
func (n noopStore) SetCheckpoint(_, _, _ string) error { return nil }
func (n noopStore) GetCheckpoint(_, _ string) (string, error) { return "", nil }

func init() {
negOne, _ = new(big.Int).SetString("-1", 10)
Expand Down
8 changes: 2 additions & 6 deletions plugins/inputs/win_eventlog/win_eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (w *WinEventLog) shouldProcessField(field string) (should bool, list string
return false, "excluded"
}

func (w *WinEventLog) shouldExcludeEmptyField(field string, fieldType string, fieldValue interface{}) (should bool) {
func (w *WinEventLog) shouldExcludeEmptyField(field, fieldType string, fieldValue interface{}) (should bool) {
if w.fieldEmptyFilter == nil || !w.fieldEmptyFilter.Match(field) {
return false
}
Expand Down Expand Up @@ -496,11 +496,7 @@ func (w *WinEventLog) renderRemoteMessage(event Event) (Event, error) {
return event, nil
}

func formatEventString(
messageFlag EvtFormatMessageFlag,
eventHandle EvtHandle,
publisherHandle EvtHandle,
) (string, error) {
func formatEventString(messageFlag EvtFormatMessageFlag, eventHandle, publisherHandle EvtHandle) (string, error) {
var bufferUsed uint32
err := _EvtFormatMessage(publisherHandle, eventHandle, 0, 0, 0, messageFlag,
0, nil, &bufferUsed)
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/win_eventlog/zsyscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func _EvtClose(object EvtHandle) error {
return err
}

func _EvtNext(resultSet EvtHandle, eventArraySize uint32, eventArray *EvtHandle, timeout uint32, flags uint32, numReturned *uint32) error {
func _EvtNext(resultSet EvtHandle, eventArraySize uint32, eventArray *EvtHandle, timeout, flags uint32, numReturned *uint32) error {
r1, _, e1 := syscall.SyscallN(
procEvtNext.Addr(),
uintptr(resultSet),
Expand Down Expand Up @@ -214,7 +214,7 @@ func _EvtFormatMessage(
return err
}

func _EvtOpenPublisherMetadata(session EvtHandle, publisherIdentity *uint16, logFilePath *uint16, locale uint32, flags uint32) (EvtHandle, error) {
func _EvtOpenPublisherMetadata(session EvtHandle, publisherIdentity, logFilePath *uint16, locale, flags uint32) (EvtHandle, error) {
r0, _, e1 := syscall.SyscallN(
procEvtOpenPublisherMetadata.Addr(),
uintptr(session),
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/win_perf_counters/pdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func PdhGetFormattedCounterValueDouble(hCounter pdhCounterHandle, lpdwType *uint
// time.Sleep(2000 * time.Millisecond)
// }
// }
func PdhGetFormattedCounterArrayDouble(hCounter pdhCounterHandle, lpdwBufferSize *uint32, lpdwBufferCount *uint32, itemBuffer *byte) uint32 {
func PdhGetFormattedCounterArrayDouble(hCounter pdhCounterHandle, lpdwBufferSize, lpdwBufferCount *uint32, itemBuffer *byte) uint32 {
ret, _, _ := pdhGetFormattedCounterArrayW.Call(
uintptr(hCounter),
uintptr(PdhFmtDouble|PdhFmtNocap100),
Expand All @@ -500,7 +500,7 @@ func PdhGetFormattedCounterArrayDouble(hCounter pdhCounterHandle, lpdwBufferSize
// call PdhGetCounterInfo and access dwQueryUserData of the pdhCounterInfo structure. phQuery is
// the handle to the query, and must be used in subsequent calls. This function returns a PDH_
// constant error code, or ErrorSuccess if the call succeeded.
func PdhOpenQuery(szDataSource uintptr, dwUserData uintptr, phQuery *pdhQueryHandle) uint32 {
func PdhOpenQuery(szDataSource, dwUserData uintptr, phQuery *pdhQueryHandle) uint32 {
ret, _, _ := pdhOpenQuery.Call(
szDataSource,
dwUserData,
Expand Down Expand Up @@ -638,7 +638,7 @@ func PdhGetRawCounterValue(hCounter pdhCounterHandle, lpdwType *uint32, pValue *
// ItemBuffer
// Caller-allocated buffer that receives the array of pdhRawCounterItem structures; the structures contain the raw instance counter values.
// Set to NULL if lpdwBufferSize is zero.
func PdhGetRawCounterArray(hCounter pdhCounterHandle, lpdwBufferSize *uint32, lpdwBufferCount *uint32, itemBuffer *byte) uint32 {
func PdhGetRawCounterArray(hCounter pdhCounterHandle, lpdwBufferSize, lpdwBufferCount *uint32, itemBuffer *byte) uint32 {
ret, _, _ := pdhGetRawCounterArrayW.Call(
uintptr(hCounter),
uintptr(unsafe.Pointer(lpdwBufferSize)), //nolint:gosec // G103: Valid use of unsafe call to pass lpdwBufferSize
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/influxdb/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type MockDialer struct {
DialContextF func() (influxdb.Conn, error)
}

func (d *MockDialer) DialContext(context.Context, string, string) (influxdb.Conn, error) {
func (d *MockDialer) DialContext(_ context.Context, _, _ string) (influxdb.Conn, error) {
return d.DialContextF()
}

Expand Down
Loading

0 comments on commit fe4246f

Please sign in to comment.