Skip to content

Commit

Permalink
Fix timeout option of Functionbeat (#16287) (#16577)
Browse files Browse the repository at this point in the history
## 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 6cc308d)
  • Loading branch information
kvch authored Feb 25, 2020
1 parent 646c927 commit d828372
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions x-pack/functionbeat/manager/gcp/template_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"path/filepath"
"time"

cloudfunctions "google.golang.org/api/cloudfunctions/v1"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions x-pack/functionbeat/provider/gcp/gcp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit d828372

Please sign in to comment.