From d82837215d09b5e42d9da6af04ae4f1d7b39b1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Tue, 25 Feb 2020 21:38:31 +0100 Subject: [PATCH] Fix timeout option of Functionbeat (#16287) (#16577) ## What does this PR do? This PR changes the type of `timeout` option of GCP functions to `string` from `time.Duration`. ## Why is it important? The option was parsed as `time.Duration` and then converted to `string` when creating the payload to upload a function. However, the format of the converted value was not accepted by GCP. This prevented users from setting the timeout from the manager. (cherry picked from commit 6cc308d8728a8a24a1882b294a051c2dcf07e0cc) --- CHANGELOG.next.asciidoc | 1 + x-pack/functionbeat/manager/gcp/template_builder.go | 7 +++---- x-pack/functionbeat/provider/gcp/gcp/config.go | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 8eed5cc72aa..8a21d1147c1 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -148,6 +148,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d *Functionbeat* +- Fix timeout option of GCP functions. {issue}16282[16282] {pull}16287[16287] ==== Added diff --git a/x-pack/functionbeat/manager/gcp/template_builder.go b/x-pack/functionbeat/manager/gcp/template_builder.go index da13f8eb8d5..f7622acc8b6 100644 --- a/x-pack/functionbeat/manager/gcp/template_builder.go +++ b/x-pack/functionbeat/manager/gcp/template_builder.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "path/filepath" - "time" cloudfunctions "google.golang.org/api/cloudfunctions/v1" yaml "gopkg.in/yaml.v2" @@ -115,7 +114,7 @@ func (d *defaultTemplateBuilder) cloudFunction(name string, config *fngcp.Functi Runtime: runtime, ServiceAccountEmail: config.ServiceAccountEmail, SourceArchiveUrl: sourceArchiveURL, - Timeout: config.Timeout.String(), + Timeout: config.Timeout, VpcConnector: config.VPCConnector, } } @@ -142,8 +141,8 @@ func (d *defaultTemplateBuilder) RawTemplate(name string) (string, error) { }, } - if config.Timeout > 0*time.Second { - properties["timeout"] = config.Timeout.String() + if config.Timeout != "" { + properties["timeout"] = config.Timeout } if config.MemorySize != "" { properties["availableMemoryMb"] = config.MemorySize diff --git a/x-pack/functionbeat/provider/gcp/gcp/config.go b/x-pack/functionbeat/provider/gcp/gcp/config.go index 9085f066380..0af370edcf2 100644 --- a/x-pack/functionbeat/provider/gcp/gcp/config.go +++ b/x-pack/functionbeat/provider/gcp/gcp/config.go @@ -6,14 +6,13 @@ package gcp import ( "fmt" - "time" ) // FunctionConfig stores the configuration of a Google Cloud Function type FunctionConfig struct { Description string `config:"description"` MemorySize string `config:"memory_size"` - Timeout time.Duration `config:"timeout" validate:"nonzero,positive"` + Timeout string `config:"timeout"` ServiceAccountEmail string `config:"service_account_email"` Labels map[string]string `config:"labels"` VPCConnector string `config:"vpc_connector"`