From 0f8f307d2130d82f694ede997028592d98606afd Mon Sep 17 00:00:00 2001 From: Robert Fekete Date: Tue, 21 Mar 2023 14:44:43 +0100 Subject: [PATCH] Adds advanced Flow examples page and examples from https://github.com/kube-logging/logging-operator/issues/1234 Examples provided by genofire --- content/docs/examples/_index.md | 2 +- content/docs/examples/flows/_index.md | 25 ++++++ .../examples/flows/logging_flow_coredns.yaml | 36 ++++++++ .../flows/logging_flow_nginx_ingress.yaml | 85 +++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 content/docs/examples/flows/_index.md create mode 100644 content/docs/examples/flows/logging_flow_coredns.yaml create mode 100644 content/docs/examples/flows/logging_flow_nginx_ingress.yaml diff --git a/content/docs/examples/_index.md b/content/docs/examples/_index.md index 4ea52d99d..30adf2213 100644 --- a/content/docs/examples/_index.md +++ b/content/docs/examples/_index.md @@ -5,7 +5,7 @@ weight: 330 ## Flow examples -The following examples show some simple flows. For more examples that use filters, see {{% xref "/docs/examples/filters-in-flows.md" %}}. +The following examples show some simple flows. For more advanced examples, see {{% xref "/docs/examples/filters-in-flows/_index.md" %}} and {{% xref "/docs/examples/flows/_index.md" %}}. ### Flow with a single output diff --git a/content/docs/examples/flows/_index.md b/content/docs/examples/flows/_index.md new file mode 100644 index 000000000..9f23de43d --- /dev/null +++ b/content/docs/examples/flows/_index.md @@ -0,0 +1,25 @@ +--- +title: Advanced Flow examples +weight: 100 +--- + +## CoreDNS + +This Flow: + +- selects [CoreDNS](https://coredns.io/) messages (every message with the `k8s-app: coredns` label), +- parses them, and +- sets a number of related [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/ecs-getting-started.html) fields based on the content of the message using the {{% xref "/docs/configuration/plugins/filters/record_modifier.md" %}} plugin. + +{{< include-code "logging_flow_coredns.yaml" "yaml" >}} + +## NGINX Ingress Controller + +This Flow: + +- selects [NGINX Ingress Controller](https://docs.nginx.com/nginx-ingress-controller/) messages (every message with the `app-kubernetes-io/name: ingress-nginx` label), +- parses them, and +- sets a number of related [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/ecs-getting-started.html) fields based on the content of the message using the {{% xref "/docs/configuration/plugins/filters/record_modifier.md" %}} plugin. +- It also adds GeoIP-related fields based on the source of the traffic using the [Fluentd GeoIP filter]({{< relref "/docs/configuration/plugins/filters/geoip.md" >}}). + +{{< include-code "logging_flow_nginx_ingress.yaml" "yaml" >}} diff --git a/content/docs/examples/flows/logging_flow_coredns.yaml b/content/docs/examples/flows/logging_flow_coredns.yaml new file mode 100644 index 000000000..5b81cfa9a --- /dev/null +++ b/content/docs/examples/flows/logging_flow_coredns.yaml @@ -0,0 +1,36 @@ +apiVersion: logging.banzaicloud.io/v1beta1 +kind: Flow +metadata: + name: coredns + namespace: kube-system +spec: + filters: + - tag_normaliser: {} + - parser: + reserve_data: true + remove_key_name_field: true + parse: + type: "regexp" + expression: '^\[(?.*)\] \[?(?.*)\]?:(?.*) - (?.*) "(?.*) (?.*) (?.*)\.? (?.*) (?.*) (?.*) (?.*)" (?.*) (?.*) (?.*) (?.*)s' + types: "source.port:integer,dns.id:integer,coredns.query.size:integer,coredns.dnssec_ok:bool,bufsize:integer,dns.header_flags:array,coredns.response.size:integer,coredns.duration:float" + - record_modifier: + records: + - source.ip: '${ record["source.address"] }' + - dns.header_flags: '${ record["dns.header_flags"].map(&:upcase) }' + - event.duration: '${ record["coredns.duration"] * 1000000000 }' + - event.kind: "event" + - event.category: "network" + - event.type: "protocol" + - event.outcome: '${ record["dns.response_code"] == "NOERROR" ? "success" : "failure" }' + - event.protocol: "dns" + - event.module: "coredns" + - related.ip: '${ record["source.address"] }' + # for dashboard + - fileset.name: "kubernetes" + # alias in elastic + - coredns.query.name: '${ record["dns.question.name"] }' + remove_keys: "coredns.duration,coredns.dnssec_ok" + match: + - select: + labels: + k8s-app: "coredns" \ No newline at end of file diff --git a/content/docs/examples/flows/logging_flow_nginx_ingress.yaml b/content/docs/examples/flows/logging_flow_nginx_ingress.yaml new file mode 100644 index 000000000..eb27d1b01 --- /dev/null +++ b/content/docs/examples/flows/logging_flow_nginx_ingress.yaml @@ -0,0 +1,85 @@ +apiVersion: logging.banzaicloud.io/v1beta1 +kind: Flow +metadata: + name: "ingress-nginx" +spec: + filters: + - tag_normaliser: {} + - parser: + reserve_data: true + remove_key_name_field: true + inject_key_prefix: "nginx." + parse: + type: "regexp" + # from https://raw.githubusercontent.com/fluent/fluentd/master/lib/fluent/plugin/parser_nginx.rb + # enharance for ingress-controller by e.g. + # https://github.com/elastic/beats/blob/v8.6.1/filebeat/module/nginx/ingress_controller/ingest/pipeline.yml + expression: '^(?[^ ]*) -?(?[^ ]*) -?(?[^ ]*) \[(?