-
Notifications
You must be signed in to change notification settings - Fork 5k
Introduce httpcommon package in libbeat (add support for Proxy) #25219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d955f54
9a5cf78
a768d97
3902e66
6d44309
dbb6088
ba2cbe7
48c4692
e87950d
a1c1ebd
d5af1e3
9eb720e
511a656
041e725
d5cec18
b3d9855
090e8ec
f7e5dfd
feecc41
f4aeca2
f445fe5
1893c01
3ec53dd
2344081
2cd6abc
1a9c368
197a5f7
87e45aa
7d194b7
796489b
7af762d
85e367f
c47a3df
43138fa
5d2be4c
1bb2121
7675353
1d4de2a
5417800
c62be8b
c8bae54
55550a3
feb2d56
4333fe7
f37c131
7e7bb06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ import ( | |
| "github.com/elastic/beats/v7/heartbeat/monitors/jobs" | ||
| "github.com/elastic/beats/v7/heartbeat/monitors/wrappers" | ||
| "github.com/elastic/beats/v7/libbeat/common" | ||
| "github.com/elastic/beats/v7/libbeat/common/transport" | ||
| "github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" | ||
| "github.com/elastic/beats/v7/libbeat/common/transport/tlscommon" | ||
| "github.com/elastic/beats/v7/libbeat/logp" | ||
| ) | ||
|
|
@@ -43,16 +43,11 @@ func create( | |
| name string, | ||
| cfg *common.Config, | ||
| ) (p plugin.Plugin, err error) { | ||
| config := defaultConfig | ||
| config := defaultConfig() | ||
| if err := cfg.Unpack(&config); err != nil { | ||
| return plugin.Plugin{}, err | ||
| } | ||
|
|
||
| tls, err := tlscommon.LoadTLSConfig(config.TLS) | ||
| if err != nil { | ||
| return plugin.Plugin{}, err | ||
| } | ||
|
|
||
| var body []byte | ||
| var enc contentEncoder | ||
|
|
||
|
|
@@ -84,8 +79,8 @@ func create( | |
| // In the event that a ProxyURL is present, or redirect support is enabled | ||
| // we execute DNS resolution requests inline with the request, not running them as a separate job, and not returning | ||
| // separate DNS rtt data. | ||
| if config.ProxyURL != "" || config.MaxRedirects > 0 { | ||
| transport, err := newRoundTripper(&config, tls) | ||
| if (config.Transport.Proxy.URL != nil && !config.Transport.Proxy.Disable) || config.MaxRedirects > 0 { | ||
| transport, err := newRoundTripper(&config) | ||
| if err != nil { | ||
| return plugin.Plugin{}, err | ||
| } | ||
|
|
@@ -94,6 +89,13 @@ func create( | |
| return newHTTPMonitorHostJob(urlStr, &config, transport, enc, body, validator) | ||
| } | ||
| } else { | ||
| // preload TLS configuration | ||
| tls, err := tlscommon.LoadTLSConfig(config.Transport.TLS) | ||
| if err != nil { | ||
| return plugin.Plugin{}, err | ||
| } | ||
| config.Transport.TLS = nil | ||
|
|
||
| makeJob = func(urlStr string) (jobs.Job, error) { | ||
| return newHTTPMonitorIPsJob(&config, urlStr, tls, enc, body, validator) | ||
| } | ||
|
|
@@ -119,27 +121,12 @@ func create( | |
| return plugin.Plugin{Jobs: js, Close: nil, Endpoints: len(config.Hosts)}, nil | ||
| } | ||
|
|
||
| func newRoundTripper(config *Config, tls *tlscommon.TLSConfig) (*http.Transport, error) { | ||
| var proxy func(*http.Request) (*url.URL, error) | ||
| if config.ProxyURL != "" { | ||
| url, err := url.Parse(config.ProxyURL) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| proxy = http.ProxyURL(url) | ||
| } | ||
|
|
||
| dialer := transport.NetDialer(config.Timeout) | ||
| tlsDialer, err := transport.TLSDialer(dialer, tls, config.Timeout) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &http.Transport{ | ||
| Proxy: proxy, | ||
| Dial: dialer.Dial, | ||
| DialTLS: tlsDialer.Dial, | ||
| TLSClientConfig: tls.ToConfig(), | ||
| DisableKeepAlives: true, | ||
| }, nil | ||
| func newRoundTripper(config *Config) (http.RoundTripper, error) { | ||
| return config.Transport.RoundTripper( | ||
| httpcommon.WithAPMHTTPInstrumentation(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to add a short bit to the heartbeat docs about the impact here? This sounds great!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update many docs due to the amount of inconsistencies between multiple http clients. The PR has a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @urso were you able to get docs updated for this? Thanks. |
||
| httpcommon.WithoutProxyEnvironmentVariables(), | ||
| httpcommon.WithKeepaliveSettings{ | ||
| Disable: true, | ||
| }, | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.