From 89a235c620bf4f07c42f33ed9883b7db8532a0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Mon, 30 Oct 2023 13:14:16 +0100 Subject: [PATCH] chore(linters): Enable perfsprint linter and fix all findings. (#14208) --- .golangci.yml | 1 + plugins/common/opcua/input/input_client.go | 2 +- .../eventhub_consumer/eventhub_consumer.go | 3 +- plugins/inputs/filestat/filestat.go | 4 +- plugins/inputs/gnmi/handler.go | 22 +++-- .../influxdb_v2_listener.go | 3 +- .../inputs/intel_baseband/intel_baseband.go | 5 +- plugins/inputs/intel_rdt/intel_rdt.go | 2 +- plugins/inputs/ipvs/ipvs.go | 8 +- plugins/inputs/passenger/passenger.go | 2 +- plugins/inputs/phpfpm/phpfpm_test.go | 5 +- .../webhooks/github/github_webhooks_models.go | 92 +++++++++---------- plugins/outputs/http/http.go | 3 +- plugins/outputs/loki/loki.go | 3 +- .../postgresql/postgresql_bench_test.go | 2 +- plugins/outputs/warp10/warp10.go | 2 +- .../yandex_cloud_monitoring.go | 2 +- 17 files changed, 85 insertions(+), 76 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6f5e55a67..254429649 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,6 +24,7 @@ linters: - nakedret - nilerr - nolintlint + - perfsprint - prealloc - predeclared - revive diff --git a/plugins/common/opcua/input/input_client.go b/plugins/common/opcua/input/input_client.go index a33b31ea3..5ee49d7bd 100644 --- a/plugins/common/opcua/input/input_client.go +++ b/plugins/common/opcua/input/input_client.go @@ -420,7 +420,7 @@ func (o *OpcUAInputClient) MetricForNode(nodeIdx int) telegraf.Metric { } fields[nmm.Tag.FieldName] = o.LastReceivedData[nodeIdx].Value - fields["Quality"] = strings.TrimSpace(fmt.Sprint(o.LastReceivedData[nodeIdx].Quality)) + fields["Quality"] = strings.TrimSpace(o.LastReceivedData[nodeIdx].Quality.Error()) if !o.StatusCodeOK(o.LastReceivedData[nodeIdx].Quality) { mp := newMP(nmm) o.Log.Debugf("status not OK for node %q(metric name %q, tags %q)", diff --git a/plugins/inputs/eventhub_consumer/eventhub_consumer.go b/plugins/inputs/eventhub_consumer/eventhub_consumer.go index 0ea4a83bb..a90dfecc1 100644 --- a/plugins/inputs/eventhub_consumer/eventhub_consumer.go +++ b/plugins/inputs/eventhub_consumer/eventhub_consumer.go @@ -5,6 +5,7 @@ import ( "context" _ "embed" "fmt" + "strconv" "sync" "time" @@ -295,7 +296,7 @@ func (e *EventHub) createMetrics(event *eventhubClient.Event) ([]telegraf.Metric } if event.SystemProperties.PartitionID != nil && e.PartitionIDTag != "" { - metrics[i].AddTag(e.PartitionIDTag, fmt.Sprintf("%d", *event.SystemProperties.PartitionID)) + metrics[i].AddTag(e.PartitionIDTag, strconv.Itoa(int(*event.SystemProperties.PartitionID))) } if event.SystemProperties.PartitionKey != nil && e.PartitionKeyTag != "" { metrics[i].AddTag(e.PartitionKeyTag, *event.SystemProperties.PartitionKey) diff --git a/plugins/inputs/filestat/filestat.go b/plugins/inputs/filestat/filestat.go index a7299c89b..113084e4c 100644 --- a/plugins/inputs/filestat/filestat.go +++ b/plugins/inputs/filestat/filestat.go @@ -4,7 +4,7 @@ package filestat import ( "crypto/md5" //nolint:gosec // G501: Blocklisted import crypto/md5: weak cryptographic primitive - md5 hash is what is desired in this case _ "embed" - "fmt" + "encoding/hex" "io" "os" @@ -131,7 +131,7 @@ func getMd5(file string) (string, error) { // fatal error return "", err } - return fmt.Sprintf("%x", hash.Sum(nil)), nil + return hex.EncodeToString(hash.Sum(nil)), nil } func init() { diff --git a/plugins/inputs/gnmi/handler.go b/plugins/inputs/gnmi/handler.go index 039a7790c..861c87bf0 100644 --- a/plugins/inputs/gnmi/handler.go +++ b/plugins/inputs/gnmi/handler.go @@ -8,14 +8,10 @@ import ( "io" "net" "path" + "strconv" "strings" "time" - "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/internal/choice" - "github.com/influxdata/telegraf/metric" - jnprHeader "github.com/influxdata/telegraf/plugins/inputs/gnmi/extensions/jnpr_gnmi_extention" - "github.com/influxdata/telegraf/selfstat" gnmiLib "github.com/openconfig/gnmi/proto/gnmi" gnmiExt "github.com/openconfig/gnmi/proto/gnmi_ext" "google.golang.org/grpc" @@ -23,6 +19,12 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" + + "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/internal/choice" + "github.com/influxdata/telegraf/metric" + jnprHeader "github.com/influxdata/telegraf/plugins/inputs/gnmi/extensions/jnpr_gnmi_extention" + "github.com/influxdata/telegraf/selfstat" ) const eidJuniperTelemetryHeader = 1 @@ -140,11 +142,11 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon h.log.Errorf("unmarshal gnmi Juniper Header extension failed: %v", err) break } - // Add only relevant Tags from the Juniper Header extention. - // These are requiered for aggregation - prefixTags["component_id"] = fmt.Sprint(juniperHeader.GetComponentId()) - prefixTags["component"] = fmt.Sprint(juniperHeader.GetComponent()) - prefixTags["sub_component_id"] = fmt.Sprint(juniperHeader.GetSubComponentId()) + // Add only relevant Tags from the Juniper Header extension. + // These are required for aggregation + prefixTags["component_id"] = strconv.FormatUint(uint64(juniperHeader.GetComponentId()), 10) + prefixTags["component"] = juniperHeader.GetComponent() + prefixTags["sub_component_id"] = strconv.FormatUint(uint64(juniperHeader.GetSubComponentId()), 10) } default: diff --git a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go index 1536535e7..e96ff088d 100644 --- a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go +++ b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go @@ -12,6 +12,7 @@ import ( "io" "net" "net/http" + "strconv" "time" "github.com/influxdata/telegraf" @@ -323,7 +324,7 @@ func tooLarge(res http.ResponseWriter, maxLength int64) error { b, _ := json.Marshal(map[string]string{ "code": fmt.Sprint(Invalid), "message": "http: request body too large", - "maxLength": fmt.Sprint(maxLength)}) + "maxLength": strconv.FormatInt(maxLength, 10)}) _, err := res.Write(b) return err } diff --git a/plugins/inputs/intel_baseband/intel_baseband.go b/plugins/inputs/intel_baseband/intel_baseband.go index c9fe9f814..152238b0f 100644 --- a/plugins/inputs/intel_baseband/intel_baseband.go +++ b/plugins/inputs/intel_baseband/intel_baseband.go @@ -7,6 +7,7 @@ import ( _ "embed" "errors" "fmt" + "strconv" "time" "github.com/influxdata/telegraf" @@ -162,7 +163,7 @@ func (b *Baseband) gatherVFMetric(acc telegraf.Accumulator, metricName string) e tags := map[string]string{ "operation": metric.operationName, "metric": metricNameToTagName(metricName), - "vf": fmt.Sprintf("%v", i), + "vf": strconv.Itoa(i), } acc.AddGauge(pluginName, fields, tags) } @@ -189,7 +190,7 @@ func (b *Baseband) gatherEngineMetric(acc telegraf.Accumulator, metricName strin tags := map[string]string{ "operation": metric.operationName, "metric": metricNameToTagName(metricName), - "engine": fmt.Sprintf("%v", i), + "engine": strconv.Itoa(i), } acc.AddGauge(pluginName, fields, tags) } diff --git a/plugins/inputs/intel_rdt/intel_rdt.go b/plugins/inputs/intel_rdt/intel_rdt.go index 8d61cbb20..e888187f9 100644 --- a/plugins/inputs/intel_rdt/intel_rdt.go +++ b/plugins/inputs/intel_rdt/intel_rdt.go @@ -211,7 +211,7 @@ func (r *IntelRDT) associateProcessesWithPIDs(providedProcesses []string) (map[s for _, availableProcess := range availableProcesses { if choice.Contains(availableProcess.Name, providedProcesses) { pid := availableProcess.PID - mapProcessPIDs[availableProcess.Name] = mapProcessPIDs[availableProcess.Name] + fmt.Sprintf("%d", pid) + "," + mapProcessPIDs[availableProcess.Name] = mapProcessPIDs[availableProcess.Name] + strconv.Itoa(pid) + "," } } for key := range mapProcessPIDs { diff --git a/plugins/inputs/ipvs/ipvs.go b/plugins/inputs/ipvs/ipvs.go index 48d089bc3..70c6715ad 100644 --- a/plugins/inputs/ipvs/ipvs.go +++ b/plugins/inputs/ipvs/ipvs.go @@ -121,7 +121,7 @@ func destinationTags(d *ipvs.Destination) map[string]string { } } -// helper: convert protocol uint16 to human readable string (if possible) +// helper: convert protocol uint16 to human-readable string (if possible) func protocolToString(p uint16) string { switch p { case syscall.IPPROTO_TCP: @@ -131,11 +131,11 @@ func protocolToString(p uint16) string { case syscall.IPPROTO_SCTP: return "sctp" default: - return fmt.Sprintf("%d", p) + return strconv.FormatUint(uint64(p), 10) } } -// helper: convert addressFamily to a human readable string +// helper: convert addressFamily to a human-readable string func addressFamilyToString(af uint16) string { switch af { case syscall.AF_INET: @@ -143,7 +143,7 @@ func addressFamilyToString(af uint16) string { case syscall.AF_INET6: return "inet6" default: - return fmt.Sprintf("%d", af) + return strconv.FormatUint(uint64(af), 10) } } diff --git a/plugins/inputs/passenger/passenger.go b/plugins/inputs/passenger/passenger.go index c5f3a1399..7123cc70b 100644 --- a/plugins/inputs/passenger/passenger.go +++ b/plugins/inputs/passenger/passenger.go @@ -198,7 +198,7 @@ func importMetric(stat []byte, acc telegraf.Accumulator) error { "group_name": group.Name, "app_root": group.AppRoot, "supergroup_name": sg.Name, - "pid": fmt.Sprintf("%d", process.Pid), + "pid": strconv.Itoa(process.Pid), "code_revision": process.CodeRevision, "life_status": process.LifeStatus, "process_group_id": process.ProcessGroupID, diff --git a/plugins/inputs/phpfpm/phpfpm_test.go b/plugins/inputs/phpfpm/phpfpm_test.go index 78b3779b0..073cf9b1e 100644 --- a/plugins/inputs/phpfpm/phpfpm_test.go +++ b/plugins/inputs/phpfpm/phpfpm_test.go @@ -13,6 +13,7 @@ import ( "net/http" "net/http/fcgi" "net/http/httptest" + "strconv" "testing" "github.com/stretchr/testify/require" @@ -25,7 +26,7 @@ type statServer struct{} // We create a fake server to return test data func (s statServer) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") - w.Header().Set("Content-Length", fmt.Sprint(len(outputSample))) + w.Header().Set("Content-Length", strconv.Itoa(len(outputSample))) fmt.Fprint(w, outputSample) } @@ -33,7 +34,7 @@ func TestPhpFpmGeneratesMetrics_From_Http(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { require.Equal(t, "ok", r.URL.Query().Get("test")) w.Header().Set("Content-Type", "text/plain") - w.Header().Set("Content-Length", fmt.Sprint(len(outputSample))) + w.Header().Set("Content-Length", strconv.Itoa(len(outputSample))) _, err := fmt.Fprint(w, outputSample) require.NoError(t, err) })) diff --git a/plugins/inputs/webhooks/github/github_webhooks_models.go b/plugins/inputs/webhooks/github/github_webhooks_models.go index 497d3f13c..d9c0a6e09 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_models.go +++ b/plugins/inputs/webhooks/github/github_webhooks_models.go @@ -1,7 +1,7 @@ package github import ( - "fmt" + "strconv" "time" "github.com/influxdata/telegraf" @@ -95,9 +95,9 @@ func (s CommitCommentEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -122,9 +122,9 @@ func (s CreateEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -149,9 +149,9 @@ func (s DeleteEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -175,9 +175,9 @@ func (s DeploymentEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -204,9 +204,9 @@ func (s DeploymentStatusEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -234,9 +234,9 @@ func (s ForkEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -260,9 +260,9 @@ func (s GollumEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -285,10 +285,10 @@ func (s IssueCommentEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), - "issue": fmt.Sprintf("%v", s.Issue.Number), + "admin": strconv.FormatBool(s.Sender.Admin), + "issue": strconv.Itoa(s.Issue.Number), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -314,10 +314,10 @@ func (s IssuesEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), - "issue": fmt.Sprintf("%v", s.Issue.Number), + "admin": strconv.FormatBool(s.Sender.Admin), + "issue": strconv.Itoa(s.Issue.Number), "action": s.Action, } f := map[string]interface{}{ @@ -342,9 +342,9 @@ func (s MemberEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -369,7 +369,7 @@ func (s MembershipEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), "action": s.Action, } f := map[string]interface{}{ @@ -390,9 +390,9 @@ func (s PageBuildEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -413,9 +413,9 @@ func (s PublicEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -439,10 +439,10 @@ func (s PullRequestEvent) NewMetric() telegraf.Metric { "event": event, "action": s.Action, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), - "prNumber": fmt.Sprintf("%v", s.PullRequest.Number), + "admin": strconv.FormatBool(s.Sender.Admin), + "prNumber": strconv.Itoa(s.PullRequest.Number), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -472,10 +472,10 @@ func (s PullRequestReviewCommentEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), - "prNumber": fmt.Sprintf("%v", s.PullRequest.Number), + "admin": strconv.FormatBool(s.Sender.Admin), + "prNumber": strconv.Itoa(s.PullRequest.Number), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -508,9 +508,9 @@ func (s PushEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -535,9 +535,9 @@ func (s ReleaseEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -559,9 +559,9 @@ func (s RepositoryEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -584,9 +584,9 @@ func (s StatusEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -610,9 +610,9 @@ func (s TeamAddEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, @@ -634,9 +634,9 @@ func (s WatchEvent) NewMetric() telegraf.Metric { t := map[string]string{ "event": event, "repository": s.Repository.Repository, - "private": fmt.Sprintf("%v", s.Repository.Private), + "private": strconv.FormatBool(s.Repository.Private), "user": s.Sender.User, - "admin": fmt.Sprintf("%v", s.Sender.Admin), + "admin": strconv.FormatBool(s.Sender.Admin), } f := map[string]interface{}{ "stars": s.Repository.Stars, diff --git a/plugins/outputs/http/http.go b/plugins/outputs/http/http.go index c778e40ad..d483efb0a 100644 --- a/plugins/outputs/http/http.go +++ b/plugins/outputs/http/http.go @@ -7,6 +7,7 @@ import ( "context" "crypto/sha256" _ "embed" + "encoding/hex" "fmt" "io" "net/http" @@ -150,7 +151,7 @@ func (h *HTTP) writeMetric(reqBody []byte) error { reqBodyBuffer = buf // sha256 is hex encoded - hash := fmt.Sprintf("%x", sum) + hash := hex.EncodeToString(sum[:]) payloadHash = &hash } diff --git a/plugins/outputs/loki/loki.go b/plugins/outputs/loki/loki.go index c711de3c6..2c8b99350 100644 --- a/plugins/outputs/loki/loki.go +++ b/plugins/outputs/loki/loki.go @@ -10,6 +10,7 @@ import ( "io" "net/http" "sort" + "strconv" "strings" "time" @@ -131,7 +132,7 @@ func (l *Loki) Write(metrics []telegraf.Metric) error { line += fmt.Sprintf("%s=\"%v\" ", f.Key, f.Value) } - s.insertLog(tags, Log{fmt.Sprintf("%d", m.Time().UnixNano()), line}) + s.insertLog(tags, Log{strconv.FormatInt(m.Time().UnixNano(), 10), line}) } return l.writeMetrics(s) diff --git a/plugins/outputs/postgresql/postgresql_bench_test.go b/plugins/outputs/postgresql/postgresql_bench_test.go index 08570142e..21ef640db 100644 --- a/plugins/outputs/postgresql/postgresql_bench_test.go +++ b/plugins/outputs/postgresql/postgresql_bench_test.go @@ -65,7 +65,7 @@ func batchGenerator(args batchGeneratorArgs) <-chan []telegraf.Metric { for i := 0; i < args.tagCardinality; i++ { tags := MSS{} for j := 0; j < args.numTags; j++ { - tags[fmt.Sprintf("tag_%d", j)] = fmt.Sprintf("%d", rand.Int()) + tags[fmt.Sprintf("tag_%d", j)] = strconv.Itoa(rand.Int()) } tagSets = append(tagSets, tags) } diff --git a/plugins/outputs/warp10/warp10.go b/plugins/outputs/warp10/warp10.go index c11526b9a..f0dddab43 100644 --- a/plugins/outputs/warp10/warp10.go +++ b/plugins/outputs/warp10/warp10.go @@ -110,7 +110,7 @@ func (w *Warp10) GenWarp10Payload(metrics []telegraf.Metric) string { collectString = append(collectString, messageLine) } } - return fmt.Sprint(strings.Join(collectString, "")) + return strings.Join(collectString, "") } // Write metrics to Warp10 diff --git a/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go b/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go index f0b8a8114..afe49d263 100644 --- a/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go +++ b/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go @@ -135,7 +135,7 @@ func (a *YandexCloudMonitoring) Write(metrics []telegraf.Metric) error { yandexCloudMonitoringMetric{ Name: field.Key, Labels: m.Tags(), - TS: fmt.Sprint(m.Time().Format(time.RFC3339)), + TS: m.Time().Format(time.RFC3339), Value: value, }, )