-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[receiver/awsfirehosereceiver] Add support to ingest logs from services that send directly to firehose #36184
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 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 logs sent from services directly to Firehose | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36184] | ||
|
||
# (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: [user] |
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
10 changes: 10 additions & 0 deletions
10
receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog/firehoselog.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,10 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package firehoselog // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog" | ||
|
||
type firehoseLog struct { | ||
Timestamp int64 `json:"timestamp"` | ||
FirehoseARN string `json:"firehoseARN"` | ||
Message string `json:"message"` | ||
} | ||
47 changes: 47 additions & 0 deletions
47
receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog/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 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package firehoselog // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog" | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"time" | ||
) | ||
|
||
const ( | ||
attributeAWSFirehoseARN = "aws.firehose.arn" | ||
) | ||
|
||
// resourceAttributes are the firehose log attributes that define a unique resource. | ||
type resourceAttributes struct { | ||
firehoseARN string | ||
} | ||
|
||
// resourceLogsBuilder provides convenient access to the 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(attributeAWSFirehoseARN, ra.firehoseARN) | ||
} | ||
|
||
// 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 firehoseLog) { | ||
logLine := rlb.rls.AppendEmpty() | ||
// pcommon.Timestamp is a time specified as UNIX Epoch time in nanoseconds | ||
// but timestamp in cloudwatch logs are in milliseconds. | ||
logLine.SetTimestamp(pcommon.Timestamp(log.Timestamp * int64(time.Millisecond))) | ||
logLine.Body().SetStr(log.Message) | ||
} |
1 change: 1 addition & 0 deletions
1
receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog/testdata/firehose_log.json
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 @@ | ||
{"requestId":"test-request-id-firehoselogs","timestamp":1646096348000,"records":[{"data":"eyJ2ZXJzaW9uIjoiMS4xMDAwMDAiLCJhY2NvdW50X2lkIjoiNDI4MTUyNTAyNDY3IiwicmVnaW9uIjoidXMtZWFzdC0xIiwidnBjX2lkIjoidnBjLWU4NzIyZDkyIiwicXVlcnlfdGltZXN0YW1wIjoiMjAyMi0wNC0xNVQxNTo1NTozMFoiLCJxdWVyeV9uYW1lIjoiMTcyLjE0NC41Mi4xMTYuaW4tYWRkci5hcnBhLiIsInF1ZXJ5X3R5cGUiOiJQVFIiLCJxdWVyeV9jbGFzcyI6IklOIiwicmNvZGUiOiIiLCJhbnN3ZXJzIjpbXSwic3JjYWRkciI6IjE3Mi4zMS44NC40MyIsInNyY3BvcnQiOiI0Mzc4NiIsInRyYW5zcG9ydCI6IlVEUCIsInNyY2lkcyI6eyJpbnN0YW5jZSI6ImktMDY0NmMwNDM1NTU0Y2M1ZWQifX0="}]} |
54 changes: 54 additions & 0 deletions
54
receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog/unmarshaler.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,54 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package firehoselog // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog" | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsfirehosereceiver/internal/unmarshaler" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const ( | ||
TypeStr = "firehoselogs" | ||
) | ||
|
||
// Unmarshaler for the Firehose log record format. | ||
type Unmarshaler struct { | ||
logger *zap.Logger | ||
} | ||
|
||
var _ unmarshaler.LogsUnmarshaler = (*Unmarshaler)(nil) | ||
|
||
// NewUnmarshaler creates a new instance of the Unmarshaler. | ||
func NewUnmarshaler(logger *zap.Logger) *Unmarshaler { | ||
return &Unmarshaler{logger} | ||
} | ||
|
||
// Unmarshal deserializes the records into firehoselogs and uses the | ||
// resourceLogsBuilder to group them into a single plog.Logs. | ||
func (u Unmarshaler) Unmarshal(records [][]byte, commonAttributes map[string]string, firehoseARN string, timestamp int64) (plog.Logs, error) { | ||
md := plog.NewLogs() | ||
builders := make(map[resourceAttributes]*resourceLogsBuilder) | ||
for _, record := range records { | ||
var log firehoseLog | ||
log.Message = string(record) | ||
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. This will lead to unparsed JSON stored in the log record body, right? Should we be attempting to decode the record as JSON, and storing that as a structured body? |
||
log.Timestamp = timestamp | ||
attrs := resourceAttributes{ | ||
firehoseARN: firehoseARN, | ||
} | ||
|
||
lb, ok := builders[attrs] | ||
if !ok { | ||
lb = newResourceLogsBuilder(md, attrs) | ||
builders[attrs] = lb | ||
} | ||
lb.AddLog(log) | ||
} | ||
return md, nil | ||
} | ||
|
||
// Type of the serialized messages. | ||
func (u Unmarshaler) Type() string { | ||
return TypeStr | ||
} |
26 changes: 26 additions & 0 deletions
26
receiver/awsfirehosereceiver/internal/unmarshaler/firehoselog/unmarshaler_test.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,26 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package firehoselog | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestUnmarshal(t *testing.T) { | ||
body, err := os.ReadFile("testdata/firehose_log.json") | ||
require.NoError(t, err) | ||
|
||
unmarshaler := NewUnmarshaler(zap.NewNop()) | ||
var records [][]byte | ||
records = append(records, body) | ||
got, err := unmarshaler.Unmarshal(records, nil, "arn:aws:firehose:us-east-1:123456789:deliverystream/testStream", 1646096348000) | ||
require.NoError(t, err) | ||
require.NotNil(t, got) | ||
require.Equal(t, 1, got.ResourceLogs().Len()) | ||
require.Equal(t, 1, got.ResourceLogs().At(0).ScopeLogs().Len()) | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
receiver/awsfirehosereceiver/testdata/firehoselogs_config.yaml
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,7 @@ | ||
awsfirehose: | ||
endpoint: 0.0.0.0:4433 | ||
record_type: firehoselogs | ||
access_key: "some_access_key" | ||
tls: | ||
cert_file: server.crt | ||
key_file: server.key |
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.
Nothing produces JSON with these fields does it? IIUC it's just for passing around in memory? If that's the case, I'd suggest dropping the
json:"..."
tags, as they confused me, and may confuse others.This is unlike cwlog, where the
cWLog
struct holds the JSON structure of logs coming from CloudWatch.