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: yaml: Support passing arbitrary objects to processors #8874

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

tchrono
Copy link
Contributor

@tchrono tchrono commented May 26, 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 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.

I have added an example processor which uses the new feature, here's a config that can be used to test it:

service:
    flush: 0.2
    log_level: info

pipeline:
    inputs:
        - name: event_type
          tag: event
          type: logs
          processors:
            logs:
              - name: log_replacer
                replacement:
                  some_extra_data:
                    some_string: "hello world"
                    unquoted_literals:
                        - some_int: 4
                        - some_float: 3.1
                        - some_bool: true
                    quoted_literals:
                        - some_quoted_int: "4"
                        - some_quoted_float: '3.1'
                        - some_quoted_bool: "true"

    outputs:
        - name: stdout
          format: json
          match: event

This example processor is optional and required some small changes to the CFL library. I only put this processor to make it easier testing the new YAML feature. I can also remove this example processor (and the CFL changes) before it is merged.

Here's a command to run it locally and demonstrate the yaml parsing using JSON syntax highlighting:

/build/bin/fluent-bit -c log-replacer.yaml | jq '.'

@pwhelan @cosmo0920


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:

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

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

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.

@tchrono tchrono marked this pull request as draft May 27, 2024 10:31
@tchrono tchrono force-pushed the thiago/yaml-config-map-to-cfl branch from e766f24 to 6afb673 Compare May 27, 2024 12:13
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.

Could you submit your cfl patches into https://github.com/fluent/cfl repo?

@tchrono
Copy link
Contributor Author

tchrono commented May 31, 2024

Could you submit your cfl patches into https://github.com/fluent/cfl repo?

@cosmo0920 I'm not certain these patches are a good idea. I only did this as a quick workaround to allow both the processor plugin and the engine to have a reference to the same values (shared ownership doesn't seem such a good idea in this case).

I can imagine two better solutions to the problem:

  • allow a CFL object to have a refcount. cfl_variant_destroy decreases the refcount and frees the memory when it reaches 0
  • a new return code to processor plugins, which tells the engine to not free the CFL object when it converts back to msgpack.

In any case, would be better to do this separately from the yaml-specific changes. I can remove the last two commits of this PR so we can merge without CFL changes. What do you think?

@cosmo0920
Copy link
Contributor

  • allow a CFL object to have a refcount. cfl_variant_destroy decreases the refcount and frees the memory when it reaches 0

I like this option if applicative this selection should make to be able to implement another place to handle the reference and malloc/free management.

a new return code to processor plugins, which tells the engine to not free the CFL object when it converts back to msgpack.

Not sure we could implement this mechanism. Because all of hot-reloading should be completed in flb_reload.c.

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
Copy link
Contributor Author

tchrono commented Jun 5, 2024

As discussed privately with @cosmo0920 , I have removed the example processor and CFL changes since they belong in a different PR

@edsiper
Copy link
Member

edsiper commented Jun 13, 2024

I see some comments from @pwhelan on this one, are we expecting more changes or a different proposal ?

@edsiper
Copy link
Member

edsiper commented Jun 24, 2024

ping @pwhelan

Copy link
Contributor

@pwhelan pwhelan left a comment

Choose a reason for hiding this comment

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

LGTM

@edsiper edsiper merged commit 4b16a1c into fluent:master Jul 8, 2024
43 checks passed
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.

4 participants