Skip to content

Commit

Permalink
[doc][processor/filter] update examples on readme to ensure validity (#…
Browse files Browse the repository at this point in the history
…18918)

doc: update README.md where all the examples are valid
  • Loading branch information
edwintye authored Feb 27, 2023
1 parent ca0d35c commit 57cfee7
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions processor/filterprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ For metrics:
- `match_type`: `strict`|`regexp`|`expr`
- `metric_names`: (only for a `match_type` of `strict` or `regexp`) list of strings
or re2 regex patterns
- `expressions`: (only for a `match_type` of `expr`) list of expr expressions
(see "Using an 'expr' match_type" below)
- `expressions`: (only for a `match_type` of `expr`) list of `expr` expressions
(see "Using an `expr` match_type" below)
- `resource_attributes`: ResourceAttributes defines a list of possible resource
attributes to match metrics against.
A match occurs if any resource attribute matches all expressions in this given list.
Expand All @@ -62,7 +62,7 @@ This processor uses [re2 regex][re2_regex] for regex syntax.

[re2_regex]: https://github.com/google/re2/wiki/Syntax

More details can found at [include/exclude metrics](../attributesprocessor/README.md#includeexclude-filtering).
More details can be found at [include/exclude metrics](../attributesprocessor/README.md#includeexclude-filtering).

Examples:

Expand All @@ -76,8 +76,8 @@ processors:
- prefix/.*
- prefix_.*
resource_attributes:
- Key: container.name
Value: app_container_1
- key: container.name
value: app_container_1
exclude:
match_type: strict
metric_names:
Expand All @@ -88,22 +88,22 @@ processors:
include:
match_type: strict
resource_attributes:
- Key: host.name
Value: just_this_one_hostname
- key: host.name
value: just_this_one_hostname
filter/regexp:
logs:
include:
match_type: regexp
resource_attributes:
- Key: host.name
Value: prefix.*
- key: host.name
value: prefix.*
filter/regexp_record:
logs:
include:
match_type: regexp
record_attributes:
- Key: record_attr
Value: prefix_.*
- key: record_attr
value: prefix_.*
# Filter on severity text field
filter/severity_text:
logs:
Expand Down Expand Up @@ -132,12 +132,12 @@ processors:
Refer to the config files in [testdata](./testdata) for detailed
examples on using the processor.
## Using an 'expr' match_type
## Using an "expr" match_type
In addition to matching metric names with the 'strict' or 'regexp' match types, the filter processor
In addition to matching metric names with the `strict` or `regexp` match types, the filter processor
supports matching entire `Metric`s using the [expr](https://github.com/antonmedv/expr) expression engine.

The 'expr' filter evaluates the supplied boolean expressions _per datapoint_ on a metric, and returns a result
The `expr` filter evaluates the supplied boolean expressions _per datapoint_ on a metric, and returns a result
for the entire metric. If any datapoint evaluates to true then the entire metric evaluates to true, otherwise
false.

Expand Down Expand Up @@ -172,12 +172,12 @@ with a label of 'my_label="abc123"'.

### Support for multiple expressions

As with "strict" and "regexp", multiple "expr" `expressions` are allowed.
As with `strict` and `regexp`, multiple `expr` expressions are allowed.

For example, the following two filters have the same effect: they filter out metrics named "system.cpu.time" and
"system.disk.io".

```
```yaml
processors:
filter/expr:
metrics:
Expand All @@ -195,7 +195,7 @@ processors:
- system.disk.io
```

The expressions are effectively ORed per datapoint. So for the above 'expr' configuration, given a datapoint, if its
The expressions are effectively ORed per datapoint. So for the above `expr` configuration, given a datapoint, if its
parent Metric's name is "system.cpu.time" or "system.disk.io" then there's a match. The conditions are tested against
all the datapoints in a Metric until there's a match, in which case the entire Metric is considered a match, and in
the above example the Metric will be excluded. If after testing all the datapoints in a Metric against all the
Expand All @@ -209,48 +209,48 @@ Following example will include only the metrics coming from `app_container_1` (t

```yaml
processors:
filter:
filter/resource_attributes_include:
metrics:
include:
match_type: strict
metric_names:
- hello_world
- hello/world
resource_attributes:
- Key: container.name
Value: app_container_1
- key: container.name
value: app_container_1
```

Following example will exclude all the metrics coming from `app_container_1` (the value for `container.name` resource attribute is `app_container_1`).

```yaml
processors:
filter:
filter/resource_attributes_exclude:
metrics:
exclude:
match_type: strict
metric_names:
- hello_world
- hello/world
resource_attributes:
- Key: container.name
Value: app_container_1
- key: container.name
value: app_container_1
```

We can also use `regexp` to filter metrics using resource attributes. Following example will include only the metrics coming from `app_container_1` or `app_container_2` (the value for `container.name` resource attribute is either `app_container_1` or `app_container_2`).

```yaml
processors:
filter:
filter/resource_attributes_regexp:
metrics:
exclude:
match_type: regexp
metric_names:
- hello_world
- hello/world
resource_attributes:
- Key: container.name
Value: (app_container_1|app_container_1)
- key: container.name
value: (app_container_1|app_container_1)
```

In case the no metric names are provided, `matric_names` being empty, the filtering is only done at resource level.
Expand All @@ -267,7 +267,7 @@ non-empty value for a valid configuration.

```yaml
processors:
filter:
filter/spans:
spans:
include:
match_type: strict
Expand All @@ -282,14 +282,14 @@ processors:
- hello_world
- hello/world
attributes:
- Key: container.name
Value: (app_container_1|app_container_2)
- key: container.name
value: (app_container_1|app_container_2)
libraries:
- Name: opentelemetry
Version: 0.0-beta
- name: opentelemetry
version: 0.0-beta
resources:
- Key: container.host
Value: (localhost|127.0.0.1)
- key: container.host
value: (localhost|127.0.0.1)
```

## OTTL
Expand Down Expand Up @@ -353,7 +353,7 @@ Examples:

```yaml
processors:
filter:
filter/ottl:
traces:
span:
- 'attributes["container.name"] == "app_container_1"'
Expand All @@ -364,7 +364,7 @@ processors:
- 'IsMatch(name, ".*grpc.*") == true'
metrics:
metric:
- 'name == "my.metric" and attributes["my_label"] == "abc123"'
- 'name == "my.metric" and resource.attributes["my_label"] == "abc123"'
- 'type == METRIC_DATA_TYPE_HISTOGRAM'
datapoint:
- 'metric.type == METRIC_DATA_TYPE_SUMMARY'
Expand Down

0 comments on commit 57cfee7

Please sign in to comment.