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

loki_out: add stuctured_metadata_map_keys #9530

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

Conversation

0x006EA1E5
Copy link

@0x006EA1E5 0x006EA1E5 commented Oct 25, 2024

Resolves #9463

  • Adds stuctured_metadata_map_keys config to dynamically populate stuctured_metadata from a map

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

fluent/fluent-bit-docs#1527

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.

@0x006EA1E5 0x006EA1E5 force-pushed the loki_out-structured_metadata_map branch from 7f1db76 to a9cdcad Compare October 26, 2024 12:24
@patrick-stephens patrick-stephens added the ok-package-test Run PR packaging tests label Oct 28, 2024
@0x006EA1E5 0x006EA1E5 force-pushed the loki_out-structured_metadata_map branch from a9cdcad to e9fee7d Compare October 29, 2024 11:05
* Adds stuctured_metadata_map_keys config to dynamically populate stuctured_metadata from a map
* Add docker-compose to test loki backend

Signed-off-by: Greg Eales <[email protected]>
if (kv->ra_key != NULL && kv->ra_val == NULL) {

/* try to get the value for the record accessor */
if (flb_ra_get_kv_pair(kv->ra_key, *map, &start_key, &out_key, &out_val)
Copy link
Member

Choose a reason for hiding this comment

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

flb_ra_* API do not use msgpack-c return codes like MSGPACK_UNPACK_CONTINUE, need to check the return values and adjust it

Copy link
Author

Choose a reason for hiding this comment

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

I'm a bit confused as to the meaning of the return code from flb_ra_get_kv_pair. I see from the source it is commented that this should

Returns FLB_TRUE if the pattern matched a kv pair, otherwise it returns FLB_FALSE

Where FLB_TRUE is 1 and FLB_FALSE is 0

However, actually reading the code, if this doesn't hit the FLB_FALSE code path, it actually just returns whatever the following call to flb_ra_key_value_get returns, and function flb_ra_key_value_get actually seems to return 0 for okay, and -1 for not okay..

It looks like we are getting return codes as follows:

  • Valid RA, normal happy path - this will delegate to flb_ra_key_value_get and return 0
  • Syntactically invalid RA key, such as $$ - this will return FLB_FALSE (also 0) via get_ra_parser.
    • This PR then proceeds assuming things are okay, then to check out_val and finally log No valid map data found for key $ (test case flb_test_structured_metadata_map_invalid_ra_key)
  • Syntactically valid RA key, such as $missing_map which doesn't reference anything - this will delegate to flb_ra_key_value_get and return -1 (test case structured_metadata_map_single_missing_map)

It seems like the main option here to to test for not equal to -1, and then check out_val.

Otherwise, we have to change how flb_ra_get_kv_pair works to agree with its comment, which I assume would break some important things elsewhere?

@@ -91,6 +92,7 @@ struct flb_loki {
struct flb_record_accessor *ra_k8s; /* kubernetes record accessor */
struct mk_list labels_list; /* list of flb_loki_kv nodes */
struct mk_list structured_metadata_list; /* list of flb_loki_kv nodes */
struct mk_list structured_metadata_map_keys_list; /* list of flb_loki_kv nodes */
Copy link
Author

Choose a reason for hiding this comment

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

Do the comment start positions need to be aligned, or is it okay for this one to stick out further?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say line them up if you can

Copy link
Author

Choose a reason for hiding this comment

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

This pushed a couple of the lines over 90 characters long.
I could align the righthand side instead, like this?

    int ra_used;                           /* number of record accessor label keys */
    struct flb_record_accessor *ra_k8s;              /* kubernetes record accessor */
    struct mk_list labels_list;                       /* list of flb_loki_kv nodes */
    struct mk_list structured_metadata_list;          /* list of flb_loki_kv nodes */
    struct mk_list structured_metadata_map_keys_list; /* list of flb_loki_kv nodes */
    struct mk_list remove_keys_derived;              /* remove_keys with label RAs */
    struct flb_mp_accessor *remove_mpa;      /* remove_keys multi-pattern accessor */
    struct flb_record_accessor *ra_tenant_id_key;         /* dynamic tenant id key */

Copy link
Contributor

Choose a reason for hiding this comment

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

seems reasonable to me

Signed-off-by: Greg Eales <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-package-test Run PR packaging tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loki Output structured_metadata from Map-like data structure
4 participants