|
|
|
@ -667,25 +667,12 @@ func (p *Policy) Shutdown(ctx context.Context) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewLogtailTransport returns an HTTP Transport particularly suited to uploading
|
|
|
|
|
// logs to the given host name. This includes:
|
|
|
|
|
// - If DNS lookup fails, consult the bootstrap DNS list of Tailscale hostnames.
|
|
|
|
|
// DialContext is a net.Dialer.DialContext specialized for use by logtail.
|
|
|
|
|
// It does the following:
|
|
|
|
|
// - If DNS lookup fails, consults the bootstrap DNS list of Tailscale hostnames.
|
|
|
|
|
// - If TLS connection fails, try again using LetsEncrypt's built-in root certificate,
|
|
|
|
|
// for the benefit of older OS platforms which might not include it.
|
|
|
|
|
func NewLogtailTransport(host string) *http.Transport {
|
|
|
|
|
// Start with a copy of http.DefaultTransport and tweak it a bit.
|
|
|
|
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
|
|
|
|
|
|
|
|
|
tr.Proxy = tshttpproxy.ProxyFromEnvironment
|
|
|
|
|
tshttpproxy.SetTransportGetProxyConnectHeader(tr)
|
|
|
|
|
|
|
|
|
|
// We do our own zstd compression on uploads, and responses never contain any payload,
|
|
|
|
|
// so don't send "Accept-Encoding: gzip" to save a few bytes on the wire, since there
|
|
|
|
|
// will never be any body to decompress:
|
|
|
|
|
tr.DisableCompression = true
|
|
|
|
|
|
|
|
|
|
// Log whenever we dial:
|
|
|
|
|
tr.DialContext = func(ctx context.Context, netw, addr string) (net.Conn, error) {
|
|
|
|
|
func DialContext(ctx context.Context, netw, addr string) (net.Conn, error) {
|
|
|
|
|
nd := netns.FromDialer(log.Printf, &net.Dialer{
|
|
|
|
|
Timeout: 30 * time.Second,
|
|
|
|
|
KeepAlive: netknob.PlatformTCPKeepAlive(),
|
|
|
|
@ -729,7 +716,24 @@ func NewLogtailTransport(host string) *http.Transport {
|
|
|
|
|
log.Printf("logtail: bootstrap dial succeeded")
|
|
|
|
|
}
|
|
|
|
|
return c, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewLogtailTransport returns an HTTP Transport particularly suited to uploading
|
|
|
|
|
// logs to the given host name. See DialContext for details on how it works.
|
|
|
|
|
func NewLogtailTransport(host string) *http.Transport {
|
|
|
|
|
// Start with a copy of http.DefaultTransport and tweak it a bit.
|
|
|
|
|
tr := http.DefaultTransport.(*http.Transport).Clone()
|
|
|
|
|
|
|
|
|
|
tr.Proxy = tshttpproxy.ProxyFromEnvironment
|
|
|
|
|
tshttpproxy.SetTransportGetProxyConnectHeader(tr)
|
|
|
|
|
|
|
|
|
|
// We do our own zstd compression on uploads, and responses never contain any payload,
|
|
|
|
|
// so don't send "Accept-Encoding: gzip" to save a few bytes on the wire, since there
|
|
|
|
|
// will never be any body to decompress:
|
|
|
|
|
tr.DisableCompression = true
|
|
|
|
|
|
|
|
|
|
// Log whenever we dial:
|
|
|
|
|
tr.DialContext = DialContext
|
|
|
|
|
|
|
|
|
|
// We're contacting exactly 1 hostname, so the default's 100
|
|
|
|
|
// max idle conns is very high for our needs. Even 2 is
|
|
|
|
@ -762,7 +766,7 @@ func goVersion() string {
|
|
|
|
|
type noopPretendSuccessTransport struct{}
|
|
|
|
|
|
|
|
|
|
func (noopPretendSuccessTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
|
io.ReadAll(req.Body)
|
|
|
|
|
io.Copy(io.Discard, req.Body)
|
|
|
|
|
req.Body.Close()
|
|
|
|
|
return &http.Response{
|
|
|
|
|
StatusCode: 200,
|
|
|
|
|