-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[receiver/awsfirehosereceiver] Add support for CloudWatch logs
- Loading branch information
1 parent
6b3237a
commit 977ffa7
Showing
29 changed files
with
749 additions
and
30 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: awsfirehosereceiver | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add support for CloudWatch logs | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [35077] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
receiver/awsfirehosereceiver/internal/metadata/generated_status.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/compression/compression.go
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package compression | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
) | ||
|
||
func Zip(data []byte) ([]byte, error) { | ||
var b bytes.Buffer | ||
w := gzip.NewWriter(&b) | ||
|
||
_, err := w.Write(data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err = w.Flush(); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err = w.Close(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return b.Bytes(), nil | ||
} | ||
|
||
func Unzip(data []byte) ([]byte, error) { | ||
b := bytes.NewBuffer(data) | ||
|
||
r, err := gzip.NewReader(b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var rv bytes.Buffer | ||
_, err = rv.ReadFrom(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return rv.Bytes(), nil | ||
} |
14 changes: 14 additions & 0 deletions
14
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/cwlog.go
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cwlog | ||
|
||
type cwLog struct { | ||
MessageType string `json:"messageType"` | ||
Owner string `json:"owner"` | ||
LogGroup string `json:"logGroup"` | ||
LogStream string `json:"logStream"` | ||
SubscriptionFilters []string `json:"subscriptionFilters"` | ||
LogEvents []struct { | ||
Id string `json:"id"` | ||
Timestamp int64 `json:"timestamp"` | ||
Message string `json:"message"` | ||
} `json:"logEvents"` | ||
} |
47 changes: 47 additions & 0 deletions
47
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/logsbuilder.go
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cwlog | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
conventions "go.opentelemetry.io/collector/semconv/v1.6.1" | ||
) | ||
|
||
const ( | ||
attributeCloudwatchLogGroupName = "cloudwatch.log.group.name" | ||
attributeCloudwatchLogStreamName = "cloudwatch.log.stream.name" | ||
) | ||
|
||
// resourceAttributes are the CloudWatch log attributes that define a unique resource. | ||
type resourceAttributes struct { | ||
owner, logGroup, logStream string | ||
} | ||
|
||
// resourceLogsBuilder provides convenient access to the a Resource's LogRecordSlice. | ||
type resourceLogsBuilder struct { | ||
rls plog.LogRecordSlice | ||
} | ||
|
||
// setAttributes applies the resourceAttributes to the provided Resource. | ||
func (ra *resourceAttributes) setAttributes(resource pcommon.Resource) { | ||
attrs := resource.Attributes() | ||
attrs.PutStr(conventions.AttributeCloudAccountID, ra.owner) | ||
attrs.PutStr("cloudwatch.log.group.name", ra.logStream) | ||
attrs.PutStr("cloudwatch.log.stream", ra.logGroup) | ||
} | ||
|
||
// newResourceLogsBuilder to capture logs for the Resource defined by the provided attributes. | ||
func newResourceLogsBuilder(logs plog.Logs, attrs resourceAttributes) *resourceLogsBuilder { | ||
rls := logs.ResourceLogs().AppendEmpty() | ||
attrs.setAttributes(rls.Resource()) | ||
return &resourceLogsBuilder{rls.ScopeLogs().AppendEmpty().LogRecords()} | ||
} | ||
|
||
// AddLog events to the LogRecordSlice. Resource attributes are captured when creating | ||
// the resourceLogsBuilder, so we only need to consider the LogEvents themselves. | ||
func (rlb *resourceLogsBuilder) AddLog(log cwLog) { | ||
for _, event := range log.LogEvents { | ||
logLine := rlb.rls.AppendEmpty() | ||
logLine.SetTimestamp(pcommon.Timestamp(event.Timestamp)) | ||
logLine.Body().SetStr(event.Message) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/testdata/invalid_records
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"CHANGE":-0.09,"PRICE":4.96,"TICKER_SYMBOL":"KIN","SECTOR":"ENERGY"} | ||
{"CHANGE":-1.47,"PRICE":134.74,"TICKER_SYMBOL":"DFG","SECTOR":"TECHNOLOGY"} | ||
{"CHANGE":1.96,"PRICE":57.53,"TICKER_SYMBOL":"SAC","SECTOR":"ENERGY"} | ||
{"CHANGE":0.04,"PRICE":32.84,"TICKER_SYMBOL":"PJN","SECTOR":"RETAIL"} |
2 changes: 2 additions & 0 deletions
2
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/testdata/multiple_records
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695232","timestamp":1725544035523,"message":"Hello world, here is our first log message!"}]} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695233","timestamp":1725554035523,"message":"Hello world, here is our second log message!"}]} |
6 changes: 6 additions & 0 deletions
6
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/testdata/multiple_resources
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695232","timestamp":1725544035523,"message":"Hello world, here is our first log message!"}]} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695233","timestamp":1725554035523,"message":"Hello world, here is our second log message!"}]} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test2","logStream":"test1","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695234","timestamp":1725564035523,"message":"Hello world, here is our third log message!"}]} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test2","logStream":"test2","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695235","timestamp":1725574035523,"message":"Hello world, here is our fourth log message!"}]} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test2","logStream":"test1","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695236","timestamp":1725584035523,"message":"Hello world, here is our fifth log message!"}]} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test2","logStream":"test2","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695237","timestamp":1725594035523,"message":"Hello world, here is our sixth log message!"}]} |
1 change: 1 addition & 0 deletions
1
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/testdata/single_record
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695232","timestamp":1725544035523,"message":"Hello world, here is our first log message!"}]} |
3 changes: 3 additions & 0 deletions
3
receiver/awsfirehosereceiver/internal/unmarshaler/cwlog/testdata/some_invalid_records
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695232","timestamp":1725544035523,"message":"Hello world, here is our first log message!"}]} | ||
{"CHANGE":1.96,"PRICE":57.53,"TICKER_SYMBOL":"SAC","SECTOR":"ENERGY"} | ||
{"messageType":"DATA_MESSAGE","owner":"123","logGroup":"test","logStream":"test","subscriptionFilters":["test"],"logEvents":[{"id":"38480917865042697267627490045603633139480491071049695233","timestamp":1725554035523,"message":"Hello world, here is our second log message!"}]} |
Oops, something went wrong.