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

Revive fixes - part 2 #8835

Merged
merged 8 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reverted "var" for structs/maps/slices
  • Loading branch information
Pawel Zak authored and Pawel Zak committed Feb 16, 2021
commit 20b53896f5bda960b04af4dd08da4ad87b98e3b5
4 changes: 2 additions & 2 deletions agent/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestUnalignedTicker(t *testing.T) {
time.Unix(61, 0).UTC(),
}

var actual []time.Time
actual := []time.Time{}
for !clock.Now().After(until) {
select {
case tm := <-ticker.Elapsed():
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestRollingTicker(t *testing.T) {
time.Unix(61, 0).UTC(),
}

var actual []time.Time
actual := []time.Time{}
for !clock.Now().After(until) {
select {
case tm := <-ticker.Elapsed():
Expand Down
13 changes: 7 additions & 6 deletions plugins/inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (c *CloudWatch) Gather(acc telegraf.Accumulator) error {
wg := sync.WaitGroup{}
rLock := sync.Mutex{}

var results []*cloudwatch.MetricDataResult
results := []*cloudwatch.MetricDataResult{}

// 500 is the maximum number of metric data queries a `GetMetricData` request can contain.
batchSize := 500
Expand Down Expand Up @@ -296,12 +296,12 @@ func getFilteredMetrics(c *CloudWatch) ([]filteredMetric, error) {
return c.metricCache.metrics, nil
}

var fMetrics []filteredMetric
fMetrics := []filteredMetric{}

// check for provided metric filter
if c.Metrics != nil {
for _, m := range c.Metrics {
var metrics []*cloudwatch.Metric
metrics := []*cloudwatch.Metric{}
if !hasWildcard(m.Dimensions) {
dimensions := make([]*cloudwatch.Dimension, len(m.Dimensions))
for k, d := range m.Dimensions {
Expand Down Expand Up @@ -374,7 +374,8 @@ func getFilteredMetrics(c *CloudWatch) ([]filteredMetric, error) {

// fetchNamespaceMetrics retrieves available metrics for a given CloudWatch namespace.
func (c *CloudWatch) fetchNamespaceMetrics() ([]*cloudwatch.Metric, error) {
var metrics []*cloudwatch.Metric
metrics := []*cloudwatch.Metric{}

var token *string
var params *cloudwatch.ListMetricsInput
var recentlyActive *string
Expand Down Expand Up @@ -431,7 +432,7 @@ func (c *CloudWatch) getDataQueries(filteredMetrics []filteredMetric) ([]*cloudw

c.queryDimensions = map[string]*map[string]string{}

var dataQueries []*cloudwatch.MetricDataQuery
dataQueries := []*cloudwatch.MetricDataQuery{}
for i, filtered := range filteredMetrics {
for j, metric := range filtered.metrics {
id := strconv.Itoa(j) + "_" + strconv.Itoa(i)
Expand Down Expand Up @@ -521,7 +522,7 @@ func (c *CloudWatch) getDataQueries(filteredMetrics []filteredMetric) ([]*cloudw
func (c *CloudWatch) gatherMetrics(
params *cloudwatch.GetMetricDataInput,
) ([]*cloudwatch.MetricDataResult, error) {
var results []*cloudwatch.MetricDataResult
results := []*cloudwatch.MetricDataResult{}

for {
resp, err := c.client.GetMetricData(params)
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/diskio/diskio.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (d *DiskIO) Gather(acc telegraf.Accumulator) error {
}
}

var devices []string
devices := []string{}
if d.deviceFilter == nil {
devices = d.Devices
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/modbus/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (m *Modbus) InitRegister(fields []fieldContainer, name string) error {
return err
}

var addrs []uint16
addrs := []uint16{}
for _, field := range fields {
for _, a := range field.Address {
addrs = append(addrs, a)
Expand Down Expand Up @@ -390,7 +390,7 @@ func validateFieldContainers(t []fieldContainer, n string) error {

func removeDuplicates(elements []uint16) []uint16 {
encountered := map[uint16]bool{}
var result []uint16
result := []uint16{}

for v := range elements {
if encountered[elements[v]] {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/solr/solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *Solr) filterCores(serverCores []string) []string {

// Return list of cores from solr server
func getCoresFromStatus(adminCoresStatus *AdminCoresStatus) []string {
var serverCores []string
serverCores := []string{}
for coreName := range adminCoresStatus.Status {
serverCores = append(serverCores, coreName)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (s *Stackdriver) generatetimeSeriesConfs(
return s.timeSeriesConfCache.TimeSeriesConfs, nil
}

var ret []*timeSeriesConf
ret := []*timeSeriesConf{}
req := &monitoringpb.ListMetricDescriptorsRequest{
Name: monitoring.MetricProjectPath(s.Project),
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestPartitionDatums(t *testing.T) {
Value: aws.Float64(1),
}

var zeroDatum []*cloudwatch.MetricDatum
zeroDatum := []*cloudwatch.MetricDatum{}
oneDatum := []*cloudwatch.MetricDatum{&testDatum}
twoDatum := []*cloudwatch.MetricDatum{&testDatum, &testDatum}
threeDatum := []*cloudwatch.MetricDatum{&testDatum, &testDatum, &testDatum}
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 @@ -65,7 +65,7 @@ func (d *Datadog) Connect() error {

func (d *Datadog) Write(metrics []telegraf.Metric) error {
ts := TimeSeries{}
var tempSeries []*Metric
tempSeries := []*Metric{}
metricCounter := 0

for _, m := range metrics {
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (f *File) SetSerializer(serializer serializers.Serializer) {
}

func (f *File) Connect() error {
var writers []io.Writer
writers := []io.Writer{}

if len(f.Files) == 0 {
f.Files = []string{"stdout"}
Expand Down
8 changes: 4 additions & 4 deletions plugins/outputs/riemann_legacy/riemann.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
}

func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
var events []*raidman.Event
events := []*raidman.Event{}
for fieldName, value := range p.Fields() {
host, ok := p.Tags()["host"]
if !ok {
Expand Down Expand Up @@ -123,12 +123,12 @@ func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
}

func serviceName(s string, n string, t map[string]string, f string) string {
var serviceStrings []string
serviceStrings := []string{}
serviceStrings = append(serviceStrings, n)

// we'll skip the 'host' tag
var tagStrings []string
var tagNames []string
tagStrings := []string{}
tagNames := []string{}

for tagName := range t {
tagNames = append(tagNames, tagName)
Expand Down
2 changes: 1 addition & 1 deletion plugins/processors/topk/topk.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (t *TopK) push() []telegraf.Metric {
}

// The return value that will hold the returned metrics
var ret []telegraf.Metric
var ret = make([]telegraf.Metric, 0, 0)
// Get the top K metrics for each field and add them to the return value
addedKeys := make(map[string]bool)
for _, field := range t.Fields {
Expand Down