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:unused-receiver in agent, cmd, config, internal, metric, migrations, models, testutils and tools #16340

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
6 changes: 3 additions & 3 deletions agent/accumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ func TestAddTrackingMetricGroupEmpty(t *testing.T) {
type TestMetricMaker struct {
}

func (tm *TestMetricMaker) Name() string {
func (*TestMetricMaker) Name() string {
return "TestPlugin"
}

func (tm *TestMetricMaker) LogName() string {
return tm.Name()
}

func (tm *TestMetricMaker) MakeMetric(metric telegraf.Metric) telegraf.Metric {
func (*TestMetricMaker) MakeMetric(metric telegraf.Metric) telegraf.Metric {
return metric
}

func (tm *TestMetricMaker) Log() telegraf.Logger {
func (*TestMetricMaker) Log() telegraf.Logger {
return logger.New("TestPlugin", "test", "")
}
67 changes: 17 additions & 50 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,7 @@ func (a *Agent) initPersister() error {
return nil
}

func (a *Agent) startInputs(
dst chan<- telegraf.Metric,
inputs []*models.RunningInput,
) (*inputUnit, error) {
func (*Agent) startInputs(dst chan<- telegraf.Metric, inputs []*models.RunningInput) (*inputUnit, error) {
log.Printf("D! [agent] Starting service inputs")

unit := &inputUnit{
Expand Down Expand Up @@ -447,13 +444,9 @@ func (a *Agent) runInputs(
log.Printf("D! [agent] Input channel closed")
}

// testStartInputs is a variation of startInputs for use in --test and --once
// mode. It differs by logging Start errors and returning only plugins
// successfully started.
func (a *Agent) testStartInputs(
dst chan<- telegraf.Metric,
inputs []*models.RunningInput,
) *inputUnit {
// testStartInputs is a variation of startInputs for use in --test and --once mode.
// It differs by logging Start errors and returning only plugins successfully started.
func (*Agent) testStartInputs(dst chan<- telegraf.Metric, inputs []*models.RunningInput) *inputUnit {
log.Printf("D! [agent] Starting service inputs")

unit := &inputUnit{
Expand Down Expand Up @@ -582,14 +575,8 @@ func (a *Agent) gatherLoop(
}
}

// gatherOnce runs the input's Gather function once, logging a warning each
// interval it fails to complete before.
func (a *Agent) gatherOnce(
acc telegraf.Accumulator,
input *models.RunningInput,
ticker Ticker,
interval time.Duration,
) error {
// gatherOnce runs the input's Gather function once, logging a warning each interval it fails to complete before.
func (*Agent) gatherOnce(acc telegraf.Accumulator, input *models.RunningInput, ticker Ticker, interval time.Duration) error {
done := make(chan error)
go func() {
defer panicRecover(input)
Expand Down Expand Up @@ -617,12 +604,8 @@ func (a *Agent) gatherOnce(
}
}

// startProcessors sets up the processor chain and calls Start on all
// processors. If an error occurs any started processors are Stopped.
func (a *Agent) startProcessors(
dst chan<- telegraf.Metric,
runningProcessors models.RunningProcessors,
) (chan<- telegraf.Metric, []*processorUnit, error) {
// startProcessors sets up the processor chain and calls Start on all processors. If an error occurs any started processors are Stopped.
func (*Agent) startProcessors(dst chan<- telegraf.Metric, runningProcessors models.RunningProcessors) (chan<- telegraf.Metric, []*processorUnit, error) {
var src chan telegraf.Metric
units := make([]*processorUnit, 0, len(runningProcessors))
// The processor chain is constructed from the output side starting from
Expand Down Expand Up @@ -657,11 +640,8 @@ func (a *Agent) startProcessors(
return src, units, nil
}

// runProcessors begins processing metrics and runs until the source channel is
// closed and all metrics have been written.
func (a *Agent) runProcessors(
units []*processorUnit,
) {
// runProcessors begins processing metrics and runs until the source channel is closed and all metrics have been written.
func (*Agent) runProcessors(units []*processorUnit) {
var wg sync.WaitGroup
for _, unit := range units {
wg.Add(1)
Expand All @@ -684,7 +664,7 @@ func (a *Agent) runProcessors(
}

// startAggregators sets up the aggregator unit and returns the source channel.
func (a *Agent) startAggregators(aggC, outputC chan<- telegraf.Metric, aggregators []*models.RunningAggregator) (chan<- telegraf.Metric, *aggregatorUnit) {
func (*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 Expand Up @@ -771,11 +751,7 @@ func updateWindow(start time.Time, roundInterval bool, period time.Duration) (ti
}

// push runs the push for a single aggregator every period.
func (a *Agent) push(
ctx context.Context,
aggregator *models.RunningAggregator,
acc telegraf.Accumulator,
) {
func (*Agent) push(ctx context.Context, aggregator *models.RunningAggregator, acc telegraf.Accumulator) {
for {
// Ensures that Push will be called for each period, even if it has
// already elapsed before this function is called. This is guaranteed
Expand Down Expand Up @@ -824,7 +800,7 @@ func (a *Agent) startOutputs(
}

// connectOutput connects to all outputs.
func (a *Agent) connectOutput(ctx context.Context, output *models.RunningOutput) error {
func (*Agent) connectOutput(ctx context.Context, output *models.RunningOutput) error {
log.Printf("D! [agent] Attempting connection to [%s]", output.LogName())
if err := output.Connect(); err != nil {
log.Printf("E! [agent] Failed to connect to [%s], retrying in 15s, error was %q", output.LogName(), err)
Expand Down Expand Up @@ -938,13 +914,8 @@ func (a *Agent) flushLoop(
}
}

// flushOnce runs the output's Write function once, logging a warning each
// interval it fails to complete before the flush interval elapses.
func (a *Agent) flushOnce(
output *models.RunningOutput,
ticker Ticker,
writeFunc func() error,
) error {
// flushOnce runs the output's Write function once, logging a warning each interval it fails to complete before the flush interval elapses.
func (*Agent) flushOnce(output *models.RunningOutput, ticker Ticker, writeFunc func() error) error {
done := make(chan error)
go func() {
done <- writeFunc()
Expand All @@ -963,12 +934,8 @@ func (a *Agent) flushOnce(
}
}

// flushBatch runs the output's Write function once Unlike flushOnce the
// interval elapsing is not considered during these flushes.
func (a *Agent) flushBatch(
output *models.RunningOutput,
writeFunc func() error,
) error {
// flushBatch runs the output's Write function once Unlike flushOnce the interval elapsing is not considered during these flushes.
func (*Agent) flushBatch(output *models.RunningOutput, writeFunc func() error) error {
err := writeFunc()
output.LogBufferStatus()
return err
Expand Down
12 changes: 6 additions & 6 deletions cmd/telegraf/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ func (m *MockTelegraf) Init(_ <-chan error, _ Filters, g GlobalFlags, w WindowFl
m.WindowFlags = w
}

func (m *MockTelegraf) Run() error {
func (*MockTelegraf) Run() error {
return nil
}

func (m *MockTelegraf) ListSecretStores() ([]string, error) {
func (*MockTelegraf) ListSecretStores() ([]string, error) {
ids := make([]string, 0, len(secrets))
for k := range secrets {
ids = append(ids, k)
}
return ids, nil
}

func (m *MockTelegraf) GetSecretStore(id string) (telegraf.SecretStore, error) {
func (*MockTelegraf) GetSecretStore(id string) (telegraf.SecretStore, error) {
v, found := secrets[id]
if !found {
return nil, errors.New("unknown secret store")
Expand All @@ -78,11 +78,11 @@ type MockSecretStore struct {
Secrets map[string][]byte
}

func (s *MockSecretStore) Init() error {
func (*MockSecretStore) Init() error {
return nil
}

func (s *MockSecretStore) SampleConfig() string {
func (*MockSecretStore) SampleConfig() string {
return "I'm just a dummy"
}

Expand Down Expand Up @@ -149,7 +149,7 @@ func (m *MockServer) Start(_ string) {
m.Address = "localhost:6060"
}

func (m *MockServer) ErrChan() <-chan error {
func (*MockServer) ErrChan() <-chan error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (t *Telegraf) watchLocalConfig(ctx context.Context, signals chan os.Signal,
signals <- syscall.SIGHUP
}

func (t *Telegraf) watchRemoteConfigs(ctx context.Context, signals chan os.Signal, interval time.Duration, remoteConfigs []string) {
func (*Telegraf) watchRemoteConfigs(ctx context.Context, signals chan os.Signal, interval time.Duration, remoteConfigs []string) {
configs := strings.Join(remoteConfigs, ", ")
log.Printf("I! Remote config watcher started for: %s\n", configs)

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ func (c *Config) resetMissingTomlFieldTracker() {
c.toml.MissingField = c.missingTomlField
}

func (c *Config) getFieldString(tbl *ast.Table, fieldName string) string {
func (*Config) getFieldString(tbl *ast.Table, fieldName string) string {
if node, ok := tbl.Fields[fieldName]; ok {
if kv, ok := node.(*ast.KeyValue); ok {
if str, ok := kv.Value.(*ast.String); ok {
Expand Down
67 changes: 31 additions & 36 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,10 +1198,10 @@ type MockupInputPluginParserNew struct {
ParserFunc telegraf.ParserFunc
}

func (m *MockupInputPluginParserNew) SampleConfig() string {
func (*MockupInputPluginParserNew) SampleConfig() string {
return "Mockup old parser test plugin"
}
func (m *MockupInputPluginParserNew) Gather(_ telegraf.Accumulator) error {
func (*MockupInputPluginParserNew) Gather(telegraf.Accumulator) error {
return nil
}
func (m *MockupInputPluginParserNew) SetParser(parser telegraf.Parser) {
Expand Down Expand Up @@ -1231,10 +1231,10 @@ type MockupInputPlugin struct {
parser telegraf.Parser
}

func (m *MockupInputPlugin) SampleConfig() string {
func (*MockupInputPlugin) SampleConfig() string {
return "Mockup test input plugin"
}
func (m *MockupInputPlugin) Gather(_ telegraf.Accumulator) error {
func (*MockupInputPlugin) Gather(telegraf.Accumulator) error {
return nil
}
func (m *MockupInputPlugin) SetParser(parser telegraf.Parser) {
Expand All @@ -1246,10 +1246,10 @@ type MockupInputPluginParserFunc struct {
parserFunc telegraf.ParserFunc
}

func (m *MockupInputPluginParserFunc) SampleConfig() string {
func (*MockupInputPluginParserFunc) SampleConfig() string {
return "Mockup test input plugin"
}
func (m *MockupInputPluginParserFunc) Gather(_ telegraf.Accumulator) error {
func (*MockupInputPluginParserFunc) Gather(telegraf.Accumulator) error {
return nil
}
func (m *MockupInputPluginParserFunc) SetParserFunc(pf telegraf.ParserFunc) {
Expand All @@ -1261,10 +1261,10 @@ type MockupInputPluginParserOnly struct {
parser telegraf.Parser
}

func (m *MockupInputPluginParserOnly) SampleConfig() string {
func (*MockupInputPluginParserOnly) SampleConfig() string {
return "Mockup test input plugin"
}
func (m *MockupInputPluginParserOnly) Gather(_ telegraf.Accumulator) error {
func (*MockupInputPluginParserOnly) Gather(telegraf.Accumulator) error {
return nil
}
func (m *MockupInputPluginParserOnly) SetParser(p telegraf.Parser) {
Expand All @@ -1277,18 +1277,18 @@ type MockupProcessorPluginParser struct {
ParserFunc telegraf.ParserFunc
}

func (m *MockupProcessorPluginParser) Start(_ telegraf.Accumulator) error {
func (*MockupProcessorPluginParser) Start(telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPluginParser) Stop() {
func (*MockupProcessorPluginParser) Stop() {
}
func (m *MockupProcessorPluginParser) SampleConfig() string {
func (*MockupProcessorPluginParser) SampleConfig() string {
return "Mockup test processor plugin with parser"
}
func (m *MockupProcessorPluginParser) Apply(_ ...telegraf.Metric) []telegraf.Metric {
func (*MockupProcessorPluginParser) Apply(...telegraf.Metric) []telegraf.Metric {
return nil
}
func (m *MockupProcessorPluginParser) Add(_ telegraf.Metric, _ telegraf.Accumulator) error {
func (*MockupProcessorPluginParser) Add(telegraf.Metric, telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPluginParser) SetParser(parser telegraf.Parser) {
Expand All @@ -1304,15 +1304,10 @@ type MockupProcessorPlugin struct {
state []uint64
}

func (m *MockupProcessorPlugin) Start(_ telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPlugin) Stop() {
}
func (m *MockupProcessorPlugin) SampleConfig() string {
func (*MockupProcessorPlugin) SampleConfig() string {
return "Mockup test processor plugin with parser"
}
func (m *MockupProcessorPlugin) Apply(in ...telegraf.Metric) []telegraf.Metric {
func (*MockupProcessorPlugin) Apply(in ...telegraf.Metric) []telegraf.Metric {
out := make([]telegraf.Metric, 0, len(in))
for _, m := range in {
m.AddTag("processed", "yes")
Expand All @@ -1338,18 +1333,18 @@ type MockupProcessorPluginParserOnly struct {
Parser telegraf.Parser
}

func (m *MockupProcessorPluginParserOnly) Start(_ telegraf.Accumulator) error {
func (*MockupProcessorPluginParserOnly) Start(telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPluginParserOnly) Stop() {
func (*MockupProcessorPluginParserOnly) Stop() {
}
func (m *MockupProcessorPluginParserOnly) SampleConfig() string {
func (*MockupProcessorPluginParserOnly) SampleConfig() string {
return "Mockup test processor plugin with parser"
}
func (m *MockupProcessorPluginParserOnly) Apply(_ ...telegraf.Metric) []telegraf.Metric {
func (*MockupProcessorPluginParserOnly) Apply(...telegraf.Metric) []telegraf.Metric {
return nil
}
func (m *MockupProcessorPluginParserOnly) Add(_ telegraf.Metric, _ telegraf.Accumulator) error {
func (*MockupProcessorPluginParserOnly) Add(telegraf.Metric, telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPluginParserOnly) SetParser(parser telegraf.Parser) {
Expand All @@ -1361,18 +1356,18 @@ type MockupProcessorPluginParserFunc struct {
Parser telegraf.ParserFunc
}

func (m *MockupProcessorPluginParserFunc) Start(_ telegraf.Accumulator) error {
func (*MockupProcessorPluginParserFunc) Start(telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPluginParserFunc) Stop() {
func (*MockupProcessorPluginParserFunc) Stop() {
}
func (m *MockupProcessorPluginParserFunc) SampleConfig() string {
func (*MockupProcessorPluginParserFunc) SampleConfig() string {
return "Mockup test processor plugin with parser"
}
func (m *MockupProcessorPluginParserFunc) Apply(_ ...telegraf.Metric) []telegraf.Metric {
func (*MockupProcessorPluginParserFunc) Apply(...telegraf.Metric) []telegraf.Metric {
return nil
}
func (m *MockupProcessorPluginParserFunc) Add(_ telegraf.Metric, _ telegraf.Accumulator) error {
func (*MockupProcessorPluginParserFunc) Add(telegraf.Metric, telegraf.Accumulator) error {
return nil
}
func (m *MockupProcessorPluginParserFunc) SetParserFunc(pf telegraf.ParserFunc) {
Expand All @@ -1389,16 +1384,16 @@ type MockupOutputPlugin struct {
tls.ClientConfig
}

func (m *MockupOutputPlugin) Connect() error {
func (*MockupOutputPlugin) Connect() error {
return nil
}
func (m *MockupOutputPlugin) Close() error {
func (*MockupOutputPlugin) Close() error {
return nil
}
func (m *MockupOutputPlugin) SampleConfig() string {
func (*MockupOutputPlugin) SampleConfig() string {
return "Mockup test output plugin"
}
func (m *MockupOutputPlugin) Write(_ []telegraf.Metric) error {
func (*MockupOutputPlugin) Write([]telegraf.Metric) error {
return nil
}

Expand Down Expand Up @@ -1474,11 +1469,11 @@ func (m *MockupStatePlugin) SetState(state interface{}) error {
return nil
}

func (m *MockupStatePlugin) SampleConfig() string {
func (*MockupStatePlugin) SampleConfig() string {
return "Mockup test plugin"
}

func (m *MockupStatePlugin) Gather(_ telegraf.Accumulator) error {
func (*MockupStatePlugin) Gather(telegraf.Accumulator) error {
return nil
}

Expand Down
Loading
Loading