From 64ec737675b37df6d6af5013f485a12cbdc751ad Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 18 May 2021 08:03:31 +0200 Subject: [PATCH] [7.13](backport #25741) [Elastic Agent] Fix fleet-server.yml spec to not overwrite existing keys (#25745) * Fix fleet-server.yml spec to not overwrite exsting keys. (cherry picked from commit e1676e76e5e4661567d6a71f6c398698b64852c1) --- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + .../pkg/agent/program/supported.go | 2 +- .../testdata/fleet_server-fleet-server.yml | 15 ++++ .../agent/program/testdata/fleet_server.yml | 19 ++++- .../pkg/agent/transpiler/rules.go | 75 +++++++++++++++++++ .../pkg/agent/transpiler/rules_test.go | 66 ++++++++++++++++ x-pack/elastic-agent/spec/fleet-server.yml | 2 +- 7 files changed, 177 insertions(+), 3 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index e28707cdbbd..07c6c77754b 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -67,6 +67,7 @@ - Fix AckBatch to do nothing when no actions passed {pull}25562[25562] - Add error log entry when listener creation fails {issue}23483[23482] - Handle case where policy doesn't contain Fleet connection information {pull}25707[25707] +- Fix fleet-server.yml spec to not overwrite existing keys {pull}25741[25741] ==== New features diff --git a/x-pack/elastic-agent/pkg/agent/program/supported.go b/x-pack/elastic-agent/pkg/agent/program/supported.go index da5369ce8ae..e53d7dbe26f 100644 --- a/x-pack/elastic-agent/pkg/agent/program/supported.go +++ b/x-pack/elastic-agent/pkg/agent/program/supported.go @@ -25,7 +25,7 @@ func init() { // spec/metricbeat.yml // spec/osquerybeat.yml // spec/packetbeat.yml - unpacked := packer.MustUnpack("eJzUWlt3oziXfZ+f0a9z+bjE6WbW6gebNBjskDKOJaE3JNmALTAdX2HW/PdZ4g52Ukl1fZd5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/i37maq6jJE9Gt60f8ct+/czy8cMsZBBv6DgSA1962dyJSV91B7e3q5/ilFyaUZjICh6xnTtTHgd6e7GU8KQxIwLRBPt4wP2eOM7T3VTwRyrCN0UVam6NSe1/xf7f7Xb9L/jh0BaThHgNNl9El0+d+MwaBW/KcX80z6Mycq20zaPGROtO5T5PBbtZahZ0z80a0rztxcv6baPqU9363s6zkokjAKkXvtoCsg/cmYM2seMHt2yT/1G6yjG3IyVMJQvxdX4HUCws0tgZ7Je/K986vOZAtLmq1UJbR+3jP2xhpZgESTZ6FBcf7/IOwxtGWfsUctXtKsY/byW85OaSZ8qPdRLqvNrtOQm2Uv9WddSEuNz/dXe30NX+f+hn+x//+V//+3/AgAA///5lmgc") SupportedMap = make(map[string]Spec) for f, v := range unpacked { diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml index c03696aff1f..c0c6066b55f 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server-fleet-server.yml @@ -14,3 +14,18 @@ output: inputs: - id: fleet-server-id type: fleet-server + name: fleet_server-1 + revision: 6 + server: + host: 0.0.0.0 + port: 8220 + ssl: + verification_mode: none + limits: + max_connections: 40 + runtime: + gc_percent: 50 + timeouts: + read: 5m + policy: + id: copy-policy-id diff --git a/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml index 8268f258fb5..a816197917e 100644 --- a/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml +++ b/x-pack/elastic-agent/pkg/agent/program/testdata/fleet_server.yml @@ -11,6 +11,12 @@ fleet: host: id: host-agent-id server: + host: 127.0.0.1 + port: 8822 + ssl: + verification_mode: none + policy: + id: copy-policy-id output: elasticsearch: hosts: [ 127.0.0.1:9200, 127.0.0.1:9300 ] @@ -31,4 +37,15 @@ inputs: type: fleet-server use_output: default data_stream: - type: default + namespace: default + name: fleet_server-1 + revision: 6 + server: + host: 0.0.0.0 + port: 8220 + limits: + max_connections: 40 + runtime: + gc_percent: 50 + timeouts: + read: 5m diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/rules.go b/x-pack/elastic-agent/pkg/agent/transpiler/rules.go index 6e3c55d825f..9135c751d3a 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/rules.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/rules.go @@ -88,6 +88,8 @@ func (r *RuleList) MarshalYAML() (interface{}, error) { name = "remove_key" case *FixStreamRule: name = "fix_stream" + case *InsertDefaultsRule: + name = "insert_defaults" default: return nil, fmt.Errorf("unknown rule of type %T", rule) } @@ -171,6 +173,8 @@ func (r *RuleList) UnmarshalYAML(unmarshal func(interface{}) error) error { r = &RemoveKeyRule{} case "fix_stream": r = &FixStreamRule{} + case "insert_defaults": + r = &InsertDefaultsRule{} default: return fmt.Errorf("unknown rule of type %s", name) } @@ -1430,6 +1434,77 @@ func (r *FilterValuesWithRegexpRule) Apply(_ AgentInfo, ast *AST) (err error) { return nil } +// InsertDefaultsRule inserts selected paths into keys if they do not exist. +// +// In the case that an exiting key already exists then it is not inserted. +type InsertDefaultsRule struct { + Selectors []Selector + Path string +} + +// Apply applies select into rule. +func (r *InsertDefaultsRule) Apply(_ AgentInfo, ast *AST) (err error) { + defer func() { + if err != nil { + err = errors.New(err, "failed to select data into configuration") + } + }() + + insertTo := ast.root + for _, part := range splitPath(r.Path) { + n, ok := insertTo.Find(part) + if !ok { + insertTo = nil + break + } + insertTo = n + } + + // path completely missing; easy path is just to insert all selectors + if insertTo == nil { + target := &Dict{} + for _, selector := range r.Selectors { + lookupNode, ok := Lookup(ast.Clone(), selector) + if !ok { + continue + } + target.value = append(target.value, lookupNode.Clone()) + } + if len(target.value) > 0 { + return Insert(ast, target, r.Path) + } + return nil + } + + // path does exist, so we insert the keys only if they don't exist + for _, selector := range r.Selectors { + lookupNode, ok := Lookup(ast.Clone(), selector) + if !ok { + continue + } + switch lt := lookupNode.(type) { + case *Key: + _, ok := insertTo.Find(lt.name) + if !ok { + // doesn't exist; insert it + if err := Insert(ast, lt, r.Path); err != nil { + return err + } + } + } + } + + return nil +} + +// InsertDefaults creates a InsertDefaultsRule +func InsertDefaults(path string, selectors ...Selector) *InsertDefaultsRule { + return &InsertDefaultsRule{ + Selectors: selectors, + Path: path, + } +} + // NewRuleList returns a new list of rules to be executed. func NewRuleList(rules ...Rule) *RuleList { return &RuleList{Rules: rules} diff --git a/x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go b/x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go index 0fb59107844..d6f24a8d8e3 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go @@ -653,6 +653,66 @@ logs: }, }, }, + "insert defaults into existing": { + givenYAML: ` +level_one: + key1: val1 + key2: + d_key1: val2 + d_key2: val3 + level_two: + key2: + d_key3: val3 + d_key4: val4 +rest: of +`, + expectedYAML: ` +level_one: + key1: val1 + key2: + d_key1: val2 + d_key2: val3 + level_two: + key1: val1 + key2: + d_key3: val3 + d_key4: val4 +rest: of +`, + rule: &RuleList{ + Rules: []Rule{ + InsertDefaults("level_one.level_two", "level_one.key1", "level_one.key2"), + }, + }, + }, + "insert defaults into not existing": { + givenYAML: ` +level_one: + key1: val1 + key2: + d_key1: val2 + d_key2: val3 +rest: of +`, + expectedYAML: ` +level_one: + key1: val1 + key2: + d_key1: val2 + d_key2: val3 + level_two: + key1: val1 + key2: + d_key1: val2 + d_key2: val3 +rest: of +`, + rule: &RuleList{ + Rules: []Rule{ + InsertDefaults("level_one.level_two", "level_one.key1", "level_one.key2"), + }, + }, + }, } for name, test := range testcases { @@ -716,6 +776,7 @@ func TestSerialization(t *testing.T) { CopyAllToList("t2", "insert_before", "a", "b"), FixStream(), SelectInto("target", "s1", "s2"), + InsertDefaults("target", "s1", "s2"), ) y := `- rename: @@ -781,6 +842,11 @@ func TestSerialization(t *testing.T) { - s1 - s2 path: target +- insert_defaults: + selectors: + - s1 + - s2 + path: target ` t.Run("serialize_rules", func(t *testing.T) { diff --git a/x-pack/elastic-agent/spec/fleet-server.yml b/x-pack/elastic-agent/spec/fleet-server.yml index 31cf9446da7..8cb80280842 100644 --- a/x-pack/elastic-agent/spec/fleet-server.yml +++ b/x-pack/elastic-agent/spec/fleet-server.yml @@ -28,7 +28,7 @@ rules: selectors: [ fleet.server.policy.id ] path: inputs.0.policy - - select_into: + - insert_defaults: selectors: - fleet.server.host - fleet.server.port