From 997df76da97f9b3fd61dafcda9d7dfb429d7347b Mon Sep 17 00:00:00 2001 From: schmikei Date: Fri, 14 Oct 2022 10:31:03 -0400 Subject: [PATCH 1/8] fix validation of some awscloudwatch configs --- receiver/awscloudwatchreceiver/config.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/receiver/awscloudwatchreceiver/config.go b/receiver/awscloudwatchreceiver/config.go index ce5765a0ccdd..396f96163275 100644 --- a/receiver/awscloudwatchreceiver/config.go +++ b/receiver/awscloudwatchreceiver/config.go @@ -109,10 +109,6 @@ func (c *Config) validateLogsConfig() error { } func (c *GroupConfig) validate() error { - if c.AutodiscoverConfig != nil && len(c.NamedConfigs) > 0 { - return errAutodiscoverAndNamedConfigured - } - if c.AutodiscoverConfig != nil { return validateAutodiscover(*c.AutodiscoverConfig) } From c4dbef127d72aeeffb3d21a262d5f3291d79bf8c Mon Sep 17 00:00:00 2001 From: schmikei Date: Fri, 14 Oct 2022 10:43:12 -0400 Subject: [PATCH 2/8] update readme to be more informative --- receiver/awscloudwatchreceiver/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/receiver/awscloudwatchreceiver/README.md b/receiver/awscloudwatchreceiver/README.md index 594ef03e0c5c..8776bbda15e9 100644 --- a/receiver/awscloudwatchreceiver/README.md +++ b/receiver/awscloudwatchreceiver/README.md @@ -10,7 +10,7 @@ Receives Cloudwatch events from [AWS Cloudwatch](https://aws.amazon.com/cloudwat ## Getting Started -This receiver uses the [AWS SDK Profiles](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) as mode of authentication. +This receiver uses the [AWS SDK](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html) as mode of authentication, which includes [Profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) and [IMDS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) authentication for EC2 instances. ## Configuration @@ -33,7 +33,7 @@ This receiver uses the [AWS SDK Profiles](https://docs.aws.amazon.com/cli/latest ### Group Parameters -`autodiscover` and `named` are ways to control and filter which log groups and log streams which are collected from. They are mutually exclusive and are incompatible to be configured at the same time. +`autodiscover` and `named` are ways to control and filter which log groups and log streams which are collected from. They are mutually exclusive and are incompatible and should not be configured at the same time. - `autodiscover` - `limit`: (optional; default = 50) Limits the number of discovered log groups. @@ -77,7 +77,6 @@ awscloudwatch: names: [kube-apiserver-ea9c831555adca1815ae04b87661klasdj] ``` - ## Sample Configs This receiver has a number of sample configs for reference. From 931f5bbf3e9c6cb3d0b809b419a91282d8c5f7ad Mon Sep 17 00:00:00 2001 From: schmikei Date: Fri, 14 Oct 2022 10:51:40 -0400 Subject: [PATCH 3/8] add changelog entry --- .../fix-validate-of-awscloudwatchreceiver.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 .chloggen/fix-validate-of-awscloudwatchreceiver.yaml diff --git a/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml b/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml new file mode 100755 index 000000000000..b0ce5f61e60d --- /dev/null +++ b/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml @@ -0,0 +1,16 @@ +# 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: Fix config validation for some named configurations. + +# One or more tracking issues related to the change +issues: [14953] + +# (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: From f19c3ef0400eb4d5941cf721067cc546b2bdf552 Mon Sep 17 00:00:00 2001 From: schmikei Date: Fri, 14 Oct 2022 11:07:12 -0400 Subject: [PATCH 4/8] remove unused --- receiver/awscloudwatchreceiver/config.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/receiver/awscloudwatchreceiver/config.go b/receiver/awscloudwatchreceiver/config.go index 396f96163275..cd15b9791f1f 100644 --- a/receiver/awscloudwatchreceiver/config.go +++ b/receiver/awscloudwatchreceiver/config.go @@ -66,12 +66,11 @@ type StreamConfig struct { } var ( - errNoRegion = errors.New("no region was specified") - errNoLogsConfigured = errors.New("no logs configured") - errInvalidEventLimit = errors.New("event limit is improperly configured, value must be greater than 0") - errInvalidPollInterval = errors.New("poll interval is incorrect, it must be a duration greater than one second") - errInvalidAutodiscoverLimit = errors.New("the limit of autodiscovery of log groups is improperly configured, value must be greater than 0") - errAutodiscoverAndNamedConfigured = errors.New("both autodiscover and named configs are configured, Only one or the other is permitted") + errNoRegion = errors.New("no region was specified") + errNoLogsConfigured = errors.New("no logs configured") + errInvalidEventLimit = errors.New("event limit is improperly configured, value must be greater than 0") + errInvalidPollInterval = errors.New("poll interval is incorrect, it must be a duration greater than one second") + errInvalidAutodiscoverLimit = errors.New("the limit of autodiscovery of log groups is improperly configured, value must be greater than 0") ) // Validate validates all portions of the relevant config From 8afc7381f9ba135c9929d82be6b49d69525f51e7 Mon Sep 17 00:00:00 2001 From: schmikei Date: Fri, 14 Oct 2022 11:59:45 -0400 Subject: [PATCH 5/8] fix issue number --- .chloggen/fix-validate-of-awscloudwatchreceiver.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml b/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml index b0ce5f61e60d..37e7ca834818 100755 --- a/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml +++ b/.chloggen/fix-validate-of-awscloudwatchreceiver.yaml @@ -8,7 +8,7 @@ component: awscloudwatchreceiver note: Fix config validation for some named configurations. # One or more tracking issues related to the change -issues: [14953] +issues: [14952] # (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. From 4da8166af97d4d228a3d266411149d71185da5bb Mon Sep 17 00:00:00 2001 From: schmikei Date: Tue, 18 Oct 2022 09:13:13 -0400 Subject: [PATCH 6/8] update TestLoadConfig to validate the loaded configs --- receiver/awscloudwatchreceiver/config_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/receiver/awscloudwatchreceiver/config_test.go b/receiver/awscloudwatchreceiver/config_test.go index 93acb1e6693b..d798bea2771c 100644 --- a/receiver/awscloudwatchreceiver/config_test.go +++ b/receiver/awscloudwatchreceiver/config_test.go @@ -263,6 +263,7 @@ func TestLoadConfig(t *testing.T) { require.NoError(t, err) require.NoError(t, config.UnmarshalReceiver(loaded, cfg)) require.Equal(t, cfg, tc.expectedConfig) + require.NoError(t, cfg.Validate()) }) } } From 339ab40c90c41d12627b46a27fc729e51b312b2e Mon Sep 17 00:00:00 2001 From: schmikei Date: Tue, 18 Oct 2022 09:31:26 -0400 Subject: [PATCH 7/8] custom unmarshal for autodiscover config --- receiver/awscloudwatchreceiver/config.go | 33 ++++++++++++++++--- receiver/awscloudwatchreceiver/config_test.go | 29 +++++++++++----- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/receiver/awscloudwatchreceiver/config.go b/receiver/awscloudwatchreceiver/config.go index cd15b9791f1f..36eb0f589955 100644 --- a/receiver/awscloudwatchreceiver/config.go +++ b/receiver/awscloudwatchreceiver/config.go @@ -21,6 +21,7 @@ import ( "time" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/confmap" "go.uber.org/multierr" ) @@ -66,11 +67,12 @@ type StreamConfig struct { } var ( - errNoRegion = errors.New("no region was specified") - errNoLogsConfigured = errors.New("no logs configured") - errInvalidEventLimit = errors.New("event limit is improperly configured, value must be greater than 0") - errInvalidPollInterval = errors.New("poll interval is incorrect, it must be a duration greater than one second") - errInvalidAutodiscoverLimit = errors.New("the limit of autodiscovery of log groups is improperly configured, value must be greater than 0") + errNoRegion = errors.New("no region was specified") + errNoLogsConfigured = errors.New("no logs configured") + errInvalidEventLimit = errors.New("event limit is improperly configured, value must be greater than 0") + errInvalidPollInterval = errors.New("poll interval is incorrect, it must be a duration greater than one second") + errInvalidAutodiscoverLimit = errors.New("the limit of autodiscovery of log groups is improperly configured, value must be greater than 0") + errAutodiscoverAndNamedConfigured = errors.New("both autodiscover and named configs are configured, Only one or the other is permitted") ) // Validate validates all portions of the relevant config @@ -92,6 +94,23 @@ func (c *Config) Validate() error { return errs } +// Unmarshal is a custom unmarshaller that ensures that autodiscover is nil if +// autodiscover is not specified +func (c *Config) Unmarshal(componentParser *confmap.Conf) error { + if componentParser == nil { + return errors.New("") + } + err := componentParser.Unmarshal(c, confmap.WithErrorUnused()) + if err != nil { + return err + } + + if componentParser.IsSet("logs::groups::named") && !componentParser.IsSet("logs::groups::autodiscover") { + c.Logs.Groups.AutodiscoverConfig = nil + } + return nil +} + func (c *Config) validateLogsConfig() error { if c.Logs == nil { return errNoLogsConfigured @@ -108,6 +127,10 @@ func (c *Config) validateLogsConfig() error { } func (c *GroupConfig) validate() error { + if c.AutodiscoverConfig != nil && len(c.NamedConfigs) > 0 { + return errAutodiscoverAndNamedConfigured + } + if c.AutodiscoverConfig != nil { return validateAutodiscover(*c.AutodiscoverConfig) } diff --git a/receiver/awscloudwatchreceiver/config_test.go b/receiver/awscloudwatchreceiver/config_test.go index d798bea2771c..4460a23b60ea 100644 --- a/receiver/awscloudwatchreceiver/config_test.go +++ b/receiver/awscloudwatchreceiver/config_test.go @@ -115,6 +115,27 @@ func TestValidate(t *testing.T) { }, expectedErr: errors.New("unable to parse URI for imds_endpoint"), }, + { + name: "Both Logs Autodiscover and Named Set", + config: Config{ + Region: "us-east-1", + Logs: &LogsConfig{ + MaxEventsPerRequest: defaultEventLimit, + PollInterval: defaultPollInterval, + Groups: GroupConfig{ + AutodiscoverConfig: &AutodiscoverConfig{ + Limit: defaultEventLimit, + }, + NamedConfigs: map[string]StreamConfig{ + "some-log-group": { + Names: []*string{aws.String("some-lg-name")}, + }, + }, + }, + }, + }, + expectedErr: errAutodiscoverAndNamedConfigured, + }, } for _, tc := range cases { @@ -218,10 +239,6 @@ func TestLoadConfig(t *testing.T) { PollInterval: 5 * time.Minute, MaxEventsPerRequest: defaultEventLimit, Groups: GroupConfig{ - // this is ignored since named configs are present - AutodiscoverConfig: &AutodiscoverConfig{ - Limit: defaultLogGroupLimit, - }, NamedConfigs: map[string]StreamConfig{ "/aws/eks/dev-0/cluster": {}, }, @@ -239,10 +256,6 @@ func TestLoadConfig(t *testing.T) { PollInterval: 5 * time.Minute, MaxEventsPerRequest: defaultEventLimit, Groups: GroupConfig{ - // this is ignored since named configs are present - AutodiscoverConfig: &AutodiscoverConfig{ - Limit: defaultLogGroupLimit, - }, NamedConfigs: map[string]StreamConfig{ "/aws/eks/dev-0/cluster": { Names: []*string{aws.String("kube-apiserver-ea9c831555adca1815ae04b87661klasdj")}, From fca608de00bd47f4c87c0e3e8e5d1e4d8a03face Mon Sep 17 00:00:00 2001 From: schmikei Date: Tue, 18 Oct 2022 09:45:41 -0400 Subject: [PATCH 8/8] better reflective readme --- receiver/awscloudwatchreceiver/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/awscloudwatchreceiver/README.md b/receiver/awscloudwatchreceiver/README.md index 8776bbda15e9..cfe7fcc753bc 100644 --- a/receiver/awscloudwatchreceiver/README.md +++ b/receiver/awscloudwatchreceiver/README.md @@ -33,7 +33,7 @@ This receiver uses the [AWS SDK](https://docs.aws.amazon.com/sdk-for-go/v1/devel ### Group Parameters -`autodiscover` and `named` are ways to control and filter which log groups and log streams which are collected from. They are mutually exclusive and are incompatible and should not be configured at the same time. +`autodiscover` and `named` are ways to control and filter which log groups and log streams which are collected from. They are mutually exclusive and are incompatible to be configured at the same time. - `autodiscover` - `limit`: (optional; default = 50) Limits the number of discovered log groups.