From b6b27cad8f6faa46cdacba3910e0d2600253bc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Fri, 5 Mar 2021 16:12:38 +0100 Subject: [PATCH 1/4] Use `timed.Periodic` when running the periodic scans of filestream (#24248) (#24294) (cherry picked from commit fe2653760b29e24072853440b6488dc656cd02f9) --- filebeat/input/filestream/fswatch.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/filebeat/input/filestream/fswatch.go b/filebeat/input/filestream/fswatch.go index 8c285c8a4ba..0b1e5df46f4 100644 --- a/filebeat/input/filestream/fswatch.go +++ b/filebeat/input/filestream/fswatch.go @@ -28,6 +28,7 @@ import ( "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/match" "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/go-concert/timed" "github.com/elastic/go-concert/unison" ) @@ -115,16 +116,14 @@ func defaultFileWatcherConfig() fileWatcherConfig { func (w *fileWatcher) Run(ctx unison.Canceler) { defer close(w.events) - ticker := time.NewTicker(w.interval) - defer ticker.Stop() - for { - select { - case <-ctx.Done(): - return - case <-ticker.C: - w.watch(ctx) - } - } + // run initial scan before starting regular + w.watch(ctx) + + timed.Periodic(ctx, w.interval, func() error { + w.watch(ctx) + + return nil + }) } func (w *fileWatcher) watch(ctx unison.Canceler) { From 07823b072c12d8c69002596bbc6de7c4926f6a3a Mon Sep 17 00:00:00 2001 From: Silvia Mitter Date: Fri, 5 Mar 2021 18:43:25 +0100 Subject: [PATCH 2/4] [docker][elastic-agent] minor fixes for setup (#24384) (#24394) * [docker][elastic-agent] minor fixes for setup * fix fallback ENV vars for Elasticsearch fixes #24383 --- x-pack/elastic-agent/pkg/agent/cmd/container.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/cmd/container.go b/x-pack/elastic-agent/pkg/agent/cmd/container.go index 895317b2b43..7b1e7cea8ca 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/container.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/container.go @@ -235,8 +235,8 @@ func buildEnrollArgs(token string, policyID string) ([]string, error) { func buildFleetServerConnStr() (string, error) { host := envWithDefault(defaultESHost, "FLEET_SERVER_ELASTICSEARCH_HOST", "ELASTICSEARCH_HOST") - username := envWithDefault(defaultUsername, "FLEET_SERVER_ELASTICSEARCH_USERNAME", "$ELASTICSEARCH_USERNAME") - password := envWithDefault(defaultPassword, "FLEET_SERVER_ELASTICSEARCH_PASSWORD", "$ELASTICSEARCH_PASSWORD") + username := envWithDefault(defaultUsername, "FLEET_SERVER_ELASTICSEARCH_USERNAME", "ELASTICSEARCH_USERNAME") + password := envWithDefault(defaultPassword, "FLEET_SERVER_ELASTICSEARCH_PASSWORD", "ELASTICSEARCH_PASSWORD") u, err := url.Parse(host) if err != nil { return "", err @@ -289,8 +289,8 @@ func kibanaFetchToken(client *kibana.Client, policy *kibanaPolicy, streams *cli. func kibanaClient() (*kibana.Client, error) { host := envWithDefault(defaultKibanaHost, "KIBANA_FLEET_HOST", "KIBANA_HOST") - username := envWithDefault(defaultUsername, "KIBANA_FLEET_USERNAME", "KIBANA_USERNAME", "$ELASTICSEARCH_USERNAME") - password := envWithDefault(defaultPassword, "KIBANA_FLEET_PASSWORD", "KIBANA_PASSWORD", "$ELASTICSEARCH_PASSWORD") + username := envWithDefault(defaultUsername, "KIBANA_FLEET_USERNAME", "KIBANA_USERNAME", "ELASTICSEARCH_USERNAME") + password := envWithDefault(defaultPassword, "KIBANA_FLEET_PASSWORD", "KIBANA_PASSWORD", "ELASTICSEARCH_PASSWORD") return kibana.NewClientWithConfig(&kibana.ClientConfig{ Host: host, Username: username, From 85f7e8c4f72e0e1c0493d16095c636f0bee0ad37 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Fri, 5 Mar 2021 13:15:15 -0500 Subject: [PATCH 3/4] Fix FLEET_SERVER_INSECURE_HTTP to use correct parameter on bootstrap. (#24386) (#24398) (cherry picked from commit ea4cb94abdf64f74a26bbc92e7511c401a3570e9) --- x-pack/elastic-agent/pkg/agent/cmd/container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/elastic-agent/pkg/agent/cmd/container.go b/x-pack/elastic-agent/pkg/agent/cmd/container.go index 7b1e7cea8ca..cd3a6741eca 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/container.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/container.go @@ -216,7 +216,7 @@ func buildEnrollArgs(token string, policyID string) ([]string, error) { args = append(args, "--fleet-server-cert-key", certKey) } if envBool("FLEET_SERVER_INSECURE_HTTP") { - args = append(args, "--fleet-server--insecure-http") + args = append(args, "--fleet-server-insecure-http") args = append(args, "--insecure") } } else { From 8100dd1b008f2ad39840126290382cc963b4085d Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Sat, 6 Mar 2021 11:09:51 +0100 Subject: [PATCH 4/4] [Ingest-Manager] Fix capabilities resolution in inspect command (#24346) (#24400) [Ingest-Manager] Fix capabilities resolution in inspect command (#24346) --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + .../elastic-agent/pkg/capabilities/input.go | 20 ++++++++-- .../elastic-agent/pkg/capabilities/output.go | 39 +++++++++++++++++-- .../elastic-agent/pkg/capabilities/upgrade.go | 2 +- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 4ceaff77f46..f8fa04066ef 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -37,6 +37,7 @@ - Fix reloading of log level for services {pull}[24055]24055 - Fix: Successfully installed and enrolled agent running standalone{pull}[24128]24128 - Make installer atomic on windows {pull}[24253]24253 +- Fix capabilities resolution in inspect command {pull}[24346]24346 ==== New features diff --git a/x-pack/elastic-agent/pkg/capabilities/input.go b/x-pack/elastic-agent/pkg/capabilities/input.go index 6515bd5b715..11cb818883a 100644 --- a/x-pack/elastic-agent/pkg/capabilities/input.go +++ b/x-pack/elastic-agent/pkg/capabilities/input.go @@ -92,11 +92,23 @@ func inputsMap(cfgInputs interface{}, l *logger.Logger) []map[string]interface{} inputsMap := make([]map[string]interface{}, 0, len(inputsSet)) for _, s := range inputsSet { - mm, ok := s.(map[string]interface{}) - if !ok { + switch mm := s.(type) { + case map[string]interface{}: + inputsMap = append(inputsMap, mm) + case map[interface{}]interface{}: + newMap := make(map[string]interface{}) + for k, v := range mm { + key, ok := k.(string) + if !ok { + continue + } + + newMap[key] = v + } + inputsMap = append(inputsMap, newMap) + default: continue } - inputsMap = append(inputsMap, mm) } return inputsMap @@ -188,7 +200,7 @@ func (c *multiInputsCapability) Apply(in interface{}) (interface{}, error) { inputsMap, err = c.cleanupInput(inputsMap) if err != nil { - c.log.Errorf("cleaning up config object failed for capability 'multi-outputs': %v", err) + c.log.Errorf("cleaning up config object failed for capability 'multi-inputs': %v", err) return in, nil } diff --git a/x-pack/elastic-agent/pkg/capabilities/output.go b/x-pack/elastic-agent/pkg/capabilities/output.go index bf47123f337..593b1bb3130 100644 --- a/x-pack/elastic-agent/pkg/capabilities/output.go +++ b/x-pack/elastic-agent/pkg/capabilities/output.go @@ -182,11 +182,21 @@ func (c *multiOutputsCapability) cleanupOutput(cfgMap map[string]interface{}) (m return cfgMap, nil } - outputsMap, ok := outputsIface.(map[string]interface{}) - if !ok { + switch outputsMap := outputsIface.(type) { + case map[string]interface{}: + handleOutputMapStr(outputsMap) + cfgMap[outputKey] = outputsMap + case map[interface{}]interface{}: + handleOutputMapIface(outputsMap) + cfgMap[outputKey] = outputsMap + default: return nil, fmt.Errorf("outputs must be a map") } + return cfgMap, nil +} + +func handleOutputMapStr(outputsMap map[string]interface{}) { for outputName, outputIface := range outputsMap { acceptValue := true @@ -208,7 +218,28 @@ func (c *multiOutputsCapability) cleanupOutput(cfgMap map[string]interface{}) (m delete(outputMap, conditionKey) } +} - cfgMap[outputKey] = outputsMap - return cfgMap, nil +func handleOutputMapIface(outputsMap map[interface{}]interface{}) { + for outputName, outputIface := range outputsMap { + acceptValue := true + + outputMap, ok := outputIface.(map[interface{}]interface{}) + if ok { + conditionIface, found := outputMap[conditionKey] + if found { + conditionVal, ok := conditionIface.(bool) + if ok { + acceptValue = conditionVal + } + } + } + + if !acceptValue { + delete(outputsMap, outputName) + continue + } + + delete(outputMap, conditionKey) + } } diff --git a/x-pack/elastic-agent/pkg/capabilities/upgrade.go b/x-pack/elastic-agent/pkg/capabilities/upgrade.go index 8712529c841..94969e5dd40 100644 --- a/x-pack/elastic-agent/pkg/capabilities/upgrade.go +++ b/x-pack/elastic-agent/pkg/capabilities/upgrade.go @@ -147,7 +147,7 @@ type multiUpgradeCapability struct { func (c *multiUpgradeCapability) Apply(in interface{}) (interface{}, error) { upgradeMap := upgradeObject(in) if upgradeMap == nil { - c.log.Warnf("expecting map config object but got nil for capability 'multi-outputs'") + c.log.Warnf("expecting map config object but got nil for capability 'multi-upgrade'") // not an upgrade we don't alter origin return in, nil }