mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
chore: Use http constants to replace numbers (#3846)
Signed-off-by: xin.li <xin.li@daocloud.io>
This commit is contained in:
parent
aaef0bac00
commit
9dec3c8f80
16 changed files with 25 additions and 25 deletions
|
@ -309,7 +309,7 @@ func (c *client) sendBlockHTTP(block []byte) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
again:
|
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 {
|
if err != nil {
|
||||||
logger.Panicf("BUG: unexpected error from http.NewRequest(%q): %s", c.sanitizedURL, err)
|
logger.Panicf("BUG: unexpected error from http.NewRequest(%q): %s", c.sanitizedURL, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ func (s *VMStorage) do(ctx context.Context, req *http.Request) (*http.Response,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *VMStorage) newRequestPOST() (*http.Request, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (am *AlertManager) send(ctx context.Context, alerts []Alert) error {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
writeamRequest(b, alerts, am.argFunc, am.relabelConfigs)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (c *Client) flush(ctx context.Context, wr *prompbmarshal.WriteRequest) {
|
||||||
|
|
||||||
func (c *Client) send(ctx context.Context, data []byte) error {
|
func (c *Client) send(ctx context.Context, data []byte) error {
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
req, err := http.NewRequest("POST", c.addr, r)
|
req, err := http.NewRequest(http.MethodPost, c.addr, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new HTTP request: %w", err)
|
return fmt.Errorf("failed to create new HTTP request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ func (c *Client) do(req *http.Request) (*http.Response, error) {
|
||||||
// Ping checks the health of the read source
|
// Ping checks the health of the read source
|
||||||
func (c *Client) Ping() error {
|
func (c *Client) Ping() error {
|
||||||
url := c.addr + healthPath
|
url := c.addr + healthPath
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create request to %q: %s", url, err)
|
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 {
|
func (c *Client) fetch(ctx context.Context, data []byte, streamCb StreamCallback) error {
|
||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
url := c.addr + remoteReadPath
|
url := c.addr + remoteReadPath
|
||||||
req, err := http.NewRequest("POST", url, r)
|
req, err := http.NewRequest(http.MethodPost, url, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new HTTP request: %w", err)
|
return fmt.Errorf("failed to create new HTTP request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,7 @@ func (im *Importer) flush(ctx context.Context, b []*TimeSeries) error {
|
||||||
// Ping sends a ping to im.addr.
|
// Ping sends a ping to im.addr.
|
||||||
func (im *Importer) Ping() error {
|
func (im *Importer) Ping() error {
|
||||||
url := fmt.Sprintf("%s/health", im.addr)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create request to %q: %s", im.addr, err)
|
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()
|
pr, pw := io.Pipe()
|
||||||
req, err := http.NewRequest("POST", im.importPath, pr)
|
req, err := http.NewRequest(http.MethodPost, im.importPath, pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create request to %q: %s", im.addr, err)
|
return fmt.Errorf("cannot create request to %q: %s", im.addr, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ func TestAdjustLastPoints(t *testing.T) {
|
||||||
func TestGetLatencyOffsetMillisecondsSuccess(t *testing.T) {
|
func TestGetLatencyOffsetMillisecondsSuccess(t *testing.T) {
|
||||||
f := func(url string, expectedOffset int64) {
|
f := func(url string, expectedOffset int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
r, err := http.NewRequest("GET", url, nil)
|
r, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in NewRequest(%q): %s", url, err)
|
t.Fatalf("unexpected error in NewRequest(%q): %s", url, err)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ func TestGetLatencyOffsetMillisecondsSuccess(t *testing.T) {
|
||||||
func TestGetLatencyOffsetMillisecondsFailure(t *testing.T) {
|
func TestGetLatencyOffsetMillisecondsFailure(t *testing.T) {
|
||||||
f := func(url string) {
|
f := func(url string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
r, err := http.NewRequest("GET", url, nil)
|
r, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in NewRequest(%q): %s", url, err)
|
t.Fatalf("unexpected error in NewRequest(%q): %s", url, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestGetDurationSuccess(t *testing.T) {
|
||||||
f := func(s string, dExpected int64) {
|
f := func(s string, dExpected int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s))
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in NewRequest: %s", err)
|
t.Fatalf("unexpected error in NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func TestGetDurationError(t *testing.T) {
|
||||||
f := func(s string) {
|
f := func(s string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s))
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in NewRequest: %s", err)
|
t.Fatalf("unexpected error in NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ func TestGetTimeSuccess(t *testing.T) {
|
||||||
f := func(s string, timestampExpected int64) {
|
f := func(s string, timestampExpected int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s))
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in NewRequest: %s", err)
|
t.Fatalf("unexpected error in NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func TestGetTimeError(t *testing.T) {
|
||||||
f := func(s string) {
|
f := func(s string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
urlStr := fmt.Sprintf("http://foo.bar/baz?s=%s", url.QueryEscape(s))
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in NewRequest: %s", err)
|
t.Fatalf("unexpected error in NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,7 @@ func getMetadataByPath(client *http.Client, apiPath string) ([]byte, error) {
|
||||||
|
|
||||||
// Obtain session token
|
// Obtain session token
|
||||||
sessionTokenURL := "http://169.254.169.254/latest/api/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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create request for IMDSv2 session token at url %q: %w", sessionTokenURL, err)
|
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.
|
// Use session token in the request.
|
||||||
apiURL := "http://169.254.169.254/latest/" + apiPath
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create request to %q: %w", apiURL, err)
|
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) {
|
func (cfg *Config) getRoleWebIdentityCredentials(token string) (*credentials, error) {
|
||||||
data, err := cfg.getSTSAPIResponse("AssumeRoleWithWebIdentity", func(apiURL string) (*http.Request, error) {
|
data, err := cfg.getSTSAPIResponse("AssumeRoleWithWebIdentity", func(apiURL string) (*http.Request, error) {
|
||||||
apiURL += fmt.Sprintf("&WebIdentityToken=%s", url.QueryEscape(token))
|
apiURL += fmt.Sprintf("&WebIdentityToken=%s", url.QueryEscape(token))
|
||||||
return http.NewRequest("GET", apiURL, nil)
|
return http.NewRequest(http.MethodGet, apiURL, nil)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -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) {
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create http request with given apiURL: %s, err: %w", apiURL, err)
|
return nil, fmt.Errorf("cannot create http request with given apiURL: %s, err: %w", apiURL, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ func TestNewConfig(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if got != nil {
|
if got != nil {
|
||||||
req, err := http.NewRequest("GET", "http://foo", nil)
|
req, err := http.NewRequest(http.MethodGet, "http://foo", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in http.NewRequest: %s", err)
|
t.Fatalf("unexpected error in http.NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ func TestConfigHeaders(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot create config: %s", err)
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error in http.NewRequest: %s", err)
|
t.Fatalf("unexpected error in http.NewRequest: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ func getCurrentProject() (string, error) {
|
||||||
func getGCEMetadata(path string) ([]byte, error) {
|
func getGCEMetadata(path string) ([]byte, error) {
|
||||||
// See https://cloud.google.com/compute/docs/storing-retrieving-metadata#default
|
// See https://cloud.google.com/compute/docs/storing-retrieving-metadata#default
|
||||||
metadataURL := "http://metadata.google.internal/computeMetadata/v1/" + path
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create http request for %q: %w", metadataURL, err)
|
return nil, fmt.Errorf("cannot create http request for %q: %w", metadataURL, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// 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)
|
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 {
|
if err != nil {
|
||||||
logger.Fatalf("cannot create a request for %q: %s", requestURL, err)
|
logger.Fatalf("cannot create a request for %q: %s", requestURL, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ func getAPIResponse(apiURL string, cfg *apiConfig) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest("GET", apiURL, nil)
|
req, err := http.NewRequest(http.MethodGet, apiURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create new request for openstack api url %s: %w", apiURL, err)
|
return nil, fmt.Errorf("cannot create new request for openstack api url %s: %w", apiURL, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,7 +221,7 @@ func getAPIResponse(apiURL string, cfg *apiConfig) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest("GET", apiURL, nil)
|
req, err := http.NewRequest(http.MethodGet, apiURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Panicf("BUG: cannot create new request for yandex cloud api url %s: %s", apiURL, err)
|
logger.Panicf("BUG: cannot create new request for yandex cloud api url %s: %s", apiURL, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ func TestGetExtraLabelsSuccess(t *testing.T) {
|
||||||
f := func(requestURI, expectedLabels string) {
|
f := func(requestURI, expectedLabels string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
fullURL := "http://fobar" + requestURI
|
fullURL := "http://fobar" + requestURI
|
||||||
req, err := http.NewRequest("GET", fullURL, nil)
|
req, err := http.NewRequest(http.MethodGet, fullURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot parse %q: %s", fullURL, err)
|
t.Fatalf("cannot parse %q: %s", fullURL, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue