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: yaml: add support for cfl_arrays when a property is declared as a list. #8661

Closed
wants to merge 4 commits into from

Conversation

pwhelan
Copy link
Contributor

@pwhelan pwhelan commented Apr 2, 2024

Summary

When a property is declared as a list with variant values it will be parsed using cfl_array with variants inside.

An example is this:

pipeline:
  inputs:
    - name: test
      hosts:
        - foo
        - bar

This should also work with arrays that have key/vales, ie:

pipeline:
  inputs:
    - name: test
      hosts:
        - ip: 127.0.0.1
          port: 4444

This also works with processors and will be key for an upcoming feature for the content_modifier processor:

pipeline:
  inputs:
    - name: dummy
      dummy: '{"message": "foobar", "foobar": "barfoo"}'
      processors:
        logs:
          - name: content_modifier
            actions:
              - action: insert
                key: foo
                value: bar
              - action: delete
                key: foo
              - action: delete
                key: foobar
              - action: insert
                key: bar
                value: foo

This pull request does not attempt to actually allow passing these properties to a plugin. Changes to the config and config_map layer are required for these values to actually be passed to a plugin instance.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • [N/A] Example configuration file for the change
  • [N/A] Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

Documentation

  • [N/A] Documentation required for this feature

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.

@pwhelan
Copy link
Contributor Author

pwhelan commented Apr 2, 2024

Here is a valgrind log:

2024/04/01 18:14:14] [ info] [fluent bit] version=3.0.1, commit=cf3e53ce03, pid=275574
[2024/04/01 18:14:14] [ info] [storage] ver=1.5.1, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2024/04/01 18:14:14] [ info] [output:stdout:stdout.0] worker #0 started
[2024/04/01 18:14:14] [ info] [cmetrics] version=0.7.1
[2024/04/01 18:14:14] [ info] [ctraces ] version=0.4.0
[2024/04/01 18:14:14] [ info] [input:dummy:dummy.0] initializing
[2024/04/01 18:14:14] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2024/04/01 18:14:14] [ info] [sp] stream processor started
[0] dummy.0: [[1712006055.007001399, {}], {"message"=>"foobar", "foobar"=>"barfoo"}]
[0] dummy.0: [[1712006056.003066368, {}], {"message"=>"foobar", "foobar"=>"barfoo"}]
^C[2024/04/01 18:14:17] [engine] caught signal (SIGINT)
[2024/04/01 18:14:17] [ warn] [engine] service will shutdown in max 5 seconds
[0] dummy.0: [[1712006056.991977440, {}], {"message"=>"foobar", "foobar"=>"barfoo"}]
[2024/04/01 18:14:17] [ info] [input] pausing dummy.0
[2024/04/01 18:14:17] [ info] [engine] service has stopped (0 pending tasks)
[2024/04/01 18:14:17] [ info] [input] pausing dummy.0
[2024/04/01 18:14:17] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2024/04/01 18:14:17] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==275574==
==275574== HEAP SUMMARY:
==275574==     in use at exit: 0 bytes in 0 blocks
==275574==   total heap usage: 1,992 allocs, 1,992 frees, 1,450,877 bytes allocated
==275574==
==275574== All heap blocks were freed -- no leaks are possible
==275574==
==275574== For lists of detected and suppressed errors, rerun with: -s
==275574== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Copy link
Contributor

@cosmo0920 cosmo0920 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, it looks good to me.
Is there any chance to add an internal unit test case for this PR?
Or, this will be covered by another derived works?

I'm also interested in defining to the multiple server destinations on out_forward plugin like Fluentd does.

src/config_format/flb_cf_yaml.c Show resolved Hide resolved
pwhelan added 4 commits April 11, 2024 17:40
…essors.

Add support for arrays of variant values for both plugins and processors. The
Support for these values still needs to be added to the config and config_map
levels.

Signed-off-by: Phillip Whelan <[email protected]>
Only set properties for plugins within arrays when the type is
of type variant string. This avoids memory access problems when
properties are set as lists.

Signed-off-by: Phillip Whelan <[email protected]>
a minor typo was incorrectly constructing the properties for processors.

Signed-off-by: Phillip Whelan <[email protected]>
@pwhelan
Copy link
Contributor Author

pwhelan commented Apr 12, 2024

Is there any chance to add an internal unit test case for this PR?
Or, this will be covered by another derived works?

I will be adding tests as soon as the work for config and config_format is done which will allow me to parse yaml files with the new syntax.

I could also push those changes to this branch if it is better to try and get the entire feature merged at once but I felt the config_format changes will be disruptive enough to warrant their own PR.

tchrono added a commit to tchrono/fluent-bit that referenced this pull request May 26, 2024
This was initially based on
fluent#8656 and
fluent#8661 but ended up making
few different choices:

- Instead of adding FLB_CONFIG_MAP_KVLIST and FLB_CONFIG_MAP_ARRAY as
  config map types, it adds a single FLB_CONFIG_MAP_VARIANT which
  accepts an array or map. The passed array/map can have nested values
  and accept any JSON/YAML types, which are converted to cfl types. The
  processor will simply receive a `cfl_variant` pointer and is
  responsible for releasing the memory later.
- The existing `flb_config_map_set` function is reused by passing the
  `cfl_variant` pointer (from the yaml parsing phase) as the value of a
  `flb_kv`. Then pointer is eventually moved into the processor context.

Signed-off-by: Thiago Padilha <[email protected]>
tchrono added a commit to tchrono/fluent-bit that referenced this pull request May 28, 2024
This was initially based on
fluent#8656 and
fluent#8661 but ended up making
few different choices:

- Instead of adding FLB_CONFIG_MAP_KVLIST and FLB_CONFIG_MAP_ARRAY as
  config map types, it adds a single FLB_CONFIG_MAP_VARIANT which
  accepts an array or map. The passed array/map can have nested values
  and accept any JSON/YAML types, which are converted to cfl types. The
  processor will simply receive a `cfl_variant` pointer but doesn't own
  it, the config section is responsible for releasing its memory.
- The existing `flb_config_map_set` function is reused by passing the
  `cfl_variant` pointer (from the yaml parsing phase) as the value of a
  `flb_kv`. Then pointer is eventually passed to the processor context.

Signed-off-by: Thiago Padilha <[email protected]>
tchrono added a commit to tchrono/fluent-bit that referenced this pull request May 29, 2024
This was initially based on
fluent#8656 and
fluent#8661 but ended up making
few different choices:

- Instead of adding FLB_CONFIG_MAP_KVLIST and FLB_CONFIG_MAP_ARRAY as
  config map types, it adds a single FLB_CONFIG_MAP_VARIANT which
  accepts an array or map. The passed array/map can have nested values
  and accept any JSON/YAML types, which are converted to cfl types. The
  processor will simply receive a `cfl_variant` pointer but doesn't own
  it, the config section is responsible for releasing its memory.
- The existing `flb_config_map_set` function is reused by passing the
  `cfl_variant` pointer (from the yaml parsing phase) as the value of a
  `flb_kv`. Then pointer is eventually passed to the processor context.

Signed-off-by: Thiago Padilha <[email protected]>
tchrono added a commit to tchrono/fluent-bit that referenced this pull request May 30, 2024
This was initially based on
fluent#8656 and
fluent#8661 but ended up making
few different choices:

- Instead of adding FLB_CONFIG_MAP_KVLIST and FLB_CONFIG_MAP_ARRAY as
  config map types, it adds a single FLB_CONFIG_MAP_VARIANT which
  accepts an array or map. The passed array/map can have nested values
  and accept any JSON/YAML types, which are converted to cfl types. The
  processor will simply receive a `cfl_variant` pointer but doesn't own
  it, the config section is responsible for releasing its memory.
- The existing `flb_config_map_set` function is reused by passing the
  `cfl_variant` pointer (from the yaml parsing phase) as the value of a
  `flb_kv`. Then pointer is eventually passed to the processor context.

Signed-off-by: Thiago Padilha <[email protected]>
tchrono added a commit to tchrono/fluent-bit that referenced this pull request Jun 5, 2024
This was initially based on
fluent#8656 and
fluent#8661 but ended up making
few different choices:

- Instead of adding FLB_CONFIG_MAP_KVLIST and FLB_CONFIG_MAP_ARRAY as
  config map types, it adds a single FLB_CONFIG_MAP_VARIANT which
  accepts an array or map. The passed array/map can have nested values
  and accept any JSON/YAML types, which are converted to cfl types. The
  processor will simply receive a `cfl_variant` pointer but doesn't own
  it, the config section is responsible for releasing its memory.
- The existing `flb_config_map_set` function is reused by passing the
  `cfl_variant` pointer (from the yaml parsing phase) as the value of a
  `flb_kv`. Then pointer is eventually passed to the processor context.

Signed-off-by: Thiago Padilha <[email protected]>
edsiper pushed a commit that referenced this pull request Jul 8, 2024
This was initially based on
#8656 and
#8661 but ended up making
few different choices:

- Instead of adding FLB_CONFIG_MAP_KVLIST and FLB_CONFIG_MAP_ARRAY as
  config map types, it adds a single FLB_CONFIG_MAP_VARIANT which
  accepts an array or map. The passed array/map can have nested values
  and accept any JSON/YAML types, which are converted to cfl types. The
  processor will simply receive a `cfl_variant` pointer but doesn't own
  it, the config section is responsible for releasing its memory.
- The existing `flb_config_map_set` function is reused by passing the
  `cfl_variant` pointer (from the yaml parsing phase) as the value of a
  `flb_kv`. Then pointer is eventually passed to the processor context.

Signed-off-by: Thiago Padilha <[email protected]>
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Jul 14, 2024
@github-actions github-actions bot removed the Stale label Aug 17, 2024
@pwhelan
Copy link
Contributor Author

pwhelan commented Aug 27, 2024

Superseded elsewhere.

@pwhelan pwhelan closed this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants