forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 21
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 pulse metadata flag in PLE user-agent #105
Merged
Merged
Changes from all commits
Commits
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
Add Pulse flag in PLE UserAgent
- Loading branch information
commit 863fd0df150422c628897f9229503170da249e72
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,24 @@ type Client struct { | |
tags map[string]*string | ||
logger *zap.Logger | ||
} | ||
type UserAgentOption func(*UserAgentFlag) | ||
|
||
type UserAgentFlag struct { | ||
isEnhancedContainerInsights bool | ||
isPulseApm bool | ||
} | ||
|
||
func WithEnabledContainerInsights(flag bool) UserAgentOption { | ||
return func(ua *UserAgentFlag) { | ||
ua.isEnhancedContainerInsights = flag | ||
} | ||
} | ||
|
||
func WithEnabledPulseApm(flag bool) UserAgentOption { | ||
return func(ua *UserAgentFlag) { | ||
ua.isPulseApm = flag | ||
} | ||
} | ||
|
||
// Create a log client based on the actual cloudwatch logs client. | ||
func newCloudWatchLogClient(svc cloudwatchlogsiface.CloudWatchLogsAPI, logRetention int64, tags map[string]*string, logger *zap.Logger) *Client { | ||
|
@@ -50,12 +68,21 @@ func newCloudWatchLogClient(svc cloudwatchlogsiface.CloudWatchLogsAPI, logRetent | |
} | ||
|
||
// NewClient create Client | ||
func NewClient(logger *zap.Logger, awsConfig *aws.Config, buildInfo component.BuildInfo, logGroupName string, logRetention int64, tags map[string]*string, sess *session.Session, enhancedContainerInsights bool) *Client { | ||
func NewClient(logger *zap.Logger, awsConfig *aws.Config, buildInfo component.BuildInfo, logGroupName string, logRetention int64, tags map[string]*string, sess *session.Session, opts ...UserAgentOption) *Client { | ||
client := cloudwatchlogs.New(sess, awsConfig) | ||
client.Handlers.Build.PushBackNamed(handler.NewRequestCompressionHandler([]string{"PutLogEvents"}, logger)) | ||
client.Handlers.Build.PushBackNamed(handler.RequestStructuredLogHandler) | ||
// temporarily disable the flag | ||
client.Handlers.Build.PushFrontNamed(newCollectorUserAgentHandler(buildInfo, logGroupName, enhancedContainerInsights)) | ||
|
||
// Loop through each option | ||
option := &UserAgentFlag{ | ||
isEnhancedContainerInsights: false, | ||
isPulseApm: false, | ||
} | ||
for _, opt := range opts { | ||
opt(option) | ||
} | ||
|
||
client.Handlers.Build.PushFrontNamed(newCollectorUserAgentHandler(buildInfo, logGroupName, option)) | ||
return newCloudWatchLogClient(client, logRetention, tags, logger) | ||
} | ||
|
||
|
@@ -190,13 +217,20 @@ func (client *Client) CreateStream(logGroup, streamName *string) (token string, | |
return "", nil | ||
} | ||
|
||
func newCollectorUserAgentHandler(buildInfo component.BuildInfo, logGroupName string, enhancedContainerInsights bool) request.NamedHandler { | ||
fn := request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version) | ||
if enhancedContainerInsights && enhancedContainerInsightsEKSPattern.MatchString(logGroupName) { | ||
fn = request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, "EnhancedEKSContainerInsights") | ||
} else if containerInsightsRegexPattern.MatchString(logGroupName) { | ||
fn = request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, "ContainerInsights") | ||
func newCollectorUserAgentHandler(buildInfo component.BuildInfo, logGroupName string, userAgentFlag *UserAgentFlag) request.NamedHandler { | ||
extraStr := "" | ||
|
||
switch { | ||
case userAgentFlag.isEnhancedContainerInsights && enhancedContainerInsightsEKSPattern.MatchString(logGroupName): | ||
extraStr = "EnhancedEKSContainerInsights" | ||
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. nit: these flag strings could be consts |
||
case containerInsightsRegexPattern.MatchString(logGroupName): | ||
extraStr = "ContainerInsights" | ||
case userAgentFlag.isPulseApm: | ||
extraStr = "Pulse" | ||
} | ||
|
||
fn := request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, extraStr) | ||
|
||
return request.NamedHandler{ | ||
Name: "otel.collector.UserAgentHandler", | ||
Fn: fn, | ||
|
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
Oops, something went wrong.
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.
Would be good to call all these vars and methods
awsApm
instead ofpulse
. Rest LGTM!This comment was marked as resolved.
Sorry, something went wrong.
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.
Oh interesting.. yeah that would need a bunch of changes on the agent side if thats the case. Please let us know once you hear back Min.