Skip to content

Commit

Permalink
[receiver/awscloudwatch] allow named groups with no stream spec (#32346)
Browse files Browse the repository at this point in the history
**Description:** Allow receiving named loggroups without stream
filtering as indicated by a given example linked in the README

**Link to tracking Issue:** #32345

**Testing:** Adds additional unit test for this specific config case.

**Documentation:** None, implementation matches the given docs/example
which was not the case before
  • Loading branch information
mikel-jason authored Apr 18, 2024
1 parent 169e1c2 commit c542a03
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .chloggen/aws-cw-receiver-full-named-loggroups.yaml
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: 'bug_fix'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: awscloudwatchreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The receiver now supports extracting data from named loggroups without requiring filters for log streams. This was already advertised as feature, but ignored during initialization.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32345]

# (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]
3 changes: 3 additions & 0 deletions receiver/awscloudwatchreceiver/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func newLogsReceiver(cfg *Config, logger *zap.Logger, consumer consumer.Logs) *l
if len(sc.Names) > 0 {
groups = append(groups, &streamNames{group: logGroupName, names: sc.Names})
}
if len(sc.Prefixes) == 0 && len(sc.Names) == 0 {
groups = append(groups, &streamNames{group: logGroupName})
}
}

// safeguard from using both
Expand Down
34 changes: 34 additions & 0 deletions receiver/awscloudwatchreceiver/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ func TestPrefixedNamedStreamsConfig(t *testing.T) {
require.NoError(t, plogtest.CompareLogs(expected, logs, plogtest.IgnoreObservedTimestamp()))
}

func TestNamedConfigNoStreamFilter(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Region = "us-west-1"
cfg.Logs.PollInterval = 1 * time.Second
cfg.Logs.Groups = GroupConfig{
NamedConfigs: map[string]StreamConfig{
testLogGroupName: {},
},
}

sink := &consumertest.LogsSink{}
alertRcvr := newLogsReceiver(cfg, zap.NewNop(), sink)
alertRcvr.client = defaultMockClient()

err := alertRcvr.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)

require.Eventually(t, func() bool {
return sink.LogRecordCount() > 0
}, 2*time.Second, 10*time.Millisecond)

groupRequests := alertRcvr.groupRequests
require.Len(t, groupRequests, 1)
require.Equal(t, groupRequests[0].groupName(), "test-log-group-name")

err = alertRcvr.Shutdown(context.Background())
require.NoError(t, err)

logs := sink.AllLogs()[0]
expected, err := golden.ReadLogs(filepath.Join("testdata", "processed", "prefixed.yaml"))
require.NoError(t, err)
require.NoError(t, plogtest.CompareLogs(expected, logs, plogtest.IgnoreObservedTimestamp()))
}

func TestDiscovery(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Region = "us-west-1"
Expand Down

0 comments on commit c542a03

Please sign in to comment.