chore(linters): Enable perfsprint linter and fix all findings. (#14208)

This commit is contained in:
Paweł Żak 2023-10-30 13:14:16 +01:00 committed by GitHub
parent 12d8c3d0f3
commit 89a235c620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 85 additions and 76 deletions

View File

@ -24,6 +24,7 @@ linters:
- nakedret - nakedret
- nilerr - nilerr
- nolintlint - nolintlint
- perfsprint
- prealloc - prealloc
- predeclared - predeclared
- revive - revive

View File

@ -420,7 +420,7 @@ func (o *OpcUAInputClient) MetricForNode(nodeIdx int) telegraf.Metric {
} }
fields[nmm.Tag.FieldName] = o.LastReceivedData[nodeIdx].Value 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) { if !o.StatusCodeOK(o.LastReceivedData[nodeIdx].Quality) {
mp := newMP(nmm) mp := newMP(nmm)
o.Log.Debugf("status not OK for node %q(metric name %q, tags %q)", o.Log.Debugf("status not OK for node %q(metric name %q, tags %q)",

View File

@ -5,6 +5,7 @@ import (
"context" "context"
_ "embed" _ "embed"
"fmt" "fmt"
"strconv"
"sync" "sync"
"time" "time"
@ -295,7 +296,7 @@ func (e *EventHub) createMetrics(event *eventhubClient.Event) ([]telegraf.Metric
} }
if event.SystemProperties.PartitionID != nil && e.PartitionIDTag != "" { 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 != "" { if event.SystemProperties.PartitionKey != nil && e.PartitionKeyTag != "" {
metrics[i].AddTag(e.PartitionKeyTag, *event.SystemProperties.PartitionKey) metrics[i].AddTag(e.PartitionKeyTag, *event.SystemProperties.PartitionKey)

View File

@ -4,7 +4,7 @@ package filestat
import ( import (
"crypto/md5" //nolint:gosec // G501: Blocklisted import crypto/md5: weak cryptographic primitive - md5 hash is what is desired in this case "crypto/md5" //nolint:gosec // G501: Blocklisted import crypto/md5: weak cryptographic primitive - md5 hash is what is desired in this case
_ "embed" _ "embed"
"fmt" "encoding/hex"
"io" "io"
"os" "os"
@ -131,7 +131,7 @@ func getMd5(file string) (string, error) {
// fatal error // fatal error
return "", err return "", err
} }
return fmt.Sprintf("%x", hash.Sum(nil)), nil return hex.EncodeToString(hash.Sum(nil)), nil
} }
func init() { func init() {

View File

@ -8,14 +8,10 @@ import (
"io" "io"
"net" "net"
"path" "path"
"strconv"
"strings" "strings"
"time" "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" gnmiLib "github.com/openconfig/gnmi/proto/gnmi"
gnmiExt "github.com/openconfig/gnmi/proto/gnmi_ext" gnmiExt "github.com/openconfig/gnmi/proto/gnmi_ext"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -23,6 +19,12 @@ import (
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto" "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 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) h.log.Errorf("unmarshal gnmi Juniper Header extension failed: %v", err)
break break
} }
// Add only relevant Tags from the Juniper Header extention. // Add only relevant Tags from the Juniper Header extension.
// These are requiered for aggregation // These are required for aggregation
prefixTags["component_id"] = fmt.Sprint(juniperHeader.GetComponentId()) prefixTags["component_id"] = strconv.FormatUint(uint64(juniperHeader.GetComponentId()), 10)
prefixTags["component"] = fmt.Sprint(juniperHeader.GetComponent()) prefixTags["component"] = juniperHeader.GetComponent()
prefixTags["sub_component_id"] = fmt.Sprint(juniperHeader.GetSubComponentId()) prefixTags["sub_component_id"] = strconv.FormatUint(uint64(juniperHeader.GetSubComponentId()), 10)
} }
default: default:

View File

@ -12,6 +12,7 @@ import (
"io" "io"
"net" "net"
"net/http" "net/http"
"strconv"
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -323,7 +324,7 @@ func tooLarge(res http.ResponseWriter, maxLength int64) error {
b, _ := json.Marshal(map[string]string{ b, _ := json.Marshal(map[string]string{
"code": fmt.Sprint(Invalid), "code": fmt.Sprint(Invalid),
"message": "http: request body too large", "message": "http: request body too large",
"maxLength": fmt.Sprint(maxLength)}) "maxLength": strconv.FormatInt(maxLength, 10)})
_, err := res.Write(b) _, err := res.Write(b)
return err return err
} }

View File

@ -7,6 +7,7 @@ import (
_ "embed" _ "embed"
"errors" "errors"
"fmt" "fmt"
"strconv"
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -162,7 +163,7 @@ func (b *Baseband) gatherVFMetric(acc telegraf.Accumulator, metricName string) e
tags := map[string]string{ tags := map[string]string{
"operation": metric.operationName, "operation": metric.operationName,
"metric": metricNameToTagName(metricName), "metric": metricNameToTagName(metricName),
"vf": fmt.Sprintf("%v", i), "vf": strconv.Itoa(i),
} }
acc.AddGauge(pluginName, fields, tags) acc.AddGauge(pluginName, fields, tags)
} }
@ -189,7 +190,7 @@ func (b *Baseband) gatherEngineMetric(acc telegraf.Accumulator, metricName strin
tags := map[string]string{ tags := map[string]string{
"operation": metric.operationName, "operation": metric.operationName,
"metric": metricNameToTagName(metricName), "metric": metricNameToTagName(metricName),
"engine": fmt.Sprintf("%v", i), "engine": strconv.Itoa(i),
} }
acc.AddGauge(pluginName, fields, tags) acc.AddGauge(pluginName, fields, tags)
} }

View File

@ -211,7 +211,7 @@ func (r *IntelRDT) associateProcessesWithPIDs(providedProcesses []string) (map[s
for _, availableProcess := range availableProcesses { for _, availableProcess := range availableProcesses {
if choice.Contains(availableProcess.Name, providedProcesses) { if choice.Contains(availableProcess.Name, providedProcesses) {
pid := availableProcess.PID 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 { for key := range mapProcessPIDs {

View File

@ -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 { func protocolToString(p uint16) string {
switch p { switch p {
case syscall.IPPROTO_TCP: case syscall.IPPROTO_TCP:
@ -131,11 +131,11 @@ func protocolToString(p uint16) string {
case syscall.IPPROTO_SCTP: case syscall.IPPROTO_SCTP:
return "sctp" return "sctp"
default: 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 { func addressFamilyToString(af uint16) string {
switch af { switch af {
case syscall.AF_INET: case syscall.AF_INET:
@ -143,7 +143,7 @@ func addressFamilyToString(af uint16) string {
case syscall.AF_INET6: case syscall.AF_INET6:
return "inet6" return "inet6"
default: default:
return fmt.Sprintf("%d", af) return strconv.FormatUint(uint64(af), 10)
} }
} }

View File

@ -198,7 +198,7 @@ func importMetric(stat []byte, acc telegraf.Accumulator) error {
"group_name": group.Name, "group_name": group.Name,
"app_root": group.AppRoot, "app_root": group.AppRoot,
"supergroup_name": sg.Name, "supergroup_name": sg.Name,
"pid": fmt.Sprintf("%d", process.Pid), "pid": strconv.Itoa(process.Pid),
"code_revision": process.CodeRevision, "code_revision": process.CodeRevision,
"life_status": process.LifeStatus, "life_status": process.LifeStatus,
"process_group_id": process.ProcessGroupID, "process_group_id": process.ProcessGroupID,

View File

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"net/http/fcgi" "net/http/fcgi"
"net/http/httptest" "net/http/httptest"
"strconv"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -25,7 +26,7 @@ type statServer struct{}
// We create a fake server to return test data // We create a fake server to return test data
func (s statServer) ServeHTTP(w http.ResponseWriter, _ *http.Request) { func (s statServer) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain") 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) 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) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "ok", r.URL.Query().Get("test")) require.Equal(t, "ok", r.URL.Query().Get("test"))
w.Header().Set("Content-Type", "text/plain") 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) _, err := fmt.Fprint(w, outputSample)
require.NoError(t, err) require.NoError(t, err)
})) }))

View File

@ -1,7 +1,7 @@
package github package github
import ( import (
"fmt" "strconv"
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -95,9 +95,9 @@ func (s CommitCommentEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -122,9 +122,9 @@ func (s CreateEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -149,9 +149,9 @@ func (s DeleteEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -175,9 +175,9 @@ func (s DeploymentEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -204,9 +204,9 @@ func (s DeploymentStatusEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -234,9 +234,9 @@ func (s ForkEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -260,9 +260,9 @@ func (s GollumEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -285,10 +285,10 @@ func (s IssueCommentEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
"issue": fmt.Sprintf("%v", s.Issue.Number), "issue": strconv.Itoa(s.Issue.Number),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -314,10 +314,10 @@ func (s IssuesEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
"issue": fmt.Sprintf("%v", s.Issue.Number), "issue": strconv.Itoa(s.Issue.Number),
"action": s.Action, "action": s.Action,
} }
f := map[string]interface{}{ f := map[string]interface{}{
@ -342,9 +342,9 @@ func (s MemberEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -369,7 +369,7 @@ func (s MembershipEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
"action": s.Action, "action": s.Action,
} }
f := map[string]interface{}{ f := map[string]interface{}{
@ -390,9 +390,9 @@ func (s PageBuildEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -413,9 +413,9 @@ func (s PublicEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -439,10 +439,10 @@ func (s PullRequestEvent) NewMetric() telegraf.Metric {
"event": event, "event": event,
"action": s.Action, "action": s.Action,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
"prNumber": fmt.Sprintf("%v", s.PullRequest.Number), "prNumber": strconv.Itoa(s.PullRequest.Number),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -472,10 +472,10 @@ func (s PullRequestReviewCommentEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
"prNumber": fmt.Sprintf("%v", s.PullRequest.Number), "prNumber": strconv.Itoa(s.PullRequest.Number),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -508,9 +508,9 @@ func (s PushEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -535,9 +535,9 @@ func (s ReleaseEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -559,9 +559,9 @@ func (s RepositoryEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -584,9 +584,9 @@ func (s StatusEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -610,9 +610,9 @@ func (s TeamAddEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,
@ -634,9 +634,9 @@ func (s WatchEvent) NewMetric() telegraf.Metric {
t := map[string]string{ t := map[string]string{
"event": event, "event": event,
"repository": s.Repository.Repository, "repository": s.Repository.Repository,
"private": fmt.Sprintf("%v", s.Repository.Private), "private": strconv.FormatBool(s.Repository.Private),
"user": s.Sender.User, "user": s.Sender.User,
"admin": fmt.Sprintf("%v", s.Sender.Admin), "admin": strconv.FormatBool(s.Sender.Admin),
} }
f := map[string]interface{}{ f := map[string]interface{}{
"stars": s.Repository.Stars, "stars": s.Repository.Stars,

View File

@ -7,6 +7,7 @@ import (
"context" "context"
"crypto/sha256" "crypto/sha256"
_ "embed" _ "embed"
"encoding/hex"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -150,7 +151,7 @@ func (h *HTTP) writeMetric(reqBody []byte) error {
reqBodyBuffer = buf reqBodyBuffer = buf
// sha256 is hex encoded // sha256 is hex encoded
hash := fmt.Sprintf("%x", sum) hash := hex.EncodeToString(sum[:])
payloadHash = &hash payloadHash = &hash
} }

View File

@ -10,6 +10,7 @@ import (
"io" "io"
"net/http" "net/http"
"sort" "sort"
"strconv"
"strings" "strings"
"time" "time"
@ -131,7 +132,7 @@ func (l *Loki) Write(metrics []telegraf.Metric) error {
line += fmt.Sprintf("%s=\"%v\" ", f.Key, f.Value) 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) return l.writeMetrics(s)

View File

@ -65,7 +65,7 @@ func batchGenerator(args batchGeneratorArgs) <-chan []telegraf.Metric {
for i := 0; i < args.tagCardinality; i++ { for i := 0; i < args.tagCardinality; i++ {
tags := MSS{} tags := MSS{}
for j := 0; j < args.numTags; j++ { 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) tagSets = append(tagSets, tags)
} }

View File

@ -110,7 +110,7 @@ func (w *Warp10) GenWarp10Payload(metrics []telegraf.Metric) string {
collectString = append(collectString, messageLine) collectString = append(collectString, messageLine)
} }
} }
return fmt.Sprint(strings.Join(collectString, "")) return strings.Join(collectString, "")
} }
// Write metrics to Warp10 // Write metrics to Warp10

View File

@ -135,7 +135,7 @@ func (a *YandexCloudMonitoring) Write(metrics []telegraf.Metric) error {
yandexCloudMonitoringMetric{ yandexCloudMonitoringMetric{
Name: field.Key, Name: field.Key,
Labels: m.Tags(), Labels: m.Tags(),
TS: fmt.Sprint(m.Time().Format(time.RFC3339)), TS: m.Time().Format(time.RFC3339),
Value: value, Value: value,
}, },
) )