Support log group/stream creation in new cwlogsauth extension#2084
Draft
Support log group/stream creation in new cwlogsauth extension#2084
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of the issue
When using the
otlphttpexporter to send logs to the CloudWatch OTLP Logs endpoint (https://logs.<region>.amazonaws.com/v1/logs), the endpoint requires the target log group and log stream to already exist — unlike the nativePutLogEventsAPI used byawscloudwatchlogsexporter, which auto-creates them on first write.This means customers using the OTLP logs pipeline must manually pre-create log groups and streams before CWAgent can export logs, or the endpoint rejects the requests silently.
Description of changes
Adds a new
cwlogsauthextension that lazily auto-creates CloudWatch log groups and log streams when CWAgent sends logs via theotlphttpexporter to the CW OTLP Logs endpoint.The extension implements
extensionauth.HTTPClientand wraps an inner auth extension (typicallysigv4auth). It intercepts outgoing HTTP requests as aRoundTripperand:x-aws-log-groupandx-aws-log-streamfrom the outgoing request headersCreateLogGroupthenCreateLogStreamvia the AWS SDK (both idempotent —ResourceAlreadyExistsExceptionis ignored)sync.Mapso subsequent requests have zero overheadThis mirrors the lazy creation behavior of the native
cwlogs.Client.CreateStreamused byawscloudwatchlogsexporter, but for theotlphttpexporter path.Files added:
extension/cwlogsauth/config.go— Config struct with optionalauthfield for chaining with an inner auth extensionextension/cwlogsauth/factory.go— Extension factory registrationextension/cwlogsauth/extension.go— RoundTripper implementation with lazy log group/stream creation and sync.Map cacheFiles modified:
service/defaultcomponents/components.go— Registeredcwlogsauthextension factoryLicense
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Deployed application in EKS, using CW Observability EKS Add-on, patched Agent to include my changes, and used the following configuration. My log group&stream (
/test/telemetry&test-otlp) were automatically created once I wrote logs to theotlp/http_0_0_0_0_4316logs receiver.Requirements
Before commiting your code, please do the following steps.
make fmtandmake fmt-shmake lintIntegration Tests
To run integration tests against this PR, add the
ready for testinglabel.