Skip to content

Commit

Permalink
updating domain fronted roundtrip for receiving op name (#1433)
Browse files Browse the repository at this point in the history
* fix: updating domain fronted roundtrip for receiving op name

* fix: sampling broflake fronted requests
  • Loading branch information
WendelHime authored Nov 5, 2024
1 parent 6a2712c commit 69cdf5f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bypass/bypass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
3 changes: 2 additions & 1 deletion chained/broflake_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions embeddedconfig/global.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,4 @@ otel:
autoupdate_download: 1
autoupdate_install: 1
check_update: 1
broflake_fronted_roundtrip: 800000
2 changes: 1 addition & 1 deletion issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
maxLogSize = 10247680

client = &http.Client{
Transport: proxied.Fronted(0),
Transport: proxied.Fronted("issue_fronted_roundtrip", 0),
}
)

Expand Down
10 changes: 8 additions & 2 deletions proxied/fronted.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/getlantern/errors"
"github.com/getlantern/flashlight/v7/ops"
"github.com/getlantern/fronted"
)

Expand All @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion proxied/proxied.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 69cdf5f

Please sign in to comment.