-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(confighttp): add max_redirects configuration option #10877
base: main
Are you sure you want to change the base?
feat(confighttp): add max_redirects configuration option #10877
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10877 +/- ##
=======================================
Coverage 91.45% 91.45%
=======================================
Files 438 438
Lines 23827 23837 +10
=======================================
+ Hits 21791 21801 +10
Misses 1658 1658
Partials 378 378 ☔ View full report in Codecov by Sentry. |
Changes look great, if you would please reduce the diff to avoid having git history be impacted too much. |
163192c
to
26bd593
Compare
@atoulme The lint CI is failing after removing the auto formatting changes:
Should we fix them here? Or in a new PR? |
My bad, it was because of a removed space in the diffs. Moving the PR ready for review |
@atoulme Any update on this PR? Any additional feedback would be really appreciated. Thanks for taking a look. |
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.
LGTM, thanks for the edits
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.
Thanks @rogercoll, just one question
config/confighttp/confighttp.go
Outdated
func makeCheckRedirect(max *int) func(*http.Request, []*http.Request) error { | ||
if max == nil { | ||
return nil | ||
} else if *max == 0 { |
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.
Is this case needed here? if max is set to 0, will the check at line 266 return on the first call the same as is this block here?
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.
Great catch! Actually, this branch is not needed and resulted in the same output when max_redirects
was set to either 0 or 1. The max redirects function is always called when a redirect response is returned, meaning that at least one request has already been made. The variable via []*http.Request
on line 265 will always be > 0.
If max_redirects
is set to 0, the http client should not follow any redirect response (one request). If max_redirects
is 1, only one redirect response should be followed (2 total requests). max_redirects = total_requests - 1
Fixed in c98fe0a
Thanks!
@@ -105,6 +105,9 @@ type ClientConfig struct { | |||
HTTP2PingTimeout time.Duration `mapstructure:"http2_ping_timeout"` | |||
// Cookies configures the cookie management of the HTTP client. | |||
Cookies *CookiesConfig `mapstructure:"cookies"` | |||
|
|||
// Maximum number of redirections to follow, if not defined, the Client uses its default policy, which is to stop after 10 consecutive requests. | |||
MaxRedirects *int `mapstructure:"max_redirects"` |
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.
I think we can even keep it int
with 10
by default. That should be cleaner. The only problem is it'll be a significant breaking change (no redirects) for a component that doesn't use NewDefaultClientConfig
, but I don't think we have any of those in contrib. Maybe we can check... All components should use that anyway. WDYT?
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.
I am totally open to adding this, but I am concert about receivers initiating the config without using the default method (max_redirects will be set to 0). Also, the only difference is that maybe we should align with the Go library error message after 10 redirects:
func defaultCheckRedirect(req *Request, via []*Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
return nil
}
There is this ongoing effort to use the NewDefaultClientConfig
: open-telemetry/opentelemetry-collector-contrib#35457
Co-authored-by: Dmitrii Anoshin <[email protected]>
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Description
Link to tracking issue
#10870
Testing
Unit testing
Documentation
README.md