|
| 1 | +# FLP filtering language |
| 2 | + |
| 3 | +Flowlogs-pipeline uses a simple query language to filter network flows: |
| 4 | + |
| 5 | +``` |
| 6 | +(srcnamespace="netobserv" OR (srcnamespace="ingress" AND dstnamespace="netobserv")) AND srckind!="service" |
| 7 | +``` |
| 8 | + |
| 9 | +The syntax includes: |
| 10 | + |
| 11 | +- Logical boolean operators (case insensitive) |
| 12 | + - `and` |
| 13 | + - `or` |
| 14 | +- String comparison operators |
| 15 | + - equals `=` |
| 16 | + - not equals `!=` |
| 17 | + - matches regexp `=~` |
| 18 | + - not matches regexp `!~` |
| 19 | +- Unary operations |
| 20 | + - field is present: `with(field)` |
| 21 | + - field is absent: `without(field)` |
| 22 | +- Parenthesis-based priority |
| 23 | + |
| 24 | +## API integration |
| 25 | + |
| 26 | +The language is currently integrated in the "keep_entry" transform/filtering API. Example: |
| 27 | + |
| 28 | +```yaml |
| 29 | + transform: |
| 30 | + type: filter |
| 31 | + filter: |
| 32 | + rules: |
| 33 | + - type: keep_entry_query |
| 34 | + keepEntryQuery: (namespace="A" and with(workload)) or service=~"abc.+" |
| 35 | + keepEntrySampling: 10 # Optionally, a sampling ratio can be associated with the filter |
| 36 | +``` |
| 37 | +
|
| 38 | +## Integration with the NetObserv operator |
| 39 | +
|
| 40 | +In the [NetObserv operator](https://github.com/netobserv/network-observability-operator), the filtering query language is used in `FlowCollector` `spec.processor.filters`. Example: |
| 41 | + |
| 42 | +```yaml |
| 43 | +spec: |
| 44 | + processor: |
| 45 | + filters: |
| 46 | + - query: | |
| 47 | + (SrcK8S_Namespace="netobserv" OR (SrcK8S_Namespace="openshift-ingress" AND DstK8S_Namespace="netobserv")) |
| 48 | + outputTarget: Loki # The filter can target a specific output (such as Loki logs or exported data), or all outputs. |
| 49 | + sampling: 10 # Optionally, a sampling ratio can be associated with the filter |
| 50 | +``` |
| 51 | + |
| 52 | +See also the [list of field names](https://github.com/netobserv/network-observability-operator/blob/main/docs/flows-format.adoc) that are available for queries, and the [API documentation](https://github.com/netobserv/network-observability-operator/blob/main/docs/FlowCollector.md#flowcollectorspecprocessorfiltersindex-1). |
| 53 | + |
| 54 | +## Internals |
| 55 | + |
| 56 | +This language is designed using [Yacc](https://en.wikipedia.org/wiki/Yacc) / goyacc. |
| 57 | + |
| 58 | +The [definition file](../pkg/dsl/expr.y) describes the syntax based on a list of tokens. It is derived to a [go source file](../pkg/dsl/expr.y.go) using [goyacc](https://pkg.go.dev/golang.org/x/tools/cmd/goyacc), which defines constants for the tokens, among other things. The [lexer](../pkg/dsl/lexer.go) file defines structures and helpers that can be used from `expr.y`, the logic used to interpret the language in a structured way, and is also where actual characters/strings are mapped to syntax tokens. Finally, [eval.go](../pkg/dsl/eval.go) runs the desired query on actual data. |
| 59 | + |
| 60 | +When adding features to the language, you'll likely have to change `expr.y` and `lexer.go`. |
| 61 | + |
| 62 | +To regenerate `expr.y.go`, run: |
| 63 | + |
| 64 | +```bash |
| 65 | +make goyacc |
| 66 | +``` |
0 commit comments