Git Product home page Git Product logo

fluentbit-containerd-cri-o-json-log's Introduction

Fluent Bit with containerd, CRI-O and JSON

With dockerd deprecated as a Kubernetes container runtime, we moved to containerd. After the change, our fluentbit logging didn't parse our JSON logs correctly. containerd and CRI-O use the CRI Log format which is slightly different and requires additional parsing to parse JSON application logs.

We couldn't find a good end-to-end example, so we created this from various GitHub issues. There are some features missing (like multi-line logs) and we love PRs.

Enhancement

The original version of this repo used a separate filter to parse the JSON. By changing the cri parser to use the log field instead of the message field, the kubernetes filter converts the JSON if Merge_Log is set to On

We also had to add two nest filters to the config to lift the Kubernetes values to the root level.

Sample Config

config.yaml contains a complete and minimal example configuration using stdout. We have tested with stdout and Azure Log Analytics. While not tested, it should work with Elastic Search and outher output providers as well.

You will need to change the output match from myapp*.*

Config Changes

Note - there are several GitHub discussions on the challenges with multi-line CRI Logs - additional processing is necessary and not included here

In config there are three changes:

  • Add the CRI parser which is a regex parser that maps the CRI Log fields into time stream logtag and log
    • time and stream map to existing dockerd log fields
    • log contains the text of the message, which, in our case is JSON
      • The JSON is parsed and merged in the kubernetes filter
        • Merge_Log must be set to On

Note the regex expression uses log for the 4th field, not message

[PARSER]
    Name        cri
    Format      regex
    Regex       ^(?<time>[^ ]+) (?<stream>stdout|stderr) (?<logtag>[^ ]*) (?<log>.*)$
    Time_Key    time
    Time_Format %Y-%m-%dT%H:%M:%S.%L%z
  • Add the nest filters to lift the Kubernetes values to the root document
    [FILTER]
        Name          nest
        Match         kube.*
        Operation     lift
        Nested_under  kubernetes
        Add_prefix    kubernetes_

    [FILTER]
        Name          nest
        Match         kube.*
        Operation     lift
        Nested_under  kubernetes_labels
        Add_prefix    kubernetes_labels_
  • Change the Parser on the input from json or docker to cri
[INPUT]
    Name              tail
    Tag               kube.*
    Path              /var/log/containers/*.log
    Parser            cri

Attribution

Thank you!

We copied a lot of the yaml from several different GitHub issues / docs including fluentbit docs

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services.

Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines.

Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.

Any use of third-party trademarks or logos are subject to those third-party's policies.

fluentbit-containerd-cri-o-json-log's People

Contributors

bartr avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fluentbit-containerd-cri-o-json-log's Issues

ClusterFlow format

Bug Report

Description

As I have not much experience in fluentd, I struggle a bit to translate your docu into a working ClusterFlow config. I figured starting with something like thi

apiVersion: logging.banzaicloud.io/v1beta1
kind: ClusterFlow
metadata:
  name: all-logs
  namespace: cattle-logging-system
  filters:
    - parser:
        key_name: log
        parse:
          expression: >-
            ^(?<time>[^ ]+) (?<stream>stdout|stderr) (?<logtag>[^ ]*)
            (?<log>.*)$
          time_format: '%Y-%m-%dT%H:%M:%S.%L%z'
  globalOutputRefs:
    - cluster-output-splunk

But don't know where to go from there...

Expected Behavior

N/A

Reproduce

N/A

Additional Context

N/A

Logs emitted under `message` instead of `log`

Bug Report

Description

The provided instructions to create a parser for the cri logs results in the creation of a duplicate parser.

Since 1.0, the fluent-bit docker image has included a built-in list of parsers, one of which is the default cri parser.

Attempting to create another parser with the same name as described here results in an error at start-up:

[error] [parser] parser named 'cri' already exists, skip.

This built-in cri parser emits the main contents of the log under the message field, not the log field, which is contradictory to many of the statements provided.

Expected Behavior

The creation of a parser does not generate errors within fluent-bit.
The logs are emitted under the log key, as described.

Reproduce

  1. Take the provided config.yaml and configure a pod running the fluent-bit docker image with a version greater than 1.0.
  2. On start-up the pod should emit a log: [error] [parser] parser named 'cri' already exists, skip.
  3. The logs output by fluent-bit will have the main contents emitted under message instead of `log.

Additional Context

Recommend that the name of the parser specified in this documentation is changed to something like cri-log, as well as the value for Parser under [INPUT].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.