Skip to content
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

add support for multiple regions #21065

Merged
merged 4 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
4 changes: 2 additions & 2 deletions x-pack/functionbeat/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}$"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added this change because, as we're appending the function name to the role name, the role name would exceed AWS's limit of 64 characters. I can change the implementation based on the feedback from the maintainers. Other alternative is to add a conditional for creating the role.

Either ways, the 140 character limit for the function name needs to be reduced as we're already appending the function name in the role name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. However, I am bit worried if we change the role name, we might forgot to change this number. Do you mind refactoring it so the length of the pattern depends on the role name prefix? Or at least add a comment to the code about why the max length is 29?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was off by one on the limit, it can be 30 instead of 29. I've updated the regex, tests and added a comment on how I got to the number 30.

functionRE = regexp.MustCompile(functionPattern)
configOverrides = common.MustNewConfigFrom(map[string]interface{}{
"path.data": "/tmp",
Expand Down Expand Up @@ -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,
)
}
Expand Down
15 changes: 15 additions & 0 deletions x-pack/functionbeat/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
2 changes: 1 addition & 1 deletion x-pack/functionbeat/manager/aws/template_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down