Skip to content

Commit

Permalink
Cherry-pick #20994 to 7.x: [Elastic Agent] Add support for EQL based …
Browse files Browse the repository at this point in the history
…conditions (#21039)

* [Elastic Agent] Add support for EQL based conditions (#20994)

* Refactor Boolexp to Eql.

* Connect new Eql to specs and input emitter.

* Fix compare with null.

* Fix notice and go.mod.

(cherry picked from commit af91b5e)

* Fix go.mod from cherry-pick resolve.

* Add changelog.
  • Loading branch information
blakerouse authored Sep 9, 2020
1 parent 5142548 commit a15ddaa
Show file tree
Hide file tree
Showing 63 changed files with 6,556 additions and 4,048 deletions.
64 changes: 32 additions & 32 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2182,36 +2182,6 @@ Contents of probable licence file $GOMODCACHE/github.com/!azure/go-autorest/auto
limitations under the License.


--------------------------------------------------------------------------------
Dependency : github.com/Masterminds/semver
Version: v1.4.2
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/!masterminds/[email protected]/LICENSE.txt:

The Masterminds
Copyright (C) 2014-2015, Matt Butcher and Matt Farina

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/Microsoft/go-winio
Version: v0.4.15-0.20190919025122-fc70bd9a86b5
Expand Down Expand Up @@ -2555,11 +2525,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
Dependency : github.com/antlr/antlr4
Version: v0.0.0-20200326173327-a4c66dc863bb
Version: v0.0.0-20200820155224-be881fa6b91d
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/antlr/[email protected]20200326173327-a4c66dc863bb/LICENSE.txt:
Contents of probable licence file $GOMODCACHE/github.com/antlr/[email protected]20200820155224-be881fa6b91d/LICENSE.txt:

[The "BSD 3-clause license"]
Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
Expand Down Expand Up @@ -19266,6 +19236,36 @@ Contents of probable licence file $GOMODCACHE/github.com/!burnt!sushi/[email protected]
// such litigation is filed.


--------------------------------------------------------------------------------
Dependency : github.com/Masterminds/semver
Version: v1.4.2
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/!masterminds/[email protected]/LICENSE.txt:

The Masterminds
Copyright (C) 2014-2015, Matt Butcher and Matt Farina

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/Microsoft/hcsshim
Version: v0.8.7
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ require (
github.com/Azure/go-autorest/autorest/adal v0.8.1
github.com/Azure/go-autorest/autorest/azure/auth v0.4.2
github.com/Azure/go-autorest/autorest/date v0.2.0
github.com/Masterminds/semver v1.4.2
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5
github.com/Shopify/sarama v0.0.0-00010101000000-000000000000
github.com/StackExchange/wmi v0.0.0-20170221213301-9f32b5905fd6
github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc
github.com/akavel/rsrc v0.8.0 // indirect
github.com/andrewkroh/sys v0.0.0-20151128191922-287798fe3e43
github.com/antlr/antlr4 v0.0.0-20200326173327-a4c66dc863bb
github.com/antlr/antlr4 v0.0.0-20200820155224-be881fa6b91d
github.com/apoydence/eachers v0.0.0-20181020210610-23942921fe77 // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/aws/aws-lambda-go v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ github.com/andrewkroh/goja v0.0.0-20190128172624-dd2ac4456e20/go.mod h1:cI59GRkC
github.com/andrewkroh/sys v0.0.0-20151128191922-287798fe3e43 h1:WFwa9pqou0Nb4DdfBOyaBTH0GqLE74Qwdf61E7ITHwQ=
github.com/andrewkroh/sys v0.0.0-20151128191922-287798fe3e43/go.mod h1:tJPYQG4mnMeUtQvQKNkbsFrnmZOg59Qnf8CcctFv5v4=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
github.com/antlr/antlr4 v0.0.0-20200326173327-a4c66dc863bb h1:jGlQhNsk+RHK5IFSvL5wUi+ed8HZPBR2ovtGyahWOcU=
github.com/antlr/antlr4 v0.0.0-20200326173327-a4c66dc863bb/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y=
github.com/antlr/antlr4 v0.0.0-20200820155224-be881fa6b91d h1:OE3kzLBpy7pOJEzE55j9sdgrSilUPzzj++FWvp1cmIs=
github.com/antlr/antlr4 v0.0.0-20200820155224-be881fa6b91d/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y=
github.com/apoydence/eachers v0.0.0-20181020210610-23942921fe77 h1:afT88tB6u9JCKQZVAAaa9ICz/uGn5Uw9ekn6P22mYKM=
github.com/apoydence/eachers v0.0.0-20181020210610-23942921fe77/go.mod h1:bXvGk6IkT1Agy7qzJ+DjIw/SJ1AaB3AvAuMDVV+Vkoo=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
Expand Down
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
- Add new `synthetics/*` inputs to run Heartbeat {pull}20387[20387]
- Users of the Docker image can now pass `FLEET_ENROLL_INSECURE=1` to include the `--insecure` flag with the `elastic-agent enroll` command {issue}20312[20312] {pull}20713[20713]
- Add support for dynamic inputs with providers and `{{variable|"default"}}` substitution. {pull}20839[20839]
- Add support for EQL based condition on inputs {pull}20994[20994]
51 changes: 10 additions & 41 deletions x-pack/elastic-agent/pkg/agent/application/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type emitterController struct {
lock sync.RWMutex
config *config.Config
ast *transpiler.AST
vars []transpiler.Vars
vars []*transpiler.Vars
}

func (e *emitterController) Update(c *config.Config) error {
Expand All @@ -68,38 +68,6 @@ func (e *emitterController) Update(c *config.Config) error {
}
}

// sanitary check that nothing in the config is wrong when it comes to variable syntax
ast := rawAst.Clone()
inputs, ok := transpiler.Lookup(ast, "inputs")
if ok {
renderedInputs, err := renderInputs(inputs, []transpiler.Vars{
{
Mapping: map[string]interface{}{},
},
})
if err != nil {
return err
}
err = transpiler.Insert(ast, renderedInputs, "inputs")
if err != nil {
return err
}
}

programsToRun, err := program.Programs(ast)
if err != nil {
return err
}

for _, decorator := range e.modifiers.Decorators {
for outputType, ptr := range programsToRun {
programsToRun[outputType], err = decorator(outputType, ast, ptr)
if err != nil {
return err
}
}
}

e.lock.Lock()
e.config = c
e.ast = rawAst
Expand All @@ -108,7 +76,7 @@ func (e *emitterController) Update(c *config.Config) error {
return e.update()
}

func (e *emitterController) Set(vars []transpiler.Vars) {
func (e *emitterController) Set(vars []*transpiler.Vars) {
e.lock.Lock()
ast := e.ast
e.vars = vars
Expand Down Expand Up @@ -170,19 +138,16 @@ func (e *emitterController) update() error {
func emitter(ctx context.Context, log *logger.Logger, controller composable.Controller, router programsDispatcher, modifiers *configModifiers, reloadables ...reloadable) (emitterFunc, error) {
log.Debugf("Supported programs: %s", strings.Join(program.KnownProgramNames(), ", "))

init, _ := transpiler.NewVars(map[string]interface{}{})
ctrl := &emitterController{
logger: log,
controller: controller,
router: router,
modifiers: modifiers,
reloadables: reloadables,
vars: []transpiler.Vars{
{
Mapping: map[string]interface{}{},
},
},
vars: []*transpiler.Vars{init},
}
err := controller.Run(ctx, func(vars []transpiler.Vars) {
err := controller.Run(ctx, func(vars []*transpiler.Vars) {
ctrl.Set(vars)
})
if err != nil {
Expand All @@ -202,7 +167,7 @@ func readfiles(files []string, emitter emitterFunc) error {
return emitter(c)
}

func renderInputs(inputs transpiler.Node, varsArray []transpiler.Vars) (transpiler.Node, error) {
func renderInputs(inputs transpiler.Node, varsArray []*transpiler.Vars) (transpiler.Node, error) {
l, ok := inputs.Value().(*transpiler.List)
if !ok {
return nil, fmt.Errorf("inputs must be an array")
Expand All @@ -224,6 +189,10 @@ func renderInputs(inputs transpiler.Node, varsArray []transpiler.Vars) (transpil
// another error that needs to be reported
return nil, err
}
if n == nil {
// condition removed it
continue
}
dict = n.(*transpiler.Dict)
dict = promoteProcessors(dict)
hash := string(dict.Hash())
Expand Down
Loading

0 comments on commit a15ddaa

Please sign in to comment.