Skip to content

Commit 7bffe32

Browse files
authored
chore(processors): Fix linter findings for revive:exported (#17081)
1 parent 7af7451 commit 7bffe32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1229
-1253
lines changed

.golangci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ linters:
340340
- "**/plugins/common/**"
341341
- "**/plugins/outputs/**"
342342
- "**/plugins/parsers/**"
343-
- "**/plugins/processors/**"
344-
- "**/plugins/secretstores/**"
345-
- "**/plugins/serializers/**"
346343
- "**/selfstat/**"
347344
- "**/serializer.go"
348345
- "**/testutil/**"
@@ -523,7 +520,7 @@ linters:
523520

524521
# revive:exported
525522
- path: (.+)\.go$
526-
text: exported method .*\.(Init |SampleConfig |Gather |Start |Stop |GetState |SetState |SetParser |SetParserFunc |SetTranslator |Probe |Add |Push |Reset |Serialize |SerializeBatch |Get |Set |List |GetResolver )should have comment or be unexported
523+
text: exported method .*\.(Init |SampleConfig |Gather |Start |Stop |GetState |SetState |SetParser |SetParserFunc |SetTranslator |Probe |Add |Push |Reset |Serialize |SerializeBatch |Get |Set |List |GetResolver |Apply |SetSerializer )should have comment or be unexported
527524

528525
# EXC0001 errcheck: Almost all programs ignore errors on these functions, and in most cases it's ok
529526
- path: (.+)\.go$

plugins/processors/aws_ec2/ec2.go

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ import (
2828
//go:embed sample.conf
2929
var sampleConfig string
3030

31+
var allowedImdsTags = []string{
32+
"accountId",
33+
"architecture",
34+
"availabilityZone",
35+
"billingProducts",
36+
"imageId",
37+
"instanceId",
38+
"instanceType",
39+
"kernelId",
40+
"pendingTime",
41+
"privateIp",
42+
"ramdiskId",
43+
"region",
44+
"version",
45+
}
46+
47+
const (
48+
defaultMaxOrderedQueueSize = 10_000
49+
defaultMaxParallelCalls = 10
50+
defaultTimeout = 10 * time.Second
51+
defaultCacheTTL = 0 * time.Hour
52+
defaultCacheSize = 1000
53+
)
54+
3155
type AwsEc2Processor struct {
3256
ImdsTags []string `toml:"imds_tags"`
3357
EC2Tags []string `toml:"ec2_tags"`
@@ -50,40 +74,10 @@ type AwsEc2Processor struct {
5074
cancelCleanupWorker context.CancelFunc
5175
}
5276

53-
const (
54-
DefaultMaxOrderedQueueSize = 10_000
55-
DefaultMaxParallelCalls = 10
56-
DefaultTimeout = 10 * time.Second
57-
DefaultCacheTTL = 0 * time.Hour
58-
DefaultCacheSize = 1000
59-
DefaultLogCacheStats = false
60-
)
61-
62-
var allowedImdsTags = []string{
63-
"accountId",
64-
"architecture",
65-
"availabilityZone",
66-
"billingProducts",
67-
"imageId",
68-
"instanceId",
69-
"instanceType",
70-
"kernelId",
71-
"pendingTime",
72-
"privateIp",
73-
"ramdiskId",
74-
"region",
75-
"version",
76-
}
77-
7877
func (*AwsEc2Processor) SampleConfig() string {
7978
return sampleConfig
8079
}
8180

82-
func (r *AwsEc2Processor) Add(metric telegraf.Metric, _ telegraf.Accumulator) error {
83-
r.parallel.Enqueue(metric)
84-
return nil
85-
}
86-
8781
func (r *AwsEc2Processor) Init() error {
8882
r.Log.Debug("Initializing AWS EC2 Processor")
8983

@@ -151,14 +145,19 @@ func (r *AwsEc2Processor) Start(acc telegraf.Accumulator) error {
151145
}
152146

153147
if r.Ordered {
154-
r.parallel = parallel.NewOrdered(acc, r.asyncAdd, DefaultMaxOrderedQueueSize, r.MaxParallelCalls)
148+
r.parallel = parallel.NewOrdered(acc, r.asyncAdd, defaultMaxOrderedQueueSize, r.MaxParallelCalls)
155149
} else {
156150
r.parallel = parallel.NewUnordered(acc, r.asyncAdd, r.MaxParallelCalls)
157151
}
158152

159153
return nil
160154
}
161155

156+
func (r *AwsEc2Processor) Add(metric telegraf.Metric, _ telegraf.Accumulator) error {
157+
r.parallel.Enqueue(metric)
158+
return nil
159+
}
160+
162161
func (r *AwsEc2Processor) Stop() {
163162
if r.parallel != nil {
164163
r.parallel.Stop()
@@ -376,21 +375,6 @@ func (r *AwsEc2Processor) asyncAdd(metric telegraf.Metric) []telegraf.Metric {
376375
return []telegraf.Metric{metric}
377376
}
378377

379-
func init() {
380-
processors.AddStreaming("aws_ec2", func() telegraf.StreamingProcessor {
381-
return newAwsEc2Processor()
382-
})
383-
}
384-
385-
func newAwsEc2Processor() *AwsEc2Processor {
386-
return &AwsEc2Processor{
387-
MaxParallelCalls: DefaultMaxParallelCalls,
388-
TagCacheSize: DefaultCacheSize,
389-
Timeout: config.Duration(DefaultTimeout),
390-
CacheTTL: config.Duration(DefaultCacheTTL),
391-
}
392-
}
393-
394378
func getTagFromDescribeTags(o *ec2.DescribeTagsOutput, tag string) string {
395379
for _, t := range o.Tags {
396380
if *t.Key == tag {
@@ -399,3 +383,18 @@ func getTagFromDescribeTags(o *ec2.DescribeTagsOutput, tag string) string {
399383
}
400384
return ""
401385
}
386+
387+
func newAwsEc2Processor() *AwsEc2Processor {
388+
return &AwsEc2Processor{
389+
MaxParallelCalls: defaultMaxParallelCalls,
390+
TagCacheSize: defaultCacheSize,
391+
Timeout: config.Duration(defaultTimeout),
392+
CacheTTL: config.Duration(defaultCacheTTL),
393+
}
394+
}
395+
396+
func init() {
397+
processors.AddStreaming("aws_ec2", func() telegraf.StreamingProcessor {
398+
return newAwsEc2Processor()
399+
})
400+
}

plugins/processors/aws_ec2/ec2_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ func TestTracking(t *testing.T) {
138138

139139
// Prepare and start the plugin
140140
plugin := &AwsEc2Processor{
141-
MaxParallelCalls: DefaultMaxParallelCalls,
142-
TagCacheSize: DefaultCacheSize,
143-
Timeout: config.Duration(DefaultTimeout),
144-
CacheTTL: config.Duration(DefaultCacheTTL),
141+
MaxParallelCalls: defaultMaxParallelCalls,
142+
TagCacheSize: defaultCacheSize,
143+
Timeout: config.Duration(defaultTimeout),
144+
CacheTTL: config.Duration(defaultCacheTTL),
145145
ImdsTags: []string{"accountId", "instanceId"},
146146
Log: &testutil.Logger{},
147147
}
@@ -150,7 +150,7 @@ func TestTracking(t *testing.T) {
150150
// Instead of starting the plugin which tries to connect to the remote
151151
// service, we just fill the cache and start the minimum mechanics to
152152
// process the metrics.
153-
plugin.tagCache = freecache.NewCache(DefaultCacheSize)
153+
plugin.tagCache = freecache.NewCache(defaultCacheSize)
154154
require.NoError(t, plugin.tagCache.Set([]byte("accountId"), []byte("123456789"), -1))
155155
require.NoError(t, plugin.tagCache.Set([]byte("instanceId"), []byte("i-123456789123"), -1))
156156

plugins/processors/clone/clone.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
var sampleConfig string
1313

1414
type Clone struct {
15-
NameOverride string
16-
NamePrefix string
17-
NameSuffix string
18-
Tags map[string]string
15+
NameOverride string `toml:"name_override"`
16+
NamePrefix string `toml:"name_prefix"`
17+
NameSuffix string `toml:"name_suffix"`
18+
Tags map[string]string `toml:"tags"`
1919
}
2020

2121
func (*Clone) SampleConfig() string {

plugins/processors/converter/converter.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ import (
2020
//go:embed sample.conf
2121
var sampleConfig string
2222

23-
type Conversion struct {
23+
type Converter struct {
24+
Tags *conversion `toml:"tags"`
25+
Fields *conversion `toml:"fields"`
26+
Log telegraf.Logger `toml:"-"`
27+
28+
tagConversions *conversionFilter
29+
fieldConversions *conversionFilter
30+
}
31+
32+
type conversion struct {
2433
Measurement []string `toml:"measurement"`
2534
Tag []string `toml:"tag"`
2635
String []string `toml:"string"`
@@ -33,16 +42,7 @@ type Conversion struct {
3342
Base64IEEEFloat32 []string `toml:"base64_ieee_float32"`
3443
}
3544

36-
type Converter struct {
37-
Tags *Conversion `toml:"tags"`
38-
Fields *Conversion `toml:"fields"`
39-
Log telegraf.Logger `toml:"-"`
40-
41-
tagConversions *ConversionFilter
42-
fieldConversions *ConversionFilter
43-
}
44-
45-
type ConversionFilter struct {
45+
type conversionFilter struct {
4646
Measurement filter.Filter
4747
Tag filter.Filter
4848
String filter.Filter
@@ -90,13 +90,13 @@ func (p *Converter) compile() error {
9090
return nil
9191
}
9292

93-
func compileFilter(conv *Conversion) (*ConversionFilter, error) {
93+
func compileFilter(conv *conversion) (*conversionFilter, error) {
9494
if conv == nil {
9595
return nil, nil
9696
}
9797

9898
var err error
99-
cf := &ConversionFilter{}
99+
cf := &conversionFilter{}
100100
cf.Measurement, err = filter.Compile(conv.Measurement)
101101
if err != nil {
102102
return nil, err

0 commit comments

Comments
 (0)