Skip to content

Commit

Permalink
chore: Fix linter findings for revive:unused-receiver in `plugins/o…
Browse files Browse the repository at this point in the history
…utputs`
  • Loading branch information
zak-pawel committed Dec 20, 2024
1 parent d829a5b commit c9daf25
Show file tree
Hide file tree
Showing 47 changed files with 92 additions and 107 deletions.
2 changes: 1 addition & 1 deletion plugins/outputs/amon/amon.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (p *Point) setValue(v interface{}) error {
return nil
}

func (a *Amon) Close() error {
func (*Amon) Close() error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/amqp/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const (

type externalAuth struct{}

func (a *externalAuth) Mechanism() string {
func (*externalAuth) Mechanism() string {
return "EXTERNAL"
}

func (a *externalAuth) Response() string {
func (*externalAuth) Response() string {
return "\000"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
type diagnosticsMessageSubscriber struct {
}

func (ms diagnosticsMessageSubscriber) Subscribe(handler appinsights.DiagnosticsMessageHandler) appinsights.DiagnosticsMessageListener {
func (diagnosticsMessageSubscriber) Subscribe(handler appinsights.DiagnosticsMessageHandler) appinsights.DiagnosticsMessageListener {
return appinsights.NewDiagnosticsMessageListener(handler)
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ func (f *fakeIngestor) FromReader(_ context.Context, reader io.Reader, _ ...inge
return &ingest.Result{}, nil
}

func (f *fakeIngestor) FromFile(_ context.Context, _ string, _ ...ingest.FileOption) (*ingest.Result, error) {
func (*fakeIngestor) FromFile(context.Context, string, ...ingest.FileOption) (*ingest.Result, error) {
return &ingest.Result{}, nil
}

func (f *fakeIngestor) Close() error {
func (*fakeIngestor) Close() error {
return nil
}

Expand All @@ -351,7 +351,7 @@ func (m *mockIngestor) FromReader(_ context.Context, reader io.Reader, _ ...inge
return &ingest.Result{}, nil
}

func (m *mockIngestor) FromFile(_ context.Context, _ string, _ ...ingest.FileOption) (*ingest.Result, error) {
func (*mockIngestor) FromFile(context.Context, string, ...ingest.FileOption) (*ingest.Result, error) {
return &ingest.Result{}, nil
}

Expand All @@ -364,6 +364,6 @@ func (m *mockIngestor) Records() []string {
return m.records
}

func (m *mockIngestor) Close() error {
func (*mockIngestor) Close() error {
return nil
}
4 changes: 2 additions & 2 deletions plugins/outputs/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *BigQuery) Write(metrics []telegraf.Metric) error {
return s.writeCompact(metrics)
}

groupedMetrics := s.groupByMetricName(metrics)
groupedMetrics := groupByMetricName(metrics)

var wg sync.WaitGroup

Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *BigQuery) writeCompact(metrics []telegraf.Metric) error {
return inserter.Put(ctx, compactValues)
}

func (s *BigQuery) groupByMetricName(metrics []telegraf.Metric) map[string][]bigquery.ValueSaver {
func groupByMetricName(metrics []telegraf.Metric) map[string][]bigquery.ValueSaver {
groupedMetrics := make(map[string][]bigquery.ValueSaver)

for _, m := range metrics {
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/clarify/clarify.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Clarify) Init() error {
return errors.New("no credentials provided")
}

func (c *Clarify) Connect() error {
func (*Clarify) Connect() error {
return nil
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (c *Clarify) generateID(m telegraf.Metric, f *telegraf.Field) (string, erro
return id, nil
}

func (c *Clarify) SampleConfig() string {
func (*Clarify) SampleConfig() string {
return sampleConfig
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/cloud_pubsub/topic_stubbed.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func getTestResources(tT *testing.T, settings pubsub.PublishSettings, testM []te
return ps, t, metrics
}

func (t *stubTopic) ID() string {
func (*stubTopic) ID() string {
return "test-topic"
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/cloudwatch_logs/cloudwatch_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *CloudWatchLogs) Connect() error {
}

// Close closes plugin connection with remote receiver
func (c *CloudWatchLogs) Close() error {
func (*CloudWatchLogs) Close() error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/cloudwatch_logs/cloudwatch_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *mockCloudWatchLogs) Init(lsName string) {
c.pushedLogEvents = make([]types.InputLogEvent, 0)
}

func (c *mockCloudWatchLogs) DescribeLogGroups(
func (*mockCloudWatchLogs) DescribeLogGroups(
context.Context,
*cloudwatchlogs.DescribeLogGroupsInput,
...func(options *cloudwatchlogs.Options),
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *mockCloudWatchLogs) DescribeLogStreams(
return output, nil
}

func (c *mockCloudWatchLogs) CreateLogStream(
func (*mockCloudWatchLogs) CreateLogStream(
context.Context,
*cloudwatchlogs.CreateLogStreamInput,
...func(options *cloudwatchlogs.Options),
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (p *Point) setValue(v interface{}) error {
return nil
}

func (d *Datadog) Close() error {
func (*Datadog) Close() error {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/outputs/discard/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func (*Discard) SampleConfig() string {
return sampleConfig
}

func (d *Discard) Connect() error { return nil }
func (d *Discard) Close() error { return nil }
func (d *Discard) Write(_ []telegraf.Metric) error {
func (*Discard) Connect() error { return nil }
func (*Discard) Close() error { return nil }
func (*Discard) Write([]telegraf.Metric) error {
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions plugins/outputs/dynatrace/dynatrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (*Dynatrace) SampleConfig() string {
}

// Connect Connects the Dynatrace output plugin to the Telegraf stream
func (d *Dynatrace) Connect() error {
func (*Dynatrace) Connect() error {
return nil
}

Expand Down Expand Up @@ -231,8 +231,8 @@ func init() {

func (d *Dynatrace) getTypeOption(metric telegraf.Metric, field *telegraf.Field) dynatrace_metric.MetricOption {
metricName := metric.Name() + "." + field.Key
if d.isCounterMetricsMatch(d.AddCounterMetrics, metricName) ||
d.isCounterMetricsPatternsMatch(d.AddCounterMetricsPatterns, metricName) {
if isCounterMetricsMatch(d.AddCounterMetrics, metricName) ||
isCounterMetricsPatternsMatch(d.AddCounterMetricsPatterns, metricName) {
switch v := field.Value.(type) {
case float64:
return dynatrace_metric.WithFloatCounterValueDelta(v)
Expand Down Expand Up @@ -261,7 +261,7 @@ func (d *Dynatrace) getTypeOption(metric telegraf.Metric, field *telegraf.Field)
return nil
}

func (d *Dynatrace) isCounterMetricsMatch(counterMetrics []string, metricName string) bool {
func isCounterMetricsMatch(counterMetrics []string, metricName string) bool {
for _, i := range counterMetrics {
if i == metricName {
return true
Expand All @@ -270,7 +270,7 @@ func (d *Dynatrace) isCounterMetricsMatch(counterMetrics []string, metricName st
return false
}

func (d *Dynatrace) isCounterMetricsPatternsMatch(counterPatterns []string, metricName string) bool {
func isCounterMetricsPatternsMatch(counterPatterns []string, metricName string) bool {
for _, pattern := range counterPatterns {
regex, err := regexp.Compile(pattern)
if err == nil && regex.MatchString(metricName) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/dynatrace/dynatrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ type loggerStub struct {
testutil.Logger
}

func (l loggerStub) Warnf(_ string, _ ...interface{}) {
func (loggerStub) Warnf(string, ...interface{}) {
warnfCalledTimes++
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/outputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func (a *Elasticsearch) Connect() error {
}
}

a.IndexName, a.tagKeys = a.GetTagKeys(a.IndexName)
a.pipelineName, a.pipelineTagKeys = a.GetTagKeys(a.UsePipeline)
a.IndexName, a.tagKeys = GetTagKeys(a.IndexName)
a.pipelineName, a.pipelineTagKeys = GetTagKeys(a.UsePipeline)

return nil
}
Expand Down Expand Up @@ -424,7 +424,7 @@ func (a *Elasticsearch) createNewTemplate(templatePattern string) (*bytes.Buffer
return &tmpl, nil
}

func (a *Elasticsearch) GetTagKeys(indexName string) (string, []string) {
func GetTagKeys(indexName string) (string, []string) {
tagKeys := make([]string, 0)
startTag := strings.Index(indexName, "{{")

Expand Down
13 changes: 4 additions & 9 deletions plugins/outputs/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,6 @@ func TestTemplateInvalidIndexPatternIntegration(t *testing.T) {
}

func TestGetTagKeys(t *testing.T) {
e := &Elasticsearch{
DefaultTagValue: "none",
Log: testutil.Logger{},
}

tests := []struct {
IndexName string
ExpectedIndexName string
Expand Down Expand Up @@ -452,7 +447,7 @@ func TestGetTagKeys(t *testing.T) {
},
}
for _, test := range tests {
indexName, tagKeys := e.GetTagKeys(test.IndexName)
indexName, tagKeys := GetTagKeys(test.IndexName)
if indexName != test.ExpectedIndexName {
t.Errorf("Expected indexname %s, got %s\n", test.ExpectedIndexName, indexName)
}
Expand Down Expand Up @@ -553,7 +548,7 @@ func TestGetPipelineName(t *testing.T) {
DefaultPipeline: "myDefaultPipeline",
Log: testutil.Logger{},
}
e.pipelineName, e.pipelineTagKeys = e.GetTagKeys(e.UsePipeline)
e.pipelineName, e.pipelineTagKeys = GetTagKeys(e.UsePipeline)

tests := []struct {
EventTime time.Time
Expand Down Expand Up @@ -591,7 +586,7 @@ func TestGetPipelineName(t *testing.T) {
e = &Elasticsearch{
Log: testutil.Logger{},
}
e.pipelineName, e.pipelineTagKeys = e.GetTagKeys(e.UsePipeline)
e.pipelineName, e.pipelineTagKeys = GetTagKeys(e.UsePipeline)

for _, test := range tests {
pipelineName := e.getPipelineName(e.pipelineName, e.pipelineTagKeys, test.Tags)
Expand Down Expand Up @@ -669,7 +664,7 @@ func TestPipelineConfigs(t *testing.T) {

for _, test := range tests {
e := test.Elastic
e.pipelineName, e.pipelineTagKeys = e.GetTagKeys(e.UsePipeline)
e.pipelineName, e.pipelineTagKeys = GetTagKeys(e.UsePipeline)
pipelineName := e.getPipelineName(e.pipelineName, e.pipelineTagKeys, test.Tags)
require.Equal(t, test.Expected, pipelineName)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/event_hubs/event_hubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (e *EventHubs) Init() error {
return nil
}

func (e *EventHubs) Connect() error {
func (*EventHubs) Connect() error {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/outputs/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (e *Exec) SetSerializer(serializer telegraf.Serializer) {
}

// Connect satisfies the Output interface.
func (e *Exec) Connect() error {
func (*Exec) Connect() error {
return nil
}

// Close satisfies the Output interface.
func (e *Exec) Close() error {
func (*Exec) Close() error {
return nil
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func (c *CommandRunner) Run(timeout time.Duration, command, environments []strin
s = removeWindowsCarriageReturns(s)
if s.Len() > 0 {
if c.log.Level() < telegraf.Debug {
c.log.Errorf("Command error: %q", c.truncate(s))
c.log.Errorf("Command error: %q", truncate(s))
} else {
c.log.Debugf("Command error: %q", s)
}
Expand All @@ -141,7 +141,7 @@ func (c *CommandRunner) Run(timeout time.Duration, command, environments []strin
return nil
}

func (c *CommandRunner) truncate(buf bytes.Buffer) string {
func truncate(buf bytes.Buffer) string {
// Limit the number of bytes.
didTruncate := false
if buf.Len() > maxStderrBytes {
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func TestTruncate(t *testing.T) {
len: len("hola") + len("..."),
},
}
c := CommandRunner{}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := c.truncate(*tt.buf)
s := truncate(*tt.buf)
require.Len(t, s, tt.len)
})
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/graylog/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (g *gelfUDP) getChunksize() int {
return g.gelfConfig.MaxChunkSizeWan
}

func (g *gelfUDP) intToBytes(i int) ([]byte, error) {
func (*gelfUDP) intToBytes(i int) ([]byte, error) {
buf := new(bytes.Buffer)

err := binary.Write(buf, binary.LittleEndian, int8(i))
Expand All @@ -214,7 +214,7 @@ func (g *gelfUDP) intToBytes(i int) ([]byte, error) {
return buf.Bytes(), err
}

func (g *gelfUDP) compress(b []byte) (bytes.Buffer, error) {
func (*gelfUDP) compress(b []byte) (bytes.Buffer, error) {
var buf bytes.Buffer
comp := zlib.NewWriter(&buf)

Expand Down
6 changes: 3 additions & 3 deletions plugins/outputs/influxdb/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (c *httpClient) CreateDatabase(ctx context.Context, database string) error
}
defer resp.Body.Close()

body, err := c.validateResponse(resp.Body)
body, err := validateResponse(resp.Body)

// Check for poorly formatted response (can't be decoded)
if err != nil {
Expand Down Expand Up @@ -363,7 +363,7 @@ func (c *httpClient) writeBatch(ctx context.Context, db, rp string, metrics []te
return nil
}

body, err := c.validateResponse(resp.Body)
body, err := validateResponse(resp.Body)

// Check for poorly formatted response that can't be decoded
if err != nil {
Expand Down Expand Up @@ -526,7 +526,7 @@ func (c *httpClient) addHeaders(req *http.Request) error {
return nil
}

func (c *httpClient) validateResponse(response io.ReadCloser) (io.ReadCloser, error) {
func validateResponse(response io.ReadCloser) (io.ReadCloser, error) {
bodyBytes, err := io.ReadAll(response)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions plugins/outputs/influxdb/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *udpClient) URL() string {
return c.url.String()
}

func (c *udpClient) Database() string {
func (*udpClient) Database() string {
return ""
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func (c *udpClient) Write(ctx context.Context, metrics []telegraf.Metric) error
return nil
}

func (c *udpClient) CreateDatabase(_ context.Context, _ string) error {
func (*udpClient) CreateDatabase(_ context.Context, _ string) error {
return nil
}

Expand All @@ -141,5 +141,5 @@ func scanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
return 0, nil, nil
}

func (c *udpClient) Close() {
func (*udpClient) Close() {
}
Loading

0 comments on commit c9daf25

Please sign in to comment.