Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename filters with processors #1944

Merged
merged 1 commit into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha3...master[Check the HEAD d
==== Breaking changes

*Affecting all Beats*
- Rename the `filters` section to `processors`. {pull}1944[1944]

*Metricbeat*

Expand Down
15 changes: 8 additions & 7 deletions filebeat/filebeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,28 +257,29 @@ filebeat.prospectors:
# default is the number of logical CPUs available in the system.
#max_procs:

#================================ Filters =====================================
#================================ Processors =====================================

# This section defines a list of filtering rules that are applied one by one
# starting with the exported event:
# Processors are used to reduce the number of fields in the exported event or to
# enhance the event with external meta data. This section defines a list of processors
# that are applied one by one and the first one receives the initial event:
#
# event -> filter1 -> event1 -> filter2 ->event2 ...
#
# Supported actions: drop_fields, drop_event, include_fields
# Supported processors: drop_fields, drop_event, include_fields
#
# For example, the following filter configuration uses multiple actions to keep
# For example, you can use the following processors to keep
# the fields that contain CPU load percentages, but remove the fields that
# contain CPU ticks values:
#
#filters:
#processors:
#- include_fields:
# fields: ["cpu"]
#- drop_fields:
# fields: ["cpu.user", "cpu.system"]
#
# The following example drops the events that have the HTTP response code 200:
#
#filters:
#processors:
#- drop_event:
# equals:
# http.code: 200
Expand Down
2 changes: 1 addition & 1 deletion filebeat/tests/system/config/filebeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ geoip:
{%- if drop_fields or drop_event or include_fields %}

#================================ Filters =====================================
filters:
processors:

{%- if include_fields %}
- include_fields:
Expand Down
22 changes: 11 additions & 11 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ import (

"github.com/elastic/beats/libbeat/cfgfile"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/filter"
_ "github.com/elastic/beats/libbeat/filter/rules"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/paths"
"github.com/elastic/beats/libbeat/processors"
_ "github.com/elastic/beats/libbeat/processors/actions"
"github.com/elastic/beats/libbeat/publisher"
svc "github.com/elastic/beats/libbeat/service"
"github.com/satori/go.uuid"
Expand Down Expand Up @@ -107,16 +107,16 @@ type Beat struct {
Config BeatConfig // Common Beat configuration data.
Publisher *publisher.Publisher // Publisher

filters *filter.Filters // Filters
processors *processors.Processors // Processors
}

// BeatConfig struct contains the basic configuration of every beat
type BeatConfig struct {
Shipper publisher.ShipperConfig `config:",inline"`
Output map[string]*common.Config `config:"output"`
Logging logp.Logging `config:"logging"`
Filters filter.FilterPluginConfig `config:"filters"`
Path paths.Path `config:"path"`
Shipper publisher.ShipperConfig `config:",inline"`
Output map[string]*common.Config `config:"output"`
Logging logp.Logging `config:"logging"`
Processors processors.PluginConfig `config:"processors"`
Path paths.Path `config:"path"`
}

// Run initializes and runs a Beater implementation. name is the name of the
Expand Down Expand Up @@ -223,9 +223,9 @@ func (bc *instance) config() error {
// log paths values to help with troubleshooting
logp.Info(paths.Paths.String())

bc.data.filters, err = filter.New(bc.data.Config.Filters)
bc.data.processors, err = processors.New(bc.data.Config.Processors)
if err != nil {
return fmt.Errorf("error initializing filters: %v", err)
return fmt.Errorf("error initializing processors: %v", err)
}

if bc.data.Config.Shipper.MaxProcs != nil {
Expand All @@ -251,7 +251,7 @@ func (bc *instance) setup() error {
return fmt.Errorf("error initializing publisher: %v", err)
}

bc.data.Publisher.RegisterFilter(bc.data.filters)
bc.data.Publisher.RegisterProcessors(bc.data.processors)
err = bc.beater.Setup(bc.data)
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions libbeat/docs/filtering.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
//// include::../../libbeat/docs/filtering.asciidoc[]
//////////////////////////////////////////////////////////////////////////

Generic filtering is available to all Beats through libbeat. With generic filtering, you can reduce the number of
fields that are exported by the Beat by defining a list of filter actions that are applied to each event before it's
sent to the defined output. The filter actions are executed in the order that they are defined in the config file.
You can defined processors in any Beat as it is part of libbeat. Processors are used to reduce the number of
the exported fields, but also to enhance them with additional meta data.
Each processor receives an event, applies a defined action to the event and returns it. In case you define a list of
processors, then they are executed in the order they are defined in the configuration file.

You can define the filter actions under the `filters` section of the {beatname_uc} configuration file.
The processors are defined in the {beatname_uc} configuration file.
24 changes: 13 additions & 11 deletions libbeat/docs/filteringconfig.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@
//////////////////////////////////////////////////////////////////////////

[[configuration-filter]]
=== Filters Configuration
=== Processors

You can set a list of filter actions in the `filters` section of the +{beatname_lc}.yml+ config file to reduce the number
You can define a set of `processors` in the +{beatname_lc}.yml+ config file to reduce the number
of fields that are exported by the Beat.

If more filtering rules are defined, then they are executed in the order they are defined. The initial event is passed to the first filtering rule and what results from it is passed to the second filtering rule until all the filtering rules are applied. The condition that is used in the following filtering rules is running against the event that is received as input and it might defer from the original event.
If more processors are defined, then they are executed in the order they are defined. The initial event is passed to the
first processor and what results from it is passed to the second processor until all processors are applied. The
condition is checked against the event that is received as input and it might defer from the original event.

[source,yaml]
-------
event -> filter action 1 -> event1 -> filter action 2 -> event2 ...
event -> processor 1 -> event1 -> processor 2 -> event2 ...
-------

See <<exported-fields>> for the full list of possible fields.

Each filter action receives a condition and optionally a set of arguments. The action is executed only if the condition
Each processor receives a condition and optionally a set of arguments. The action is executed only if the condition
is fulfilled.

[source,yaml]
------
filters:
processors:
- action1:
condition1
[arguments]
Expand All @@ -44,7 +46,7 @@ filters:
See <<filtering-data>> for specific {beatname_uc} examples.

[[filtering-condition]]
==== Filtering condition
==== Condition

Each condition receives a field to compare or multiple fields under the same condition and then `AND` is used between
them. You can see a list of the <<exported-fields,`exported fields`>>.
Expand Down Expand Up @@ -138,7 +140,7 @@ range:
cpu.user_p: 0.8
------

==== Filtering Actions
==== Actions

The supported filter actions are:

Expand All @@ -156,7 +158,7 @@ optional and if it's missing then the defined fields are always exported. The `@

[source,yaml]
-------
filters:
processors:
- include_fields:
[condition]
fields: ["field1", "field2", ...]
Expand All @@ -178,7 +180,7 @@ even if they show up in the `drop_fields` list.

[source,yaml]
-----------------------------------------------------
filters:
processors:
- drop_fields:
[condition]
fields: ["field1", "field2", ...]
Expand All @@ -195,7 +197,7 @@ without one all the events are dropped.

[source,yaml]
------
filters:
processors:
- drop_event:
condition
------
Expand Down
87 changes: 0 additions & 87 deletions libbeat/filter/filter.go

This file was deleted.

28 changes: 0 additions & 28 deletions libbeat/filter/registry.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package rules
package actions

import (
"fmt"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/filter"
"github.com/elastic/beats/libbeat/processors"
)

type DropEvent struct {
Cond *filter.Condition
Cond *processors.Condition
}

type DropEventConfig struct {
filter.ConditionConfig `config:",inline"`
processors.ConditionConfig `config:",inline"`
}

func init() {
if err := filter.RegisterPlugin("drop_event", newDropEvent); err != nil {
if err := processors.RegisterPlugin("drop_event", newDropEvent); err != nil {
panic(err)
}
}

func newDropEvent(c common.Config) (filter.FilterRule, error) {
func newDropEvent(c common.Config) (processors.Processor, error) {

f := DropEvent{}

Expand All @@ -36,7 +36,7 @@ func newDropEvent(c common.Config) (filter.FilterRule, error) {
return nil, fmt.Errorf("fail to unpack the drop_event configuration: %s", err)
}

cond, err := filter.NewCondition(config.ConditionConfig)
cond, err := processors.NewCondition(config.ConditionConfig)
if err != nil {
return nil, err
}
Expand All @@ -48,14 +48,14 @@ func newDropEvent(c common.Config) (filter.FilterRule, error) {
func (f *DropEvent) CheckConfig(c common.Config) error {

for _, field := range c.GetFields() {
if !filter.AvailableCondition(field) {
if !processors.AvailableCondition(field) {
return fmt.Errorf("unexpected %s option in the drop_event configuration", field)
}
}
return nil
}

func (f *DropEvent) Filter(event common.MapStr) (common.MapStr, error) {
func (f *DropEvent) Run(event common.MapStr) (common.MapStr, error) {

if f.Cond != nil && !f.Cond.Check(event) {
return event, nil
Expand Down
Loading