-
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
Add a header round tripper option to httpcommon #27509
Merged
michel-laterman
merged 13 commits into
elastic:master
from
michel-laterman:http-useragent-headers
Sep 7, 2021
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5e6e358
Add a header round tripper option to httpcommon
michel-laterman 6d6d5a6
Fix useragent injection in heartbeat IPMonitor jobs
michel-laterman 8f61c1c
Add User-Agent header to kibana and eslegclient
michel-laterman 04762fd
Fix syntax errors
michel-laterman e5c7902
Get user agent from existing ingo
michel-laterman 27c93e4
change from settings.Name to b.Info.Name
michel-laterman 46ec023
Fix missing param
michel-laterman d6e9027
Rename export dashboard useragent value
michel-laterman 14e7358
Merge branch 'master' into http-useragent-headers
michel-laterman ab53cb4
Review feedback
michel-laterman 5bd4973
Merge remote-tracking branch 'origin/master' into http-useragent-headers
michel-laterman 5590c5c
Change beat.Info.Name to beat.Info.Beat
michel-laterman 4212819
Fix typo
michel-laterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -25,6 +25,8 @@ import ( | |||
"io/ioutil" | ||||
"net/http" | ||||
"net/url" | ||||
"os" | ||||
"strings" | ||||
"time" | ||||
|
||||
"go.elastic.co/apm/module/apmelasticsearch" | ||||
|
@@ -34,6 +36,7 @@ import ( | |||
"github.com/elastic/beats/v7/libbeat/common/transport/httpcommon" | ||||
"github.com/elastic/beats/v7/libbeat/common/transport/kerberos" | ||||
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon" | ||||
"github.com/elastic/beats/v7/libbeat/common/useragent" | ||||
"github.com/elastic/beats/v7/libbeat/logp" | ||||
"github.com/elastic/beats/v7/libbeat/testing" | ||||
) | ||||
|
@@ -110,6 +113,14 @@ func NewConnection(s ConnectionSettings) (*Connection, error) { | |||
} | ||||
} | ||||
|
||||
name, err := os.Executable() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps
|
||||
if err != nil { | ||||
name = "ESLegClient" | ||||
} else { | ||||
name = strings.Title(name) | ||||
} | ||||
userAgent := useragent.UserAgent(name) | ||||
|
||||
httpClient, err := s.Transport.Client( | ||||
httpcommon.WithLogger(logger), | ||||
httpcommon.WithIOStats(s.Observer), | ||||
|
@@ -119,6 +130,7 @@ func NewConnection(s ConnectionSettings) (*Connection, error) { | |||
// eg, like in https://github.com/elastic/apm-server/blob/7.7/elasticsearch/client.go | ||||
return apmelasticsearch.WrapRoundTripper(rt) | ||||
}), | ||||
httpcommon.WithHeaderRoundTripper(map[string]string{"User-Agent": userAgent}), | ||||
) | ||||
if err != nil { | ||||
return nil, err | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks for writing this excellent test!