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:enforce-map-style in plugins/aggregators, plugins/common, plugins/parsers, plugins/processors, plugins/secretstores and plugins/serializers #16039

Merged
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
2 changes: 1 addition & 1 deletion plugins/aggregators/basicstats/basicstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (b *BasicStats) Add(in telegraf.Metric) {

func (b *BasicStats) Push(acc telegraf.Accumulator) {
for _, aggregate := range b.cache {
fields := map[string]interface{}{}
fields := make(map[string]interface{})
for k, v := range aggregate.fields {
if b.statsConfig.count {
fields[k+"_count"] = v.count
Expand Down
2 changes: 1 addition & 1 deletion plugins/aggregators/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package aggregators
import "github.com/influxdata/telegraf"

// Deprecations lists the deprecated plugins
var Deprecations = map[string]telegraf.DeprecationInfo{}
var Deprecations = make(map[string]telegraf.DeprecationInfo)
2 changes: 1 addition & 1 deletion plugins/aggregators/final/final.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (m *Final) Push(acc telegraf.Accumulator) {
if m.KeepOriginalFieldNames {
fields = metric.Fields()
} else {
fields = map[string]any{}
fields = make(map[string]any, len(metric.FieldList()))
for _, field := range metric.FieldList() {
fields[field.Key+"_final"] = field.Value
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/aggregators/histogram/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func convert(in interface{}) (float64, bool) {

// copyTags copies tags
func copyTags(tags map[string]string) map[string]string {
copiedTags := map[string]string{}
copiedTags := make(map[string]string, len(tags))
for key, val := range tags {
copiedTags[key] = val
}
Expand All @@ -322,7 +322,7 @@ func isTagsIdentical(originalTags, checkedTags map[string]string) bool {

// makeFieldsWithCount assigns count value to all metric fields
func makeFieldsWithCount(fieldsWithCountIn map[string]int64) map[string]interface{} {
fieldsWithCountOut := map[string]interface{}{}
fieldsWithCountOut := make(map[string]interface{}, len(fieldsWithCountIn))
for field, count := range fieldsWithCountIn {
fieldsWithCountOut[field+"_bucket"] = count
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/aggregators/minmax/minmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m *MinMax) Add(in telegraf.Metric) {

func (m *MinMax) Push(acc telegraf.Accumulator) {
for _, aggregate := range m.cache {
fields := map[string]interface{}{}
fields := make(map[string]interface{}, len(aggregate.fields))
for k, v := range aggregate.fields {
fields[k+"_min"] = v.min
fields[k+"_max"] = v.max
Expand Down
2 changes: 1 addition & 1 deletion plugins/aggregators/quantile/quantile.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (q *Quantile) Add(in telegraf.Metric) {

func (q *Quantile) Push(acc telegraf.Accumulator) {
for _, aggregate := range q.cache {
fields := map[string]interface{}{}
fields := make(map[string]interface{}, len(aggregate.fields)*len(q.Quantiles))
for k, algo := range aggregate.fields {
for i, qtl := range q.Quantiles {
fields[k+q.suffixes[i]] = algo.Quantile(qtl)
Expand Down
2 changes: 1 addition & 1 deletion plugins/aggregators/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/influxdata/telegraf"

type Creator func() telegraf.Aggregator

var Aggregators = map[string]Creator{}
var Aggregators = make(map[string]Creator)

func Add(name string, creator Creator) {
Aggregators[name] = creator
Expand Down
3 changes: 1 addition & 2 deletions plugins/aggregators/valuecounter/valuecounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func (vc *ValueCounter) Add(in telegraf.Metric) {
// Push emits the counters
func (vc *ValueCounter) Push(acc telegraf.Accumulator) {
for _, agg := range vc.cache {
fields := map[string]interface{}{}

fields := make(map[string]interface{}, len(agg.fieldCount))
for field, count := range agg.fieldCount {
fields[field] = count
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/opcua/input/input_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func validateNodeToAdd(existing map[metricParts]struct{}, nmm *NodeMetricMapping

// InitNodeMetricMapping builds nodes from the configuration
func (o *OpcUAInputClient) InitNodeMetricMapping() error {
existing := map[metricParts]struct{}{}
existing := make(map[metricParts]struct{}, len(o.Config.RootNodes))
for _, node := range o.Config.RootNodes {
nmm, err := NewNodeMetricMapping(o.Config.MetricName, node, make(map[string]string))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions plugins/common/shim/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func createPluginsWithTomlConfig(md toml.MetaData, conf config) (loadedConfig, e
// without having to define a config dead easy.
func DefaultImportedPlugins() config {
conf := config{
Inputs: map[string][]toml.Primitive{},
Processors: map[string][]toml.Primitive{},
Outputs: map[string][]toml.Primitive{},
Inputs: make(map[string][]toml.Primitive, len(inputs.Inputs)),
Processors: make(map[string][]toml.Primitive, len(processors.Processors)),
Outputs: make(map[string][]toml.Primitive, len(outputs.Outputs)),
}
for name := range inputs.Inputs {
log.Println("No config found. Loading default config for plugin", name)
Expand Down
4 changes: 2 additions & 2 deletions plugins/parsers/csv/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (record metadataPattern) Less(i, j int) bool {

func (p *Parser) initializeMetadataSeparators() error {
// initialize metadata
p.metadataTags = map[string]string{}
p.metadataTags = make(map[string]string)

if p.MetadataRows <= 0 {
return nil
Expand All @@ -94,7 +94,7 @@ func (p *Parser) initializeMetadataSeparators() error {
}

p.metadataSeparatorList = make(metadataPattern, 0, len(p.MetadataSeparators))
patternList := map[string]bool{}
patternList := make(map[string]bool, len(p.MetadataSeparators))
for _, pattern := range p.MetadataSeparators {
if patternList[pattern] {
// Ignore further, duplicated entries
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package parsers
import "github.com/influxdata/telegraf"

// Deprecations lists the deprecated plugins
var Deprecations = map[string]telegraf.DeprecationInfo{}
var Deprecations = make(map[string]telegraf.DeprecationInfo)
2 changes: 1 addition & 1 deletion plugins/parsers/dropwizard/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (p *Parser) readDWMetrics(metricType string, dwms interface{}, metrics []te
parsed, err := p.seriesParser.Parse([]byte(measurementName))
var m telegraf.Metric
if err != nil || len(parsed) != 1 {
m = metric.New(measurementName, map[string]string{}, map[string]interface{}{}, tm)
m = metric.New(measurementName, make(map[string]string), make(map[string]interface{}), tm)
} else {
m = parsed[0]
m.SetTime(tm)
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/graphite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Config) Validate() error {

func (c *Config) validateTemplates() error {
// map to keep track of filters we see
filters := map[string]struct{}{}
filters := make(map[string]struct{}, len(c.Templates))

for i, template := range c.Templates {
parts := strings.Fields(template)
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/graphite/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
return nil, fmt.Errorf(`field %q value: %w`, fields[0], err)
}

fieldValues := map[string]interface{}{}
fieldValues := make(map[string]interface{}, 1)
if field != "" {
fieldValues[field] = v
} else {
Expand Down
12 changes: 6 additions & 6 deletions plugins/parsers/json_v2/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func (p *Parser) processMetric(input []byte, data []DataSet, tag bool, timestamp
Tag: tag,
Metric: metric.New(
p.measurementName,
map[string]string{},
map[string]interface{}{},
make(map[string]string),
make(map[string]interface{}),
timestamp,
),
Result: result,
Expand Down Expand Up @@ -341,8 +341,8 @@ func (p *Parser) expandArray(result metricNode, timestamp time.Time) ([]telegraf
result.ForEach(func(_, val gjson.Result) bool {
m := metric.New(
p.measurementName,
map[string]string{},
map[string]interface{}{},
make(map[string]string),
make(map[string]interface{}),
timestamp,
)
if val.IsObject() {
Expand Down Expand Up @@ -519,8 +519,8 @@ func (p *Parser) processObjects(input []byte, objects []Object, timestamp time.T
rootObject := metricNode{
Metric: metric.New(
p.measurementName,
map[string]string{},
map[string]interface{}{},
make(map[string]string),
make(map[string]interface{}),
timestamp,
),
Result: result,
Expand Down
3 changes: 1 addition & 2 deletions plugins/parsers/prometheus/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func mapValueType(mt dto.MetricType) telegraf.ValueType {
}

func getTagsFromLabels(m *dto.Metric, defaultTags map[string]string) map[string]string {
result := map[string]string{}

result := make(map[string]string, len(defaultTags)+len(m.Label))
for key, value := range defaultTags {
result[key] = value
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/prometheusremotewrite/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
now := time.Now()

for _, ts := range req.Timeseries {
tags := map[string]string{}
tags := make(map[string]string, len(p.DefaultTags)+len(ts.Labels))
for key, value := range p.DefaultTags {
tags[key] = value
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/parsers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Creator func(defaultMetricName string) telegraf.Parser

// Parsers contains the registry of all known parsers (following the new style)
var Parsers = map[string]Creator{}
var Parsers = make(map[string]Creator)

// Add adds a parser to the registry. Usually this function is called in the plugin's init function
func Add(name string, creator Creator) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/processors/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package processors
import "github.com/influxdata/telegraf"

// Deprecations lists the deprecated plugins
var Deprecations = map[string]telegraf.DeprecationInfo{}
var Deprecations = make(map[string]telegraf.DeprecationInfo)
2 changes: 1 addition & 1 deletion plugins/processors/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type HasUnwrap interface {

// all processors are streaming processors.
// telegraf.Processor processors are upgraded to telegraf.StreamingProcessor
var Processors = map[string]StreamingCreator{}
var Processors = make(map[string]StreamingCreator)

// Add adds a telegraf.Processor processor
func Add(name string, creator Creator) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/processors/reverse_dns/rdnscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewReverseDNSCache(ttl, lookupTimeout time.Duration, workerPoolSize int) *R
d := &ReverseDNSCache{
ttl: ttl,
lookupTimeout: lookupTimeout,
cache: map[string]*dnslookup{},
cache: make(map[string]*dnslookup),
maxWorkers: workerPoolSize,
sem: semaphore.NewWeighted(int64(workerPoolSize)),
cancelCleanupWorker: cancel,
Expand Down
2 changes: 1 addition & 1 deletion plugins/secretstores/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package secretstores
import "github.com/influxdata/telegraf"

// Deprecations lists the deprecated plugins
var Deprecations = map[string]telegraf.DeprecationInfo{}
var Deprecations = make(map[string]telegraf.DeprecationInfo)
2 changes: 1 addition & 1 deletion plugins/secretstores/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Creator func(id string) telegraf.SecretStore

// SecretStores contains the registry of all known secret-stores
var SecretStores = map[string]Creator{}
var SecretStores = make(map[string]Creator)

// Add adds a secret-store to the registry. Usually this function is called in the plugin's init function
func Add(name string, creator Creator) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/serializers/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package serializers
import "github.com/influxdata/telegraf"

// Deprecations lists the deprecated plugins
var Deprecations = map[string]telegraf.DeprecationInfo{}
var Deprecations = make(map[string]telegraf.DeprecationInfo)
4 changes: 1 addition & 3 deletions plugins/serializers/nowmetric/nowmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ func (s *Serializer) createObject(metric telegraf.Metric) OIMetrics {
oimetric.Value = field.Value

if oimetric.Node != "" {
cimapping := map[string]string{}
cimapping["node"] = oimetric.Node
oimetric.CiMapping = cimapping
oimetric.CiMapping = map[string]string{"node": oimetric.Node}
}

allmetrics = append(allmetrics, oimetric)
Expand Down
2 changes: 1 addition & 1 deletion plugins/serializers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type Creator func() Serializer

// Serializers contains the registry of all known serializers (following the new style)
var Serializers = map[string]Creator{}
var Serializers = make(map[string]Creator)

// Add adds a serializer to the registry. Usually this function is called in the plugin's init function
func Add(name string, creator Creator) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/serializers/splunkmetric/splunkmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *Serializer) createObject(metric telegraf.Metric) ([]byte, error) {
// The tags are common to all events in this timeseries
commonTags := CommonTags{}

commonTags.Fields = map[string]interface{}{}
commonTags.Fields = make(map[string]interface{}, len(metric.Tags()))

// Break tags out into key(n)=value(t) pairs
for n, t := range metric.Tags() {
Expand Down
Loading