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

Custom HTTP headers for the Elasticsearch output #3400

Merged
merged 1 commit into from
Jan 25, 2017

Conversation

tsg
Copy link
Contributor

@tsg tsg commented Jan 18, 2017

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 #1768.

@tsg
Copy link
Contributor Author

tsg commented Jan 18, 2017

@hub-cap @alexbrasetvik @joegallo Can you have a quick look at this one to see if it seems to do what you need/expect?

@joegallo
Copy link

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.

@urso
Copy link

urso commented Jan 18, 2017

@tsg seems this PR contains some more changes then just HTTP headers.

Have you considered this solution?

output.elasticsearch.headers:
- X-My-Header: Contents of the header

@joegallo
Copy link

I like @urso's suggestion -- there's some alignment with how fields are defined, then.

@tsg
Copy link
Contributor Author

tsg commented Jan 18, 2017

@joegallo @urso that's an array of dictionaries, right? So not like the fields :)

For @urso's version, I worry that people are going to mess up the syntax. I considered making it simply a dictionary, but it gets more complex when you want to provide the same header twice.

@tsg
Copy link
Contributor Author

tsg commented Jan 18, 2017

seems this PR contains some more changes then just HTTP headers.

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?

@joegallo
Copy link

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:

fields:
  my_field_1: "some value"
  my_field_2: "some other value"

output.elasticsearch.headers:
  X-My-Header: "blah"
  X-Something: "blah blah"

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.

@ruflin
Copy link
Member

ruflin commented Jan 19, 2017

An alternative option here would be:

output.elasticsearch.headers:
- `X-My-Header: Contents of the header`

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.

@tsg
Copy link
Contributor Author

tsg commented Jan 19, 2017

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

@urso
Copy link

urso commented Jan 19, 2017

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

@tsg
Copy link
Contributor Author

tsg commented Jan 22, 2017

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?

@alexbrasetvik
Copy link

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. :)

@tsg tsg force-pushed the elasticsearch_headers branch 3 times, most recently from 4e07830 to ddabd5b Compare January 23, 2017 20:52
@tsg
Copy link
Contributor Author

tsg commented Jan 23, 2017

We discussed it again and decided to go for the simplest version for the user:

output.elasticsearch.headers:
  X-My-Header: Contents of the header

and from the CLI:

metricbeat -E "output.elasticsearch.headers.X-test=Test value"

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

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.

Copy link
Contributor Author

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

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.
@urso
Copy link

urso commented Jan 24, 2017

checking HTTP module, using commas should work according to RFC. Headers are represented as map[string][]string. Every array entry is a new line, but there doesn't seem to be any kind of escaping on commas: https://github.com/golang/go/blob/master/src/net/http/header.go#L147

@monicasarbu monicasarbu merged commit b04384a into elastic:master Jan 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants