From ee9fabd8c7cc3e4eaa902ac0f9473aad58b233ea Mon Sep 17 00:00:00 2001 From: Ravi Naik Date: Fri, 11 Sep 2020 19:05:35 -0700 Subject: [PATCH 1/3] add support for multiple regions --- CHANGELOG.next.asciidoc | 1 + x-pack/functionbeat/config/config.go | 4 ++-- x-pack/functionbeat/config/config_test.go | 15 +++++++++++++++ .../functionbeat/manager/aws/template_builder.go | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 27a2a77064e..7826c2bfa06 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -692,6 +692,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Functionbeat* - Add basic ECS categorization and `cloud` fields. {pull}19174[19174] - Add support for parallelization factor for kinesis. {pull}20727[20727] +- Add support for multiple regions {pull}21064[21064] *Winlogbeat* diff --git a/x-pack/functionbeat/config/config.go b/x-pack/functionbeat/config/config.go index a95346c59c1..3a302760767 100644 --- a/x-pack/functionbeat/config/config.go +++ b/x-pack/functionbeat/config/config.go @@ -16,7 +16,7 @@ import ( ) var ( - functionPattern = "^[A-Za-z][A-Za-z0-9\\-]{0,139}$" + functionPattern = "^[A-Za-z][A-Za-z0-9\\-]{0,29}$" functionRE = regexp.MustCompile(functionPattern) configOverrides = common.MustNewConfigFrom(map[string]interface{}{ "path.data": "/tmp", @@ -103,7 +103,7 @@ type functionName string func (f *functionName) Unpack(s string) error { if !functionRE.MatchString(s) { return fmt.Errorf( - "invalid name: '%s', name must match [a-zA-Z0-9-] and be at most 140 characters", + "invalid name: '%s', name must match [a-zA-Z0-9-] and be at most 29 characters", s, ) } diff --git a/x-pack/functionbeat/config/config_test.go b/x-pack/functionbeat/config/config_test.go index af62d8ca7e4..34eee7d71d0 100644 --- a/x-pack/functionbeat/config/config_test.go +++ b/x-pack/functionbeat/config/config_test.go @@ -105,9 +105,24 @@ func TestFunctionName(t *testing.T) { assert.Equal(t, functionName("hello-world"), f) }) + t.Run("valid function name: length of 29 chars", func(t *testing.T) { + f := functionName("") + err := f.Unpack("something-which-is--29-chars") + if !assert.NoError(t, err) { + return + } + assert.Equal(t, functionName("something-which-is--29-chars"), f) + }) + t.Run("invalid function name", func(t *testing.T) { f := functionName("") err := f.Unpack("hello world") assert.Error(t, err) }) + + t.Run("invalid function name: length", func(t *testing.T) { + f := functionName("") + err := f.Unpack("something-which-is-greater-than-twenty-nine-characters") + assert.Error(t, err) + }) } diff --git a/x-pack/functionbeat/manager/aws/template_builder.go b/x-pack/functionbeat/manager/aws/template_builder.go index d28a75b3794..cc51e2c0aa4 100644 --- a/x-pack/functionbeat/manager/aws/template_builder.go +++ b/x-pack/functionbeat/manager/aws/template_builder.go @@ -264,7 +264,7 @@ func (d *defaultTemplateBuilder) roleTemplate(function installer, name string) * }, }, Path: "/", - RoleName: "functionbeat-lambda-" + name, + RoleName: "functionbeat-lambda-" + name + "-" + cloudformation.Ref("AWS::Region"), // Allow the lambda to write log to cloudwatch logs. // doc: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-policy.html Policies: policies, From 3024ba7d4c1d95d5ef0cee36adaf1ed28c67ec04 Mon Sep 17 00:00:00 2001 From: Ravi Naik Date: Fri, 11 Sep 2020 19:26:37 -0700 Subject: [PATCH 2/3] update changelog to reflect PR number --- CHANGELOG.next.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 7826c2bfa06..148f3ea73bf 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -692,7 +692,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Functionbeat* - Add basic ECS categorization and `cloud` fields. {pull}19174[19174] - Add support for parallelization factor for kinesis. {pull}20727[20727] -- Add support for multiple regions {pull}21064[21064] +- Add support for multiple regions {pull}21065[21065] *Winlogbeat* From 1c1b26994daf0385322fc5fa1abad198d297e03e Mon Sep 17 00:00:00 2001 From: Ravi B Naik Date: Wed, 6 Jan 2021 18:05:42 -0700 Subject: [PATCH 3/3] add comment about the new limit --- x-pack/functionbeat/config/config.go | 11 +++++++++-- x-pack/functionbeat/config/config_test.go | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/x-pack/functionbeat/config/config.go b/x-pack/functionbeat/config/config.go index 3a302760767..61451554728 100644 --- a/x-pack/functionbeat/config/config.go +++ b/x-pack/functionbeat/config/config.go @@ -16,7 +16,14 @@ import ( ) var ( - functionPattern = "^[A-Za-z][A-Za-z0-9\\-]{0,29}$" + // We're appending the function name to the role name. + // Limiting this to 30 because, we're prefixing the role name + // with "functionbeat-lambda-"(20 chars) and suffixing with + // the region, the max of which is "ap-southeast-2" (14 chars) + // Length constraints for roleName in AWS is 64 characters max per + // https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html + + functionPattern = "^[A-Za-z][A-Za-z0-9\\-]{0,30}$" functionRE = regexp.MustCompile(functionPattern) configOverrides = common.MustNewConfigFrom(map[string]interface{}{ "path.data": "/tmp", @@ -103,7 +110,7 @@ type functionName string func (f *functionName) Unpack(s string) error { if !functionRE.MatchString(s) { return fmt.Errorf( - "invalid name: '%s', name must match [a-zA-Z0-9-] and be at most 29 characters", + "invalid name: '%s', name must match [a-zA-Z0-9-] and be at most 30 characters", s, ) } diff --git a/x-pack/functionbeat/config/config_test.go b/x-pack/functionbeat/config/config_test.go index 34eee7d71d0..a196c096b83 100644 --- a/x-pack/functionbeat/config/config_test.go +++ b/x-pack/functionbeat/config/config_test.go @@ -105,13 +105,13 @@ func TestFunctionName(t *testing.T) { assert.Equal(t, functionName("hello-world"), f) }) - t.Run("valid function name: length of 29 chars", func(t *testing.T) { + t.Run("valid function name: length of 30 chars", func(t *testing.T) { f := functionName("") - err := f.Unpack("something-which-is--29-chars") + err := f.Unpack("something-which-is--30--chars") if !assert.NoError(t, err) { return } - assert.Equal(t, functionName("something-which-is--29-chars"), f) + assert.Equal(t, functionName("something-which-is--30--chars"), f) }) t.Run("invalid function name", func(t *testing.T) { @@ -122,7 +122,7 @@ func TestFunctionName(t *testing.T) { t.Run("invalid function name: length", func(t *testing.T) { f := functionName("") - err := f.Unpack("something-which-is-greater-than-twenty-nine-characters") + err := f.Unpack("something-which-is-greater-than-thirty-characters") assert.Error(t, err) }) }