From 8ce8fa950b40ef8ad4e90da93ef17f29240f6eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Mon, 26 Oct 2020 18:27:35 +0100 Subject: [PATCH] Fix Google Cloud Function configuration file issues (#22156) (#22158) ## What does this PR do? This PR adds a new function to to `cfgfile` to set the path to the configuration file of a Beat. This fixes the issue on GCP with Functionbeat. ## Why is it important? ATM Functionbeat cannot run on GCP. ## Related issues Closes #20864 (cherry picked from commit 13a195a16aec0468fb6de228fa3bb696c2d8aeef) --- CHANGELOG.next.asciidoc | 1 + libbeat/cfgfile/cfgfile.go | 4 ++++ x-pack/functionbeat/provider/gcp/pubsub/pubsub.go | 1 + x-pack/functionbeat/provider/gcp/storage/storage.go | 1 + x-pack/functionbeat/scripts/mage/update.go | 3 +++ 5 files changed, 10 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 39f76d50b13c..787ca45ce5bd 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -442,6 +442,7 @@ field. You can revert this change by configuring tags for the module and omittin - Do not need Google credentials if not required for the operation. {issue}17329[17329] {pull}21072[21072] - Fix dependency issues of GCP functions. {issue}20830[20830] {pull}21070[21070] - Fix catchall bucket config errors by adding more validation. {issue}17572[16282] {pull}20887[16287] +- Fix Google Cloud Function configuration issue. {issue}20864[20864] {pull}22156[22156] ==== Added diff --git a/libbeat/cfgfile/cfgfile.go b/libbeat/cfgfile/cfgfile.go index 767cbd34bc57..ff3949069314 100644 --- a/libbeat/cfgfile/cfgfile.go +++ b/libbeat/cfgfile/cfgfile.go @@ -205,6 +205,10 @@ func LoadList(file string) ([]*common.Config, error) { return c, nil } +func SetConfigPath(path string) { + *configPath = path +} + // GetPathConfig returns ${path.config}. If ${path.config} is not set, ${path.home} is returned. func GetPathConfig() string { if *configPath != "" { diff --git a/x-pack/functionbeat/provider/gcp/pubsub/pubsub.go b/x-pack/functionbeat/provider/gcp/pubsub/pubsub.go index 44f77695e946..813a0df9cc06 100644 --- a/x-pack/functionbeat/provider/gcp/pubsub/pubsub.go +++ b/x-pack/functionbeat/provider/gcp/pubsub/pubsub.go @@ -29,6 +29,7 @@ func RunPubSub(ctx context.Context, m gpubsub.Message) error { ConfigOverrides: config.FunctionOverrides, } + cfgfile.SetConfigPath("/srv/src/pubsub") cfgfile.ChangeDefaultCfgfileFlag(settings.Name) return instance.Run(settings, initFunctionbeat(ctx, m)) diff --git a/x-pack/functionbeat/provider/gcp/storage/storage.go b/x-pack/functionbeat/provider/gcp/storage/storage.go index c9d1660d67c1..2de829392d2b 100644 --- a/x-pack/functionbeat/provider/gcp/storage/storage.go +++ b/x-pack/functionbeat/provider/gcp/storage/storage.go @@ -27,6 +27,7 @@ func RunCloudStorage(ctx context.Context, e gcp.StorageEvent) error { ConfigOverrides: config.FunctionOverrides, } + cfgfile.SetConfigPath("/srv/src/storage") cfgfile.ChangeDefaultCfgfileFlag(settings.Name) return instance.Run(settings, initFunctionbeat(ctx, e)) diff --git a/x-pack/functionbeat/scripts/mage/update.go b/x-pack/functionbeat/scripts/mage/update.go index 59b56cb6bed5..99f1b9a3ce34 100644 --- a/x-pack/functionbeat/scripts/mage/update.go +++ b/x-pack/functionbeat/scripts/mage/update.go @@ -74,6 +74,9 @@ func (Update) VendorBeats() error { Exclude: []string{ ".*_test.go$", ".*.yml", + // XXX GCP function metadata lib must be removed to avoid build failures + // GH issue: https://github.com/googleapis/google-cloud-go/issues/1947 + ".*cloud.google.com/go.*/functions/metadata.*", }, } err = cp.Execute()