diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go index a36512f43..2b0e0f5dc 100644 --- a/app/vmagent/remotewrite/client.go +++ b/app/vmagent/remotewrite/client.go @@ -309,7 +309,7 @@ func (c *client) sendBlockHTTP(block []byte) bool { } again: - req, err := http.NewRequest("POST", c.remoteWriteURL, bytes.NewBuffer(block)) + req, err := http.NewRequest(http.MethodPost, c.remoteWriteURL, bytes.NewBuffer(block)) if err != nil { logger.Panicf("BUG: unexpected error from http.NewRequest(%q): %s", c.sanitizedURL, err) } diff --git a/app/vmalert/datasource/vm.go b/app/vmalert/datasource/vm.go index 83fb5060d..e9d579c69 100644 --- a/app/vmalert/datasource/vm.go +++ b/app/vmalert/datasource/vm.go @@ -174,7 +174,7 @@ func (s *VMStorage) do(ctx context.Context, req *http.Request) (*http.Response, } func (s *VMStorage) newRequestPOST() (*http.Request, error) { - req, err := http.NewRequest("POST", s.datasourceURL, nil) + req, err := http.NewRequest(http.MethodPost, s.datasourceURL, nil) if err != nil { return nil, err } diff --git a/app/vmalert/notifier/alertmanager.go b/app/vmalert/notifier/alertmanager.go index 14ec932c7..22d09784c 100644 --- a/app/vmalert/notifier/alertmanager.go +++ b/app/vmalert/notifier/alertmanager.go @@ -64,7 +64,7 @@ func (am *AlertManager) send(ctx context.Context, alerts []Alert) error { b := &bytes.Buffer{} writeamRequest(b, alerts, am.argFunc, am.relabelConfigs) - req, err := http.NewRequest("POST", am.addr, b) + req, err := http.NewRequest(http.MethodPost, am.addr, b) if err != nil { return err } diff --git a/app/vmalert/remotewrite/remotewrite.go b/app/vmalert/remotewrite/remotewrite.go index 4fb0db7c6..3479966fe 100644 --- a/app/vmalert/remotewrite/remotewrite.go +++ b/app/vmalert/remotewrite/remotewrite.go @@ -225,7 +225,7 @@ func (c *Client) flush(ctx context.Context, wr *prompbmarshal.WriteRequest) { func (c *Client) send(ctx context.Context, data []byte) error { r := bytes.NewReader(data) - req, err := http.NewRequest("POST", c.addr, r) + req, err := http.NewRequest(http.MethodPost, c.addr, r) if err != nil { return fmt.Errorf("failed to create new HTTP request: %w", err) } diff --git a/app/vmctl/remoteread/remoteread.go b/app/vmctl/remoteread/remoteread.go index 72f44cc89..49a6f9d8c 100644 --- a/app/vmctl/remoteread/remoteread.go +++ b/app/vmctl/remoteread/remoteread.go @@ -157,7 +157,7 @@ func (c *Client) do(req *http.Request) (*http.Response, error) { // Ping checks the health of the read source func (c *Client) Ping() error { url := c.addr + healthPath - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return fmt.Errorf("cannot create request to %q: %s", url, err) } @@ -174,7 +174,7 @@ func (c *Client) Ping() error { func (c *Client) fetch(ctx context.Context, data []byte, streamCb StreamCallback) error { r := bytes.NewReader(data) url := c.addr + remoteReadPath - req, err := http.NewRequest("POST", url, r) + req, err := http.NewRequest(http.MethodPost, url, r) if err != nil { return fmt.Errorf("failed to create new HTTP request: %w", err) } diff --git a/app/vmctl/vm/vm.go b/app/vmctl/vm/vm.go index 487414d3c..a35afdb14 100644 --- a/app/vmctl/vm/vm.go +++ b/app/vmctl/vm/vm.go @@ -284,7 +284,7 @@ func (im *Importer) flush(ctx context.Context, b []*TimeSeries) error { // Ping sends a ping to im.addr. func (im *Importer) Ping() error { url := fmt.Sprintf("%s/health", im.addr) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return fmt.Errorf("cannot create request to %q: %s", im.addr, err) } @@ -308,7 +308,7 @@ func (im *Importer) Import(tsBatch []*TimeSeries) error { } pr, pw := io.Pipe() - req, err := http.NewRequest("POST", im.importPath, pr) + req, err := http.NewRequest(http.MethodPost, im.importPath, pr) if err != nil { return fmt.Errorf("cannot create request to %q: %s", im.addr, err) } diff --git a/app/vmselect/prometheus/prometheus_test.go b/app/vmselect/prometheus/prometheus_test.go index b740ae652..607705447 100644 --- a/app/vmselect/prometheus/prometheus_test.go +++ b/app/vmselect/prometheus/prometheus_test.go @@ -200,7 +200,7 @@ func TestAdjustLastPoints(t *testing.T) { func TestGetLatencyOffsetMillisecondsSuccess(t *testing.T) { f := func(url string, expectedOffset int64) { t.Helper() - r, err := http.NewRequest("GET", url, nil) + r, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { t.Fatalf("unexpected error in NewRequest(%q): %s", url, err) } @@ -219,7 +219,7 @@ func TestGetLatencyOffsetMillisecondsSuccess(t *testing.T) { func TestGetLatencyOffsetMillisecondsFailure(t *testing.T) { f := func(url string) { t.Helper() - r, err := http.NewRequest("GET", url, nil) + r, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { t.Fatalf("unexpected error in NewRequest(%q): %s", url, err) } diff --git a/app/vmselect/searchutils/searchutils_test.go b/app/vmselect/searchutils/searchutils_test.go index 8090da898..73544392f 100644 --- a/app/vmselect/searchutils/searchutils_test.go +++ b/app/vmselect/searchutils/searchutils_test.go @@ -15,7 +15,7 @@ func TestGetDurationSuccess(t *testing.T) { f := func(s string, dExpected int64) { t.Helper() urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s)) - r, err := http.NewRequest("GET", urlStr, nil) + r, err := http.NewRequest(http.MethodGet, urlStr, nil) if err != nil { t.Fatalf("unexpected error in NewRequest: %s", err) } @@ -54,7 +54,7 @@ func TestGetDurationError(t *testing.T) { f := func(s string) { t.Helper() urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s)) - r, err := http.NewRequest("GET", urlStr, nil) + r, err := http.NewRequest(http.MethodGet, urlStr, nil) if err != nil { t.Fatalf("unexpected error in NewRequest: %s", err) } @@ -78,7 +78,7 @@ func TestGetTimeSuccess(t *testing.T) { f := func(s string, timestampExpected int64) { t.Helper() urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s)) - r, err := http.NewRequest("GET", urlStr, nil) + r, err := http.NewRequest(http.MethodGet, urlStr, nil) if err != nil { t.Fatalf("unexpected error in NewRequest: %s", err) } @@ -127,7 +127,7 @@ func TestGetTimeError(t *testing.T) { f := func(s string) { t.Helper() urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s)) - r, err := http.NewRequest("GET", urlStr, nil) + r, err := http.NewRequest(http.MethodGet, urlStr, nil) if err != nil { t.Fatalf("unexpected error in NewRequest: %s", err) } diff --git a/lib/awsapi/config.go b/lib/awsapi/config.go index 4dc93327f..4f3d53514 100644 --- a/lib/awsapi/config.go +++ b/lib/awsapi/config.go @@ -301,7 +301,7 @@ func getMetadataByPath(client *http.Client, apiPath string) ([]byte, error) { // Obtain session token sessionTokenURL := "http://169.254.169.254/latest/api/token" - req, err := http.NewRequest("PUT", sessionTokenURL, nil) + req, err := http.NewRequest(http.MethodPut, sessionTokenURL, nil) if err != nil { return nil, fmt.Errorf("cannot create request for IMDSv2 session token at url %q: %w", sessionTokenURL, err) } @@ -317,7 +317,7 @@ func getMetadataByPath(client *http.Client, apiPath string) ([]byte, error) { // Use session token in the request. apiURL := "http://169.254.169.254/latest/" + apiPath - req, err = http.NewRequest("GET", apiURL, nil) + req, err = http.NewRequest(http.MethodGet, apiURL, nil) if err != nil { return nil, fmt.Errorf("cannot create request to %q: %w", apiURL, err) } @@ -336,7 +336,7 @@ func getMetadataByPath(client *http.Client, apiPath string) ([]byte, error) { func (cfg *Config) getRoleWebIdentityCredentials(token string) (*credentials, error) { data, err := cfg.getSTSAPIResponse("AssumeRoleWithWebIdentity", func(apiURL string) (*http.Request, error) { apiURL += fmt.Sprintf("&WebIdentityToken=%s", url.QueryEscape(token)) - return http.NewRequest("GET", apiURL, nil) + return http.NewRequest(http.MethodGet, apiURL, nil) }) if err != nil { return nil, err diff --git a/lib/awsapi/sign.go b/lib/awsapi/sign.go index 88d182374..dba942c5d 100644 --- a/lib/awsapi/sign.go +++ b/lib/awsapi/sign.go @@ -23,7 +23,7 @@ func newSignedGetRequest(apiURL, service, region string, creds *credentials) (*h } func newSignedGetRequestWithTime(apiURL, service, region string, creds *credentials, t time.Time) (*http.Request, error) { - req, err := http.NewRequest("GET", apiURL, nil) + req, err := http.NewRequest(http.MethodGet, apiURL, nil) if err != nil { return nil, fmt.Errorf("cannot create http request with given apiURL: %s, err: %w", apiURL, err) } diff --git a/lib/promauth/config_test.go b/lib/promauth/config_test.go index def949f9a..6bf0f9c4b 100644 --- a/lib/promauth/config_test.go +++ b/lib/promauth/config_test.go @@ -115,7 +115,7 @@ func TestNewConfig(t *testing.T) { return } if got != nil { - req, err := http.NewRequest("GET", "http://foo", nil) + req, err := http.NewRequest(http.MethodGet, "http://foo", nil) if err != nil { t.Fatalf("unexpected error in http.NewRequest: %s", err) } @@ -183,7 +183,7 @@ func TestConfigHeaders(t *testing.T) { if err != nil { t.Fatalf("cannot create config: %s", err) } - req, err := http.NewRequest("GET", "http://foo", nil) + req, err := http.NewRequest(http.MethodGet, "http://foo", nil) if err != nil { t.Fatalf("unexpected error in http.NewRequest: %s", err) } diff --git a/lib/promscrape/discovery/gce/api.go b/lib/promscrape/discovery/gce/api.go index fc6c51438..8fb9d76ec 100644 --- a/lib/promscrape/discovery/gce/api.go +++ b/lib/promscrape/discovery/gce/api.go @@ -144,7 +144,7 @@ func getCurrentProject() (string, error) { func getGCEMetadata(path string) ([]byte, error) { // See https://cloud.google.com/compute/docs/storing-retrieving-metadata#default metadataURL := "http://metadata.google.internal/computeMetadata/v1/" + path - req, err := http.NewRequest("GET", metadataURL, nil) + req, err := http.NewRequest(http.MethodGet, metadataURL, nil) if err != nil { return nil, fmt.Errorf("cannot create http request for %q: %w", metadataURL, err) } diff --git a/lib/promscrape/discovery/kubernetes/api_watcher.go b/lib/promscrape/discovery/kubernetes/api_watcher.go index b50edcefa..7732847e5 100644 --- a/lib/promscrape/discovery/kubernetes/api_watcher.go +++ b/lib/promscrape/discovery/kubernetes/api_watcher.go @@ -411,7 +411,7 @@ func (gw *groupWatcher) doRequest(requestURL string) (*http.Response, error) { // Update discovery URL for old Kubernetes API, which supports only v1beta1 path. requestURL = strings.Replace(requestURL, "/apis/discovery.k8s.io/v1/", "/apis/discovery.k8s.io/v1beta1/", 1) } - req, err := http.NewRequest("GET", requestURL, nil) + req, err := http.NewRequest(http.MethodGet, requestURL, nil) if err != nil { logger.Fatalf("cannot create a request for %q: %s", requestURL, err) } diff --git a/lib/promscrape/discovery/openstack/api.go b/lib/promscrape/discovery/openstack/api.go index b97fffd94..c946a0803 100644 --- a/lib/promscrape/discovery/openstack/api.go +++ b/lib/promscrape/discovery/openstack/api.go @@ -190,7 +190,7 @@ func getAPIResponse(apiURL string, cfg *apiConfig) ([]byte, error) { if err != nil { return nil, err } - req, err := http.NewRequest("GET", apiURL, nil) + req, err := http.NewRequest(http.MethodGet, apiURL, nil) if err != nil { return nil, fmt.Errorf("cannot create new request for openstack api url %s: %w", apiURL, err) } diff --git a/lib/promscrape/discovery/yandexcloud/api.go b/lib/promscrape/discovery/yandexcloud/api.go index 77591621b..18a95a70a 100644 --- a/lib/promscrape/discovery/yandexcloud/api.go +++ b/lib/promscrape/discovery/yandexcloud/api.go @@ -221,7 +221,7 @@ func getAPIResponse(apiURL string, cfg *apiConfig) ([]byte, error) { if err != nil { return nil, err } - req, err := http.NewRequest("GET", apiURL, nil) + req, err := http.NewRequest(http.MethodGet, apiURL, nil) if err != nil { logger.Panicf("BUG: cannot create new request for yandex cloud api url %s: %s", apiURL, err) } diff --git a/lib/protoparser/common/extra_labels_test.go b/lib/protoparser/common/extra_labels_test.go index 960470b24..42b0af96f 100644 --- a/lib/protoparser/common/extra_labels_test.go +++ b/lib/protoparser/common/extra_labels_test.go @@ -14,7 +14,7 @@ func TestGetExtraLabelsSuccess(t *testing.T) { f := func(requestURI, expectedLabels string) { t.Helper() fullURL := "http://fobar" + requestURI - req, err := http.NewRequest("GET", fullURL, nil) + req, err := http.NewRequest(http.MethodGet, fullURL, nil) if err != nil { t.Fatalf("cannot parse %q: %s", fullURL, err) }