-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Allow hosts
to be used to configure http monitors
#13703
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
1 similar comment
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
1b07533
to
55cee9c
Compare
I'm a +1 on this, but we'll need to patch heartbeat to support host-like syntax, where It creates some additional questions. Do we now support paths in the hosts field? Is I think the simplest answer to these questions is to change the behavior as follows:
Thoughts @vjsamuel ? |
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.
Looking pretty good! I think it needs just a few tweaks and a handful more tests however.
|
||
for i := 0; i < len(c.Hosts); i ++ { | ||
host := c.Hosts[i] | ||
if _, err := url.ParseRequestURI(host); err != nil { |
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 could use a comment like:
For consistency we allow users to enter both URLs and host:port pairs in the
hosts
field, since internally HTTP checks must operate on hosts. Rather than parsing these using separate parsers, we simply see if the host is a valid URL, and if not, see if it becomes valid if http(s) is added in front of it.
c.Hosts = append(c.Hosts, c.URLs...) | ||
} | ||
|
||
for i := 0; i < len(c.Hosts); i ++ { |
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.
We should break this out to a separate function, something like normalizeHostURL(str string)
and add unit tests for it.
@@ -55,7 +55,7 @@ func testRequest(t *testing.T, testURL string) *beat.Event { | |||
// an empty string no cert will be set. | |||
func testTLSRequest(t *testing.T, testURL string, extraConfig map[string]interface{}) *beat.Event { | |||
configSrc := map[string]interface{}{ | |||
"urls": testURL, | |||
"hosts": testURL, |
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.
We still need to test the behavior of the url
parameter, so we should add new test permutations here handling that.
Pinging @elastic/uptime |
updateScheme := func(host string) string { | ||
if c.TLS != nil && *c.TLS.Enabled == true { | ||
return fmt.Sprint("https://", host) | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block
updateScheme := func(host string) string { | ||
if c.TLS != nil && *c.TLS.Enabled == true { | ||
return fmt.Sprint("https://", host) | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block
updateScheme := func(host string) string { | ||
if c.TLS != nil && *c.TLS.Enabled == true { | ||
return fmt.Sprint("https://", host) | ||
} else { |
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.
if block ends with a return statement, so drop this else and outdent its block
7650b72
to
3d4f2e4
Compare
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.
Much improved! Just needs one final integration test as noted.
Great work here @vjsamuel , it's much appreciated!
3d4f2e4
to
7d98946
Compare
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 WFG
7d98946
to
9309149
Compare
9309149
to
3cbef32
Compare
Currently only the http monitor allows configuring endpoints to hit via urls. Everyone else relies on hosts similar to metricbeat. This PR ensures that we also allow configuration with hosts. Eventually, the urls field can be deprecated. (cherry picked from commit 717771f)
Currently only the http monitor allows configuring endpoints to hit via
urls
. Everyone else relies onhosts
similar to metricbeat. This PR ensures that we also allow configuration withhosts
. Eventually, theurls
field can be deprecated.