From 69cdf5f16c8c4633e19a6fefa5003a7113868ed7 Mon Sep 17 00:00:00 2001 From: Wendel Hime <6754291+WendelHime@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:28:44 -0300 Subject: [PATCH] updating domain fronted roundtrip for receiving op name (#1433) * fix: updating domain fronted roundtrip for receiving op name * fix: sampling broflake fronted requests --- bypass/bypass.go | 2 +- chained/broflake_impl.go | 3 ++- embeddedconfig/global.yaml.tmpl | 1 + issue/issue.go | 2 +- proxied/fronted.go | 10 ++++++++-- proxied/proxied.go | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bypass/bypass.go b/bypass/bypass.go index f8cef13a3..6611bc34f 100644 --- a/bypass/bypass.go +++ b/bypass/bypass.go @@ -108,7 +108,7 @@ func (b *bypass) newProxy(name string, pc *commonconfig.ProxyConfig, configDir s name: name, done: make(chan bool), toggle: atomic.NewBool(mrand.Float32() < 0.5), - dfRoundTripper: proxied.Fronted(0), + dfRoundTripper: proxied.Fronted("bypass_fronted_roundtrip", 0), userConfig: userConfig, proxyRoundTripper: proxyRoundTripper(name, pc, configDir, userConfig, dialer), } diff --git a/chained/broflake_impl.go b/chained/broflake_impl.go index 4a3ddeafc..23ee2f879 100644 --- a/chained/broflake_impl.go +++ b/chained/broflake_impl.go @@ -140,7 +140,8 @@ func makeBroflakeOptions(pc *config.ProxyConfig) ( // Broflake's HTTP client isn't currently configurable via PluggableTransportSettings, and so // we just give it this domain fronted client in all cases wo.HttpClient = &http.Client{ - Transport: proxied.Fronted(masqueradeTimeout), + Transport: proxied.Fronted("broflake_fronted_roundtrip", masqueradeTimeout), + Timeout: 60 * time.Second, } // Override QUICLayerOptions defaults as applicable diff --git a/embeddedconfig/global.yaml.tmpl b/embeddedconfig/global.yaml.tmpl index baff2bc79..dd055a907 100644 --- a/embeddedconfig/global.yaml.tmpl +++ b/embeddedconfig/global.yaml.tmpl @@ -422,3 +422,4 @@ otel: autoupdate_download: 1 autoupdate_install: 1 check_update: 1 + broflake_fronted_roundtrip: 800000 diff --git a/issue/issue.go b/issue/issue.go index 7c918124a..3d737987f 100644 --- a/issue/issue.go +++ b/issue/issue.go @@ -22,7 +22,7 @@ var ( maxLogSize = 10247680 client = &http.Client{ - Transport: proxied.Fronted(0), + Transport: proxied.Fronted("issue_fronted_roundtrip", 0), } ) diff --git a/proxied/fronted.go b/proxied/fronted.go index 2f2c93b76..824f2f0c4 100644 --- a/proxied/fronted.go +++ b/proxied/fronted.go @@ -5,6 +5,7 @@ import ( "time" "github.com/getlantern/errors" + "github.com/getlantern/flashlight/v7/ops" "github.com/getlantern/fronted" ) @@ -14,15 +15,16 @@ const DefaultMasqueradeTimeout = 5 * time.Minute // fronting. // // Leave masqueradeTimeout as 0 to use a default value. -func Fronted(masqueradeTimeout time.Duration) http.RoundTripper { +func Fronted(opName string, masqueradeTimeout time.Duration) http.RoundTripper { if masqueradeTimeout == 0 { masqueradeTimeout = DefaultMasqueradeTimeout } - return frontedRoundTripper{masqueradeTimeout: masqueradeTimeout} + return frontedRoundTripper{masqueradeTimeout: masqueradeTimeout, opName: opName} } type frontedRoundTripper struct { masqueradeTimeout time.Duration + opName string } // Use a wrapper for fronted.NewDirect to avoid blocking @@ -31,6 +33,10 @@ type frontedRoundTripper struct { func (f frontedRoundTripper) RoundTrip( req *http.Request, ) (*http.Response, error) { + if f.opName != "" { + op := ops.Begin(f.opName) + defer op.End() + } rt, ok := fronted.NewFronted(f.masqueradeTimeout) if !ok { return nil, errors.New("Unable to obtain direct fronter") diff --git a/proxied/proxied.go b/proxied/proxied.go index e311c4c3b..ab4b2bf49 100644 --- a/proxied/proxied.go +++ b/proxied/proxied.go @@ -609,7 +609,7 @@ func ChainedThenDirectThenFrontedClient(timeout time.Duration, rootCA string) *h TLSHandshakeTimeout: 10 * time.Second, ResponseHeaderTimeout: 30 * time.Second, } - frt := Fronted(10 * time.Second) + frt := Fronted("", 10*time.Second) return &http.Client{ Timeout: timeout * 2, Transport: serialTransport{chained, drt, frt},