-
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
Custom HTTP headers for the Elasticsearch output #3400
Conversation
791aadf
to
5b4e744
Compare
@hub-cap @alexbrasetvik @joegallo Can you have a quick look at this one to see if it seems to do what you need/expect? |
That seems workable to me. If you can get me a build I can even drop it into things on my end and try it out. |
@tsg seems this PR contains some more changes then just HTTP headers. Have you considered this solution?
|
I like @urso's suggestion -- there's some alignment with how |
That's because it needs a rebase on top of #3394. Have a look at the second commit only for this change. Or did you mean something else? |
I don't really know yaml that well, so I'm not sure what things are called, but what I was getting was that there's a little bit of symmetry between the configs if they were like this:
But yeah, I haven't thought about the implications for multiple values for the same header, and I don't really know the ins and outs of what the above would mean for yaml. I definitely wouldn't say my preference is at all strong, and I'm happy to defer to you. |
An alternative option here would be:
So the header would be string value. This would allow to set multiple headers with the same name. It is allowed under certain circumstances (https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2) but not sure if that is a real use case. Also it would help in case there are some special chars in the field name which are not compatible with yaml, but not sure if this can happen. Currently I like the one proposed by @tsg best because it is the most expressive and extensible one. |
@joegallo Yeah, the only issue with the your proposed version, which I agree is the cleanest, is the multiple values for the same header case. I know that's probably not even useful in practice, but it feels wrong not to support it. |
@tsg in heartbeat headers can already be configured using the dictionary approach: https://github.com/elastic/beats/blob/master/heartbeat/monitors/active/http/config.go#L42 Having a configurable HTTP client in multiple places in beats (elasticsearch output, heartbeat, metricbeat) we should consider refactoring the HTTP client abstracting in order to provide a common and consistent configuration experience. |
5b4e744
to
5b0f2d0
Compare
Rebased to master. @urso +1 on unifying the client handling, but my understanding is that the cloud team is waiting for this feature, so I wouldn't block it on that. If we plan to make it generic, it's even more important that we support the case of multiple headers with the same name, right? |
No strong opinions on duplicate headers here. We don't need it, I see mentions of contrived Set-Cookie and Accept examples on the interwebs for it. We'd like to not wait for a full rewrite of the http client handling, though. :) |
4e07830
to
ddabd5b
Compare
We discussed it again and decided to go for the simplest version for the user:
and from the CLI:
The reason is that if someone needs multiple values for a single header, they can separate them with commas, which per the RFC should have the same meaning for the server. The PR and description is updated to reflect the above. |
@@ -112,6 +112,10 @@ output.elasticsearch: | |||
# Optional HTTP Path | |||
#path: "/elasticsearch" | |||
|
|||
# Custom HTTP headers to add to each request | |||
#headers: | |||
# X-My-Header: Contents of the header |
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.
Maybe mention somewhere in the config file that you can pass multiple values separated by comma.
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.
I added a line in the configuration.
[source,yaml] | ||
------------------------------------------------------------------------------ | ||
output.elasticsearch.headers: | ||
X-My-Header: Contents of the header |
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.
s/Contents of the header/Header contents
Configuration looks like this: ``` output.elasticsearch.headers: X-My-Header: Contents of the header ``` To use from the CLI: ``` metricbeat -E "output.elasticsearch.headers.X-test=Test value" ``` It's not possible to set the same header name more than once with different values, but it is possible to separate header values with a comma, which has the same meaning as per the RFC. Closes elastic#1768.
ddabd5b
to
2073858
Compare
checking HTTP module, using commas should work according to RFC. Headers are represented as |
Configuration looks like this:
To use from the CLI:
It's not possible to set the same header name more than once with different values,
but it is possible to separate header values with a comma, which has the same meaning
as per the RFC.
Closes #1768.