Skip to content
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 default timeouts to metricbeat HTTP helpers #11032

Merged
merged 5 commits into from
Mar 19, 2019

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Mar 1, 2019

Set a default request timeout of 10 seconds to metricbeat HTTP helpers
so there are less chances of leaking established connections as reported
in #11014.

Add a connection timeout that defaults to two seconds so connections
fail faster in case of network connectivity problems.

@jsoriano jsoriano added module review Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Mar 1, 2019
@jsoriano jsoriano self-assigned this Mar 1, 2019
@jsoriano jsoriano requested a review from a team as a code owner March 1, 2019 19:15
@jsoriano jsoriano added needs_backport PR is waiting to be backported to other branches. v7.0.0 breaking change labels Mar 1, 2019
Set a default request timeout of 10 seconds to metricbeat HTTP helpers
so there are less chances of leaking established connections.

Add a connection timeout that defaults to two seconds so connections
fail fast in case of network connectivity problems.
@jsoriano jsoriano requested a review from a team March 1, 2019 19:18
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jsoriano
Copy link
Member Author

jsoriano commented Mar 4, 2019

@ruflin what do you think about this change?

@mirkochip
Copy link
Contributor

LGTM as well. That's actually a good one, especially because of this: https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779

Many thanks for this change.

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM but left 2 minor comments.

metricbeat/helper/http.go Show resolved Hide resolved
Timeout time.Duration `config:"timeout"`
Headers map[string]string `config:"headers"`
BearerTokenFile string `config:"bearer_token_file"`
}{}
}{
ConnectTimeout: 2 * time.Second,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone sets ConnectionTimeout > Timeout or Timeout > Period? Should we allow that or is it an invalid config?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone sets ConnectionTimeout > Timeout or Timeout > Period? Should we allow that or is it an invalid config?

At the moment somehow we are allowing Timeout > Period when no timeout is set (what would be like an infinite timeout). We could add some sanity checks for that and print at least a warning.

ConnectionTimeout > Timeout is allowed, but in that case the connection timeout won't ever happen. Not sure if we should do anything in that case, as much to print some info message to inform the user that the connection timeout will be ignored.

There's also this: https://golang.org/pkg/net/http/#Transport.MaxConnsPerHost

@roncohen good one. How do you think we can use it here? I think we could set it to a high but sane value (like 20, or 100), but I wonder if it would make sense to expose it in the config.

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

metricbeat/helper/http.go Show resolved Hide resolved
metricbeat/helper/http.go Outdated Show resolved Hide resolved
@ruflin
Copy link
Member

ruflin commented Mar 19, 2019

@jsoriano I wonder if the http test failure is related in CI.

@jsoriano
Copy link
Member Author

@jsoriano I wonder if the http test failure is related in CI.

Failure seems related, it looks like the server cannot close if the request is still in progress, I am closing the channel now so the request finishes.

@jsoriano jsoriano merged commit 1cdc88b into elastic:master Mar 19, 2019
@jsoriano jsoriano deleted the metricbeat-http-timeout branch March 19, 2019 17:28
@jsoriano jsoriano removed the needs_backport PR is waiting to be backported to other branches. label Mar 19, 2019
jsoriano added a commit to jsoriano/beats that referenced this pull request Mar 19, 2019
Set a default request timeout of 10 seconds to metricbeat HTTP helpers
so there are less chances of leaking established connections.

Add a connection timeout that defaults to two seconds so connections
fail fast in case of network connectivity problems.

(cherry picked from commit 1cdc88b)
jsoriano added a commit to jsoriano/beats that referenced this pull request Mar 20, 2019
After the refactor done in elastic#11032, baseData was not being passed to the
HTTP helper, so authentication was not working.

Added a test to avoid regressions here.

Fix elastic#11351
jsoriano added a commit that referenced this pull request Mar 21, 2019
After the refactor done in #11032, baseData was not being passed to the
HTTP helper, so authentication was not working.

Added a test to avoid regressions here.

Fix #11351
jsoriano added a commit to jsoriano/beats that referenced this pull request Mar 21, 2019
After the refactor done in elastic#11032, baseData was not being passed to the
HTTP helper, so authentication was not working.

Added a test to avoid regressions here.

Fix elastic#11351
jsoriano added a commit that referenced this pull request Mar 27, 2019
…lpers (#11319)

Set a default request timeout of 10 seconds to metricbeat HTTP helpers
so there are less chances of leaking established connections.

Add a connection timeout that defaults to two seconds so connections
fail fast in case of network connectivity problems.

(cherry picked from commit 1cdc88b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants