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

Fix metricbeat http module not parsing headers correctly #8564 #8585

Merged
merged 3 commits into from
Oct 23, 2018

Conversation

sayden
Copy link
Contributor

@sayden sayden commented Oct 5, 2018

Refer to #8564 for more info

@sayden sayden added bug module Metricbeat Metricbeat needs_backport PR is waiting to be backported to other branches. labels Oct 5, 2018
Copy link
Contributor

@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.

Could you add a changelog entry? Seems like there is no system test generating that with headers and is the reason CI didn't detect it. Should we add one?

@@ -14,7 +14,7 @@
description: >
HTTP request information
fields:
- name: header
- name: headers
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
Contributor Author

@sayden sayden Oct 5, 2018

Choose a reason for hiding this comment

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

Do you mean that it can produce a conflict? Means, I think I'm lacking context to understand your comment 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant it positive that it will not cause a conflict which is good.

@sayden
Copy link
Contributor Author

sayden commented Oct 17, 2018

@ruflin I think I need your review here. Also @jsoriano if you don't mind to take a look

@@ -58,6 +58,8 @@ def start(self):
stderr=subprocess.STDOUT,
bufsize=0,
)
# If a "No such file or directory" error points you here, run
Copy link
Contributor

Choose a reason for hiding this comment

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

Good note, it's an error message I wanted to improve for some time.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed these are good comments 🙂

What about handling these exceptions to print these messages so nobody has to look for these comments here? (It can be done in a future PR in any case)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once it's merge, I'll open a new PR to address this errors and print them. It wasn't the good moment then and I'd like to understand better why the error happens instead of assuming some behavior and print some message that could be wrong and misleads the devs.

@@ -33,12 +41,15 @@ def test_json(self):
self.assertEqual(len(output), 1)
evt = output[0]

print(json.dumps(evt))
Copy link
Contributor

Choose a reason for hiding this comment

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

left over?

assert evt["http"]["test"]["hello"] == "world"

# Delete dynamic namespace part for fields comparison
del evt["http"]["test"]

self.assertItemsEqual(self.de_dot(HTTP_FIELDS), evt.keys(), evt)
print(json.dumps(evt))
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover? Did you plan to add here something around the new header you specified above?

@sayden sayden added the review label Oct 17, 2018
@ruflin
Copy link
Contributor

ruflin commented Oct 18, 2018

Can you rebase and take a look at my comments?

@sayden sayden force-pushed the metricbeat-http-headers-bugfix branch from 26c0a57 to 0fd2644 Compare October 18, 2018 09:30
@sayden
Copy link
Contributor Author

sayden commented Oct 18, 2018

Rebase done and comments addressed. I was trying hard to improve the tests on this module but I was hitting the wall with some unknown errors. I'll do it in a different PR

Copy link
Contributor

@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.

Changes LGTM. Needs rebase on top of master to pass ingest phase.

@sayden sayden force-pushed the metricbeat-http-headers-bugfix branch from 0fd2644 to 061c096 Compare October 18, 2018 16:55
@sayden
Copy link
Contributor Author

sayden commented Oct 18, 2018

😕 rebase done but both tests complain about autopep8

@ruflin
Copy link
Contributor

ruflin commented Oct 18, 2018

I assume if both complain, there is something off with the formatting. Try to run make fmt locally to see if you get a diff.

@sayden
Copy link
Contributor Author

sayden commented Oct 18, 2018

make fmt complains too about format here
https://github.com/elastic/beats/blob/master/metricbeat/module/elasticsearch/elasticsearch_integration_test.go#L129

and here
https://github.com/elastic/beats/blob/master/metricbeat/module/envoyproxy/server/data.go#L67

Which can be considered actual formatting errors, yes, because they aren't properly aligned.

@sayden
Copy link
Contributor Author

sayden commented Oct 18, 2018

When changing to 1.10.3 it seems that the formatter doesn't complain about those two files (althought I still think they aren't properly formatted ¯_(ツ)_/¯ )

Buuuuut tests still complain about autopep8

@ruflin you told me that you saw some diffs on a Python file so maybe it is something related with the Python version (2.7.10) instead of with Go version?

➜  metricbeat git:(metricbeat-http-headers-bugfix) go version
go version go1.10.3 darwin/amd64

➜  metricbeat git:(metricbeat-http-headers-bugfix) make clean && make fmt
New python executable in /Users/privacy/go/src/github.com/elastic/beats/metricbeat/build/python-env/bin/python
Installing setuptools, pip, wheel...done.

➜  metricbeat git:(metricbeat-http-headers-bugfix) . build/python-env/bin/activate

(python-env) ➜  metricbeat git:(metricbeat-http-headers-bugfix) make fmt

(python-env) ➜  metricbeat git:(metricbeat-http-headers-bugfix) python --version
Python 2.7.10

@ruflin
Copy link
Contributor

ruflin commented Oct 19, 2018

I think the problem is that you are running make fmt instead the metricbeat directory but the diff is in libbeat. Best run make clean and make fmt in the beats directory so it is applied to all files.

My pyhton version is 2.7.15 but I don't think it makes a diff here because of the note above.

@sayden
Copy link
Contributor Author

sayden commented Oct 19, 2018

Running make clean && make fmt from the root and with Go 1.10.3 seems to finally format only the required file

@ruflin
Copy link
Contributor

ruflin commented Oct 19, 2018

jenkins, test this


func serveHeader(w http.ResponseWriter, r *http.Request) {
fmt.Println("Key: " + r.Header.Get("key"))
fmt.Fprintf(w, `{"key":"%s"}`, r.Header.Get("key"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This writes to the body of the http output instead of the headers I think?

@sayden sayden force-pushed the metricbeat-http-headers-bugfix branch from dd22a24 to 7001ba6 Compare October 22, 2018 09:44
@sayden sayden force-pushed the metricbeat-http-headers-bugfix branch from 7001ba6 to 6ea540a Compare October 22, 2018 09:45
@sayden
Copy link
Contributor Author

sayden commented Oct 22, 2018

@ruflin Changelog is added, although I'm not sure if there's some problem with Github yet because I have seen some conflict with CHANGELOG file which doesn't appear now.

@@ -88,6 +88,8 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff]
- Avoid mapping issues in kubernetes module. {pull}8487[8487]
- Fix issue that would prevent kafka module to find a proper broker when port is not set {pull}8613[8613]
- Fix range colors in multiple visualizations. {issue}8633[8633] {pull}8634[8634]
- Add Kafka dashboard. {pull}8457[8457]
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be here.

@sayden sayden force-pushed the metricbeat-http-headers-bugfix branch from b9d567b to beda237 Compare October 23, 2018 08:32
@sayden sayden merged commit ace94f0 into elastic:master Oct 23, 2018
@sayden sayden added v6.5.0 and removed needs_backport PR is waiting to be backported to other branches. labels Oct 23, 2018
@sayden sayden deleted the metricbeat-http-headers-bugfix branch August 25, 2022 12:51
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.

3 participants