diff --git a/.golangci.yml b/.golangci.yml index 4f4c2ee79..9f5fa8a32 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -117,6 +117,7 @@ linters-settings: - unnecessaryDefer - weakCond # performance + - appendCombine - equalFold - indexAlloc - hugeParam diff --git a/plugins/aggregators/histogram/histogram_test.go b/plugins/aggregators/histogram/histogram_test.go index 8a7b2ce22..f87cc4584 100644 --- a/plugins/aggregators/histogram/histogram_test.go +++ b/plugins/aggregators/histogram/histogram_test.go @@ -187,9 +187,10 @@ func TestHistogramWithReset(t *testing.T) { // TestHistogramWithAllFields tests two metrics for one period and for all fields func TestHistogramWithAllFields(t *testing.T) { - var cfg []config - cfg = append(cfg, config{Metric: "first_metric_name", Buckets: []float64{0.0, 15.5, 20.0, 30.0, 40.0}}) - cfg = append(cfg, config{Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}}) + cfg := []config{ + {Metric: "first_metric_name", Buckets: []float64{0.0, 15.5, 20.0, 30.0, 40.0}}, + {Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}}, + } histogram := NewTestHistogram(cfg, false, true, false) acc := &testutil.Accumulator{} @@ -265,9 +266,10 @@ func TestHistogramWithAllFields(t *testing.T) { // TestHistogramWithAllFieldsNonCumulative tests two metrics for one period and for all fields func TestHistogramWithAllFieldsNonCumulative(t *testing.T) { - var cfg []config - cfg = append(cfg, config{Metric: "first_metric_name", Buckets: []float64{0.0, 15.5, 20.0, 30.0, 40.0}}) - cfg = append(cfg, config{Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}}) + cfg := []config{ + {Metric: "first_metric_name", Buckets: []float64{0.0, 15.5, 20.0, 30.0, 40.0}}, + {Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}}, + } histogram := NewTestHistogram(cfg, false, false, false) acc := &testutil.Accumulator{} @@ -429,9 +431,10 @@ func TestHistogramMetricExpiration(t *testing.T) { timeNow = time.Now }() - var cfg []config - cfg = append(cfg, config{Metric: "first_metric_name", Fields: []string{"a"}, Buckets: []float64{0.0, 10.0, 20.0, 30.0, 40.0}}) - cfg = append(cfg, config{Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}}) + cfg := []config{ + {Metric: "first_metric_name", Fields: []string{"a"}, Buckets: []float64{0.0, 10.0, 20.0, 30.0, 40.0}}, + {Metric: "second_metric_name", Buckets: []float64{0.0, 4.0, 10.0, 23.0, 30.0}}, + } histogram := NewTestHistogramWithExpirationInterval(cfg, false, true, false, telegrafConfig.Duration(30)) acc := &testutil.Accumulator{} diff --git a/plugins/common/opcua/opcua_util.go b/plugins/common/opcua/opcua_util.go index 338450f66..035c2353f 100644 --- a/plugins/common/opcua/opcua_util.go +++ b/plugins/common/opcua/opcua_util.go @@ -19,6 +19,7 @@ import ( "github.com/gopcua/opcua" "github.com/gopcua/opcua/debug" "github.com/gopcua/opcua/ua" + "github.com/influxdata/telegraf/config" ) @@ -151,9 +152,11 @@ func (o *OpcUAClient) generateClientOpts(endpoints []*ua.EndpointDescription) ([ appname := "Telegraf" // ApplicationURI is automatically read from the cert so is not required if a cert if provided - opts = append(opts, opcua.ApplicationURI(appuri)) - opts = append(opts, opcua.ApplicationName(appname)) - opts = append(opts, opcua.RequestTimeout(time.Duration(o.Config.RequestTimeout))) + opts = append(opts, + opcua.ApplicationURI(appuri), + opcua.ApplicationName(appname), + opcua.RequestTimeout(time.Duration(o.Config.RequestTimeout)), + ) certFile := o.Config.Certificate keyFile := o.Config.PrivateKey diff --git a/plugins/inputs/apcupsd/apcupsd_test.go b/plugins/inputs/apcupsd/apcupsd_test.go index 5c79a3b5c..5ea9af55c 100644 --- a/plugins/inputs/apcupsd/apcupsd_test.go +++ b/plugins/inputs/apcupsd/apcupsd_test.go @@ -218,8 +218,7 @@ func genOutput() [][]byte { out := make([][]byte, 0, 2*len(kvs)) for _, kv := range kvs { lenb, kvb := kvBytes(kv) - out = append(out, lenb) - out = append(out, kvb) + out = append(out, lenb, kvb) } return out @@ -233,8 +232,7 @@ func genBadOutput() [][]byte { out := make([][]byte, 0, 2*len(kvs)) for _, kv := range kvs { lenb, kvb := kvBytes(kv) - out = append(out, lenb) - out = append(out, kvb) + out = append(out, lenb, kvb) } return out diff --git a/plugins/inputs/ipmi_sensor/ipmi_sensor.go b/plugins/inputs/ipmi_sensor/ipmi_sensor.go index a323e8971..f90398e04 100644 --- a/plugins/inputs/ipmi_sensor/ipmi_sensor.go +++ b/plugins/inputs/ipmi_sensor/ipmi_sensor.go @@ -118,8 +118,7 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error { if os.IsNotExist(err) { dumpOpts := opts // init cache file - dumpOpts = append(dumpOpts, "dump") - dumpOpts = append(dumpOpts, cacheFile) + dumpOpts = append(dumpOpts, "dump", cacheFile) name := m.Path if m.UseSudo { // -n - avoid prompting the user for input of any kind @@ -132,8 +131,7 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error { return fmt.Errorf("failed to run command %q: %w - %s", strings.Join(sanitizeIPMICmd(cmd.Args), " "), err, string(out)) } } - opts = append(opts, "-S") - opts = append(opts, cacheFile) + opts = append(opts, "-S", cacheFile) } if m.MetricVersion == 2 { opts = append(opts, "elist") diff --git a/plugins/inputs/lanz/lanz_test.go b/plugins/inputs/lanz/lanz_test.go index f2a8b5815..b65eae5e0 100644 --- a/plugins/inputs/lanz/lanz_test.go +++ b/plugins/inputs/lanz/lanz_test.go @@ -56,8 +56,10 @@ func TestLanzGeneratesMetrics(t *testing.T) { l := NewLanz() - l.Servers = append(l.Servers, "tcp://switch01.int.example.com:50001") - l.Servers = append(l.Servers, "tcp://switch02.int.example.com:50001") + l.Servers = append(l.Servers, + "tcp://switch01.int.example.com:50001", + "tcp://switch02.int.example.com:50001", + ) deviceURL1, err := url.Parse(l.Servers[0]) if err != nil { t.Fail() diff --git a/plugins/inputs/lustre2/lustre2_test.go b/plugins/inputs/lustre2/lustre2_test.go index 5988fe834..ef199be69 100644 --- a/plugins/inputs/lustre2/lustre2_test.go +++ b/plugins/inputs/lustre2/lustre2_test.go @@ -316,81 +316,80 @@ func TestLustre2GeneratesJobstatsMetrics(t *testing.T) { } // make this for two tags - var fields []map[string]interface{} - - fields = append(fields, map[string]interface{}{ - "jobstats_read_calls": uint64(1), - "jobstats_read_min_size": uint64(4096), - "jobstats_read_max_size": uint64(4096), - "jobstats_read_bytes": uint64(4096), - "jobstats_write_calls": uint64(25), - "jobstats_write_min_size": uint64(1048576), - "jobstats_write_max_size": uint64(16777216), - "jobstats_write_bytes": uint64(26214400), - "jobstats_ost_getattr": uint64(0), - "jobstats_ost_setattr": uint64(0), - "jobstats_punch": uint64(1), - "jobstats_ost_sync": uint64(0), - "jobstats_destroy": uint64(0), - "jobstats_create": uint64(0), - "jobstats_ost_statfs": uint64(0), - "jobstats_get_info": uint64(0), - "jobstats_set_info": uint64(0), - "jobstats_quotactl": uint64(0), - "jobstats_open": uint64(5), - "jobstats_close": uint64(4), - "jobstats_mknod": uint64(6), - "jobstats_link": uint64(8), - "jobstats_unlink": uint64(90), - "jobstats_mkdir": uint64(521), - "jobstats_rmdir": uint64(520), - "jobstats_rename": uint64(9), - "jobstats_getattr": uint64(11), - "jobstats_setattr": uint64(1), - "jobstats_getxattr": uint64(3), - "jobstats_setxattr": uint64(4), - "jobstats_statfs": uint64(1205), - "jobstats_sync": uint64(2), - "jobstats_samedir_rename": uint64(705), - "jobstats_crossdir_rename": uint64(200), - }) - - fields = append(fields, map[string]interface{}{ - "jobstats_read_calls": uint64(1), - "jobstats_read_min_size": uint64(1024), - "jobstats_read_max_size": uint64(1024), - "jobstats_read_bytes": uint64(1024), - "jobstats_write_calls": uint64(25), - "jobstats_write_min_size": uint64(2048), - "jobstats_write_max_size": uint64(2048), - "jobstats_write_bytes": uint64(51200), - "jobstats_ost_getattr": uint64(0), - "jobstats_ost_setattr": uint64(0), - "jobstats_punch": uint64(1), - "jobstats_ost_sync": uint64(0), - "jobstats_destroy": uint64(0), - "jobstats_create": uint64(0), - "jobstats_ost_statfs": uint64(0), - "jobstats_get_info": uint64(0), - "jobstats_set_info": uint64(0), - "jobstats_quotactl": uint64(0), - "jobstats_open": uint64(6), - "jobstats_close": uint64(7), - "jobstats_mknod": uint64(8), - "jobstats_link": uint64(9), - "jobstats_unlink": uint64(20), - "jobstats_mkdir": uint64(200), - "jobstats_rmdir": uint64(210), - "jobstats_rename": uint64(8), - "jobstats_getattr": uint64(10), - "jobstats_setattr": uint64(2), - "jobstats_getxattr": uint64(4), - "jobstats_setxattr": uint64(5), - "jobstats_statfs": uint64(1207), - "jobstats_sync": uint64(3), - "jobstats_samedir_rename": uint64(706), - "jobstats_crossdir_rename": uint64(201), - }) + fields := []map[string]interface{}{ + { + "jobstats_read_calls": uint64(1), + "jobstats_read_min_size": uint64(4096), + "jobstats_read_max_size": uint64(4096), + "jobstats_read_bytes": uint64(4096), + "jobstats_write_calls": uint64(25), + "jobstats_write_min_size": uint64(1048576), + "jobstats_write_max_size": uint64(16777216), + "jobstats_write_bytes": uint64(26214400), + "jobstats_ost_getattr": uint64(0), + "jobstats_ost_setattr": uint64(0), + "jobstats_punch": uint64(1), + "jobstats_ost_sync": uint64(0), + "jobstats_destroy": uint64(0), + "jobstats_create": uint64(0), + "jobstats_ost_statfs": uint64(0), + "jobstats_get_info": uint64(0), + "jobstats_set_info": uint64(0), + "jobstats_quotactl": uint64(0), + "jobstats_open": uint64(5), + "jobstats_close": uint64(4), + "jobstats_mknod": uint64(6), + "jobstats_link": uint64(8), + "jobstats_unlink": uint64(90), + "jobstats_mkdir": uint64(521), + "jobstats_rmdir": uint64(520), + "jobstats_rename": uint64(9), + "jobstats_getattr": uint64(11), + "jobstats_setattr": uint64(1), + "jobstats_getxattr": uint64(3), + "jobstats_setxattr": uint64(4), + "jobstats_statfs": uint64(1205), + "jobstats_sync": uint64(2), + "jobstats_samedir_rename": uint64(705), + "jobstats_crossdir_rename": uint64(200), + }, + { + "jobstats_read_calls": uint64(1), + "jobstats_read_min_size": uint64(1024), + "jobstats_read_max_size": uint64(1024), + "jobstats_read_bytes": uint64(1024), + "jobstats_write_calls": uint64(25), + "jobstats_write_min_size": uint64(2048), + "jobstats_write_max_size": uint64(2048), + "jobstats_write_bytes": uint64(51200), + "jobstats_ost_getattr": uint64(0), + "jobstats_ost_setattr": uint64(0), + "jobstats_punch": uint64(1), + "jobstats_ost_sync": uint64(0), + "jobstats_destroy": uint64(0), + "jobstats_create": uint64(0), + "jobstats_ost_statfs": uint64(0), + "jobstats_get_info": uint64(0), + "jobstats_set_info": uint64(0), + "jobstats_quotactl": uint64(0), + "jobstats_open": uint64(6), + "jobstats_close": uint64(7), + "jobstats_mknod": uint64(8), + "jobstats_link": uint64(9), + "jobstats_unlink": uint64(20), + "jobstats_mkdir": uint64(200), + "jobstats_rmdir": uint64(210), + "jobstats_rename": uint64(8), + "jobstats_getattr": uint64(10), + "jobstats_setattr": uint64(2), + "jobstats_getxattr": uint64(4), + "jobstats_setxattr": uint64(5), + "jobstats_statfs": uint64(1207), + "jobstats_sync": uint64(3), + "jobstats_samedir_rename": uint64(706), + "jobstats_crossdir_rename": uint64(201), + }, + } for index := 0; index < len(fields); index++ { acc.AssertContainsTaggedFields(t, "lustre2", fields[index], tags[index]) diff --git a/plugins/inputs/systemd_units/systemd_units.go b/plugins/inputs/systemd_units/systemd_units.go index ffc715db4..5ecd26d7b 100644 --- a/plugins/inputs/systemd_units/systemd_units.go +++ b/plugins/inputs/systemd_units/systemd_units.go @@ -208,10 +208,12 @@ func setSystemctl(timeout config.Duration, unitType string, pattern string) (*by psplit := strings.SplitN(pattern, " ", -1) params = append(params, psplit...) } - params = append(params, "--all", "--plain") - // add type as configured in config - params = append(params, fmt.Sprintf("--type=%s", unitType)) - params = append(params, "--no-legend") + params = append(params, + "--all", "--plain", + // add type as configured in config + "--type="+unitType, + "--no-legend", + ) cmd := exec.Command(systemctlPath, params...) var out bytes.Buffer cmd.Stdout = &out diff --git a/plugins/inputs/upsd/upsd_test.go b/plugins/inputs/upsd/upsd_test.go index b335f8fa4..532c26af9 100644 --- a/plugins/inputs/upsd/upsd_test.go +++ b/plugins/inputs/upsd/upsd_test.go @@ -6,8 +6,9 @@ import ( "testing" "time" - "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" + + "github.com/influxdata/telegraf/testutil" ) func TestUpsdGather(t *testing.T) { @@ -201,45 +202,46 @@ type interaction struct { func genOutput() []interaction { m := make([]interaction, 0) - m = append(m, interaction{ - Expected: "VER\n", - Response: "1\n", - }) - m = append(m, interaction{ - Expected: "NETVER\n", - Response: "1\n", - }) - m = append(m, interaction{ - Expected: "LIST UPS\n", - Response: `BEGIN LIST UPS + m = append(m, + interaction{ + Expected: "VER\n", + Response: "1\n", + }, + interaction{ + Expected: "NETVER\n", + Response: "1\n", + }, + interaction{ + Expected: "LIST UPS\n", + Response: `BEGIN LIST UPS UPS fake "fakescription" END LIST UPS `, - }) - m = append(m, interaction{ - Expected: "LIST CLIENT fake\n", - Response: `BEGIN LIST CLIENT fake + }, + interaction{ + Expected: "LIST CLIENT fake\n", + Response: `BEGIN LIST CLIENT fake CLIENT fake 192.168.1.1 END LIST CLIENT fake `, - }) - m = append(m, interaction{ - Expected: "LIST CMD fake\n", - Response: `BEGIN LIST CMD fake + }, + interaction{ + Expected: "LIST CMD fake\n", + Response: `BEGIN LIST CMD fake END LIST CMD fake `, - }) - m = append(m, interaction{ - Expected: "GET UPSDESC fake\n", - Response: "UPSDESC fake \"stub-ups-description\"\n", - }) - m = append(m, interaction{ - Expected: "GET NUMLOGINS fake\n", - Response: "NUMLOGINS fake 1\n", - }) - m = append(m, interaction{ - Expected: "LIST VAR fake\n", - Response: `BEGIN LIST VAR fake + }, + interaction{ + Expected: "GET UPSDESC fake\n", + Response: "UPSDESC fake \"stub-ups-description\"\n", + }, + interaction{ + Expected: "GET NUMLOGINS fake\n", + Response: "NUMLOGINS fake 1\n", + }, + interaction{ + Expected: "LIST VAR fake\n", + Response: `BEGIN LIST VAR fake VAR fake device.serial "ABC123" VAR fake device.model "Model 12345" VAR fake input.voltage "242.0" @@ -257,7 +259,8 @@ VAR fake battery.mfr.date "2016-07-26" VAR fake ups.status "OL" END LIST VAR fake `, - }) + }, + ) m = appendVariable(m, "device.serial", "STRING:64") m = appendVariable(m, "device.model", "STRING:64") m = appendVariable(m, "input.voltage", "NUMBER") @@ -278,14 +281,16 @@ END LIST VAR fake } func appendVariable(m []interaction, name string, typ string) []interaction { - m = append(m, interaction{ - Expected: "GET DESC fake " + name + "\n", - Response: "DESC fake" + name + " \"No description here\"\n", - }) - m = append(m, interaction{ - Expected: "GET TYPE fake " + name + "\n", - Response: "TYPE fake " + name + " " + typ + "\n", - }) + m = append(m, + interaction{ + Expected: "GET DESC fake " + name + "\n", + Response: "DESC fake" + name + " \"No description here\"\n", + }, + interaction{ + Expected: "GET TYPE fake " + name + "\n", + Response: "TYPE fake " + name + " " + typ + "\n", + }, + ) return m } diff --git a/plugins/outputs/dynatrace/dynatrace_test.go b/plugins/outputs/dynatrace/dynatrace_test.go index 75182093f..dc9138b41 100644 --- a/plugins/outputs/dynatrace/dynatrace_test.go +++ b/plugins/outputs/dynatrace/dynatrace_test.go @@ -166,8 +166,10 @@ func TestSendMetrics(t *testing.T) { // Init metrics // Simple metrics are exported as a gauge unless in additional_counters - expected = append(expected, "simple_metric.value,dt.metrics.source=telegraf gauge,3.14 1289430000000") - expected = append(expected, "simple_metric.counter,dt.metrics.source=telegraf count,delta=5 1289430000000") + expected = append(expected, + "simple_metric.value,dt.metrics.source=telegraf gauge,3.14 1289430000000", + "simple_metric.counter,dt.metrics.source=telegraf count,delta=5 1289430000000", + ) d.AddCounterMetrics = append(d.AddCounterMetrics, "simple_metric.counter") m1 := metric.New( "simple_metric", @@ -177,8 +179,10 @@ func TestSendMetrics(t *testing.T) { ) // Even if Type() returns counter, all metrics are treated as a gauge unless explicitly added to additional_counters - expected = append(expected, "counter_type.value,dt.metrics.source=telegraf gauge,3.14 1289430000000") - expected = append(expected, "counter_type.counter,dt.metrics.source=telegraf count,delta=5 1289430000000") + expected = append(expected, + "counter_type.value,dt.metrics.source=telegraf gauge,3.14 1289430000000", + "counter_type.counter,dt.metrics.source=telegraf count,delta=5 1289430000000", + ) d.AddCounterMetrics = append(d.AddCounterMetrics, "counter_type.counter") m2 := metric.New( "counter_type", @@ -188,12 +192,14 @@ func TestSendMetrics(t *testing.T) { telegraf.Counter, ) - expected = append(expected, "complex_metric.int,dt.metrics.source=telegraf gauge,1 1289430000000") - expected = append(expected, "complex_metric.int64,dt.metrics.source=telegraf gauge,2 1289430000000") - expected = append(expected, "complex_metric.float,dt.metrics.source=telegraf gauge,3 1289430000000") - expected = append(expected, "complex_metric.float64,dt.metrics.source=telegraf gauge,4 1289430000000") - expected = append(expected, "complex_metric.true,dt.metrics.source=telegraf gauge,1 1289430000000") - expected = append(expected, "complex_metric.false,dt.metrics.source=telegraf gauge,0 1289430000000") + expected = append(expected, + "complex_metric.int,dt.metrics.source=telegraf gauge,1 1289430000000", + "complex_metric.int64,dt.metrics.source=telegraf gauge,2 1289430000000", + "complex_metric.float,dt.metrics.source=telegraf gauge,3 1289430000000", + "complex_metric.float64,dt.metrics.source=telegraf gauge,4 1289430000000", + "complex_metric.true,dt.metrics.source=telegraf gauge,1 1289430000000", + "complex_metric.false,dt.metrics.source=telegraf gauge,0 1289430000000", + ) m3 := metric.New( "complex_metric", map[string]string{}, diff --git a/plugins/outputs/mongodb/mongodb.go b/plugins/outputs/mongodb/mongodb.go index 9034b724d..0b998bdb0 100644 --- a/plugins/outputs/mongodb/mongodb.go +++ b/plugins/outputs/mongodb/mongodb.go @@ -206,8 +206,10 @@ func marshalMetric(metric telegraf.Metric) bson.D { for k, v := range metric.Tags() { tags = append(tags, primitive.E{Key: k, Value: v}) } - bdoc = append(bdoc, primitive.E{Key: "tags", Value: tags}) - bdoc = append(bdoc, primitive.E{Key: "timestamp", Value: metric.Time()}) + bdoc = append(bdoc, + primitive.E{Key: "tags", Value: tags}, + primitive.E{Key: "timestamp", Value: metric.Time()}, + ) return bdoc } diff --git a/plugins/outputs/mqtt/homie.go b/plugins/outputs/mqtt/homie.go index 0a6065a46..16f56af77 100644 --- a/plugins/outputs/mqtt/homie.go +++ b/plugins/outputs/mqtt/homie.go @@ -23,9 +23,11 @@ func (m *MQTT) collectHomieDeviceMessages(topic string, metric telegraf.Metric) if err != nil { return nil, "", fmt.Errorf("generating device name failed: %w", err) } - messages = append(messages, message{topic + "/$homie", []byte("4.0")}) - messages = append(messages, message{topic + "/$name", []byte(deviceName)}) - messages = append(messages, message{topic + "/$state", []byte("ready")}) + messages = append(messages, + message{topic + "/$homie", []byte("4.0")}, + message{topic + "/$name", []byte(deviceName)}, + message{topic + "/$state", []byte("ready")}, + ) m.homieSeen[topic] = make(map[string]bool) } @@ -43,14 +45,10 @@ func (m *MQTT) collectHomieDeviceMessages(topic string, metric telegraf.Metric) nodeIDs = append(nodeIDs, id) } sort.Strings(nodeIDs) - messages = append(messages, message{ - topic + "/$nodes", - []byte(strings.Join(nodeIDs, ",")), - }) - messages = append(messages, message{ - topic + "/" + nodeID + "/$name", - []byte(nodeName), - }) + messages = append(messages, + message{topic + "/$nodes", []byte(strings.Join(nodeIDs, ","))}, + message{topic + "/" + nodeID + "/$name", []byte(nodeName)}, + ) } properties := make([]string, 0, len(metric.TagList())+len(metric.FieldList())) diff --git a/plugins/outputs/mqtt/mqtt.go b/plugins/outputs/mqtt/mqtt.go index 258673493..b40e23b77 100644 --- a/plugins/outputs/mqtt/mqtt.go +++ b/plugins/outputs/mqtt/mqtt.go @@ -270,9 +270,11 @@ func (m *MQTT) collectHomieV4(hostname string, metrics []telegraf.Metric) []mess continue } propID := normalizeID(tag.Key) - collection = append(collection, message{path + "/" + propID, []byte(tag.Value)}) - collection = append(collection, message{path + "/" + propID + "/$name", []byte(tag.Key)}) - collection = append(collection, message{path + "/" + propID + "/$datatype", []byte("string")}) + collection = append(collection, + message{path + "/" + propID, []byte(tag.Value)}, + message{path + "/" + propID + "/$name", []byte(tag.Key)}, + message{path + "/" + propID + "/$datatype", []byte("string")}, + ) } for _, field := range metric.FieldList() { @@ -283,9 +285,11 @@ func (m *MQTT) collectHomieV4(hostname string, metrics []telegraf.Metric) []mess continue } propID := normalizeID(field.Key) - collection = append(collection, message{path + "/" + propID, []byte(v)}) - collection = append(collection, message{path + "/" + propID + "/$name", []byte(field.Key)}) - collection = append(collection, message{path + "/" + propID + "/$datatype", []byte(dt)}) + collection = append(collection, + message{path + "/" + propID, []byte(v)}, + message{path + "/" + propID + "/$name", []byte(field.Key)}, + message{path + "/" + propID + "/$datatype", []byte(dt)}, + ) } } diff --git a/plugins/outputs/opentsdb/opentsdb_test.go b/plugins/outputs/opentsdb/opentsdb_test.go index 0c35f3d63..24d4f8737 100644 --- a/plugins/outputs/opentsdb/opentsdb_test.go +++ b/plugins/outputs/opentsdb/opentsdb_test.go @@ -187,18 +187,14 @@ func TestWriteIntegration(t *testing.T) { // Verify positive and negative test cases of writing data metrics := testutil.MockMetrics() - metrics = append(metrics, testutil.TestMetric(float64(1.0), - "justametric.float")) - metrics = append(metrics, testutil.TestMetric(int64(123456789), - "justametric.int")) - metrics = append(metrics, testutil.TestMetric(uint64(123456789012345), - "justametric.uint")) - metrics = append(metrics, testutil.TestMetric("Lorem Ipsum", - "justametric.string")) - metrics = append(metrics, testutil.TestMetric(float64(42.0), - "justametric.anotherfloat")) - metrics = append(metrics, testutil.TestMetric(float64(42.0), - "metric w/ specialchars")) + metrics = append(metrics, + testutil.TestMetric(float64(1.0), "justametric.float"), + testutil.TestMetric(int64(123456789), "justametric.int"), + testutil.TestMetric(uint64(123456789012345), "justametric.uint"), + testutil.TestMetric("Lorem Ipsum", "justametric.string"), + testutil.TestMetric(float64(42.0), "justametric.anotherfloat"), + testutil.TestMetric(float64(42.0), "metric w/ specialchars"), + ) err = o.Write(metrics) require.NoError(t, err) diff --git a/plugins/outputs/websocket/websocket_test.go b/plugins/outputs/websocket/websocket_test.go index a6c74a77d..8d33152fe 100644 --- a/plugins/outputs/websocket/websocket_test.go +++ b/plugins/outputs/websocket/websocket_test.go @@ -8,12 +8,12 @@ import ( "testing" "time" + ws "github.com/gorilla/websocket" + "github.com/stretchr/testify/require" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/testutil" - - ws "github.com/gorilla/websocket" - "github.com/stretchr/testify/require" ) // testSerializer serializes to a number of metrics to simplify tests here. @@ -151,9 +151,10 @@ func TestWebSocket_Write_OK(t *testing.T) { w := initWebSocket(s) connect(t, w) - var metrics []telegraf.Metric - metrics = append(metrics, testutil.TestMetric(0.4, "test")) - metrics = append(metrics, testutil.TestMetric(0.5, "test")) + metrics := []telegraf.Metric{ + testutil.TestMetric(0.4, "test"), + testutil.TestMetric(0.5, "test"), + } err := w.Write(metrics) require.NoError(t, err)