fix: re-init azure monitor http client on context deadline error (#11030)
This commit is contained in:
parent
9c02a47e8f
commit
e28793cff1
|
|
@ -3,12 +3,14 @@ package azure_monitor
|
|||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -109,12 +111,7 @@ func (a *AzureMonitor) Connect() error {
|
|||
a.Timeout = config.Duration(defaultRequestTimeout)
|
||||
}
|
||||
|
||||
a.client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
Timeout: time.Duration(a.Timeout),
|
||||
}
|
||||
a.initHTTPClient()
|
||||
|
||||
var err error
|
||||
var region string
|
||||
|
|
@ -168,6 +165,15 @@ func (a *AzureMonitor) Connect() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *AzureMonitor) initHTTPClient() {
|
||||
a.client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
Timeout: time.Duration(a.Timeout),
|
||||
}
|
||||
}
|
||||
|
||||
// vmMetadata retrieves metadata about the current Azure VM
|
||||
func vmInstanceMetadata(c *http.Client) (region string, resourceID string, err error) {
|
||||
req, err := http.NewRequest("GET", vmInstanceMetadataURL, nil)
|
||||
|
|
@ -313,6 +319,10 @@ func (a *AzureMonitor) send(body []byte) error {
|
|||
|
||||
resp, err := a.client.Do(req)
|
||||
if err != nil {
|
||||
if err.(*url.Error).Unwrap() == context.DeadlineExceeded {
|
||||
a.initHTTPClient()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
|
|
|||
Loading…
Reference in New Issue