From 28299c1102ae120e9793e3f1b3d6e18cf55201b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 12:46:48 -0500 Subject: [PATCH 1/4] chore(deps): Bump github.com/Azure/azure-sdk-for-go/sdk/azcore from 1.13.0 to 1.14.0 (#15862) --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 348d76b48c8e9..8db7492b9f1b3 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/99designs/keyring v1.2.2 github.com/Azure/azure-event-hubs-go/v3 v3.6.2 github.com/Azure/azure-kusto-go v0.16.1 - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 diff --git a/go.sum b/go.sum index e832d401cdf2e..38166c7290ace 100644 --- a/go.sum +++ b/go.sum @@ -646,8 +646,8 @@ github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVt github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k= github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU= github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 h1:GJHeeA2N7xrG3q30L2UXDyuWRzDM900/65j70wcM4Ww= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0/go.mod h1:l38EPgmsp71HHLq9j7De57JcKOWPyhrsW1Awm1JS6K0= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0 h1:nyQWyZvwGTvunIMxi1Y9uXkcyr+I7TeNrr/foo4Kpk8= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0/go.mod h1:l38EPgmsp71HHLq9j7De57JcKOWPyhrsW1Awm1JS6K0= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH5sE0o6eCJuNDTmH09nDpbc= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= From ffee74c1886736f172909481f6b61e091d11c9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Fri, 13 Sep 2024 19:47:18 +0200 Subject: [PATCH 2/4] chore: Fix linter findings for `revive:enforce-repeated-arg-type-style` in `plugins/inputs/[h-n]*` (#15850) --- .../inputs/http_listener_v2/http_listener_v2_test.go | 2 +- plugins/inputs/http_response/http_response_test.go | 9 +-------- plugins/inputs/hugepages/hugepages.go | 7 +------ plugins/inputs/infiniband/infiniband_linux.go | 2 +- .../influxdb_listener/influxdb_listener_test.go | 2 +- .../influxdb_v2_listener/influxdb_v2_listener_test.go | 2 +- plugins/inputs/intel_pmt/intel_pmt.go | 2 +- plugins/inputs/intel_pmt/intel_pmt_test.go | 2 +- plugins/inputs/intel_pmt/xml_parser.go | 4 ++-- plugins/inputs/intel_pmu/config.go | 4 ++-- plugins/inputs/intel_pmu/intel_pmu.go | 2 +- plugins/inputs/intel_pmu/intel_pmu_test.go | 2 +- plugins/inputs/intel_pmu/resolver.go | 2 +- plugins/inputs/intel_powerstat/intel_powerstat.go | 4 ++-- plugins/inputs/intel_rdt/intel_rdt.go | 2 +- plugins/inputs/ipmi_sensor/ipmi_sensor.go | 2 +- plugins/inputs/jenkins/client.go | 2 +- plugins/inputs/knx_listener/knx_listener_test.go | 2 +- plugins/inputs/kube_inventory/client.go | 2 +- plugins/inputs/leofs/leofs_test.go | 2 +- plugins/inputs/mcrouter/mcrouter.go | 2 +- plugins/inputs/mongodb/mongodb_server.go | 11 ++--------- plugins/inputs/mongodb/mongostat.go | 2 +- plugins/inputs/mqtt_consumer/topic_parser.go | 2 +- plugins/inputs/mysql/mysql.go | 2 +- plugins/inputs/nfsclient/nfsclient.go | 2 +- .../nginx_plus_api/nginx_plus_api_metrics_test.go | 2 +- plugins/inputs/nsd/nsd.go | 2 +- 28 files changed, 32 insertions(+), 51 deletions(-) diff --git a/plugins/inputs/http_listener_v2/http_listener_v2_test.go b/plugins/inputs/http_listener_v2/http_listener_v2_test.go index 6d9113f17770b..2dbe902efee6b 100644 --- a/plugins/inputs/http_listener_v2/http_listener_v2_test.go +++ b/plugins/inputs/http_listener_v2/http_listener_v2_test.go @@ -111,7 +111,7 @@ func getHTTPSClient() *http.Client { } } -func createURL(listener *HTTPListenerV2, scheme string, path string, rawquery string) string { +func createURL(listener *HTTPListenerV2, scheme, path, rawquery string) string { var port int if strings.HasPrefix(listener.ServiceAddress, "tcp://") { port = listener.listener.Addr().(*net.TCPAddr).Port diff --git a/plugins/inputs/http_response/http_response_test.go b/plugins/inputs/http_response/http_response_test.go index 1adfcee01420e..20c60a00df9e3 100644 --- a/plugins/inputs/http_response/http_response_test.go +++ b/plugins/inputs/http_response/http_response_test.go @@ -149,14 +149,7 @@ func setUpTestMux() http.Handler { return mux } -func checkOutput( - t *testing.T, - acc *testutil.Accumulator, - presentFields map[string]interface{}, - presentTags map[string]interface{}, - absentFields []string, - absentTags []string, -) { +func checkOutput(t *testing.T, acc *testutil.Accumulator, presentFields, presentTags map[string]interface{}, absentFields, absentTags []string) { t.Helper() if presentFields != nil { checkFields(t, presentFields, acc) diff --git a/plugins/inputs/hugepages/hugepages.go b/plugins/inputs/hugepages/hugepages.go index ea615d0f59f4a..926f10540e9c1 100644 --- a/plugins/inputs/hugepages/hugepages.go +++ b/plugins/inputs/hugepages/hugepages.go @@ -152,12 +152,7 @@ func (h *Hugepages) gatherStatsPerNode(acc telegraf.Accumulator) error { return nil } -func (h *Hugepages) gatherFromHugepagePath( - acc telegraf.Accumulator, - measurement, path string, - fileFilter map[string]string, - defaultTags map[string]string, -) error { +func (h *Hugepages) gatherFromHugepagePath(acc telegraf.Accumulator, measurement, path string, fileFilter, defaultTags map[string]string) error { // read metrics from: hugepages/hugepages-*/* hugepagesDirs, err := os.ReadDir(path) if err != nil { diff --git a/plugins/inputs/infiniband/infiniband_linux.go b/plugins/inputs/infiniband/infiniband_linux.go index 7f95e8be7ccf0..72bbc4714d763 100644 --- a/plugins/inputs/infiniband/infiniband_linux.go +++ b/plugins/inputs/infiniband/infiniband_linux.go @@ -40,7 +40,7 @@ func (i *Infiniband) Gather(acc telegraf.Accumulator) error { } // Add the statistics to the accumulator -func addStats(dev string, port string, stats []rdmamap.RdmaStatEntry, acc telegraf.Accumulator) { +func addStats(dev, port string, stats []rdmamap.RdmaStatEntry, acc telegraf.Accumulator) { // Allow users to filter by card and port tags := map[string]string{"device": dev, "port": port} fields := make(map[string]interface{}) diff --git a/plugins/inputs/influxdb_listener/influxdb_listener_test.go b/plugins/inputs/influxdb_listener/influxdb_listener_test.go index 22defcb594afa..0ecb6a9c65df6 100644 --- a/plugins/inputs/influxdb_listener/influxdb_listener_test.go +++ b/plugins/inputs/influxdb_listener/influxdb_listener_test.go @@ -95,7 +95,7 @@ func getSecureClient() *http.Client { } } -func createURL(listener *InfluxDBListener, scheme string, path string, rawquery string) string { +func createURL(listener *InfluxDBListener, scheme, path, rawquery string) string { u := url.URL{ Scheme: scheme, Host: "localhost:" + strconv.Itoa(listener.port), diff --git a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_test.go b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_test.go index 21e10882b3bd1..6a819881be07f 100644 --- a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_test.go +++ b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_test.go @@ -96,7 +96,7 @@ func getSecureClient() *http.Client { } } -func createURL(listener *InfluxDBV2Listener, scheme string, path string, rawquery string) string { +func createURL(listener *InfluxDBV2Listener, scheme, path, rawquery string) string { u := url.URL{ Scheme: scheme, Host: "localhost:" + strconv.Itoa(listener.port), diff --git a/plugins/inputs/intel_pmt/intel_pmt.go b/plugins/inputs/intel_pmt/intel_pmt.go index 2b05823b40af5..1df882f33ae21 100644 --- a/plugins/inputs/intel_pmt/intel_pmt.go +++ b/plugins/inputs/intel_pmt/intel_pmt.go @@ -299,7 +299,7 @@ func getTelemSample(s sample, buf []byte, offset uint64) (uint64, error) { // Returns: // // error - error if getting values has failed, if sample IDref is missing or if equation evaluation has failed. -func (p *IntelPMT) aggregateSamples(acc telegraf.Accumulator, guid string, data []byte, numaNode string, pciBdf string) error { +func (p *IntelPMT) aggregateSamples(acc telegraf.Accumulator, guid string, data []byte, numaNode, pciBdf string) error { results, err := p.getSampleValues(guid, data) if err != nil { return err diff --git a/plugins/inputs/intel_pmt/intel_pmt_test.go b/plugins/inputs/intel_pmt/intel_pmt_test.go index 01e485f67f9f1..4a35bc3bdb7a2 100644 --- a/plugins/inputs/intel_pmt/intel_pmt_test.go +++ b/plugins/inputs/intel_pmt/intel_pmt_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" ) -func createTempFile(t *testing.T, dir string, pattern string, data []byte) (*os.File, os.FileInfo) { +func createTempFile(t *testing.T, dir, pattern string, data []byte) (*os.File, os.FileInfo) { tempFile, err := os.CreateTemp(dir, pattern) if err != nil { t.Fatalf("error creating a temporary file %v: %v", tempFile.Name(), err) diff --git a/plugins/inputs/intel_pmt/xml_parser.go b/plugins/inputs/intel_pmt/xml_parser.go index 79329dfbb6289..159e84e448a03 100644 --- a/plugins/inputs/intel_pmt/xml_parser.go +++ b/plugins/inputs/intel_pmt/xml_parser.go @@ -199,7 +199,7 @@ func (p *IntelPMT) readXMLs() error { // Returns: // // error - if reading XML has failed. -func (p *IntelPMT) getAllXMLData(guid string, dtMetricsFound map[string]bool, smFound map[string]bool) error { +func (p *IntelPMT) getAllXMLData(guid string, dtMetricsFound, smFound map[string]bool) error { for _, mapping := range p.pmtMetadata.Mappings.Mapping { if mapping.GUID == guid { basedir := mapping.XMLSet.Basedir @@ -246,7 +246,7 @@ func (a *aggregator) calculateMasks() { } } -func computeMask(msb uint64, lsb uint64) uint64 { +func computeMask(msb, lsb uint64) uint64 { msbMask := uint64(0xffffffffffffffff) & ((1 << (msb + 1)) - 1) lsbMask := uint64(0xffffffffffffffff) & (1< Date: Mon, 16 Sep 2024 17:56:55 +0200 Subject: [PATCH 3/4] chore: Fix linter findings for `revive:enforce-repeated-arg-type-style` in `plugins/inputs/[a-g]*` (#15849) --- plugins/inputs/aerospike/aerospike.go | 27 +++++++------------ plugins/inputs/aerospike/aerospike_test.go | 2 +- plugins/inputs/aliyuncms/aliyuncms.go | 4 +-- plugins/inputs/azure_monitor/azure_monitor.go | 5 +--- .../azure_monitor/azure_monitor_test.go | 2 +- plugins/inputs/beanstalkd/beanstalkd_test.go | 2 +- plugins/inputs/bond/bond.go | 6 ++--- .../cisco_telemetry_mdt.go | 9 +++++-- .../cloudwatch_metric_streams_test.go | 2 +- plugins/inputs/couchbase/couchbase.go | 4 +-- plugins/inputs/cpu/cpu_test.go | 3 +-- plugins/inputs/dcos/client.go | 2 +- .../directory_monitor/directory_monitor.go | 2 +- plugins/inputs/dns_query/dns_query.go | 2 +- plugins/inputs/docker/docker.go | 3 +-- plugins/inputs/docker/stats_helpers.go | 2 +- plugins/inputs/dovecot/dovecot.go | 6 ++--- plugins/inputs/dpdk/dpdk_utils.go | 2 +- plugins/inputs/ecs/ecs.go | 2 +- .../elasticsearch_query/aggregation_parser.go | 2 +- .../elasticsearch_query/aggregation_query.go | 2 +- plugins/inputs/exec/exec_test.go | 2 +- plugins/inputs/execd/shim/shim_test.go | 2 +- plugins/inputs/fibaro/hc2/parser.go | 2 +- plugins/inputs/fibaro/hc3/parser.go | 2 +- plugins/inputs/filecount/filecount_test.go | 2 +- plugins/inputs/github/github.go | 2 +- plugins/inputs/gnmi/gnmi.go | 2 +- .../google_cloud_storage_test.go | 2 +- plugins/inputs/graylog/graylog.go | 2 +- 30 files changed, 51 insertions(+), 58 deletions(-) diff --git a/plugins/inputs/aerospike/aerospike.go b/plugins/inputs/aerospike/aerospike.go index 22a775b4975fd..3dc552062fada 100644 --- a/plugins/inputs/aerospike/aerospike.go +++ b/plugins/inputs/aerospike/aerospike.go @@ -198,7 +198,7 @@ func (a *Aerospike) getNodeInfo(n *as.Node, infoPolicy *as.InfoPolicy) (map[stri return stats, nil } -func (a *Aerospike) parseNodeInfo(acc telegraf.Accumulator, stats map[string]string, hostPort string, nodeName string) { +func (a *Aerospike) parseNodeInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, nodeName string) { nTags := map[string]string{ "aerospike_host": hostPort, "node_name": nodeName, @@ -239,7 +239,7 @@ func (a *Aerospike) getNamespaceInfo(namespace string, n *as.Node, infoPolicy *a return stats, err } -func (a *Aerospike) parseNamespaceInfo(acc telegraf.Accumulator, stats map[string]string, hostPort string, namespace string, nodeName string) { +func (a *Aerospike) parseNamespaceInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, namespace, nodeName string) { nTags := map[string]string{ "aerospike_host": hostPort, "node_name": nodeName, @@ -304,7 +304,7 @@ func (a *Aerospike) getSetInfo(namespaceSet string, n *as.Node, infoPolicy *as.I return stats, nil } -func (a *Aerospike) parseSetInfo(acc telegraf.Accumulator, stats map[string]string, hostPort string, namespaceSet string, nodeName string) { +func (a *Aerospike) parseSetInfo(acc telegraf.Accumulator, stats map[string]string, hostPort, namespaceSet, nodeName string) { stat := strings.Split( strings.TrimSuffix( stats["sets/"+namespaceSet], ";"), ":") @@ -326,7 +326,7 @@ func (a *Aerospike) parseSetInfo(acc telegraf.Accumulator, stats map[string]stri acc.AddFields("aerospike_set", nFields, nTags, time.Now()) } -func (a *Aerospike) getTTLHistogram(acc telegraf.Accumulator, hostPort string, namespace string, set string, n *as.Node, infoPolicy *as.InfoPolicy) error { +func (a *Aerospike) getTTLHistogram(acc telegraf.Accumulator, hostPort, namespace, set string, n *as.Node, infoPolicy *as.InfoPolicy) error { stats, err := a.getHistogram(namespace, set, "ttl", n, infoPolicy) if err != nil { return err @@ -338,14 +338,7 @@ func (a *Aerospike) getTTLHistogram(acc telegraf.Accumulator, hostPort string, n return nil } -func (a *Aerospike) getObjectSizeLinearHistogram( - acc telegraf.Accumulator, - hostPort string, - namespace string, - set string, - n *as.Node, - infoPolicy *as.InfoPolicy, -) error { +func (a *Aerospike) getObjectSizeLinearHistogram(acc telegraf.Accumulator, hostPort, namespace, set string, n *as.Node, infoPolicy *as.InfoPolicy) error { stats, err := a.getHistogram(namespace, set, "object-size-linear", n, infoPolicy) if err != nil { return err @@ -357,7 +350,7 @@ func (a *Aerospike) getObjectSizeLinearHistogram( return nil } -func (a *Aerospike) getHistogram(namespace string, set string, histogramType string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) { +func (a *Aerospike) getHistogram(namespace, set, histogramType string, n *as.Node, infoPolicy *as.InfoPolicy) (map[string]string, error) { var queryArg string if len(set) > 0 { queryArg = fmt.Sprintf("histogram:type=%s;namespace=%v;set=%v", histogramType, namespace, set) @@ -372,7 +365,7 @@ func (a *Aerospike) getHistogram(namespace string, set string, histogramType str return stats, nil } -func (a *Aerospike) parseHistogram(acc telegraf.Accumulator, stats map[string]string, nTags map[string]string, histogramType string) { +func (a *Aerospike) parseHistogram(acc telegraf.Accumulator, stats, nTags map[string]string, histogramType string) { nFields := make(map[string]interface{}) for _, stat := range stats { @@ -422,12 +415,12 @@ func (a *Aerospike) parseHistogram(acc telegraf.Accumulator, stats map[string]st acc.AddFields(fmt.Sprintf("aerospike_histogram_%v", strings.ReplaceAll(histogramType, "-", "_")), nFields, nTags, time.Now()) } -func splitNamespaceSet(namespaceSet string) (namespace string, set string) { +func splitNamespaceSet(namespaceSet string) (namespace, set string) { split := strings.Split(namespaceSet, "/") return split[0], split[1] } -func parseAerospikeValue(key string, v string) interface{} { +func parseAerospikeValue(key, v string) interface{} { if protectedHexFields[key] { return v } else if parsed, err := strconv.ParseInt(v, 10, 64); err == nil { @@ -443,7 +436,7 @@ func parseAerospikeValue(key string, v string) interface{} { return v } -func createTags(hostPort string, nodeName string, namespace string, set string) map[string]string { +func createTags(hostPort, nodeName, namespace, set string) map[string]string { nTags := map[string]string{ "aerospike_host": hostPort, "node_name": nodeName, diff --git a/plugins/inputs/aerospike/aerospike_test.go b/plugins/inputs/aerospike/aerospike_test.go index 27efb3466a703..1f3090f7a23b9 100644 --- a/plugins/inputs/aerospike/aerospike_test.go +++ b/plugins/inputs/aerospike/aerospike_test.go @@ -473,7 +473,7 @@ func TestAerospikeParseValue(t *testing.T) { require.Equal(t, `1992929191`, val, "must be left as a string") } -func FindTagValue(acc *testutil.Accumulator, measurement string, key string, value string) bool { +func FindTagValue(acc *testutil.Accumulator, measurement, key, value string) bool { for _, p := range acc.Metrics { if p.Measurement == measurement { v, ok := p.Tags[key] diff --git a/plugins/inputs/aliyuncms/aliyuncms.go b/plugins/inputs/aliyuncms/aliyuncms.go index dfc3cdfac5c89..56203e567c413 100644 --- a/plugins/inputs/aliyuncms/aliyuncms.go +++ b/plugins/inputs/aliyuncms/aliyuncms.go @@ -342,7 +342,7 @@ func (s *AliyunCMS) gatherMetric(acc telegraf.Accumulator, metricName string, me } // tag helper -func parseTag(tagSpec string, data interface{}) (tagKey string, tagValue string, err error) { +func parseTag(tagSpec string, data interface{}) (tagKey, tagValue string, err error) { var ( ok bool queryPath = tagSpec @@ -474,7 +474,7 @@ L: } // Formatting helpers -func formatField(metricName string, statistic string) string { +func formatField(metricName, statistic string) string { if metricName == statistic { statistic = "value" } diff --git a/plugins/inputs/azure_monitor/azure_monitor.go b/plugins/inputs/azure_monitor/azure_monitor.go index 46806a560022a..495b67ec7d637 100644 --- a/plugins/inputs/azure_monitor/azure_monitor.go +++ b/plugins/inputs/azure_monitor/azure_monitor.go @@ -171,10 +171,7 @@ func (am *AzureMonitor) setReceiver() error { } func (acm *azureClientsManager) createAzureClients( - subscriptionID string, - clientID string, - clientSecret string, - tenantID string, + subscriptionID, clientID, clientSecret, tenantID string, clientOptions azcore.ClientOptions, ) (*receiver.AzureClients, error) { if clientSecret != "" { diff --git a/plugins/inputs/azure_monitor/azure_monitor_test.go b/plugins/inputs/azure_monitor/azure_monitor_test.go index ffbfc4adaa991..4bada838645b5 100644 --- a/plugins/inputs/azure_monitor/azure_monitor_test.go +++ b/plugins/inputs/azure_monitor/azure_monitor_test.go @@ -27,7 +27,7 @@ type mockAzureMetricDefinitionsClient struct{} type mockAzureMetricsClient struct{} -func (mam *mockAzureClientsManager) createAzureClients(_ string, _ string, _ string, _ string, _ azcore.ClientOptions) (*receiver.AzureClients, error) { +func (mam *mockAzureClientsManager) createAzureClients(_, _, _, _ string, _ azcore.ClientOptions) (*receiver.AzureClients, error) { return &receiver.AzureClients{ Ctx: context.Background(), ResourcesClient: &mockAzureResourcesClient{}, diff --git a/plugins/inputs/beanstalkd/beanstalkd_test.go b/plugins/inputs/beanstalkd/beanstalkd_test.go index 88c311103358d..204db8b7063ab 100644 --- a/plugins/inputs/beanstalkd/beanstalkd_test.go +++ b/plugins/inputs/beanstalkd/beanstalkd_test.go @@ -345,7 +345,7 @@ func getOverviewTags(server string) map[string]string { } } -func getTubeTags(server string, tube string) map[string]string { +func getTubeTags(server, tube string) map[string]string { return map[string]string{ "name": tube, "server": server, diff --git a/plugins/inputs/bond/bond.go b/plugins/inputs/bond/bond.go index cfcb4f3b45184..929d469510fe3 100644 --- a/plugins/inputs/bond/bond.go +++ b/plugins/inputs/bond/bond.go @@ -79,7 +79,7 @@ func (bond *Bond) Gather(acc telegraf.Accumulator) error { return nil } -func (bond *Bond) gatherBondInterface(bondName string, rawFile string, acc telegraf.Accumulator) error { +func (bond *Bond) gatherBondInterface(bondName, rawFile string, acc telegraf.Accumulator) error { splitIndex := strings.Index(rawFile, "Slave Interface:") if splitIndex == -1 { splitIndex = len(rawFile) @@ -98,7 +98,7 @@ func (bond *Bond) gatherBondInterface(bondName string, rawFile string, acc teleg return nil } -func (bond *Bond) gatherBondPart(bondName string, rawFile string, acc telegraf.Accumulator) error { +func (bond *Bond) gatherBondPart(bondName, rawFile string, acc telegraf.Accumulator) error { fields := make(map[string]interface{}) tags := map[string]string{ "bond": bondName, @@ -210,7 +210,7 @@ func (bond *Bond) gatherSysDetails(bondName string, files sysFiles, acc telegraf acc.AddFields("bond_sys", fields, tags) } -func (bond *Bond) gatherSlavePart(bondName string, rawFile string, acc telegraf.Accumulator) error { +func (bond *Bond) gatherSlavePart(bondName, rawFile string, acc telegraf.Accumulator) error { var slaveCount int tags := map[string]string{ "bond": bondName, diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go index f52533fcba24c..8f34c173126dc 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go @@ -649,8 +649,13 @@ func (c *CiscoTelemetryMDT) getMeasurementName(encodingPath string) string { return measurement } -func (c *CiscoTelemetryMDT) parseContentField(grouper *metric.SeriesGrouper, field *telemetry.TelemetryField, prefix string, - encodingPath string, tags map[string]string, timestamp time.Time) { +func (c *CiscoTelemetryMDT) parseContentField( + grouper *metric.SeriesGrouper, + field *telemetry.TelemetryField, + prefix, encodingPath string, + tags map[string]string, + timestamp time.Time, +) { name := strings.ReplaceAll(field.Name, "-", "_") if (name == "modTs" || name == "createTs") && decodeValue(field) == "never" { diff --git a/plugins/inputs/cloudwatch_metric_streams/cloudwatch_metric_streams_test.go b/plugins/inputs/cloudwatch_metric_streams/cloudwatch_metric_streams_test.go index fa10aa9aa3e20..3379c34c128c5 100644 --- a/plugins/inputs/cloudwatch_metric_streams/cloudwatch_metric_streams_test.go +++ b/plugins/inputs/cloudwatch_metric_streams/cloudwatch_metric_streams_test.go @@ -69,7 +69,7 @@ func getHTTPSClient() *http.Client { } } -func createURL(scheme string, path string) string { +func createURL(scheme, path string) string { u := url.URL{ Scheme: scheme, Host: "localhost:8080", diff --git a/plugins/inputs/couchbase/couchbase.go b/plugins/inputs/couchbase/couchbase.go index df349dfbd07ce..e13d732131db8 100644 --- a/plugins/inputs/couchbase/couchbase.go +++ b/plugins/inputs/couchbase/couchbase.go @@ -180,7 +180,7 @@ func (cb *Couchbase) basicBucketStats(basicStats map[string]interface{}) map[str return fields } -func (cb *Couchbase) gatherDetailedBucketStats(server, bucket string, nodeHostname string, fields map[string]interface{}) error { +func (cb *Couchbase) gatherDetailedBucketStats(server, bucket, nodeHostname string, fields map[string]interface{}) error { extendedBucketStats := &BucketStats{} err := cb.queryDetailedBucketStats(server, bucket, nodeHostname, extendedBucketStats) if err != nil { @@ -421,7 +421,7 @@ func (cb *Couchbase) addBucketFieldChecked(fields map[string]interface{}, fieldK cb.addBucketField(fields, fieldKey, values[len(values)-1]) } -func (cb *Couchbase) queryDetailedBucketStats(server, bucket string, nodeHostname string, bucketStats *BucketStats) error { +func (cb *Couchbase) queryDetailedBucketStats(server, bucket, nodeHostname string, bucketStats *BucketStats) error { url := server + "/pools/default/buckets/" + bucket if nodeHostname != "" { url += "/nodes/" + nodeHostname diff --git a/plugins/inputs/cpu/cpu_test.go b/plugins/inputs/cpu/cpu_test.go index d91d74ecd3fcd..225be81c91152 100644 --- a/plugins/inputs/cpu/cpu_test.go +++ b/plugins/inputs/cpu/cpu_test.go @@ -124,8 +124,7 @@ func assertContainsTaggedFloat( t *testing.T, acc *testutil.Accumulator, field string, - expectedValue float64, - delta float64, + expectedValue, delta float64, ) { var actualValue float64 measurement := "cpu" // always cpu diff --git a/plugins/inputs/dcos/client.go b/plugins/inputs/dcos/client.go index 25c345978bb9f..01b8af20f441a 100644 --- a/plugins/inputs/dcos/client.go +++ b/plugins/inputs/dcos/client.go @@ -254,7 +254,7 @@ func (c *clusterClient) GetAppMetrics(ctx context.Context, node, container strin return c.getMetrics(ctx, c.toURL(path)) } -func createGetRequest(address string, token string) (*http.Request, error) { +func createGetRequest(address, token string) (*http.Request, error) { req, err := http.NewRequest("GET", address, nil) if err != nil { return nil, err diff --git a/plugins/inputs/directory_monitor/directory_monitor.go b/plugins/inputs/directory_monitor/directory_monitor.go index 5df2bd44c801d..b0b5a81a3a6d7 100644 --- a/plugins/inputs/directory_monitor/directory_monitor.go +++ b/plugins/inputs/directory_monitor/directory_monitor.go @@ -336,7 +336,7 @@ func (monitor *DirectoryMonitor) sendMetrics(metrics []telegraf.Metric) error { return nil } -func (monitor *DirectoryMonitor) moveFile(srcPath string, dstBaseDir string) { +func (monitor *DirectoryMonitor) moveFile(srcPath, dstBaseDir string) { // Appends any subdirectories in the srcPath to the dstBaseDir and // creates those subdirectories. basePath := strings.Replace(srcPath, monitor.Directory, "", 1) diff --git a/plugins/inputs/dns_query/dns_query.go b/plugins/inputs/dns_query/dns_query.go index a710416bc3cb5..cfef4adfb8d66 100644 --- a/plugins/inputs/dns_query/dns_query.go +++ b/plugins/inputs/dns_query/dns_query.go @@ -107,7 +107,7 @@ func (d *DNSQuery) Gather(acc telegraf.Accumulator) error { return nil } -func (d *DNSQuery) query(domain string, server string) (map[string]interface{}, map[string]string, error) { +func (d *DNSQuery) query(domain, server string) (map[string]interface{}, map[string]string, error) { tags := map[string]string{ "server": server, "domain": domain, diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 189b48528416d..b5e41c9ee9f24 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -608,8 +608,7 @@ func (d *Docker) parseContainerStats( stat *typeContainer.StatsResponse, acc telegraf.Accumulator, tags map[string]string, - id string, - daemonOSType string, + id, daemonOSType string, ) { tm := stat.Read diff --git a/plugins/inputs/docker/stats_helpers.go b/plugins/inputs/docker/stats_helpers.go index a80b98fa948d4..97d8fc06e94fe 100644 --- a/plugins/inputs/docker/stats_helpers.go +++ b/plugins/inputs/docker/stats_helpers.go @@ -66,7 +66,7 @@ func CalculateMemUsageUnixNoCache(mem container.MemoryStats) float64 { return float64(mem.Usage) } -func CalculateMemPercentUnixNoCache(limit float64, usedNoCache float64) float64 { +func CalculateMemPercentUnixNoCache(limit, usedNoCache float64) float64 { // MemoryStats.Limit will never be 0 unless the container is not running and we haven't // got any data from cgroup if limit != 0 { diff --git a/plugins/inputs/dovecot/dovecot.go b/plugins/inputs/dovecot/dovecot.go index 080723b50597c..ac5ec22de46f6 100644 --- a/plugins/inputs/dovecot/dovecot.go +++ b/plugins/inputs/dovecot/dovecot.go @@ -65,7 +65,7 @@ func (d *Dovecot) Gather(acc telegraf.Accumulator) error { return nil } -func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype string, filter string) error { +func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype, filter string) error { var proto string if strings.HasPrefix(addr, "/") { @@ -124,7 +124,7 @@ func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype stri return nil } -func gatherStats(buf *bytes.Buffer, acc telegraf.Accumulator, host string, qtype string) { +func gatherStats(buf *bytes.Buffer, acc telegraf.Accumulator, host, qtype string) { lines := strings.Split(buf.String(), "\n") head := strings.Split(lines[0], "\t") vals := lines[1:] @@ -160,7 +160,7 @@ func gatherStats(buf *bytes.Buffer, acc telegraf.Accumulator, host string, qtype } } -func splitSec(tm string) (sec int64, msec int64) { +func splitSec(tm string) (sec, msec int64) { var err error ss := strings.Split(tm, ".") diff --git a/plugins/inputs/dpdk/dpdk_utils.go b/plugins/inputs/dpdk/dpdk_utils.go index debb311ece1ed..c8115d435a7a5 100644 --- a/plugins/inputs/dpdk/dpdk_utils.go +++ b/plugins/inputs/dpdk/dpdk_utils.go @@ -14,7 +14,7 @@ import ( "github.com/influxdata/telegraf/filter" ) -func commandWithParams(command string, params string) string { +func commandWithParams(command, params string) string { if params != "" { return command + "," + params } diff --git a/plugins/inputs/ecs/ecs.go b/plugins/inputs/ecs/ecs.go index a99f9912221bd..93ead677e74ae 100644 --- a/plugins/inputs/ecs/ecs.go +++ b/plugins/inputs/ecs/ecs.go @@ -193,7 +193,7 @@ func copyTags(in map[string]string) map[string]string { } // returns a new map with the merged content values of the two input maps -func mergeTags(a map[string]string, b map[string]string) map[string]string { +func mergeTags(a, b map[string]string) map[string]string { c := copyTags(a) for k, v := range b { c[k] = v diff --git a/plugins/inputs/elasticsearch_query/aggregation_parser.go b/plugins/inputs/elasticsearch_query/aggregation_parser.go index 352a3a2570b5a..8a507bebd3c80 100644 --- a/plugins/inputs/elasticsearch_query/aggregation_parser.go +++ b/plugins/inputs/elasticsearch_query/aggregation_parser.go @@ -124,7 +124,7 @@ func recurseResponse(acc telegraf.Accumulator, aggNameFunction map[string]string return m, nil } -func getResponseAggregation(function string, aggName string, aggs elastic5.Aggregations) (agg interface{}) { +func getResponseAggregation(function, aggName string, aggs elastic5.Aggregations) (agg interface{}) { switch function { case "avg": agg, _ = aggs.Avg(aggName) diff --git a/plugins/inputs/elasticsearch_query/aggregation_query.go b/plugins/inputs/elasticsearch_query/aggregation_query.go index 1a69750ceb7da..56caa06ea693c 100644 --- a/plugins/inputs/elasticsearch_query/aggregation_query.go +++ b/plugins/inputs/elasticsearch_query/aggregation_query.go @@ -197,7 +197,7 @@ func (aggregation *esAggregation) buildAggregationQuery() error { return nil } -func getFunctionAggregation(function string, aggfield string) (elastic5.Aggregation, error) { +func getFunctionAggregation(function, aggfield string) (elastic5.Aggregation, error) { var agg elastic5.Aggregation switch function { diff --git a/plugins/inputs/exec/exec_test.go b/plugins/inputs/exec/exec_test.go index fa752f26a3490..9ef1f705c88cd 100644 --- a/plugins/inputs/exec/exec_test.go +++ b/plugins/inputs/exec/exec_test.go @@ -73,7 +73,7 @@ type runnerMock struct { err error } -func newRunnerMock(out []byte, errout []byte, err error) Runner { +func newRunnerMock(out, errout []byte, err error) Runner { return &runnerMock{ out: out, errout: errout, diff --git a/plugins/inputs/execd/shim/shim_test.go b/plugins/inputs/execd/shim/shim_test.go index 4e047cc8bccff..33aa87f6ec4ea 100644 --- a/plugins/inputs/execd/shim/shim_test.go +++ b/plugins/inputs/execd/shim/shim_test.go @@ -53,7 +53,7 @@ func TestShimStdinSignalingWorks(t *testing.T) { <-exited } -func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (metricProcessed chan bool, exited chan bool) { +func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdout, stderr io.Writer) (metricProcessed, exited chan bool) { metricProcessed = make(chan bool) exited = make(chan bool) inp := &testInput{ diff --git a/plugins/inputs/fibaro/hc2/parser.go b/plugins/inputs/fibaro/hc2/parser.go index c409cd2f3076a..28b002e2db3ea 100644 --- a/plugins/inputs/fibaro/hc2/parser.go +++ b/plugins/inputs/fibaro/hc2/parser.go @@ -7,7 +7,7 @@ import ( "github.com/influxdata/telegraf" ) -func Parse(acc telegraf.Accumulator, sectionBytes []byte, roomBytes []byte, deviecsBytes []byte) error { +func Parse(acc telegraf.Accumulator, sectionBytes, roomBytes, deviecsBytes []byte) error { var tmpSections []Sections if err := json.Unmarshal(sectionBytes, &tmpSections); err != nil { return err diff --git a/plugins/inputs/fibaro/hc3/parser.go b/plugins/inputs/fibaro/hc3/parser.go index 6e1409f77e8fe..d89e7a181cb2e 100644 --- a/plugins/inputs/fibaro/hc3/parser.go +++ b/plugins/inputs/fibaro/hc3/parser.go @@ -9,7 +9,7 @@ import ( "github.com/influxdata/telegraf/internal" ) -func Parse(acc telegraf.Accumulator, sectionBytes []byte, roomBytes []byte, deviecsBytes []byte) error { +func Parse(acc telegraf.Accumulator, sectionBytes, roomBytes, deviecsBytes []byte) error { var tmpSections []Sections if err := json.Unmarshal(sectionBytes, &tmpSections); err != nil { return err diff --git a/plugins/inputs/filecount/filecount_test.go b/plugins/inputs/filecount/filecount_test.go index ffe321751b7a1..1e89d0cbcedf4 100644 --- a/plugins/inputs/filecount/filecount_test.go +++ b/plugins/inputs/filecount/filecount_test.go @@ -239,7 +239,7 @@ func getFakeFileSystem(basePath string) fakeFileSystem { return fakeFileSystem{files: fileList} } -func fileCountEquals(t *testing.T, fc FileCount, expectedCount int, expectedSize int) { +func fileCountEquals(t *testing.T, fc FileCount, expectedCount, expectedSize int) { tags := map[string]string{"directory": getTestdataDir()} acc := testutil.Accumulator{} require.NoError(t, acc.GatherError(fc.Gather)) diff --git a/plugins/inputs/github/github.go b/plugins/inputs/github/github.go index 390102030b479..a054775175d79 100644 --- a/plugins/inputs/github/github.go +++ b/plugins/inputs/github/github.go @@ -158,7 +158,7 @@ func (g *GitHub) handleRateLimit(response *githubLib.Response, err error) { } } -func splitRepositoryName(repositoryName string) (owner string, repository string, err error) { +func splitRepositoryName(repositoryName string) (owner, repository string, err error) { splits := strings.SplitN(repositoryName, "/", 2) if len(splits) != 2 { diff --git a/plugins/inputs/gnmi/gnmi.go b/plugins/inputs/gnmi/gnmi.go index 7b731952252bb..5015bbeb6b1b1 100644 --- a/plugins/inputs/gnmi/gnmi.go +++ b/plugins/inputs/gnmi/gnmi.go @@ -377,7 +377,7 @@ func (c *GNMI) newSubscribeRequest() (*gnmiLib.SubscribeRequest, error) { } // ParsePath from XPath-like string to gNMI path structure -func parsePath(origin string, pathToParse string, target string) (*gnmiLib.Path, error) { +func parsePath(origin, pathToParse, target string) (*gnmiLib.Path, error) { gnmiPath, err := xpath.ToGNMIPath(pathToParse) if err != nil { return nil, err diff --git a/plugins/inputs/google_cloud_storage/google_cloud_storage_test.go b/plugins/inputs/google_cloud_storage/google_cloud_storage_test.go index 367e825eb8a0a..f3d94d8c4d68c 100644 --- a/plugins/inputs/google_cloud_storage/google_cloud_storage_test.go +++ b/plugins/inputs/google_cloud_storage/google_cloud_storage_test.go @@ -333,7 +333,7 @@ func stateFullGCSServer(t *testing.T) *httptest.Server { return srv } -func serveBlobs(t *testing.T, w http.ResponseWriter, urlPath string, offsetKey string) { +func serveBlobs(t *testing.T, w http.ResponseWriter, urlPath, offsetKey string) { singleObjectNotFound := readJSON(t, "testdata/single_object_not_found.json") firstFile := readJSON(t, "testdata/first_file.json") secondFile := readJSON(t, "testdata/second_file.json") diff --git a/plugins/inputs/graylog/graylog.go b/plugins/inputs/graylog/graylog.go index 3fcc61621938e..6ee9da071311c 100644 --- a/plugins/inputs/graylog/graylog.go +++ b/plugins/inputs/graylog/graylog.go @@ -173,7 +173,7 @@ func (h *GrayLog) gatherServer( // Returns: // // void -func (h *GrayLog) flatten(item map[string]interface{}, fields map[string]interface{}, id string) { +func (h *GrayLog) flatten(item, fields map[string]interface{}, id string) { if id != "" { id = id + "_" } From ccdbc4c480297592cc11fc13f9bfe5e665f1e582 Mon Sep 17 00:00:00 2001 From: Lars Stegman Date: Mon, 16 Sep 2024 17:57:55 +0200 Subject: [PATCH 4/4] perf(agent): Reduce complexity of creating new metrics to 'O(N_fields)' (#15889) --- metric/metric.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metric/metric.go b/metric/metric.go index f07f54c2672e6..b68afdc491b83 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -56,7 +56,8 @@ func New( if v == nil { continue } - m.AddField(k, v) + + m.MetricFields = append(m.MetricFields, &telegraf.Field{Key: k, Value: v}) } }