Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config_format: new config reader with YAML support (#4331) #4621

Merged
merged 51 commits into from
Jan 27, 2022

Conversation

edsiper
Copy link
Member

@edsiper edsiper commented Jan 17, 2022

The following patch introduces a new interface called 'config_format'. This new interface implements a new layer to read and compose a configuration 'context' for Fluent Bit.

The idea started on discussion #4331 where initially looking for feedback to extend the format and support 'groups' (or sub section) many needs were expressed like other formats.

The actual implementation which comes from lib/monkey, is not flexible enough and adds complexity when trying to extend it.

The new 'config_format' is a 'layer' that generate configuration contexts:

      +-------------+     +---------------+     +----------------------------+
      | Config File | <-- | Config Format | --> | Fluent Bit Readers & Setup |
      +-------------+     +---------------+     +----------------------------+

The advantage of this is that 'config_format' supports different 'backends' to read data from: this implementation supports 'fluentbit' (current) format but also 'YAML' format.

                          +---------------+
                          | Config Format |
                          +------+-+------+
                                 | |
              +------------------+ +-------------+
              | fluentbit format | | YAML format |
              +------------------+ +-------------+

'fluentbit' format is a backport format from lib/monkey with API changes, the YAML format is parsed by using libyaml when available.

The concepts of configuration keeps being the same:

 - sections: define a block
 - properties: key/value pairs that belongs to a section

The following examples are identical configurations in different formats:

--- fluentbit format ---

[SERVICE]
    flush     1
    log_level info
    
[INPUT]
    name      tail
    path      /var/log/containers/*.log
    parser    docker
   
[INPUT]
    name      forward
    listen    0.0.0.0
    
[OUTPUT]
    name      stdout
    match     *

Now the identical representation in YAML:

service:
    flush:       1
    log_level:   info

pipeline:    
    inputs:
        tail:
            path: "/var/log/containers/*.log"
            parser: docker
    
        forward:
            listen: 0.0.0.0
    
    outputs:
        stdout:
            match: "*"

another YAML example:

# setting up a local environment variable
env:
    flush_interval: 1

# service configuration
service:
    flush:       ${flush_interval}
    log_level:   info
    http_server: on

# pipeline 1
pipeline:
    inputs:
        dummy:
            samples: 100
            tag: example
    outputs:
        stdout:
            match: example

# pipeline 2
pipeline:
    inputs:
        tail:
            path: /var/log/containers/coredns*.log
            read_from_head: true
            tag: kube.*

    filters:
        kubernetes:
            match: kube.*

    outputs:
        stdout:
            match: kube.*

To Do

  • config format API
  • fluentbit format reader
  • YAML
    • format reader
    • support environment variables (aka @set A=B)
  • Migrate service conf reader to config format (WIP)
  • Migrate 'static config' reader to config format (is there anybody using this feature ?)
  • Migrate command-line options to use config format
  • Migrate library API (internal) to config format (double-check)
  • Migrate parsers reader to config format
  • migrate upstream servers readers to config format
  • migrate stream processor reader to config format
  • migrate external plugins reader to config format
  • groups (sub-sections support)
    • API
    • fluentbit format
    • YAML format

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Signed-off-by: Eduardo Silva <[email protected]>
The following patch introduces a new interface called 'config_format'. This
new interface implements a new layer to read and compose a configuration
'context' for Fluent Bit.

The idea started on discussion #4331 where initially looking for feedback
to extend the format and support 'groups' (or sub section) many needs were
expressed like other formats.

In the actual implementation which comes from lib/monkey, is not flexible
enough and adds complexity when trying to extend it.

The new 'config_format' is a 'layer' that generate configuration contexts:

  +-------------+     +---------------+     +----------------------------+
  | Config File | <-- | Config Format | --> | Fluent Bit Readers & Setup |
  +-------------+     +---------------+     +----------------------------+

The advantage of this is that 'config_format' supports different 'backends'
to read data from: this implementation supports 'fluentbit' (current) format
but also 'YAML' format.

                      +---------------+
                      | Config Format |
                      +------+-+------+
                             | |
          +------------------+ +-------------+
          | fluentbit format | | YAML format |
          +------------------+ +-------------+

'fluentbit' format is a backport format from lib/monkey with API changes, the
YAML format is parsed by using libyaml when available.

The concepts of configuration keeps being the same:

 - sections: define a block
 - properties: key/value pairs that belongs to a section

The following examples are identical configurations in different formats:

--- fluentbit format ---

[SERVICE]
    flush     1
    log_level info

[INPUT]
    name      tail
    path      /var/log/containers/*.log
    parser    docker

[INPUT]
    name      forward
    listen    0.0.0.0

[OUTPUT]
    name      stdout
    match     *

--- eof ---

Now the identical representation in YAML:

--- YAML format ---
service:
    flush:       1
    log_level:   info

inputs:
    tail:
        path: "/var/log/containers/*.log"
        parser: docker

    forward:
        listen: 0.0.0.0

outputs:
    stdout:
        match: "*"

--- eof ---

== Notes ==

 - Fluent Bit config reader is still using the old mechanism, the next patches
   will migrate to this interface.

 - 'Groups' are not implemented/supported yet.

Signed-off-by: Eduardo Silva <[email protected]>
@lecaros lecaros added this to the Fluent Bit v1.9 milestone Jan 20, 2022
@edsiper
Copy link
Member Author

edsiper commented Jan 27, 2022

YAML + Environment vars:

https://asciinema.org/a/Zz6ZAS3D6ZJgBtH3rjYwNmzqx

note: YAML schema will change a bit now

the following patch makes possible to separate 'visually' only
the components of a pipeline. This is useful when having uses
that certain inputs must go through certain filters and outputs.

This change do not touch routing, it's just a visual separation.

--- start of fluent-bit.yaml ---
env:
    flush_interval: 1

service:
    flush:       ${flush_interval}
    log_level:   info
    http_server: on

pipeline:
    inputs:
        dummy:
            samples: 100
            tag: example
    outputs:
        stdout:
            match: example

pipeline:
    inputs:
        tail:
            path: /var/log/containers/coredns*.log
            read_from_head: true
            tag: kube.*

    filters:
        kubernetes:
            match: kube.*

    outputs:
        stdout:
            match: kube.*

--- end of file ---

Signed-off-by: Eduardo Silva <[email protected]>
@edsiper edsiper merged commit fa820da into master Jan 27, 2022
@patrick-stephens
Copy link
Contributor

@edsiper do we have a docs PR to document the YAML format we're using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants