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

[Heartbeat] Fix missing url.* fields on TCP NXDOMAIN #10787

Merged
merged 1 commit into from
Mar 11, 2019

Conversation

andrewvc
Copy link
Contributor

TCP checks are not adding URL fields on NXDOMAIN endpoints. This fixes that issue.

It does so by ensuring that URL metadata is added before executing the check, and not during, as done previously.

A side effect of this is that we now perform DNS lookups once per {hostname,port} instead of once per {hostname}. This is worth the increased simplicity however, as the code would be quite convoluted otherwise, which would put us at risk for more bugs.

Related (but different) 6.x issue: #10777

@andrewvc andrewvc added bug review needs_backport PR is waiting to be backported to other branches. Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team labels Feb 16, 2019
@andrewvc andrewvc self-assigned this Feb 16, 2019
@andrewvc andrewvc requested a review from urso February 16, 2019 15:48
@andrewvc andrewvc requested a review from a team as a code owner February 16, 2019 15:48
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime

@@ -91,10 +91,6 @@ func setupServer(t *testing.T, serverCreator func(http.Handler) *httptest.Server
return server, port
}

func tcpMonitorChecks(host string, ip string, port uint16, status string) mapval.Validator {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This helper function had a number of unused arguments and was more confusing than helpful.

@andrewvc andrewvc requested review from ruflin and removed request for urso March 5, 2019 20:25
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, perhaps you can help me out in one comment below. This needs a changelog entry.

A more general comment. One thing I would like to see is tests that generate golden files which can be compared like I introduced here for Metricbeat: #10648 For me this would give me more confidence reviewing such PR's. We have the mapval tests which do a very similar thing but having the exact end json and seeing it's modified or not would be pretty useful. Also I would hope this would make it very easy to add new testing scenarios by specifying the endpoint it should ping and then generate the expected output. The data.json which would be generated could also be used in the documentation as examples.

heartbeat/monitors/active/dialchain/builder.go Outdated Show resolved Hide resolved
return err
}

eventext.MergeEventFields(event, common.MapStr{"url": wrappers.URLFields(u)})
Copy link
Member

Choose a reason for hiding this comment

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

Trying to find out where this is now ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's been moved here: https://github.com/elastic/beats/pull/10787/files/8d33ef28de0ef07f1e8d26318aba21f7c20bff89#diff-ff8455f217780e07b3802951d4451126R151

I'll open a future refactor after this is merged to move dialchain/builder.go into the tcp package. Everything in that file is actually only used by TCP, and it's confusing that there's TCP specific code that looks very generic in dialchain/builder.go.

@andrewvc
Copy link
Contributor Author

andrewvc commented Mar 6, 2019

@ruflin I don't think it needs a changelog because this bug was never released.

Golden files would not have caught this because it only applies to ICMP. Mapval tests would have caught it just as well, but the reason we don't have them is due to the difficulty of testing ICMP. Indeed there are mapval tests for HTTP and TCP that would have caught this bug there should it have existed.

Additionally, golden files don't work well for heartbeat because a lot of the data is timing data which is variable, so there's no golden number. Mapval works well for describing the shape of data.

Going forward it's clear that we need to find a way to run ICMP tests. Options there are:

  1. Enable CI tests to run as root inside a full VM
  2. Have a 'dummy' mode for testing where actual ICMP pings are not sent.

In general I favor the former as it means we'd be testing the real codepath.

@andrewvc
Copy link
Contributor Author

andrewvc commented Mar 6, 2019

@ruflin BTW, ready for a re-review, I think I've addressed all issues here.

TCP checks are not adding URL fields on NXDOMAIN endpoints. This fixes that issue.

It does so by ensuring that URL metadata is added before executing the check, and not during, as done previously.

A side effect of this is that we now perform DNS lookups once per `{hostname,port}` instead of once per `{hostname}`. This is worth the increased simplicity however, as the code would be quite convoluted otherwise, which would put us at risk for more bugs.

Related (but different) 6.x issue: elastic#10777

Fix import formatting
@andrewvc
Copy link
Contributor Author

Merging after resolving a conflict in some tests.

@andrewvc andrewvc merged commit 821baec into elastic:master Mar 11, 2019
andrewvc added a commit to andrewvc/beats that referenced this pull request Mar 11, 2019
TCP checks are not adding URL fields on NXDOMAIN endpoints. This fixes that issue.

It does so by ensuring that URL metadata is added before executing the check, and not during, as done previously.

A side effect of this is that we now perform DNS lookups once per `{hostname,port}` instead of once per `{hostname}`. This is worth the increased simplicity however, as the code would be quite convoluted otherwise, which would put us at risk for more bugs.

Related (but different) 6.x issue: elastic#10777

Fix import formatting

(cherry picked from commit 821baec)
@andrewvc andrewvc added v7.0.0 and removed needs_backport PR is waiting to be backported to other branches. labels Mar 11, 2019
andrewvc added a commit that referenced this pull request Mar 12, 2019
TCP checks are not adding URL fields on NXDOMAIN endpoints. This fixes that issue.

It does so by ensuring that URL metadata is added before executing the check, and not during, as done previously.

A side effect of this is that we now perform DNS lookups once per `{hostname,port}` instead of once per `{hostname}`. This is worth the increased simplicity however, as the code would be quite convoluted otherwise, which would put us at risk for more bugs.

Related (but different) 6.x issue: #10777

Fix import formatting

(cherry picked from commit 821baec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Heartbeat review Team:obs-ds-hosted-services Label for the Observability Hosted Services team v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants