Using multiple filters for the same record - is it possible?
Is it possible to use multiple filters for the same record?
I'm trying to do the following:
filter-kubernetes.conf: |
[FILTER]
Name kubernetes
Match kube.*
Kube_URL https://kubernetes.default.svc:443
Merge_JSON_Log On
Annotations Off
filter-logging.conf: |
[FILTER]
Name grep
Match kube.*
Regex kubernetes.namespace_name logging
input-kubernetes.conf: |
[INPUT]
Name tail
Tag kube.*
Path /var/log/containers/*.log
Parser docker
DB /var/log/flb_kube.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
output-fluentd.conf: |
[OUTPUT]
Name forward
Match *
Host ${FLUENTD_HOST}
Port ${FLUENTD_PORT}
fluent-bit.conf: |
[SERVICE]
Flush 10
Log_Level info
Daemon off
Parsers_File parsers.conf
@INCLUDE input-kubernetes.conf
@INCLUDE filter-kubernetes.conf
@INCLUDE filter-logging.conf
@INCLUDE output-fluentd.conf
parsers.conf: |
[PARSER]
Name docker
Format json
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%L
Time_Keep On
however it does not seems to be working fine, what I wanted to happen is that filter-kubernetes add kubernetes metadata into the log and then filter-logging excludes the logs coming from logging namespace.
I think the missing feature is at this level:
Regex kubernetes.namespace_name logging
In the record, namespace likely is a map key of kubernetes, but Regex configuration in the filter assumes you are asking for a key called "kubernetes.namespace" so that may be the reason why it's not working.
@edsiper can it be resolved on fluentd side? If yes, then I think it would be nice to have it here also.
@edsiper I have a similar request. I'd like to prune some of the added kubernetes fields, for example remove the kubernetes.docker_id field via a record_modifier filter after the kubernetes filter, but it won't match due to the reason you stated. Does the filter chain pass along the full json representation of a record allowing this functionality. Or is there a better way to do this? Thanks!
definitely this is an enhancement request.
@loburm @wpalmeri for your specific use case, do you need it only on Grep Filter ?
@edsiper I think that should be enough.
Main use cases for me: read logs from specified namespaces only or ignore some namespaces.
@edsiper I would request this enhancement for the RecordModifier filter as well
@edsiper Having:
"kubernetes": {
"pod_name": "***",
"namespace_name": "logging",
"pod_id": "216cd7ae-1c7e-11e8-bb40-000c298df552",
"labels": {
"app": "***",
"pod-template-hash": "3079797978"
},
"host": "***",
"container_name": "***",
"docker_id": "370face382c7603fdd309d8c6aaaf434fd98b92421ce7c7c8aafe7697d4aa362"
}
and
[FILTER]
Name grep
Match kube.*
Regex kubernetes logging
it doesn't work either. It think it might be because the value of "kubernetes" is another JSON object upon which, right now, regexp don't apply. Maybe it should be treated as a string in this case or be able to have a 'nested' field like kubernetes.labels.app on plugins that use this, like record_modifier or grep.
What do you guys think?
Meanwhile, I am using fluent-bit with forward to a fluentd server configured something like this:
<source>
@type forward
port 24284
</source>
<filter kube.**>
@type grep
<regexp>
key $.kubernetes.namespace_name
pattern logging
</regexp>
</filter>
<match kube.**>
@type file
path /tmp/logging
time_slice_format %Y%m%d
time_slice_wait 10m
time_format %Y%m%dT%H%M%S%z
</match>
It's a good enough workaround for me at the moment.
I believe I'm looking for the same thing here - the ability to apply regex / exclude patterns on nested keys - so I'll add my vote for this enhancement.
tip: why not to take advantage of the Exclude_Path configuration property ?
In Kubernetes every logfile have the namespace name in the same log file, so you can do it there. Note that I think that the ideal solution is to add a kind of Exclude_Namespace in Kubernetes filter configuration.
@MihaiAnei I don't think this is a workaround, I prefer the approach of just forwarding to a fluentd aggregator with minimal parsing or filtering in fluent-bit. Then make the aggregator do the grunt work as this tends to be a "bigger" resource
anybody managed exclude certain namespace logs without using fluntd aggregator?
Since the path and exclude_path variables can handle wildcards I'm able to exclude namespaces.
exclude_path /var/logs/containers/*preprod*.log
I have the similar request, would like to apply the kubernetes filter to enrich my logs and then apply a grep filter to only output log with errors.
Is this already possible in the latest 0.13.8 version somehow ?
I've logged the following enhancement request for filter kubernetes:
https://github.com/fluent/fluent-bit/issues/755
the other requirement I see on this thread is about improve Grep to support nested fields, no ETA for that one yet.
I think that my pull request would help (https://github.com/fluent/fluent-bit/pull/753): it allows formatting the tag as kubernetes.<namespace>.<pod>.<container> and you can then match on specific namespace based on this tag.
Same problem for me too, i want grep log coming from kubernetes by regex matching on specific annotation
[FILTER] Name grep Match kube.* Regex kubernetes.annotations.log true
it search a "kubernetes.annotations.log" field but kubernetes output is a map like "kubernetes"=>{"annotations"=>{"log"=>"true"}}
how to specify this in the Regex ???
@tuxtof I think your use case is the one which the fluentbit.io/exclude annotation targets (not exactly though, as you seem to want to include some logs instead of excluding others). See this page https://docs.fluentbit.io/manual/filter/kubernetes for the documentation on how to use this annotation.
@yann-soubeyrand yes this is the same idea, but i want just select few container to log among a large number of them, so i can change all my container to put exclude annotations, i want no log by default and just activate some of them
Can we extract the multiple fields from single field by doing multiple filters?
For example: the field "log" has string '172.17.0.1 - - [02/Nov/2018:13:16:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.1" "-" '
I want to do one more filtering and extract the fields, such as "client", "time", "http_method", "path" and so on. is this possible with fluent-bit?