mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-23 12:44:05 -08:00
golangci-lint: enable usestdlibvars linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
633224886a
commit
d496687c8e
|
@ -26,6 +26,7 @@ linters:
|
|||
- testifylint
|
||||
- unconvert
|
||||
- unused
|
||||
- usestdlibvars
|
||||
|
||||
issues:
|
||||
max-same-issues: 0
|
||||
|
|
|
@ -482,7 +482,7 @@ func CheckServerStatus(serverURL *url.URL, checkEndpoint string, roundTripper ht
|
|||
return err
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("GET", config.Address, nil)
|
||||
request, err := http.NewRequest(http.MethodGet, config.Address, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ const appListPath string = "/apps"
|
|||
func fetchApps(ctx context.Context, server string, client *http.Client) (*Applications, error) {
|
||||
url := fmt.Sprintf("%s%s", server, appListPath)
|
||||
|
||||
request, err := http.NewRequest("GET", url, nil)
|
||||
request, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func newRobotDiscovery(conf *SDConfig, _ log.Logger) (*robotDiscovery, error) {
|
|||
}
|
||||
|
||||
func (d *robotDiscovery) refresh(context.Context) ([]*targetgroup.Group, error) {
|
||||
req, err := http.NewRequest("GET", d.endpoint+"/server", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, d.endpoint+"/server", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger, clientOpts []config.HTTPCli
|
|||
}
|
||||
|
||||
func (d *Discovery) Refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
||||
req, err := http.NewRequest("GET", d.url, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, d.url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -339,7 +339,7 @@ type appListClient func(ctx context.Context, client *http.Client, url string) (*
|
|||
|
||||
// fetchApps requests a list of applications from a marathon server.
|
||||
func fetchApps(ctx context.Context, client *http.Client, url string) (*appList, error) {
|
||||
request, err := http.NewRequest("GET", url, nil)
|
||||
request, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ const hypervisorListBody = `
|
|||
// HandleHypervisorListSuccessfully mocks os-hypervisors detail call.
|
||||
func (m *SDMock) HandleHypervisorListSuccessfully() {
|
||||
m.Mux.HandleFunc("/os-hypervisors/detail", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(m.t, r, "GET")
|
||||
testMethod(m.t, r, http.MethodGet)
|
||||
testHeader(m.t, r, "X-Auth-Token", tokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
@ -536,7 +536,7 @@ const serverListBody = `
|
|||
// HandleServerListSuccessfully mocks server detail call.
|
||||
func (m *SDMock) HandleServerListSuccessfully() {
|
||||
m.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(m.t, r, "GET")
|
||||
testMethod(m.t, r, http.MethodGet)
|
||||
testHeader(m.t, r, "X-Auth-Token", tokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
@ -575,7 +575,7 @@ const listOutput = `
|
|||
// HandleFloatingIPListSuccessfully mocks floating ips call.
|
||||
func (m *SDMock) HandleFloatingIPListSuccessfully() {
|
||||
m.Mux.HandleFunc("/os-floating-ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(m.t, r, "GET")
|
||||
testMethod(m.t, r, http.MethodGet)
|
||||
testHeader(m.t, r, "X-Auth-Token", tokenID)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
|
|
@ -189,7 +189,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", d.url, bytes.NewBuffer(bodyBytes))
|
||||
req, err := http.NewRequest(http.MethodPost, d.url, bytes.NewBuffer(bodyBytes))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
|||
endpoint = fmt.Sprintf("%s?groups=%s", endpoint, groups)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func (rc *HTTPResourceClient) Fetch(ctx context.Context) (*v3.DiscoveryResponse,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("POST", rc.endpoint, bytes.NewBuffer(reqBody))
|
||||
request, err := http.NewRequest(http.MethodPost, rc.endpoint, bytes.NewBuffer(reqBody))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ testmetric,test_label=test_label_value2 value=5.1234 123456789123
|
|||
|
||||
server := httptest.NewServer(http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, "POST", r.Method, "Unexpected method.")
|
||||
require.Equal(t, http.MethodPost, r.Method, "Unexpected method.")
|
||||
require.Equal(t, "/write", r.URL.Path, "Unexpected path.")
|
||||
b, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err, "Error reading body.")
|
||||
|
|
|
@ -105,7 +105,7 @@ func (c *Client) Write(samples model.Samples) error {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(buf))
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewBuffer(buf))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package labels
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -810,7 +811,7 @@ var benchmarkLabels = []Label{
|
|||
{"job", "node"},
|
||||
{"instance", "123.123.1.211:9090"},
|
||||
{"path", "/api/v1/namespaces/<namespace>/deployments/<name>"},
|
||||
{"method", "GET"},
|
||||
{"method", http.MethodGet},
|
||||
{"namespace", "system"},
|
||||
{"status", "500"},
|
||||
{"prometheus", "prometheus-core-1"},
|
||||
|
|
|
@ -590,7 +590,7 @@ func labelsToOpenAPILabelSet(modelLabelSet labels.Labels) models.LabelSet {
|
|||
}
|
||||
|
||||
func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []byte) error {
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(b))
|
||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -726,7 +726,7 @@ var UserAgent = fmt.Sprintf("Prometheus/%s", version.Version)
|
|||
|
||||
func (s *targetScraper) scrape(ctx context.Context) (*http.Response, error) {
|
||||
if s.req == nil {
|
||||
req, err := http.NewRequest("GET", s.URL().String(), nil)
|
||||
req, err := http.NewRequest(http.MethodGet, s.URL().String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ type RecoverableError struct {
|
|||
// Store sends a batch of samples to the HTTP endpoint, the request is the proto marshalled
|
||||
// and encoded bytes from codec.go.
|
||||
func (c *Client) Store(ctx context.Context, req []byte, attempt int) error {
|
||||
httpReq, err := http.NewRequest("POST", c.urlString, bytes.NewReader(req))
|
||||
httpReq, err := http.NewRequest(http.MethodPost, c.urlString, bytes.NewReader(req))
|
||||
if err != nil {
|
||||
// Errors from NewRequest are from unparsable URLs, so are not
|
||||
// recoverable.
|
||||
|
@ -290,7 +290,7 @@ func (c *Client) Read(ctx context.Context, query *prompb.Query) (*prompb.QueryRe
|
|||
}
|
||||
|
||||
compressed := snappy.Encode(nil, data)
|
||||
httpReq, err := http.NewRequest("POST", c.urlString, bytes.NewReader(compressed))
|
||||
httpReq, err := http.NewRequest(http.MethodPost, c.urlString, bytes.NewReader(compressed))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create request: %w", err)
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ func TestSampledReadEndpoint(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
compressed := snappy.Encode(nil, data)
|
||||
request, err := http.NewRequest("POST", "", bytes.NewBuffer(compressed))
|
||||
request, err := http.NewRequest(http.MethodPost, "", bytes.NewBuffer(compressed))
|
||||
require.NoError(t, err)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
@ -170,7 +170,7 @@ func BenchmarkStreamReadEndpoint(b *testing.B) {
|
|||
|
||||
for i := 0; i < b.N; i++ {
|
||||
compressed := snappy.Encode(nil, data)
|
||||
request, err := http.NewRequest("POST", "", bytes.NewBuffer(compressed))
|
||||
request, err := http.NewRequest(http.MethodPost, "", bytes.NewBuffer(compressed))
|
||||
require.NoError(b, err)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
@ -268,7 +268,7 @@ func TestStreamReadEndpoint(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
compressed := snappy.Encode(nil, data)
|
||||
request, err := http.NewRequest("POST", "", bytes.NewBuffer(compressed))
|
||||
request, err := http.NewRequest(http.MethodPost, "", bytes.NewBuffer(compressed))
|
||||
require.NoError(t, err)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestCompressionHandler_Gzip(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("GET", server.URL+"/foo_endpoint", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, server.URL+"/foo_endpoint", nil)
|
||||
req.Header.Set(acceptEncodingHeader, gzipEncoding)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
@ -120,7 +120,7 @@ func TestCompressionHandler_Deflate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("GET", server.URL+"/foo_endpoint", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, server.URL+"/foo_endpoint", nil)
|
||||
req.Header.Set(acceptEncodingHeader, deflateEncoding)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
|
|
@ -41,7 +41,7 @@ func TestCORSHandler(t *testing.T) {
|
|||
dummyOrigin := "https://foo.com"
|
||||
|
||||
// OPTIONS with legit origin
|
||||
req, err := http.NewRequest("OPTIONS", server.URL+"/any_path", nil)
|
||||
req, err := http.NewRequest(http.MethodOptions, server.URL+"/any_path", nil)
|
||||
require.NoError(t, err, "could not create request")
|
||||
|
||||
req.Header.Set("Origin", dummyOrigin)
|
||||
|
@ -53,7 +53,7 @@ func TestCORSHandler(t *testing.T) {
|
|||
require.Equal(t, dummyOrigin, AccessControlAllowOrigin, "expected Access-Control-Allow-Origin header")
|
||||
|
||||
// OPTIONS with bad origin
|
||||
req, err = http.NewRequest("OPTIONS", server.URL+"/any_path", nil)
|
||||
req, err = http.NewRequest(http.MethodOptions, server.URL+"/any_path", nil)
|
||||
require.NoError(t, err, "could not create request")
|
||||
|
||||
req.Header.Set("Origin", "https://not-foo.com")
|
||||
|
|
|
@ -3354,7 +3354,7 @@ func TestParseTimeParam(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
req, err := http.NewRequest("GET", "localhost:42/foo?"+test.paramName+"="+test.paramValue, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "localhost:42/foo?"+test.paramName+"="+test.paramValue, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
result := test.result
|
||||
|
@ -3491,7 +3491,7 @@ func TestOptionsMethod(t *testing.T) {
|
|||
s := httptest.NewServer(r)
|
||||
defer s.Close()
|
||||
|
||||
req, err := http.NewRequest("OPTIONS", s.URL+"/any_path", nil)
|
||||
req, err := http.NewRequest(http.MethodOptions, s.URL+"/any_path", nil)
|
||||
require.NoError(t, err, "Error creating OPTIONS request")
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestApiStatusCodes(t *testing.T) {
|
|||
r := createPrometheusAPI(q)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/v1/query?query=up", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/v1/query?query=up", nil)
|
||||
|
||||
r.ServeHTTP(rec, req)
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ func TestFederation(t *testing.T) {
|
|||
for name, scenario := range scenarios {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
h.config.GlobalConfig.ExternalLabels = scenario.externalLabels
|
||||
req := httptest.NewRequest("GET", "http://example.org/federate?"+scenario.params, nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "http://example.org/federate?"+scenario.params, nil)
|
||||
res := httptest.NewRecorder()
|
||||
|
||||
h.federation(res, req)
|
||||
|
@ -265,7 +265,7 @@ func TestFederation_NotReady(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
req := httptest.NewRequest("GET", "http://example.org/federate?"+scenario.params, nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "http://example.org/federate?"+scenario.params, nil)
|
||||
res := httptest.NewRecorder()
|
||||
|
||||
h.federation(res, req)
|
||||
|
@ -381,7 +381,7 @@ func TestFederationWithNativeHistograms(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
req := httptest.NewRequest("GET", "http://example.org/federate?match[]=test_metric", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "http://example.org/federate?match[]=test_metric", nil)
|
||||
req.Header.Add("Accept", `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited,application/openmetrics-text;version=1.0.0;q=0.8,application/openmetrics-text;version=0.0.1;q=0.75,text/plain;version=0.0.4;q=0.5,*/*;q=0.1`)
|
||||
res := httptest.NewRecorder()
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ func TestDebugHandler(t *testing.T) {
|
|||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", tc.url, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, tc.url, nil)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -335,7 +335,7 @@ func TestHTTPMetrics(t *testing.T) {
|
|||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", "/-/ready", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "/-/ready", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
handler.router.ServeHTTP(w, req)
|
||||
|
|
Loading…
Reference in a new issue