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

filter_modify: Add data type condition checker to Modify filter. #2539

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zihengCat
Copy link
Contributor

@zihengCat zihengCat commented Sep 11, 2020

Summary

It would be good if Fluent Bit supports strong data type condition check when applied in structured log stream. I implemented a data type condition checker for Modify filter.

Check data type using lua filter isn't clear enough for end-user and costs more performance overhead.

Usage

Modify filter supports two new conditions. See modify_filter_example.conf below.

Condition Parameter 1 Parameter 2 Description
Key_Value_Type_Matches STRING:KEY STRING:VALUE Is true if KEY exists and its value data type is VALUE.
Key_Value_Type_Does_Not_Match STRING:KEY STRING:VALUE Is true if KEY exists and its value data type is not VALUE.

Parameter 2 data type string literal could be:

  • null
  • bool
  • number
  • int
  • float
  • str
  • array
  • map
[INPUT]
    Name dummy
    Tag  test
    dummy {"nullType": null, "boolType": true, "intType": 123, "floatType": 3.14159, "strType": "awesome!", "arrayType": [1, 2, 3], "mapType": {"k": "v"}}

[OUTPUT]
    Name  stdout
    Match *

[FILTER]
    Name  modify
    Match *

    Condition Key_Value_Type_Matches             nullType          null
    Condition Key_Value_Type_Matches             boolType          bool
    Condition Key_Value_Type_Matches             intType           number
    Condition Key_Value_Type_Matches             intType           int
    Condition Key_Value_Type_Matches             floatType         float
    Condition Key_Value_Type_Matches             strType           str
    Condition Key_Value_Type_Matches             arrayType         array
    Condition Key_Value_Type_Matches             mapType           map

    Condition Key_Value_Type_Does_Not_Match      mapType           array

    Rename nullType nullTypeMatches
    Rename mapType mapTypeDoesNotMatch

modify_filter_example.conf

Unit Tests

Here comes unit testing results.

13/31 Test #13: flb-rt-filter_kubernetes .........   Passed  193.00 sec
      Start 14: flb-rt-filter_parser
14/31 Test #14: flb-rt-filter_parser .............   Passed   20.00 sec
      Start 15: flb-rt-filter_modify
15/31 Test #15: flb-rt-filter_modify .............   Passed   55.00 sec
      Start 16: flb-rt-core_engine
16/31 Test #16: flb-rt-core_engine ...............   Passed   20.00 sec

Addresses

#2530


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

Documentation

  • 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.

@edsiper
Copy link
Member

edsiper commented Sep 28, 2020

thanks for this PR.

  • is it nil a configuration value ?, if so, can it be null ? , that's more representative for end-users
  • does number covers int and float ?

@edsiper edsiper self-assigned this Sep 28, 2020
@edsiper edsiper added the waiting-for-user Waiting for more information, tests or requested changes label Sep 28, 2020
@zihengCat
Copy link
Contributor Author

@edsiper
Fine.

  • Change nil to null.
  • number covers both int and float, corresponding to JSON number data type.

src/flb_hash.c Outdated
@@ -41,7 +41,7 @@
* 2. It will not produce the same results on little-endian and big-endian
* machines.
*/
static unsigned int gen_hash(const void *key, int len)
unsigned int gen_hash(const void *key, int len)
Copy link
Member

Choose a reason for hiding this comment

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

public interfaces must be prefixed with flb_, e.g: flb_hash_gen_hash or flb_hash_generate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@edsiper Done!

  • Rename gen_hash to flb_hash_generate.

@zihengCat zihengCat requested a review from edsiper November 2, 2020 03:23
@PettitWesley PettitWesley dismissed a stale review via 716a2f2 July 26, 2021 20:43
@philomory
Copy link

Is there any chance this might eventually be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-user Waiting for more information, tests or requested changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants