From 370b926c6773ce1e303f9ae061a67bd71caa1c23 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 17 May 2021 14:00:41 -0400 Subject: [PATCH 1/3] Fix fleet-server.yml spec to not overwrite exsting keys. --- .../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 +- 6 files changed, 176 insertions(+), 3 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/program/supported.go b/x-pack/elastic-agent/pkg/agent/program/supported.go index 9cfac186565..93bc6e722cb 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("eJzUelt3oziX9v33M/r2m5mXQ0g3s1Zf2E6DwQ4p4wQJ3SFhA7aE6RgfYNb891kSBwO2U0lVzbwzF7UqIUKHrb2f/exn8x+/7bMV+UeQsX/dr96Pq/d/Kxj97d9/w8zI0esuWnhjZ+45lKSIkijbYLB4tEzjhJdyiaCtIGjNfGhLAUCxr978W0rKXQROu8iaWLm7tPbWxM59oMVI8XIENGnOvIMP7D0CCz2c2jJaWvtJMoqsRDas5BRZTI4xM1IEZIrTxQEDfYte5Yc5HMe+ss8RO1MEF8l81FsjJqaUE8UrQuYVc+bGoWmsieoWCBg5KTSKmZFg09t+g24Rgrfh+6kv6ycE7Q3f47el+zu3xZvkLb2tt4RS+M2Vnh+fX0en9dKawUVWhOBMSbmbWZNRbpnOkUzpOjT1NTZpGT6J5xH/F0CX4tddVO+7fR6afzxaJj2QqScRYS/+fHzEVN9gRWPYpJvwaRdhph+J2KsUYWCcXqJ27MmH7u4lGTNsejQctc+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6bPZwpImy2XJbR93jJ2xwIjITJIssGhuP5+UbcE2SrJgkctX9GuEvzzWs5PaiZdqvRQL6nOr9GSm2Qv9WfT2FNBTtWH1P8rusr/D/1k9/sv//0v/xMAAP//PEBz+A==") 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..c0f3be099c5 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_defauls: + 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 From 45600511af131a15709de8c9e3ace7cfcc216188 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 17 May 2021 14:03:57 -0400 Subject: [PATCH 2/3] Add changelog. --- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index ae4acaa856a..dd282502dc2 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -66,6 +66,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 From f98bc50553b8e6d60db22e5ee8b1549c29b88f5d Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 17 May 2021 14:52:15 -0400 Subject: [PATCH 3/3] Fix test. --- x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c0f3be099c5..d6f24a8d8e3 100644 --- a/x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go +++ b/x-pack/elastic-agent/pkg/agent/transpiler/rules_test.go @@ -842,7 +842,7 @@ func TestSerialization(t *testing.T) { - s1 - s2 path: target -- insert_defauls: +- insert_defaults: selectors: - s1 - s2