diff --git a/.golangci.yml b/.golangci.yml index dfc74139f..b4830d804 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -108,8 +108,16 @@ linters-settings: gofumpt: extra-rules: true perfsprint: - # Optimizes `fmt.Errorf`. + # Optimizes even if it requires an int or uint type cast. + int-conversion: true + # Optimizes into `err.Error()` even if it is only equivalent for non-nil errors. + err-error: true + # Optimizes `fmt.Errorf`. errorf: true + # Optimizes `fmt.Sprintf` with only one argument. + sprintf1: true + # Optimizes into strings concatenation. + strconcat: false revive: # By default, revive will enable only the linting rules that are named in the configuration file. # So, it's needed to explicitly enable all required rules here. diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index f8a4ecd8c..6321f16d3 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -153,7 +153,7 @@ func init() { // serverOnlyFlag creates server-only kingpin flag. func serverOnlyFlag(app *kingpin.Application, name, help string) *kingpin.FlagClause { - return app.Flag(name, fmt.Sprintf("%s Use with server mode only.", help)). + return app.Flag(name, help+" Use with server mode only."). PreAction(func(parseContext *kingpin.ParseContext) error { // This will be invoked only if flag is actually provided by user. serverOnlyFlags = append(serverOnlyFlags, "--"+name) @@ -163,7 +163,7 @@ func serverOnlyFlag(app *kingpin.Application, name, help string) *kingpin.FlagCl // agentOnlyFlag creates agent-only kingpin flag. func agentOnlyFlag(app *kingpin.Application, name, help string) *kingpin.FlagClause { - return app.Flag(name, fmt.Sprintf("%s Use with agent mode only.", help)). + return app.Flag(name, help+" Use with agent mode only."). PreAction(func(parseContext *kingpin.ParseContext) error { // This will be invoked only if flag is actually provided by user. agentOnlyFlags = append(agentOnlyFlags, "--"+name) diff --git a/cmd/prometheus/query_log_test.go b/cmd/prometheus/query_log_test.go index 25abf5e96..0de147250 100644 --- a/cmd/prometheus/query_log_test.go +++ b/cmd/prometheus/query_log_test.go @@ -60,7 +60,7 @@ func (p *queryLogTest) skip(t *testing.T) { t.Skip("changing prefix has no effect on rules") } // Some systems don't support IPv4 or IPv6. - l, err := net.Listen("tcp", fmt.Sprintf("%s:0", p.host)) + l, err := net.Listen("tcp", p.host+":0") if err != nil { t.Skip("ip version not supported") } diff --git a/discovery/azure/azure.go b/discovery/azure/azure.go index ec1c51ace..9809561a8 100644 --- a/discovery/azure/azure.go +++ b/discovery/azure/azure.go @@ -71,7 +71,7 @@ const ( ) var ( - userAgent = fmt.Sprintf("Prometheus/%s", version.Version) + userAgent = "Prometheus/" + version.Version // DefaultSDConfig is the default Azure SD configuration. DefaultSDConfig = SDConfig{ diff --git a/discovery/digitalocean/digitalocean.go b/discovery/digitalocean/digitalocean.go index fce8d1a35..ba9c4ec6d 100644 --- a/discovery/digitalocean/digitalocean.go +++ b/discovery/digitalocean/digitalocean.go @@ -132,7 +132,7 @@ func NewDiscovery(conf *SDConfig, logger *slog.Logger, metrics discovery.Discove Transport: rt, Timeout: time.Duration(conf.RefreshInterval), }, - godo.SetUserAgent(fmt.Sprintf("Prometheus/%s", version.Version)), + godo.SetUserAgent("Prometheus/"+version.Version), ) if err != nil { return nil, fmt.Errorf("error setting up digital ocean agent: %w", err) diff --git a/discovery/digitalocean/mock_test.go b/discovery/digitalocean/mock_test.go index 62d963c3b..93da90539 100644 --- a/discovery/digitalocean/mock_test.go +++ b/discovery/digitalocean/mock_test.go @@ -56,7 +56,7 @@ const tokenID = "3c9a75a2-24fd-4508-b4f2-11f18aa97411" // HandleDropletsList mocks droplet list. func (m *SDMock) HandleDropletsList() { m.Mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", tokenID) { + if r.Header.Get("Authorization") != "Bearer "+tokenID { w.WriteHeader(http.StatusForbidden) return } diff --git a/discovery/eureka/client.go b/discovery/eureka/client.go index 52e8ce7b4..c0c8fe901 100644 --- a/discovery/eureka/client.go +++ b/discovery/eureka/client.go @@ -23,7 +23,7 @@ import ( "github.com/prometheus/common/version" ) -var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) +var userAgent = "Prometheus/" + version.Version type Applications struct { VersionsDelta int `xml:"versions__delta"` diff --git a/discovery/hetzner/mock_test.go b/discovery/hetzner/mock_test.go index d192a4eae..0a41e2143 100644 --- a/discovery/hetzner/mock_test.go +++ b/discovery/hetzner/mock_test.go @@ -56,7 +56,7 @@ const hcloudTestToken = "LRK9DAWQ1ZAEFSrCNEEzLCUwhYX1U3g7wMg4dTlkkDC96fyDuyJ39nV // HandleHcloudServers mocks the cloud servers list endpoint. func (m *SDMock) HandleHcloudServers() { m.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", hcloudTestToken) { + if r.Header.Get("Authorization") != "Bearer "+hcloudTestToken { w.WriteHeader(http.StatusUnauthorized) return } @@ -432,7 +432,7 @@ func (m *SDMock) HandleHcloudServers() { // HandleHcloudNetworks mocks the cloud networks list endpoint. func (m *SDMock) HandleHcloudNetworks() { m.Mux.HandleFunc("/networks", func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", hcloudTestToken) { + if r.Header.Get("Authorization") != "Bearer "+hcloudTestToken { w.WriteHeader(http.StatusUnauthorized) return } diff --git a/discovery/hetzner/robot.go b/discovery/hetzner/robot.go index 958f8f710..437df9ea0 100644 --- a/discovery/hetzner/robot.go +++ b/discovery/hetzner/robot.go @@ -39,7 +39,7 @@ const ( hetznerLabelRobotCancelled = hetznerRobotLabelPrefix + "cancelled" ) -var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) +var userAgent = "Prometheus/" + version.Version // Discovery periodically performs Hetzner Robot requests. It implements // the Discoverer interface. diff --git a/discovery/http/http.go b/discovery/http/http.go index 667fd36f6..2920bae6e 100644 --- a/discovery/http/http.go +++ b/discovery/http/http.go @@ -44,7 +44,7 @@ var ( HTTPClientConfig: config.DefaultHTTPClientConfig, RefreshInterval: model.Duration(60 * time.Second), } - userAgent = fmt.Sprintf("Prometheus/%s", version.Version) + userAgent = "Prometheus/" + version.Version matchContentType = regexp.MustCompile(`^(?i:application\/json(;\s*charset=("utf-8"|utf-8))?)$`) ) diff --git a/discovery/ionos/server.go b/discovery/ionos/server.go index 18e89b1d4..b85890dba 100644 --- a/discovery/ionos/server.go +++ b/discovery/ionos/server.go @@ -15,7 +15,6 @@ package ionos import ( "context" - "fmt" "log/slog" "net" "net/http" @@ -77,7 +76,7 @@ func newServerDiscovery(conf *SDConfig, _ *slog.Logger) (*serverDiscovery, error Transport: rt, Timeout: time.Duration(conf.RefreshInterval), } - cfg.UserAgent = fmt.Sprintf("Prometheus/%s", version.Version) + cfg.UserAgent = "Prometheus/" + version.Version d.client = ionoscloud.NewAPIClient(cfg) diff --git a/discovery/ionos/server_test.go b/discovery/ionos/server_test.go index 30f358e32..a640a0c55 100644 --- a/discovery/ionos/server_test.go +++ b/discovery/ionos/server_test.go @@ -98,7 +98,7 @@ func mockIONOSServers(w http.ResponseWriter, r *http.Request) { return } if r.URL.Path != fmt.Sprintf("%s/datacenters/%s/servers", ionoscloud.DefaultIonosBasePath, ionosTestDatacenterID) { - http.Error(w, fmt.Sprintf("bad url: %s", r.URL.Path), http.StatusNotFound) + http.Error(w, "bad url: "+r.URL.Path, http.StatusNotFound) return } w.Header().Set("Content-Type", "application/json") diff --git a/discovery/kubernetes/kubernetes.go b/discovery/kubernetes/kubernetes.go index 9aff89e4f..04404ddba 100644 --- a/discovery/kubernetes/kubernetes.go +++ b/discovery/kubernetes/kubernetes.go @@ -61,7 +61,7 @@ const ( var ( // Http header. - userAgent = fmt.Sprintf("Prometheus/%s", version.Version) + userAgent = "Prometheus/" + version.Version // DefaultSDConfig is the default Kubernetes SD configuration. DefaultSDConfig = SDConfig{ HTTPClientConfig: config.DefaultHTTPClientConfig, diff --git a/discovery/kubernetes/service_test.go b/discovery/kubernetes/service_test.go index dde3aaea5..8e4e32d99 100644 --- a/discovery/kubernetes/service_test.go +++ b/discovery/kubernetes/service_test.go @@ -15,7 +15,6 @@ package kubernetes import ( "context" - "fmt" "testing" "github.com/prometheus/common/model" @@ -55,7 +54,7 @@ func makeMultiPortService() *v1.Service { func makeSuffixedService(suffix string) *v1.Service { return &v1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("testservice%s", suffix), + Name: "testservice" + suffix, Namespace: "default", }, Spec: v1.ServiceSpec{ diff --git a/discovery/linode/linode.go b/discovery/linode/linode.go index 90a91fc92..94bdd17ce 100644 --- a/discovery/linode/linode.go +++ b/discovery/linode/linode.go @@ -165,7 +165,7 @@ func NewDiscovery(conf *SDConfig, logger *slog.Logger, metrics discovery.Discove Timeout: time.Duration(conf.RefreshInterval), }, ) - client.SetUserAgent(fmt.Sprintf("Prometheus/%s", version.Version)) + client.SetUserAgent("Prometheus/" + version.Version) d.client = &client d.Discovery = refresh.NewDiscovery( diff --git a/discovery/linode/mock_test.go b/discovery/linode/mock_test.go index 50f0572ec..0d8dcc517 100644 --- a/discovery/linode/mock_test.go +++ b/discovery/linode/mock_test.go @@ -15,7 +15,6 @@ package linode import ( "encoding/json" - "fmt" "net/http" "net/http/httptest" "os" @@ -56,7 +55,7 @@ func (m *SDMock) Setup() { func (m *SDMock) SetupHandlers() { for _, handler := range []string{"/v4/account/events", "/v4/linode/instances", "/v4/networking/ips", "/v4/networking/ipv6/ranges"} { m.Mux.HandleFunc(handler, func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", tokenID) { + if r.Header.Get("Authorization") != "Bearer "+tokenID { w.WriteHeader(http.StatusUnauthorized) return } diff --git a/discovery/moby/dockerswarm.go b/discovery/moby/dockerswarm.go index ba4225341..8af3ffd64 100644 --- a/discovery/moby/dockerswarm.go +++ b/discovery/moby/dockerswarm.go @@ -38,7 +38,7 @@ const ( swarmLabel = model.MetaLabelPrefix + "dockerswarm_" ) -var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) +var userAgent = "Prometheus/" + version.Version // DefaultDockerSwarmSDConfig is the default Docker Swarm SD configuration. var DefaultDockerSwarmSDConfig = DockerSwarmSDConfig{ diff --git a/discovery/puppetdb/puppetdb.go b/discovery/puppetdb/puppetdb.go index 561bf78ba..ad47410ea 100644 --- a/discovery/puppetdb/puppetdb.go +++ b/discovery/puppetdb/puppetdb.go @@ -64,7 +64,7 @@ var ( HTTPClientConfig: config.DefaultHTTPClientConfig, } matchContentType = regexp.MustCompile(`^(?i:application\/json(;\s*charset=("utf-8"|utf-8))?)$`) - userAgent = fmt.Sprintf("Prometheus/%s", version.Version) + userAgent = "Prometheus/" + version.Version ) func init() { diff --git a/discovery/scaleway/baremetal.go b/discovery/scaleway/baremetal.go index c313e6695..93446556a 100644 --- a/discovery/scaleway/baremetal.go +++ b/discovery/scaleway/baremetal.go @@ -93,7 +93,7 @@ func newBaremetalDiscovery(conf *SDConfig) (*baremetalDiscovery, error) { Transport: rt, Timeout: time.Duration(conf.RefreshInterval), }), - scw.WithUserAgent(fmt.Sprintf("Prometheus/%s", version.Version)), + scw.WithUserAgent("Prometheus/"+version.Version), scw.WithProfile(profile), ) if err != nil { diff --git a/discovery/scaleway/instance.go b/discovery/scaleway/instance.go index 2542c6325..fb5b8fa35 100644 --- a/discovery/scaleway/instance.go +++ b/discovery/scaleway/instance.go @@ -104,7 +104,7 @@ func newInstanceDiscovery(conf *SDConfig) (*instanceDiscovery, error) { Transport: rt, Timeout: time.Duration(conf.RefreshInterval), }), - scw.WithUserAgent(fmt.Sprintf("Prometheus/%s", version.Version)), + scw.WithUserAgent("Prometheus/"+version.Version), scw.WithProfile(profile), ) if err != nil { diff --git a/discovery/vultr/mock_test.go b/discovery/vultr/mock_test.go index bfc24d06f..714935c2b 100644 --- a/discovery/vultr/mock_test.go +++ b/discovery/vultr/mock_test.go @@ -55,7 +55,7 @@ const APIKey = "ABCBTDG35OTGH2UKCC3S6CNMDUPCN3ZWSGFQ" // HandleInstanceList mocks vultr instances list. func (m *SDMock) HandleInstanceList() { m.Mux.HandleFunc("/v2/instances", func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", APIKey) { + if r.Header.Get("Authorization") != "Bearer "+APIKey { w.WriteHeader(http.StatusForbidden) return } diff --git a/discovery/vultr/vultr.go b/discovery/vultr/vultr.go index ee92f0169..6db35c7a2 100644 --- a/discovery/vultr/vultr.go +++ b/discovery/vultr/vultr.go @@ -135,7 +135,7 @@ func NewDiscovery(conf *SDConfig, logger *slog.Logger, metrics discovery.Discove Timeout: time.Duration(conf.RefreshInterval), }) - d.client.SetUserAgent(fmt.Sprintf("Prometheus/%s", version.Version)) + d.client.SetUserAgent("Prometheus/" + version.Version) if err != nil { return nil, fmt.Errorf("error setting up vultr agent: %w", err) diff --git a/discovery/xds/client.go b/discovery/xds/client.go index 027ceb271..33f9c42f3 100644 --- a/discovery/xds/client.go +++ b/discovery/xds/client.go @@ -30,7 +30,7 @@ import ( "github.com/prometheus/common/version" ) -var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) +var userAgent = "Prometheus/" + version.Version // ResourceClient exposes the xDS protocol for a single resource type. // See https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol#rest-json-polling-subscriptions . @@ -140,7 +140,7 @@ func makeXDSResourceHTTPEndpointURL(protocolVersion ProtocolVersion, serverURL * return nil, errors.New("invalid xDS server URL protocol. must be either 'http' or 'https'") } - serverURL.Path = path.Join(serverURL.Path, string(protocolVersion), fmt.Sprintf("discovery:%s", resourceType)) + serverURL.Path = path.Join(serverURL.Path, string(protocolVersion), "discovery:"+resourceType) return serverURL, nil } diff --git a/notifier/notifier.go b/notifier/notifier.go index 956fd4652..3fab232d4 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -56,7 +56,7 @@ const ( alertmanagerLabel = "alertmanager" ) -var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) +var userAgent = "Prometheus/" + version.Version // Alert is a generic representation of an alert in the Prometheus eco-system. type Alert struct { diff --git a/promql/bench_test.go b/promql/bench_test.go index 943baceec..617b553ae 100644 --- a/promql/bench_test.go +++ b/promql/bench_test.go @@ -571,7 +571,7 @@ func BenchmarkParser(b *testing.B) { }) } for _, c := range errCases { - name := fmt.Sprintf("%s (should fail)", c) + name := c + " (should fail)" b.Run(name, func(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { diff --git a/promql/engine.go b/promql/engine.go index 13f8b0697..ab92ad881 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -102,15 +102,15 @@ type ( ) func (e ErrQueryTimeout) Error() string { - return fmt.Sprintf("query timed out in %s", string(e)) + return "query timed out in " + string(e) } func (e ErrQueryCanceled) Error() string { - return fmt.Sprintf("query was canceled in %s", string(e)) + return "query was canceled in " + string(e) } func (e ErrTooManySamples) Error() string { - return fmt.Sprintf("query processing would load too many samples into memory in %s", string(e)) + return "query processing would load too many samples into memory in " + string(e) } func (e ErrStorage) Error() string { diff --git a/promql/parser/prettier.go b/promql/parser/prettier.go index 9870d6da7..412204881 100644 --- a/promql/parser/prettier.go +++ b/promql/parser/prettier.go @@ -58,7 +58,7 @@ func (e *AggregateExpr) Pretty(level int) string { s += "(\n" if e.Op.IsAggregatorWithParam() { - s += fmt.Sprintf("%s,\n", e.Param.Pretty(level+1)) + s += e.Param.Pretty(level+1) + ",\n" } s += fmt.Sprintf("%s\n%s)", e.Expr.Pretty(level+1), indent(level)) return s @@ -97,7 +97,7 @@ func (e Expressions) Pretty(level int) string { // Do not prefix the indent since respective nodes will indent itself. s := "" for i := range e { - s += fmt.Sprintf("%s,\n", e[i].Pretty(level)) + s += e[i].Pretty(level) + ",\n" } return s[:len(s)-2] } diff --git a/rules/alerting.go b/rules/alerting.go index e7f15baef..7b0e72c6b 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -589,7 +589,7 @@ func (r *AlertingRule) String() string { byt, err := yaml.Marshal(ar) if err != nil { - return fmt.Sprintf("error marshaling alerting rule: %s", err.Error()) + return "error marshaling alerting rule: " + err.Error() } return string(byt) diff --git a/rules/manager_test.go b/rules/manager_test.go index 6afac993d..5fa7798d4 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -15,7 +15,6 @@ package rules import ( "context" - "fmt" "io/fs" "math" "os" @@ -195,7 +194,7 @@ func TestAlertingRule(t *testing.T) { func TestForStateAddSamples(t *testing.T) { for _, queryOffset := range []time.Duration{0, time.Minute} { - t.Run(fmt.Sprintf("queryOffset %s", queryOffset.String()), func(t *testing.T) { + t.Run("queryOffset "+queryOffset.String(), func(t *testing.T) { storage := promqltest.LoadedStorage(t, ` load 5m http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 95 105 105 95 85 @@ -357,7 +356,7 @@ func sortAlerts(items []*Alert) { func TestForStateRestore(t *testing.T) { for _, queryOffset := range []time.Duration{0, time.Minute} { - t.Run(fmt.Sprintf("queryOffset %s", queryOffset.String()), func(t *testing.T) { + t.Run("queryOffset "+queryOffset.String(), func(t *testing.T) { storage := promqltest.LoadedStorage(t, ` load 5m http_requests{job="app-server", instance="0", group="canary", severity="overwrite-me"} 75 85 50 0 0 25 0 0 40 0 120 @@ -842,7 +841,7 @@ func TestUpdate(t *testing.T) { // Change group rules and reload. for i, g := range rgs.Groups { for j, r := range g.Rules { - rgs.Groups[i].Rules[j].Expr.SetString(fmt.Sprintf("%s * 0", r.Expr.Value)) + rgs.Groups[i].Rules[j].Expr.SetString(r.Expr.Value + " * 0") } } reloadAndValidate(rgs, t, tmpFile, ruleManager, ogs) diff --git a/scrape/scrape.go b/scrape/scrape.go index eeab208d6..ae40d42bf 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -786,7 +786,7 @@ func acceptEncodingHeader(enableCompression bool) string { return "identity" } -var UserAgent = fmt.Sprintf("Prometheus/%s", version.Version) +var UserAgent = "Prometheus/" + version.Version func (s *targetScraper) scrape(ctx context.Context) (*http.Response, error) { if s.req == nil { diff --git a/storage/remote/client.go b/storage/remote/client.go index ad766be9b..04af5209e 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -66,7 +66,7 @@ const ( var ( // UserAgent represents Prometheus version to use for user agent header. - UserAgent = fmt.Sprintf("Prometheus/%s", version.Version) + UserAgent = "Prometheus/" + version.Version remoteWriteContentTypeHeaders = map[config.RemoteWriteProtoMsg]string{ config.RemoteWriteProtoMsgV1: appProtoContentType, // Also application/x-protobuf;proto=prometheus.WriteRequest but simplified for compatibility with 1.x spec. diff --git a/tsdb/chunks/chunks.go b/tsdb/chunks/chunks.go index f505d762b..7bb618c30 100644 --- a/tsdb/chunks/chunks.go +++ b/tsdb/chunks/chunks.go @@ -184,7 +184,7 @@ func ChunkFromSamplesGeneric(s Samples) (Meta, error) { return emptyChunk, errors.New("did not expect to start a second chunk") } default: - panic(fmt.Sprintf("unknown sample type %s", sampleType.String())) + panic("unknown sample type " + sampleType.String()) } } return Meta{ diff --git a/tsdb/compact_test.go b/tsdb/compact_test.go index 310fe8f25..ad3f0b2cd 100644 --- a/tsdb/compact_test.go +++ b/tsdb/compact_test.go @@ -1645,7 +1645,7 @@ func TestSparseHistogramSpaceSavings(t *testing.T) { lbls := labels.FromStrings( "__name__", fmt.Sprintf("rpc_durations_%d_histogram_seconds", i), "instance", "localhost:8080", - "job", fmt.Sprintf("sparse_histogram_schema_%s", schemaDescription[sid]), + "job", "sparse_histogram_schema_"+schemaDescription[sid], ) allSparseSeries = append(allSparseSeries, struct { baseLabels labels.Labels diff --git a/tsdb/db_test.go b/tsdb/db_test.go index 306dc4579..3ab607497 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -5673,7 +5673,7 @@ func testQuerierOOOQuery(t *testing.T, }, } for _, tc := range tests { - t.Run(fmt.Sprintf("name=%s", tc.name), func(t *testing.T) { + t.Run("name="+tc.name, func(t *testing.T) { opts.OutOfOrderCapMax = tc.oooCap db := openTestDB(t, opts, nil) db.DisableCompactions() @@ -6004,7 +6004,7 @@ func testChunkQuerierOOOQuery(t *testing.T, }, } for _, tc := range tests { - t.Run(fmt.Sprintf("name=%s", tc.name), func(t *testing.T) { + t.Run("name="+tc.name, func(t *testing.T) { opts.OutOfOrderCapMax = tc.oooCap db := openTestDB(t, opts, nil) db.DisableCompactions() @@ -6187,7 +6187,7 @@ func testOOONativeHistogramsWithCounterResets(t *testing.T, scenario sampleTypeS }, } for _, tc := range tests { - t.Run(fmt.Sprintf("name=%s", tc.name), func(t *testing.T) { + t.Run("name="+tc.name, func(t *testing.T) { db := openTestDB(t, opts, nil) db.DisableCompactions() db.EnableOOONativeHistograms() diff --git a/tsdb/ooo_head_read_test.go b/tsdb/ooo_head_read_test.go index bc1cb67d1..c90ec85f4 100644 --- a/tsdb/ooo_head_read_test.go +++ b/tsdb/ooo_head_read_test.go @@ -839,7 +839,7 @@ func testOOOHeadChunkReader_Chunk(t *testing.T, scenario sampleTypeScenario) { } for _, tc := range tests { - t.Run(fmt.Sprintf("name=%s", tc.name), func(t *testing.T) { + t.Run("name="+tc.name, func(t *testing.T) { db := newTestDBWithOpts(t, opts) app := db.Appender(context.Background()) @@ -1010,7 +1010,7 @@ func testOOOHeadChunkReader_Chunk_ConsistentQueryResponseDespiteOfHeadExpanding( } for _, tc := range tests { - t.Run(fmt.Sprintf("name=%s", tc.name), func(t *testing.T) { + t.Run("name="+tc.name, func(t *testing.T) { db := newTestDBWithOpts(t, opts) app := db.Appender(context.Background()) @@ -1117,7 +1117,7 @@ func TestSortMetaByMinTimeAndMinRef(t *testing.T) { } for _, tc := range tests { - t.Run(fmt.Sprintf("name=%s", tc.name), func(t *testing.T) { + t.Run("name="+tc.name, func(t *testing.T) { slices.SortFunc(tc.inputMetas, lessByMinTimeAndMinRef) require.Equal(t, tc.expMetas, tc.inputMetas) }) diff --git a/util/documentcli/documentcli.go b/util/documentcli/documentcli.go index 6964952af..954610749 100644 --- a/util/documentcli/documentcli.go +++ b/util/documentcli/documentcli.go @@ -82,7 +82,7 @@ func createFlagRow(flag *kingpin.FlagModel) []string { } if valueType.Kind() == reflect.Struct { if _, found := valueType.FieldByName("slice"); found { - name = fmt.Sprintf(`%s ...`, name) + name += " ..." } } @@ -105,7 +105,7 @@ func writeFlagTable(writer io.Writer, level int, fgm *kingpin.FlagGroupModel) er } } - return writeTable(writer, rows, fmt.Sprintf("%s Flags", strings.Repeat("#", level+2))) + return writeTable(writer, rows, strings.Repeat("#", level+2)+" Flags") } func createArgRow(arg *kingpin.ArgModel) []string { @@ -136,7 +136,7 @@ func writeArgTable(writer io.Writer, level int, agm *kingpin.ArgGroupModel) erro rows = append(rows, row) } - return writeTable(writer, rows, fmt.Sprintf("%s Arguments", strings.Repeat("#", level+2))) + return writeTable(writer, rows, strings.Repeat("#", level+2)+" Arguments") } func createCmdRow(cmd *kingpin.CmdModel) []string { diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 0168bc57e..7cfe5efa1 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -3464,7 +3464,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E r.RemoteAddr = "127.0.0.1:20201" return r, err } - r, err := http.NewRequest(m, fmt.Sprintf("http://example.com?%s", q.Encode()), nil) + r, err := http.NewRequest(m, "http://example.com?"+q.Encode(), nil) r.RemoteAddr = "127.0.0.1:20201" return r, err } @@ -3773,7 +3773,7 @@ func TestAdminEndpoints(t *testing.T) { } endpoint := tc.endpoint(api) - req, err := http.NewRequest(tc.method, fmt.Sprintf("?%s", tc.values.Encode()), nil) + req, err := http.NewRequest(tc.method, "?"+tc.values.Encode(), nil) require.NoError(t, err) res := setUnavailStatusOnTSDBNotReady(endpoint(req)) @@ -4149,7 +4149,7 @@ func TestTSDBStatus(t *testing.T) { t.Run(strconv.Itoa(i), func(t *testing.T) { api := &API{db: tc.db, gatherer: prometheus.DefaultGatherer} endpoint := tc.endpoint(api) - req, err := http.NewRequest(tc.method, fmt.Sprintf("?%s", tc.values.Encode()), nil) + req, err := http.NewRequest(tc.method, "?"+tc.values.Encode(), nil) require.NoError(t, err, "Error when creating test request") res := endpoint(req) assertAPIError(t, res.err, tc.errType) @@ -4479,7 +4479,7 @@ func TestQueryTimeout(t *testing.T) { "timeout": []string{"1s"}, } ctx := context.Background() - req, err := http.NewRequest(tc.method, fmt.Sprintf("http://example.com?%s", query.Encode()), nil) + req, err := http.NewRequest(tc.method, "http://example.com?"+query.Encode(), nil) require.NoError(t, err) req.RemoteAddr = "127.0.0.1:20201"