Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws/logs_monitoring_go/internal/handling/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (h CloudwatchHandler) newCloudwatchBaseEntry(data events.CloudwatchLogsData
func (h CloudwatchHandler) newCloudwatchLogEntry(event events.CloudwatchLogsLogEvent, entry model.LogEntry) model.LogEntry {
tags, service, message := extractFromMessage(event.Message)
entry.Service = cmp.Or(h.cfg.Service, service, entry.Source)
entry.Tags = slices.Concat(tags, model.Tags{"service:" + entry.Service}, h.cfg.Tags)
entry.Tags = slices.Concat(tags, h.cfg.Tags)
entry.Message = message
entry.ID = event.ID
entry.Timestamp = event.Timestamp
Expand Down
7 changes: 3 additions & 4 deletions aws/logs_monitoring_go/internal/handling/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TestCloudwatchHandler_Handle(t *testing.T) {
Source: "lambda",
SourceCategory: "aws",
Service: "lambda",
Tags: model.Tags{"service:lambda"},
Host: "/aws/lambda/testing-datadog",
ID: "ev1",
Timestamp: 1583425836114,
Expand Down Expand Up @@ -101,7 +100,7 @@ func TestCloudwatchHandler_Handle(t *testing.T) {
want: []model.LogEntry{
{
Message: "first", Source: "lambda", SourceCategory: "aws",
Service: "lambda", Tags: model.Tags{"service:lambda"},
Service: "lambda",
Host: "/aws/lambda/fn", ID: "a1", Timestamp: 1000,
Metadata: model.CloudwatchMetadata{
LambdaOrigin: model.LambdaOrigin{ARN: "arn:aws:lambda:us-east-1:123456789012:function:forwarder"},
Expand All @@ -110,7 +109,7 @@ func TestCloudwatchHandler_Handle(t *testing.T) {
},
{
Message: "second", Source: "lambda", SourceCategory: "aws",
Service: "lambda", Tags: model.Tags{"service:lambda"},
Service: "lambda",
Host: "/aws/lambda/fn", ID: "a2", Timestamp: 2000,
Metadata: model.CloudwatchMetadata{
LambdaOrigin: model.LambdaOrigin{ARN: "arn:aws:lambda:us-east-1:123456789012:function:forwarder"},
Expand Down Expand Up @@ -140,7 +139,7 @@ func TestCloudwatchHandler_Handle(t *testing.T) {
{
Message: "hello", Source: "custom-source", SourceCategory: "aws",
Service: "custom-service",
Tags: model.Tags{"service:custom-service", "env:prod", "team:infra"},
Tags: model.Tags{"env:prod", "team:infra"},
Host: "custom-host", ID: "ev1", Timestamp: 1000,
Metadata: model.CloudwatchMetadata{
LambdaOrigin: model.LambdaOrigin{ARN: "arn:aws:lambda:us-east-1:123456789012:function:forwarder"},
Expand Down
2 changes: 1 addition & 1 deletion aws/logs_monitoring_go/internal/handling/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h S3Handler) newS3LogEntry(record events.S3EventRecord, message string, la
entry.Metadata = metadata
entry.Source = cmp.Or(h.cfg.Source, S3Source(key))
entry.Service = cmp.Or(h.cfg.Service, service, entry.Source)
entry.Tags = slices.Concat(tags, model.Tags{"service:" + entry.Service}, h.cfg.Tags)
entry.Tags = slices.Concat(tags, h.cfg.Tags)
return entry
}

Expand Down
20 changes: 10 additions & 10 deletions aws/logs_monitoring_go/internal/handling/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestProcessS3Record(t *testing.T) {
},
cfg: testutil.EmptyConfig(),
chanSize: 1,
want: []model.LogEntry{wantS3Entry("line1", "s3", "s3", model.Tags{"service:s3"})},
want: []model.LogEntry{wantS3Entry("line1", "s3", "s3", nil)},
},
"multiple lines": {
mockSetup: func(m *MockS3APIClient) {
Expand All @@ -59,9 +59,9 @@ func TestProcessS3Record(t *testing.T) {
cfg: testutil.EmptyConfig(),
chanSize: 3,
want: []model.LogEntry{
wantS3Entry("line1", "s3", "s3", model.Tags{"service:s3"}),
wantS3Entry("line2", "s3", "s3", model.Tags{"service:s3"}),
wantS3Entry("line3", "s3", "s3", model.Tags{"service:s3"}),
wantS3Entry("line1", "s3", "s3", nil),
wantS3Entry("line2", "s3", "s3", nil),
wantS3Entry("line3", "s3", "s3", nil),
},
},
"empty file": {
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestProcessS3Record(t *testing.T) {
},
cfg: testutil.EmptyConfig(),
chanSize: 1,
want: []model.LogEntry{wantS3Entry(`{"msg":"hello"}`, "s3", "myapp", model.Tags{"env:prod", "service:myapp"})},
want: []model.LogEntry{wantS3Entry(`{"msg":"hello"}`, "s3", "myapp", model.Tags{"env:prod"})},
},
"invalid utf8 stripped": {
mockSetup: func(m *MockS3APIClient) {
Expand All @@ -102,7 +102,7 @@ func TestProcessS3Record(t *testing.T) {
},
cfg: testutil.EmptyConfig(),
chanSize: 1,
want: []model.LogEntry{wantS3Entry("helloworld", "s3", "s3", model.Tags{"service:s3"})},
want: []model.LogEntry{wantS3Entry("helloworld", "s3", "s3", nil)},
},
"multiline groups continuation lines": {
mockSetup: func(m *MockS3APIClient) {
Expand All @@ -114,8 +114,8 @@ func TestProcessS3Record(t *testing.T) {
cfg: &config.Config{S3MultilineLogRegex: regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)},
chanSize: 2,
want: []model.LogEntry{
wantS3Entry("2024-01-15 ERROR NullPointer\n at com.foo.Bar\n", "s3", "s3", model.Tags{"service:s3"}),
wantS3Entry("2024-01-15 INFO started", "s3", "s3", model.Tags{"service:s3"}),
wantS3Entry("2024-01-15 ERROR NullPointer\n at com.foo.Bar\n", "s3", "s3", nil),
wantS3Entry("2024-01-15 INFO started", "s3", "s3", nil),
},
},
"multiline flushes at eof": {
Expand All @@ -127,7 +127,7 @@ func TestProcessS3Record(t *testing.T) {
},
cfg: &config.Config{S3MultilineLogRegex: regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)},
chanSize: 1,
want: []model.LogEntry{wantS3Entry("2024-01-15 ERROR\n stacktrace", "s3", "s3", model.Tags{"service:s3"})},
want: []model.LogEntry{wantS3Entry("2024-01-15 ERROR\n stacktrace", "s3", "s3", nil)},
},
"custom tags passed through": {
mockSetup: func(m *MockS3APIClient) {
Expand All @@ -138,7 +138,7 @@ func TestProcessS3Record(t *testing.T) {
},
cfg: &config.Config{Tags: model.Tags{"env:prod", "team:aws"}},
chanSize: 1,
want: []model.LogEntry{wantS3Entry("line1", "s3", "s3", model.Tags{"service:s3", "env:prod", "team:aws"})},
want: []model.LogEntry{wantS3Entry("line1", "s3", "s3", model.Tags{"env:prod", "team:aws"})},
},
}

Expand Down
Loading