Pass HTTP transport to the proxy

When we proxy requests we should use same transport as we use when collecting alerts & silences
This commit is contained in:
Łukasz Mierzwa
2018-01-23 21:37:56 -08:00
parent d5a7cb9ace
commit 49d1ed2e1e
3 changed files with 4 additions and 3 deletions

View File

@@ -40,7 +40,7 @@ type Alertmanager struct {
reader uri.Reader
// implements how we fetch requests from the Alertmanager, we don't set it
// by default so it's nil and http.DefaultTransport is used
httpTransport http.RoundTripper
HTTPTransport http.RoundTripper `json:"-"`
// lock protects data access while updating
lock sync.RWMutex
// fields for storing pulled data

View File

@@ -46,7 +46,7 @@ func NewAlertmanager(name, upstreamURI string, opts ...Option) (*Alertmanager, e
}
var err error
am.reader, err = uri.NewReader(am.URI, am.RequestTimeout, am.httpTransport)
am.reader, err = uri.NewReader(am.URI, am.RequestTimeout, am.HTTPTransport)
if err != nil {
return am, err
}
@@ -112,7 +112,7 @@ func WithRequestTimeout(timeout time.Duration) Option {
// a custom HTTP transport (http.RoundTripper implementation)
func WithHTTPTransport(httpTransport http.RoundTripper) Option {
return func(am *Alertmanager) error {
am.httpTransport = httpTransport
am.HTTPTransport = httpTransport
return nil
}
}

View File

@@ -37,6 +37,7 @@ func NewAlertmanagerProxy(alertmanager *alertmanager.Alertmanager) (*httputil.Re
req.Header.Del("Accept-Encoding")
log.Debugf("[%s] Proxy request for %s", alertmanager.Name, req.URL.Path)
},
Transport: alertmanager.HTTPTransport,
ModifyResponse: func(resp *http.Response) error {
// drop Content-Length header from upstream responses, gzip middleware
// will compress those and that could cause a mismatch