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

Allow hosts to be used to configure http monitors #13703

Merged
merged 4 commits into from
Sep 17, 2019

Conversation

vjsamuel
Copy link
Contributor

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.

@vjsamuel vjsamuel requested a review from a team as a code owner September 16, 2019 18:45
@elasticmachine
Copy link
Collaborator

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
@elasticmachine
Copy link
Collaborator

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?

@vjsamuel vjsamuel force-pushed the make_urls_hosts_http branch from 1b07533 to 55cee9c Compare September 16, 2019 18:47
@andrewvc
Copy link
Contributor

andrewvc commented Sep 16, 2019

I'm a +1 on this, but we'll need to patch heartbeat to support host-like syntax, where hostname:port would be treated as either http|https depending on whether ssl.enabled are present. The urls field requires the protocol.

It creates some additional questions. Do we now support paths in the hosts field? Is hosts: ["foo:123/my/path"] a valid path? Do hosts and urls share the same config?

I think the simplest answer to these questions is to change the behavior as follows:

  1. Use the same parsing logic for urls and hosts
  2. For HTTP hosts will first attempt to parse the input as an URL, if it passes it will use it. If it does not it will attempt to prefix the string with http:// or https:// based on whether ssl.enabled is present, then attempt to parse that as a URL.

Thoughts @vjsamuel ?

Copy link
Contributor

@andrewvc andrewvc left a 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 {
Copy link
Contributor

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 ++ {
Copy link
Contributor

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,
Copy link
Contributor

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.

@andrewvc andrewvc added Team:obs-ds-hosted-services Label for the Observability Hosted Services team enhancement Heartbeat labels Sep 16, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime

updateScheme := func(host string) string {
if c.TLS != nil && *c.TLS.Enabled == true {
return fmt.Sprint("https://", host)
} else {

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 {

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 {

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

@vjsamuel vjsamuel force-pushed the make_urls_hosts_http branch 2 times, most recently from 7650b72 to 3d4f2e4 Compare September 16, 2019 23:39
Copy link
Contributor

@andrewvc andrewvc left a 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!

heartbeat/tests/system/test_monitor.py Outdated Show resolved Hide resolved
@vjsamuel vjsamuel force-pushed the make_urls_hosts_http branch from 3d4f2e4 to 7d98946 Compare September 17, 2019 16:56
Copy link
Contributor

@andrewvc andrewvc left a comment

Choose a reason for hiding this comment

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

LGTM WFG

@vjsamuel vjsamuel force-pushed the make_urls_hosts_http branch from 7d98946 to 9309149 Compare September 17, 2019 17:04
@vjsamuel vjsamuel force-pushed the make_urls_hosts_http branch from 9309149 to 3cbef32 Compare September 17, 2019 17:29
@andrewvc andrewvc merged commit 717771f into elastic:master Sep 17, 2019
andrewvc pushed a commit to andrewvc/beats that referenced this pull request Sep 17, 2019
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)
@andrewvc andrewvc self-assigned this Sep 17, 2019
@vjsamuel vjsamuel deleted the make_urls_hosts_http branch September 17, 2019 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team v7.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants