forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 27
Adding AgentHealth Middleware to Exporters #266
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a96c0c
moving to start() for exporters to have handlers
Paramadon cb1f3df
all exporter tests are passing now need to test this on ec2
Paramadon 0cd05cb
fixing tests
Paramadon 15fda03
restoring files
Paramadon cbb2dee
adding fixed change
Paramadon 4bd7a1e
resolving some comments
Paramadon 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 hidden or 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 hidden or 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 hidden or 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,7 @@ type emfExporter struct { | |
pusherMap map[cwlogs.StreamKey]cwlogs.Pusher | ||
svcStructuredLog *cwlogs.Client | ||
config *Config | ||
set exporter.Settings | ||
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. can we name this |
||
|
||
metricTranslator metricTranslator | ||
|
||
|
@@ -57,42 +58,23 @@ func newEmfExporter(config *Config, set exporter.Settings) (*emfExporter, error) | |
|
||
config.logger = set.Logger | ||
|
||
// create AWS session | ||
awsConfig, session, err := awsutil.GetAWSConfigSession(set.Logger, &awsutil.Conn{}, &config.AWSSessionSettings) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// create CWLogs client with aws session config | ||
svcStructuredLog := cwlogs.NewClient(set.Logger, | ||
awsConfig, | ||
set.BuildInfo, | ||
config.LogGroupName, | ||
config.LogRetention, | ||
config.Tags, | ||
session, | ||
cwlogs.WithEnabledContainerInsights(config.IsEnhancedContainerInsights()), | ||
cwlogs.WithEnabledAppSignals(config.IsAppSignalsEnabled()), | ||
) | ||
|
||
collectorIdentifier, err := uuid.NewRandom() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Initialize emfExporter without AWS session and structured logs | ||
emfExporter := &emfExporter{ | ||
svcStructuredLog: svcStructuredLog, | ||
config: config, | ||
metricTranslator: newMetricTranslator(*config), | ||
retryCnt: *awsConfig.MaxRetries, | ||
retryCnt: config.AWSSessionSettings.MaxRetries, | ||
collectorID: collectorIdentifier.String(), | ||
pusherMap: map[cwlogs.StreamKey]cwlogs.Pusher{}, | ||
processResourceLabels: func(map[string]string) {}, | ||
} | ||
|
||
if config.IsAppSignalsEnabled() { | ||
userAgent := appsignals.NewUserAgent() | ||
svcStructuredLog.Handlers().Build.PushBackNamed(userAgent.Handler()) | ||
emfExporter.processResourceLabels = userAgent.Process | ||
} | ||
|
||
|
@@ -148,7 +130,10 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e | |
fmt.Println(*putLogEvent.InputLogEvent.Message) | ||
} | ||
} else if strings.EqualFold(outputDestination, outputDestinationCloudWatch) { | ||
emfPusher := emf.getPusher(putLogEvent.StreamKey) | ||
emfPusher, err := emf.getPusher(putLogEvent.StreamKey) | ||
if err != nil { | ||
return fmt.Errorf("failed to get pusher: %w", err) | ||
} | ||
if emfPusher != nil { | ||
returnError := emfPusher.AddLogEntry(putLogEvent) | ||
if returnError != nil { | ||
|
@@ -177,12 +162,24 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e | |
return nil | ||
} | ||
|
||
func (emf *emfExporter) getPusher(key cwlogs.StreamKey) cwlogs.Pusher { | ||
var ok bool | ||
if _, ok = emf.pusherMap[key]; !ok { | ||
emf.pusherMap[key] = cwlogs.NewPusher(key, emf.retryCnt, *emf.svcStructuredLog, emf.config.logger) | ||
func (emf *emfExporter) getPusher(key cwlogs.StreamKey) (cwlogs.Pusher, error) { | ||
emf.pusherMapLock.Lock() | ||
okankoAMZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defer emf.pusherMapLock.Unlock() | ||
Comment on lines
+166
to
+167
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. good find |
||
|
||
if emf.svcStructuredLog == nil { | ||
return nil, errors.New("CloudWatch Logs client not initialized") | ||
} | ||
return emf.pusherMap[key] | ||
|
||
pusher, exists := emf.pusherMap[key] | ||
if !exists { | ||
if emf.set.Logger != nil { | ||
pusher = cwlogs.NewPusher(key, emf.retryCnt, *emf.svcStructuredLog, emf.set.Logger) | ||
} else { | ||
pusher = cwlogs.NewPusher(key, emf.retryCnt, *emf.svcStructuredLog, emf.config.logger) | ||
} | ||
emf.pusherMap[key] = pusher | ||
} | ||
return pusher, nil | ||
} | ||
|
||
func (emf *emfExporter) listPushers() []cwlogs.Pusher { | ||
|
@@ -197,9 +194,32 @@ func (emf *emfExporter) listPushers() []cwlogs.Pusher { | |
} | ||
|
||
func (emf *emfExporter) start(_ context.Context, host component.Host) error { | ||
// Create AWS session here | ||
awsConfig, session, err := awsutil.GetAWSConfigSession(emf.config.logger, &awsutil.Conn{}, &emf.config.AWSSessionSettings) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// create CWLogs client with aws session config | ||
svcStructuredLog := cwlogs.NewClient(emf.config.logger, | ||
awsConfig, | ||
emf.set.BuildInfo, | ||
emf.config.LogGroupName, | ||
emf.config.LogRetention, | ||
emf.config.Tags, | ||
session, | ||
cwlogs.WithEnabledContainerInsights(emf.config.IsEnhancedContainerInsights()), | ||
cwlogs.WithEnabledAppSignals(emf.config.IsAppSignalsEnabled()), | ||
) | ||
|
||
// Assign to the struct | ||
emf.svcStructuredLog = svcStructuredLog | ||
|
||
// Optionally configure middleware | ||
if emf.config.MiddlewareID != nil { | ||
awsmiddleware.TryConfigure(emf.config.logger, host, *emf.config.MiddlewareID, awsmiddleware.SDKv1(emf.svcStructuredLog.Handlers())) | ||
awsmiddleware.TryConfigure(emf.config.logger, host, *emf.config.MiddlewareID, awsmiddleware.SDKv1(svcStructuredLog.Handlers())) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
Oops, something went wrong.
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.
can we name this something like exporter settings?