-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add more granular otel instrumentation #48
Merged
+82
−59
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
04ed44c
Add more granular otel instrumentation
myleshorton e10c7c8
Improved method name
myleshorton 05fc29c
Latest utls to get around dependabot security warning
myleshorton 4fd7b26
Fixed test
myleshorton 4862191
Another test fix
myleshorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,66 +257,78 @@ func (f *fronted) RoundTripHijack(req *http.Request) (*http.Response, net.Conn, | |
op.FailIf(err) | ||
return nil, nil, err | ||
} | ||
provider := f.providerFor(m) | ||
if provider == nil { | ||
log.Debugf("Skipping masquerade with disabled/unknown provider '%s'", m.getProviderID()) | ||
masqueradeGood(false) | ||
continue | ||
} | ||
frontedHost := provider.Lookup(originHost) | ||
if frontedHost == "" { | ||
// this error is not the masquerade's fault in particular | ||
// so it is returned as good. | ||
conn.Close() | ||
masqueradeGood(true) | ||
err := fmt.Errorf("no domain fronting mapping for '%s'. Please add it to provider_map.yaml or equivalent for %s", | ||
m.getProviderID(), originHost) | ||
op.FailIf(err) | ||
return nil, nil, err | ||
} | ||
log.Debugf("Translated origin %s -> %s for provider %s...", originHost, frontedHost, m.getProviderID()) | ||
|
||
reqi, err := cloneRequestWith(req, frontedHost, getBody()) | ||
if err != nil { | ||
return nil, nil, op.FailIf(log.Errorf("Failed to copy http request with origin translated to %v?: %v", frontedHost, err)) | ||
} | ||
|
||
// don't clobber/confuse Connection header on Upgrade requests. | ||
disableKeepAlives := true | ||
if strings.EqualFold(reqi.Header.Get("Connection"), "upgrade") { | ||
disableKeepAlives = false | ||
} | ||
|
||
tr := frontedHTTPTransport(conn, disableKeepAlives) | ||
resp, err := tr.RoundTrip(reqi) | ||
if err != nil { | ||
log.Debugf("Could not complete request: %v", err) | ||
masqueradeGood(false) | ||
continue | ||
} | ||
|
||
err = provider.ValidateResponse(resp) | ||
resp, conn, err := f.requestWithConn(req, conn, m, originHost, getBody, masqueradeGood) | ||
if err != nil { | ||
log.Debugf("Could not complete request: %v", err) | ||
resp.Body.Close() | ||
masqueradeGood(false) | ||
continue | ||
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 now continue on all validation errors |
||
} | ||
|
||
masqueradeGood(true) | ||
return resp, conn, nil | ||
} | ||
|
||
return nil, nil, op.FailIf(errors.New("could not complete request even with retries")) | ||
} | ||
|
||
func (f *fronted) requestWithConn(req *http.Request, conn net.Conn, m MasqueradeInterface, originHost string, getBody func() io.ReadCloser, masqueradeGood func(bool) bool) (*http.Response, net.Conn, error) { | ||
op := ops.Begin("request_with_conn") | ||
defer op.End() | ||
provider := f.providerFor(m) | ||
if provider == nil { | ||
log.Debugf("Skipping masquerade with disabled/unknown provider '%s'", m.getProviderID()) | ||
masqueradeGood(false) | ||
return nil, nil, op.FailIf(log.Errorf("Skipping masquerade with disabled/unknown provider '%s'", m.getProviderID())) | ||
} | ||
frontedHost := provider.Lookup(originHost) | ||
if frontedHost == "" { | ||
// this error is not the masquerade's fault in particular | ||
// so it is returned as good. | ||
conn.Close() | ||
masqueradeGood(true) | ||
err := fmt.Errorf("no domain fronting mapping for '%s'. Please add it to provider_map.yaml or equivalent for %s", | ||
m.getProviderID(), originHost) | ||
op.FailIf(err) | ||
return nil, nil, err | ||
} | ||
log.Debugf("Translated origin %s -> %s for provider %s...", originHost, frontedHost, m.getProviderID()) | ||
|
||
reqi, err := cloneRequestWith(req, frontedHost, getBody()) | ||
if err != nil { | ||
return nil, nil, op.FailIf(log.Errorf("Failed to copy http request with origin translated to %v?: %v", frontedHost, err)) | ||
} | ||
disableKeepAlives := true | ||
if strings.EqualFold(reqi.Header.Get("Connection"), "upgrade") { | ||
disableKeepAlives = false | ||
} | ||
|
||
tr := frontedHTTPTransport(conn, disableKeepAlives) | ||
resp, err := tr.RoundTrip(reqi) | ||
if err != nil { | ||
log.Debugf("Could not complete request: %v", err) | ||
masqueradeGood(false) | ||
return nil, nil, err | ||
} | ||
|
||
err = provider.ValidateResponse(resp) | ||
if err != nil { | ||
log.Debugf("Could not complete request: %v", err) | ||
resp.Body.Close() | ||
masqueradeGood(false) | ||
return nil, nil, err | ||
} | ||
|
||
masqueradeGood(true) | ||
return resp, conn, nil | ||
} | ||
|
||
// Dial dials out using all available masquerades until one succeeds. | ||
func (f *fronted) dialAll(ctx context.Context) (net.Conn, MasqueradeInterface, func(bool) bool, error) { | ||
conn, m, masqueradeGood, err := f.dialAllWith(ctx, f.masquerades) | ||
return conn, m, masqueradeGood, err | ||
} | ||
|
||
func (f *fronted) dialAllWith(ctx context.Context, masquerades sortedMasquerades) (net.Conn, MasqueradeInterface, func(bool) bool, error) { | ||
defer func(op ops.Op) { op.End() }(ops.Begin("dial_all_with")) | ||
// never take more than a minute trying to find a dialer | ||
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute) | ||
defer cancel() | ||
|
@@ -491,6 +503,8 @@ type directTransport struct { | |
} | ||
|
||
func (ddf *directTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) { | ||
defer func(op ops.Op) { op.End() }(ops.Begin("direct_transport_roundtrip")) | ||
|
||
// The connection is already encrypted by domain fronting. We need to rewrite URLs starting | ||
// with "https://" to "http://", lest we get an error for doubling up on TLS. | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually a bug where we'd return entirely instead of continuing to retry