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 TLS support for metric beat http server #11482

Closed
wants to merge 3 commits into from
Closed

Add TLS support for metric beat http server #11482

wants to merge 3 commits into from

Conversation

leopucci
Copy link
Contributor

@leopucci leopucci commented Mar 26, 2019

No description provided.

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

@leopucci
Copy link
Contributor Author

This patch solves #11457

@leopucci leopucci marked this pull request as ready for review March 26, 2019 21:02
@leopucci leopucci requested a review from a team as a code owner March 26, 2019 21:02
@leopucci
Copy link
Contributor Author

How to use:
add ssl config on http.yml

- module: http
  metricsets:
    - server
  host: "localhost"
  port: "8080"
  enabled: true
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
  ssl.certificate: "/etc/pki/client/cert.pem"
  ssl.key: "/etc/pki/client/cert.key"
  paths:
    - path: "/foo"
      namespace: "foo"
  #    fields: # added to the the response in root. overwrites existing fields
  #      key: "value"

@leopucci
Copy link
Contributor Author

@andrewkroh can you help me understand what this means so I could solve it?

./helper/server/http/config.go
./helper/server/http/http.go
Code differs from goimports' style ^

@leopucci
Copy link
Contributor Author

@ruflin ruflin added module review Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Mar 27, 2019
@ruflin
Copy link
Member

ruflin commented Mar 27, 2019

@leopucci Run make fmt and it should solve your issue.

Any chance to get some tests added to this PR? It also needs a changelog entry.

@leopucci
Copy link
Contributor Author

@ruflin the CI build is failing... i don't know how to make fmt on the CI build.
I will add some tests and add the changelog :)

@ruflin
Copy link
Member

ruflin commented Mar 27, 2019

The CI build is failing because some linting rules are not passing. You need to run make fmt inside the Beats directory and then commit again.

@leopucci
Copy link
Contributor Author

Thanks!

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. Can you also add an entry to the CHANGELOG.next.asciidoc file under the "Added" section for Metricbeat.

metricbeat/helper/server/http/http.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http.go Outdated Show resolved Hide resolved
@leopucci
Copy link
Contributor Author

Thanks @andrewkroh for reviewing. Will change right away

metricbeat/helper/server/http/http.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http.go Outdated Show resolved Hide resolved
@leopucci
Copy link
Contributor Author

@andrewkroh Thanks for the revisions :)

@ruflin
Copy link
Member

ruflin commented Mar 29, 2019

Thanks for all the work @leopucci I think this will also need an update in the docs about the new options: https://github.com/elastic/beats/blob/master/metricbeat/module/http/server/_meta/docs.asciidoc To make CI happy, you must run make fmt update again.

@leopucci
Copy link
Contributor Author

@ruflin @andrewkroh Thanks for helping me to understand the whole process

@leopucci leopucci requested a review from a team as a code owner March 29, 2019 19:23
Copy link
Contributor

@odacremolbap odacremolbap left a comment

Choose a reason for hiding this comment

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

Hey @leopucci

awesome code here!
just a couple minor glitches at tests

Thanks a lot for the PR

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
@leopucci
Copy link
Contributor Author

Hola @odacremolbap !
I have changed the tests to TDT....
GO is a powerful language. I'm excited with it.
Thanks for taking some time to review my code :)

@odacremolbap
Copy link
Contributor

@leopucci Thanks a lot for going down this rabbit hole!

I think we are getting to a nice pattern here, let's improve it a bit more. Let me re-review.

@leopucci
Copy link
Contributor Author

:) I have made some more changes trying to understand why Travis ci is failing.. Locally the tests happen OK!

Copy link
Contributor

@odacremolbap odacremolbap left a comment

Choose a reason for hiding this comment

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

Looking very good, thanks for the effort, it is being worth it :-)

Check for requested changes and bring your own opinion on them

metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
metricbeat/helper/server/http/http_test.go Outdated Show resolved Hide resolved
@leopucci
Copy link
Contributor Author

@odacremolbap Thanks for your help! I've tested and committed the new code!

@odacremolbap
Copy link
Contributor

The reason tests are not succeeding is https://github.com/elastic/beats/blob/master/metricbeat/tests/system/test_http.py#L58

I'll have time in some hours to take a deeper look, but you can probably go ahead and modify that string to match the prefix for the HTTP and HTTPS server start log line

@leopucci
Copy link
Contributor Author

leopucci commented Apr 1, 2019

I will!

@leopucci
Copy link
Contributor Author

leopucci commented Apr 1, 2019

Done :)

@@ -130,6 +148,11 @@ func (h *HttpServer) handleFunc(writer http.ResponseWriter, req *http.Request) {

case "GET":
writer.WriteHeader(http.StatusOK)
writer.Write([]byte("HTTP Server accepts data via POST"))
if h.server.TLSConfig != nil && h.server.TLSConfig.Certificates != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if h.server.TLSConfig != nil && h.server.TLSConfig.Certificates != nil {
if h.server.TLSConfig != nil {

Copy link
Contributor Author

@leopucci leopucci Apr 1, 2019

Choose a reason for hiding this comment

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

This can't be done. I've tested and for some reason, HTTP server creates a TLSConfig after calling ListenAndServe(), so the HTTP server will print the wrong message if we remove that, and HTTP tests will fail.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, OK. Then I'm glad you tested it!

metricbeat/module/http/server/_meta/docs.asciidoc Outdated Show resolved Hide resolved
metricbeat/module/http/server/_meta/docs.asciidoc Outdated Show resolved Hide resolved
@leopucci
Copy link
Contributor Author

leopucci commented Apr 1, 2019

\o/!

@odacremolbap
Copy link
Contributor

@leopucci thanks again for this contribution, this is looking superb 🍕
please, squash & merge

@odacremolbap
Copy link
Contributor

... and rebase ... 😉

Update config.go
Update http.go
Update config.go
Adding ssl tests, adjusting review requests
@odacremolbap
Copy link
Contributor

@leopucci
I would say you can merge master at your branch, and keep your changes to solve the conflict.
https://github.com/elastic/beats/pull/11482/conflicts

Looks like it is only the coredns line conflicting there, so be sure to include that one at your branch and you should be good to go.

Ping me if I can help

@leopucci
Copy link
Contributor Author

leopucci commented Apr 1, 2019

@odacremolbap Strange... my file already includes coredns line. Don't know if it is the `` around it. The only mod on this file is the new SSL support
Screenshot_61

@odacremolbap
Copy link
Contributor

weird
maybe you can try to solve the conflict using GH UI, the Resolve conflicts button.

@leopucci
Copy link
Contributor Author

leopucci commented Apr 2, 2019

@odacremolbap Only those with write access to this repository can merge pull requests.
I think i will not be able to resolve the conflict. On the UI the buttons are not enabled

if err != nil && err != http.ErrServerClosed {
logp.Critical("Unable to start HTTP server due to error: %v", err)
if h.server.TLSConfig != nil {
logp.Info("Starting HTTPS server on %s", h.server.Addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it HTTP here?

Copy link
Contributor Author

@leopucci leopucci Apr 2, 2019

Choose a reason for hiding this comment

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

Hi Kaiyan, it is HTTPS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hummmm... there is this logp.Critical that is not adjusted.. thanks i will change it now

@leopucci
Copy link
Contributor Author

leopucci commented Apr 2, 2019

@andrewkroh @odacremolbap today was git branches learning day... recreated all pull requests...
#11611
Sorry for the mess!

@odacremolbap
Copy link
Contributor

you are super welcomed, @leopucci
glad to see you try this hard

@leopucci
Copy link
Contributor Author

leopucci commented Apr 2, 2019

=)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metricbeat Metricbeat module review Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants