|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * logging/performance_reliability/logging-content-filtering.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="logging-content-filter-drop-records_{context}"] |
| 7 | += Configuring content filters to drop unwanted log records |
| 8 | + |
| 9 | +When the `drop` filter is configured, the log collector evaluates log streams according to the filters before forwarding. The collector drops unwanted log records that match the specified configuration. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* You have installed the {clo}. |
| 14 | +* You have administrator permissions. |
| 15 | +* You have created a `ClusterLogForwarder` custom resource (CR). |
| 16 | +
|
| 17 | +.Procedure |
| 18 | + |
| 19 | +. Add a configuration for a filter to the `filters` spec in the `ClusterLogForwarder` CR. |
| 20 | ++ |
| 21 | +The following example shows how to configure the `ClusterLogForwarder` CR to drop log records based on regular expressions: |
| 22 | ++ |
| 23 | +.Example `ClusterLogForwarder` CR |
| 24 | +[source,yaml] |
| 25 | +---- |
| 26 | +apiVersion: logging.openshift.io/v1 |
| 27 | +kind: ClusterLogForwarder |
| 28 | +metadata: |
| 29 | +# ... |
| 30 | +spec: |
| 31 | + filters: |
| 32 | + - name: <filter_name> |
| 33 | + type: drop # <1> |
| 34 | + drop: # <2> |
| 35 | + test: # <3> |
| 36 | + - field: .kubernetes.labels."foo-bar/baz" # <4> |
| 37 | + matches: .+ # <5> |
| 38 | + - field: .kubernetes.pod_name |
| 39 | + notMatches: "my-pod" # <6> |
| 40 | + pipelines: |
| 41 | + - name: <pipeline_name> # <7> |
| 42 | + filterRefs: ["<filter_name>"] |
| 43 | +# ... |
| 44 | +---- |
| 45 | +<1> Specifies the type of filter. The `drop` filter drops log records that match the filter configuration. |
| 46 | +<2> Specifies configuration options for applying the `drop` filter. |
| 47 | +<3> Specifies the configuration for tests that are used to evaluate whether a log record is dropped. |
| 48 | +** If all the conditions specified for a test are true, the test passes and the log record is dropped. |
| 49 | +** When multiple tests are specified for the `drop` filter configuration, if any of the tests pass, the record is dropped. |
| 50 | +** If there is an error evaluating a condition, for example, the field is missing from the log record being evaluated, that condition evaluates to false. |
| 51 | +<4> Specifies a dot-delimited field path, which is a path to a field in the log record. The path can contain alpha-numeric characters and underscores (`a-zA-Z0-9_`), for example, `.kubernetes.namespace_name`. If segments contain characters outside of this range, the segment must be in quotes, for example, `.kubernetes.labels."foo.bar-bar/baz"`. You can include multiple field paths in a single `test` configuration, but they must all evaluate to true for the test to pass and the `drop` filter to be applied. |
| 52 | +<5> Specifies a regular expression. If log records match this regular expression, they are dropped. You can set either the `matches` or `notMatches` condition for a single `field` path, but not both. |
| 53 | +<6> Specifies a regular expression. If log records do not match this regular expression, they are dropped. You can set either the `matches` or `notMatches` condition for a single `field` path, but not both. |
| 54 | +<7> Specifies the pipeline that the `drop` filter is applied to. |
| 55 | + |
| 56 | +. Apply the `ClusterLogForwarder` CR by running the following command: |
| 57 | ++ |
| 58 | +[source,terminal] |
| 59 | +---- |
| 60 | +$ oc apply -f <filename>.yaml |
| 61 | +---- |
| 62 | + |
| 63 | +.Additional examples |
| 64 | + |
| 65 | +The following additional example shows how you can configure the `drop` filter to only keep higher priority log records: |
| 66 | + |
| 67 | +[source,yaml] |
| 68 | +---- |
| 69 | +apiVersion: logging.openshift.io/v1 |
| 70 | +kind: ClusterLogForwarder |
| 71 | +metadata: |
| 72 | +# ... |
| 73 | +spec: |
| 74 | + filters: |
| 75 | + - name: important |
| 76 | + type: drop |
| 77 | + drop: |
| 78 | + test: |
| 79 | + - field: .message |
| 80 | + notMatches: "(?i)critical|error" |
| 81 | + - field: .level |
| 82 | + matches: "info|warning" |
| 83 | +# ... |
| 84 | +---- |
| 85 | + |
| 86 | +In addition to including multiple field paths in a single `test` configuration, you can also include additional tests that are treated as _OR_ checks. In the following example, records are dropped if either `test` configuration evaluates to true. However, for the second `test` configuration, both field specs must be true for it to be evaluated to true: |
| 87 | + |
| 88 | +[source,yaml] |
| 89 | +---- |
| 90 | +apiVersion: logging.openshift.io/v1 |
| 91 | +kind: ClusterLogForwarder |
| 92 | +metadata: |
| 93 | +# ... |
| 94 | +spec: |
| 95 | + filters: |
| 96 | + - name: important |
| 97 | + type: drop |
| 98 | + drop: |
| 99 | + test: |
| 100 | + - field: .kubernetes.namespace_name |
| 101 | + matches: "^open" |
| 102 | + test: |
| 103 | + - field: .log_type |
| 104 | + matches: "application" |
| 105 | + - field: .kubernetes.pod_name |
| 106 | + notMatches: "my-pod" |
| 107 | +# ... |
| 108 | +---- |
0 commit comments