[Heartbeat] Set HTTP user-agent in Heartbeat#14297
Conversation
|
Pinging @elastic/uptime (:uptime) |
By default heartbeat uses the golang user agent, which is blacklisted by a number of services, including elastic.co. URLs like https://www.elastic.co/products/beats/heartbeat do not work with the default go user agent due to such blacklists. This changes the default user agent to be 'elastic_heartbeat'. While the HTTP spec allows UAs to add version numbers to the end this PR does not add the version number for two reasons: 1. Adding the version wouldn't practically be of use to anyone as one UA version numbers for an uptime check aren't practically useful. 2. It would needlessly add complexity to this commit. Resolves elastic#10170 (comment)
|
We set the User-Agent in Filebeat for the client that connects to Google Pub/Sub and in the client that connects to MISP. It would be good to align all of these to use the same exact format. I recommend creating a util in libbeat to get the User-Agent string and make each of these use that. beats/x-pack/filebeat/input/googlepubsub/input.go Lines 180 to 184 in 6b6408f |
|
Love the util idea! I'm glad to do that in this PR.
…On Mon, Oct 28, 2019, 7:59 PM Andrew Kroh ***@***.***> wrote:
We set the User-Agent in Filebeat for the client that connects to Google
Pub/Sub and in the client that connects to MISP. It would be good to align
all of these to use the same exact format.
I recommend create a util in libbeat to get the User-Agent string and make
each of these use that.
https://github.com/elastic/beats/blob/6b6408f843f61e6169e1a7d9eec2acb9c92cd95c/x-pack/filebeat/input/googlepubsub/input.go#L180-L184
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#14297?email_source=notifications&email_token=AABACY6E76FCIA3QKB7GG5TQQ6DHXA5CNFSM4JGB4JW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECO4EXQ#issuecomment-547209822>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABACYYKXY4GXK2AE3KNDB3QQ6DHXANCNFSM4JGB4JWQ>
.
|
|
@ruflin I'll do the util thing in this PR. ++ on adding docs. |
|
@ruflin @andrewkroh I've updated this PR to make a common helper function |
andrewkroh
left a comment
There was a problem hiding this comment.
LGTM. But there's one more to update at https://github.com/elastic/beats/blob/master/x-pack/filebeat/input/httpjson/input.go#L325.
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/elastic/beats/libbeat/common/useragent" |
There was a problem hiding this comment.
Move this down to the grouping of github.com/elastic imports.
| } | ||
|
|
||
| if enc != nil { | ||
| enc.AddHeaders(&request.Header) |
There was a problem hiding this comment.
concerning the implementation, you might want to take a look at https://github.com/elastic/beats/blob/fleet/agent/kibana/round_trippers.go#L33-L52 and use http.Roundtripper interface.
There was a problem hiding this comment.
What's the advantage of adding it there vs. here? Seems like they're fairly equivalent in this case.
There was a problem hiding this comment.
There are, but you make sure that all connection through the http client get the headers no matter what.
There was a problem hiding this comment.
But, you are right I am not familliar enough with hearthbeat client. so it might be equivalent in that case.
There was a problem hiding this comment.
I think in our case it's equivalent since this is the only entry point through to the client. I think I'll leave the code here so there's only one spot where header stuff happens, which at least to me, seems easier to maintain, but I agree with you, generally speaking if you share the HTTP client it should go in the round tripper.
|
@andrewkroh I've added it to the httpjson module as well. @ruflin I think this is ready for a final review. |
ruflin
left a comment
There was a problem hiding this comment.
PR LGTM. I still think we should have this in our docs somewhere.
|
@ruflin I just added the docs for this. If it's still good let me know with another LGTM. |
| *`method`*:: The HTTP method to use. Valid values are `"HEAD"`, `"GET"` and | ||
| `"POST"`. | ||
| *`headers`*:: A dictionary of additional HTTP headers to send. | ||
| *`headers`*:: A dictionary of additional HTTP headers to send. By default heartbeat |
There was a problem hiding this comment.
Nit: It would be nice to have a header example posted here. So if someone configures a tool where he needs to filter on the headers, he can just copy-paste it here (or at least have the pattern).
|
jenkins, test this |
ruflin
left a comment
There was a problem hiding this comment.
The code LGTM, but CI ...
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/elastic/beats/libbeat/common/useragent" |
|
Build failures unrelated |
By default heartbeat uses the golang user agent, which is blacklisted by a number of services, including elastic.co. URLs like https://www.elastic.co/products/beats/heartbeat do not work with the default go user agent due to such blacklists. This changes the default user agent to be 'Elastic Heartbeat/VERSION (PLATFORM INFO)' Resolves elastic#10170 (comment) (cherry picked from commit 956f87c)
|
This change is probably incorrect. A better User-Agent would be something like |
|
Thanks @OrangeDog , I've opened an issue to track this here #14747 |
By default heartbeat uses the golang user agent, which is blacklisted by a number of services, including elastic.co. URLs like https://www.elastic.co/products/beats/heartbeat do not work with the default go user agent due to such blacklists. This changes the default user agent to be 'Elastic Heartbeat/VERSION (PLATFORM INFO)' Resolves elastic#10170 (comment)
By default heartbeat uses the golang user agent, which is blacklisted by a number of services, including elastic.co. URLs like https://www.elastic.co/products/beats/heartbeat do not work with the
default go user agent due to such blacklists.
This changes the default user agent to be 'Elastic Heartbeat/VERSION (PLATFORM INFO)'
Resolves #10170 (comment)