mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-05 22:32:20 +01:00
lib/promscrape/discoveryutils: cleanup after 5df9fddaf2
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3468
This commit is contained in:
parent
e8624fd781
commit
7792ba3272
@ -40,9 +40,6 @@ const (
|
|||||||
|
|
||||||
// DefaultClientReadTimeout is the maximum duration for waiting the response from GetAPI*
|
// DefaultClientReadTimeout is the maximum duration for waiting the response from GetAPI*
|
||||||
DefaultClientReadTimeout = time.Minute
|
DefaultClientReadTimeout = time.Minute
|
||||||
|
|
||||||
// DefaultClientWriteTimeout is the maximum duration for waiting the request to be sent to GetAPI* and GetBlockingAPI*
|
|
||||||
DefaultClientWriteTimeout = 10 * time.Second
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func concurrencyLimitChInit() {
|
func concurrencyLimitChInit() {
|
||||||
@ -73,9 +70,8 @@ type Client struct {
|
|||||||
|
|
||||||
// HTTPClient is a wrapper around http.Client with timeouts.
|
// HTTPClient is a wrapper around http.Client with timeouts.
|
||||||
type HTTPClient struct {
|
type HTTPClient struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
WriteTimeout time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultDialer = &net.Dialer{}
|
var defaultDialer = &net.Dialer{}
|
||||||
@ -147,14 +143,12 @@ func NewClient(apiServer string, ac *promauth.Config, proxyURL *proxy.URL, proxy
|
|||||||
|
|
||||||
c := &Client{
|
c := &Client{
|
||||||
client: &HTTPClient{
|
client: &HTTPClient{
|
||||||
client: client,
|
client: client,
|
||||||
ReadTimeout: DefaultClientReadTimeout,
|
ReadTimeout: DefaultClientReadTimeout,
|
||||||
WriteTimeout: DefaultClientWriteTimeout,
|
|
||||||
},
|
},
|
||||||
blockingClient: &HTTPClient{
|
blockingClient: &HTTPClient{
|
||||||
client: blockingClient,
|
client: blockingClient,
|
||||||
ReadTimeout: BlockingClientReadTimeout,
|
ReadTimeout: BlockingClientReadTimeout,
|
||||||
WriteTimeout: DefaultClientWriteTimeout,
|
|
||||||
},
|
},
|
||||||
apiServer: apiServer,
|
apiServer: apiServer,
|
||||||
setHTTPHeaders: setHTTPHeaders,
|
setHTTPHeaders: setHTTPHeaders,
|
||||||
@ -221,7 +215,7 @@ func (c *Client) getAPIResponseWithParamsAndClient(client *HTTPClient, path stri
|
|||||||
modifyRequest(req)
|
modifyRequest(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := doRequestWithPossibleRetry(client, req)
|
resp, err := doRequestWithPossibleRetry(client, req, deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot fetch %q: %w", requestURL, err)
|
return nil, fmt.Errorf("cannot fetch %q: %w", requestURL, err)
|
||||||
}
|
}
|
||||||
@ -252,13 +246,9 @@ func (c *Client) Stop() {
|
|||||||
c.clientCancel()
|
c.clientCancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRequestWithPossibleRetry(hc *HTTPClient, req *http.Request) (*http.Response, error) {
|
func doRequestWithPossibleRetry(hc *HTTPClient, req *http.Request, deadline time.Time) (*http.Response, error) {
|
||||||
sleepTime := time.Second
|
sleepTime := time.Second
|
||||||
discoveryRequests.Inc()
|
discoveryRequests.Inc()
|
||||||
deadline, ok := req.Context().Deadline()
|
|
||||||
if !ok {
|
|
||||||
deadline = time.Now().Add(hc.WriteTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
resp, err := hc.client.Do(req)
|
resp, err := hc.client.Do(req)
|
||||||
|
Loading…
Reference in New Issue
Block a user