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

Should rewrite_tag allow for a static new tag? #7330

Closed
braydonk opened this issue May 5, 2023 · 6 comments
Closed

Should rewrite_tag allow for a static new tag? #7330

braydonk opened this issue May 5, 2023 · 6 comments

Comments

@braydonk
Copy link
Contributor

braydonk commented May 5, 2023

Bug Report

Describe the bug
It appears that using a static pattern for the new tag in rewrite_tag, aka one that does not use any record accesor functionality, will cause fluent bit to rewrite the tag as a blank string.

To Reproduce

  • Steps to reproduce the problem:
    The best way to observe the behaviour is to first run Fluent Bit with this config, where you can see it work as expected:
[SERVICE]
    Flush     1
    Log_Level debug

[INPUT]
    NAME   dummy
    Dummy  {"tool": "fluent", "sub": {"s1": {"s2": "bit"}}}
    Tag    a

[FILTER]
    Name          rewrite_tag
    Match         a
    Rule          $tool ^(fluent)$ b.$TAG false 
    Emitter_Name  re_emitted

[OUTPUT]
    Name file
    Match a
    Path choose/a/log/path
    File a.txt

[OUTPUT]
    Name file
    Match b.a
    Path choose/a/log/path
    File b.txt

In this scenario, a.txt is empty, and b.txt contains:

b.a: [1683322738.028321063, {"tool":"fluent","sub":{"s1":{"s2":"bit"}}}]
b.a: [1683322739.028365827, {"tool":"fluent","sub":{"s1":{"s2":"bit"}}}]
b.a: [1683322740.028366062, {"tool":"fluent","sub":{"s1":{"s2":"bit"}}}]
...

Next, run Fluent Bit with this slightly altered config:

[SERVICE]
    Flush     1
    Log_Level debug

[INPUT]
    NAME   dummy
    Dummy  {"tool": "fluent", "sub": {"s1": {"s2": "bit"}}}
    Tag    a

[FILTER]
    Name          rewrite_tag
    Match         a
    Rule          $tool ^(fluent)$ b false
    Emitter_Name  re_emitted

[OUTPUT]
    Name file
    Match a
    Path choose/a/log/path
    File a.txt

[OUTPUT]
    Name file
    Match b
    Path choose/a/log/path
    File b.txt

In this scenario, both b.txt and a.txt are empty. Changing the Rule in rewrite_tag such that we keep the original log, a.txt has the following:

a: [1683323220.028342314, {"tool":"fluent","sub":{"s1":{"s2":"bit"}}}]
a: [1683323221.028380836, {"tool":"fluent","sub":{"s1":{"s2":"bit"}}}]
a: [1683323222.028332510, {"tool":"fluent","sub":{"s1":{"s2":"bit"}}}]
...

Expected behavior
I should be allowed to successfully rewrite a tag to something static without any record accesor functionality.

Your Environment

  • Version used: 2.0.12
  • Configuration: See reproduction
  • Filters and plugins: rewrite_tag

Additional context
I am almost certain the problem is in this function:

flb_sds_t flb_ra_translate_check(struct flb_record_accessor *ra,

If the record accesor list is empty, it won't actually process anything, simply returning an "" buf successfully. I tried to hack this by manually setting buf if ra->list was found to be empty. It worked, though it caused a double free somewhere and I don't have time yet to determine what went wrong.

@nokute78
Copy link
Collaborator

nokute78 commented May 6, 2023

Static tag is allowed.
However a single character seems not to be allowed. I think it is a bug.

Workaround is following rule (set characters)

    Rule          $tool ^(fluent)$ bb false
[SERVICE]
    Flush     1
    Log_Level debug

[INPUT]
    NAME   dummy
    Dummy  {"tool": "fluent", "sub": {"s1": {"s2": "bit"}}}
    Tag    a

[FILTER]
    Name          rewrite_tag
    Match         a
    Rule          $tool ^(fluent)$ bb false
    Emitter_Name  re_emitted

[OUTPUT]
    Name stdout
    Match a

[OUTPUT]
    Name stdout
    Match b*

@braydonk
Copy link
Contributor Author

braydonk commented May 6, 2023

Thank you @nokute78 that's very helpful. I think I found the bug, a calculation in ra_parse_buffer that does not work when the pattern is only 1 character long. I will submit a PR to resolve!

nokute78 added a commit to nokute78/fluent-bit that referenced this issue May 6, 2023
@nokute78
Copy link
Collaborator

nokute78 commented May 6, 2023

@braydonk Oops, I sent a patch #7332
Could you check it ?

@braydonk
Copy link
Contributor Author

braydonk commented May 6, 2023

No problem, thanks @nokute78! Looks like how I was intending to fix it anyway.

@nokute78
Copy link
Collaborator

nokute78 commented May 6, 2023

@braydonk Thank you for reviewing.

@braydonk
Copy link
Contributor Author

braydonk commented May 6, 2023

Thanks for fixing this! Backport issue is #7335

@braydonk braydonk closed this as completed May 6, 2023
Syn3rman pushed a commit to Syn3rman/fluent-bit that referenced this issue May 9, 2023
leonardo-albertovich pushed a commit that referenced this issue May 9, 2023
This patch is to allow a single character for `flb_ra_translate`.

Currently, `flb_ra_translate` doesn't allow a single character and it causes a issue like #7330.

Note: This is a backport of PR 7332

Signed-off-by: Aditya Prajapati <[email protected]>
Co-authored-by: Takahiro Yamashita <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants