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
@@ -78,6 +78,7 @@ struct flb_loki {
struct mk_list *labels;
struct mk_list *label_keys;
struct mk_list *structured_metadata;
struct mk_list *structured_metadata_map_keys;
Copy link
Author

Choose a reason for hiding this comment

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

is this config property name okay structured_metadata_map_keys?

"{\"sub_key1\": \"sub_value1\", \"sub_key2\": false}}, \"map2\": {\"key4\": " \
"\"value1\", \"key5\": false}, \"map3\": {\"key1\": \"map3_value1\", \"key2\": " \
"\"map3_value2\"}}]"
void flb_test_structured_metadata_map_params(char *remove_keys,
Copy link
Author

Choose a reason for hiding this comment

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

There are quite a few different variations on this test, so I have created this function which takes various parameters, and then called it for each actual test (below)

{"structured_metadata_map_and_explicit",
flb_test_structured_metadata_map_and_explicit},
{"structured_metadata_map_single_missing_map",
flb_test_structured_metadata_map_single_missing_map},
Copy link
Author

Choose a reason for hiding this comment

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

Any test cases missing that I should add?

&ctx->structured_metadata_map_keys_list);
}
/*
* explicit structured_metadata entries override
Copy link
Author

Choose a reason for hiding this comment

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

I believe this works as expected.

The intention is, if we try to add an entry to the structured_metadata with the same key twice (first from the new structured_metadata_map_keys, then from the existing structured_metadata), then the second entry should "win" and overrwite the first.

I am assuming msgpack works this way. But maybe I actually need to do some kind of explicit check, and only add a new entry where there is not already one for a given key?

* separate item. Non-string map values are serialised to JSON, as Loki requires
* all values to be strings.
*/
static void pack_maps(struct flb_loki *ctx,
Copy link
Author

Choose a reason for hiding this comment

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

This essentially tries to follow the flow of the proceeding pack_kv function.

Do you need a more detailed spec of what exactly this is supposed to be doing?

It should implement the proposal descibed in the FR #9463

@0x006EA1E5
Copy link
Author

I added a PR for the docs here fluent/fluent-bit-docs#1527

@0x006EA1E5
Copy link
Author

0x006EA1E5 commented Jan 14, 2025

Example config file, for sending logs to Loki at Grafana Cloud:

service:
  log_level: debug

pipeline:
  inputs:
    - name: dummy
      tag: logs
      dummy: '{"message":"simple log generated","logger":"com.example.me.MyClass","level":"INFO","hostname":"OM-M07GV2J252","structured_metadata_attributes":{"a":"hello","b":"world!"}}'

  outputs:
    - name: loki
      match: logs
      host: ${LOKI_HOST}
      http_passwd: ${GRAFANA_TOKEN}
      http_user: ${LOKI_USER_ID}
      remove_keys: hostname
      label_keys: $level,$logger
      labels: service_name=test
      structured_metadata: $hostname
      structured_metadata_map_keys: $structured_metadata_attributes
      line_format: key_value
      drop_single_key: on
      compress: gzip
      port: 443
      tls: true
      tls.verify: true

Debug log output:

* Copyright (C) 2015-2024 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

______ _                  _    ______ _ _             ___  _____ 
|  ___| |                | |   | ___ (_) |           /   ||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   __/ /| || |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / / /_| ||  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V /\___  |\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/     |_(_)___/ 


[2025/01/14 16:50:27] [ info] Configuration:
[2025/01/14 16:50:27] [ info]  flush time     | 1.000000 seconds
[2025/01/14 16:50:27] [ info]  grace          | 5 seconds
[2025/01/14 16:50:27] [ info]  daemon         | 0
[2025/01/14 16:50:27] [ info] ___________
[2025/01/14 16:50:27] [ info]  inputs:
[2025/01/14 16:50:27] [ info]      dummy
[2025/01/14 16:50:27] [ info] ___________
[2025/01/14 16:50:27] [ info]  filters:
[2025/01/14 16:50:27] [ info] ___________
[2025/01/14 16:50:27] [ info]  outputs:
[2025/01/14 16:50:27] [ info]      loki.0
[2025/01/14 16:50:27] [ info] ___________
[2025/01/14 16:50:27] [ info]  collectors:
[2025/01/14 16:50:27] [ info] [fluent bit] version=4.0.0, commit=4f158a5d1c, pid=107098
[2025/01/14 16:50:27] [debug] [engine] coroutine stack size: 196608 bytes (192.0K)
[2025/01/14 16:50:27] [ info] [storage] ver=1.5.2, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2025/01/14 16:50:27] [ info] [simd    ] disabled
[2025/01/14 16:50:27] [ info] [cmetrics] version=0.9.9
[2025/01/14 16:50:27] [ info] [ctraces ] version=0.5.7
[2025/01/14 16:50:27] [ info] [input:dummy:dummy.0] initializing
[2025/01/14 16:50:27] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2025/01/14 16:50:27] [debug] [dummy:dummy.0] created event channels: read=25 write=26
[2025/01/14 16:50:27] [debug] [loki:loki.0] created event channels: read=27 write=28
[2025/01/14 16:50:27] [debug] [output:loki:loki.0] remove_mpa size: 4
[2025/01/14 16:50:27] [ info] [output:loki:loki.0] configured, hostname=logs-prod-006.grafana.net:443
[2025/01/14 16:50:27] [ info] [sp] stream processor started
[2025/01/14 16:50:29] [debug] [task] created task=0xf0fe24071540 id=0 OK
[2025/01/14 16:50:29] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is connected
[2025/01/14 16:50:29] [debug] [http_client] not using http_proxy for header
[2025/01/14 16:50:30] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 16:50:30] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 16:50:30] [debug] [out flush] cb_destroy coro_id=0
[2025/01/14 16:50:30] [debug] [task] destroy task=0xf0fe24071540 (task_id=0)
[2025/01/14 16:50:30] [debug] [task] created task=0xf0fe240a19a0 id=0 OK
[2025/01/14 16:50:30] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 16:50:30] [debug] [http_client] not using http_proxy for header
[2025/01/14 16:50:30] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 16:50:30] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 16:50:30] [debug] [out flush] cb_destroy coro_id=1
[2025/01/14 16:50:30] [debug] [task] destroy task=0xf0fe240a19a0 (task_id=0)
[2025/01/14 16:50:31] [debug] [task] created task=0xf0fe2408d780 id=0 OK
[2025/01/14 16:50:31] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)

@0x006EA1E5
Copy link
Author

valgrind output for flb-rt-out_loki unit test

==131535== Memcheck, a memory error detector
==131535== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==131535== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==131535== Command: /IdeaProjects/fluent-bit/cmake-build-debug/bin/flb-rt-out_loki
==131535== 
Test remove_keys_remove_map...                  [ OK ]
Test labels_ra...                               [ OK ]
Test remove_keys...                             [ OK ]
Test basic...                                   [ OK ]
Test labels...                                  [ OK ]
Test label_keys...                              [ OK ]
Test line_format...                             [ OK ]
Test drop_single_key_off...                     [ OK ]
Test drop_single_key_on...                      [ OK ]
Test drop_single_key_raw...                     [ OK ]
Test label_map_path...                          [ OK ]
Test float_value...                             [ OK ]
Test structured_metadata_map_single_map...      [ OK ]
Test structured_metadata_map_two_maps...        [ OK ]
Test structured_metadata_map_sub_map...         [ OK ]
Test structured_metadata_map_both_with_non_map_value... [ OK ]
Test structured_metadata_map_value_explicit_override_map_key... [ OK ]
Test structured_metadata_explicit_only_no_map... [ OK ]
Test structured_metadata_explicit_only_map...   [ OK ]
Test structured_metadata_map_and_explicit...    [ OK ]
Test structured_metadata_map_single_missing_map... [ OK ]
SUCCESS: All unit tests have passed.
==131535== 
==131535== HEAP SUMMARY:
==131535==     in use at exit: 0 bytes in 0 blocks
==131535==   total heap usage: 34,441 allocs, 34,441 frees, 16,366,899 bytes allocated
==131535== 
==131535== All heap blocks were freed -- no leaks are possible
==131535== 
==131535== For lists of detected and suppressed errors, rerun with: -s
==131535== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@0x006EA1E5
Copy link
Author

valgrind output from test config (confirmed sending logs correctly downstream)

==132953== Memcheck, a memory error detector
==132953== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==132953== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==132953== Command: /IdeaProjects/fluent-bit/cmake-build-debug/bin/fluent-bit -c ./fluent-bit_loki_out-structured_metadata_map.yaml
==132953== 
Fluent Bit v4.0.0
* Copyright (C) 2015-2024 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

______ _                  _    ______ _ _             ___  _____ 
|  ___| |                | |   | ___ (_) |           /   ||  _  |
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   __/ /| || |/' |
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / / /_| ||  /| |
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V /\___  |\ |_/ /
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/     |_(_)___/ 


[2025/01/14 17:45:04] [ info] Configuration:
[2025/01/14 17:45:04] [ info]  flush time     | 1.000000 seconds
[2025/01/14 17:45:04] [ info]  grace          | 5 seconds
[2025/01/14 17:45:04] [ info]  daemon         | 0
[2025/01/14 17:45:04] [ info] ___________
[2025/01/14 17:45:04] [ info]  inputs:
[2025/01/14 17:45:04] [ info]      dummy
[2025/01/14 17:45:04] [ info] ___________
[2025/01/14 17:45:04] [ info]  filters:
[2025/01/14 17:45:04] [ info] ___________
[2025/01/14 17:45:04] [ info]  outputs:
[2025/01/14 17:45:04] [ info]      loki.0
[2025/01/14 17:45:04] [ info] ___________
[2025/01/14 17:45:04] [ info]  collectors:
[2025/01/14 17:45:04] [ info] [fluent bit] version=4.0.0, commit=4f158a5d1c, pid=132953
[2025/01/14 17:45:04] [debug] [engine] coroutine stack size: 196608 bytes (192.0K)
[2025/01/14 17:45:04] [ info] [storage] ver=1.5.2, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2025/01/14 17:45:04] [ info] [simd    ] disabled
[2025/01/14 17:45:04] [ info] [cmetrics] version=0.9.9
[2025/01/14 17:45:04] [ info] [ctraces ] version=0.5.7
[2025/01/14 17:45:04] [ info] [input:dummy:dummy.0] initializing
[2025/01/14 17:45:04] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2025/01/14 17:45:04] [debug] [dummy:dummy.0] created event channels: read=25 write=26
[2025/01/14 17:45:04] [debug] [loki:loki.0] created event channels: read=27 write=28
[2025/01/14 17:45:04] [debug] [output:loki:loki.0] remove_mpa size: 4
[2025/01/14 17:45:04] [ info] [output:loki:loki.0] configured, hostname=logs-prod-006.grafana.net:443
[2025/01/14 17:45:04] [ info] [sp] stream processor started
[2025/01/14 17:45:06] [debug] [task] created task=0x5735150 id=0 OK
[2025/01/14 17:45:07] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is connected
[2025/01/14 17:45:07] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:07] [debug] [task] created task=0x58dd770 id=1 OK
[2025/01/14 17:45:07] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:07] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:07] [debug] [out flush] cb_destroy coro_id=0
[2025/01/14 17:45:07] [debug] [task] destroy task=0x5735150 (task_id=0)
[2025/01/14 17:45:07] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is connected
[2025/01/14 17:45:07] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:08] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:08] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:08] [debug] [out flush] cb_destroy coro_id=1
[2025/01/14 17:45:08] [debug] [task] destroy task=0x58dd770 (task_id=1)
[2025/01/14 17:45:08] [debug] [task] created task=0x6a7b960 id=0 OK
[2025/01/14 17:45:08] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:08] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:08] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:08] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:08] [debug] [out flush] cb_destroy coro_id=2
[2025/01/14 17:45:08] [debug] [task] destroy task=0x6a7b960 (task_id=0)
[2025/01/14 17:45:09] [debug] [task] created task=0x6b55ad0 id=0 OK
[2025/01/14 17:45:09] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:09] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:09] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:09] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:09] [debug] [out flush] cb_destroy coro_id=3
[2025/01/14 17:45:09] [debug] [task] destroy task=0x6b55ad0 (task_id=0)
[2025/01/14 17:45:10] [debug] [task] created task=0x6c2dd80 id=0 OK
[2025/01/14 17:45:10] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:10] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:10] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:10] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:10] [debug] [out flush] cb_destroy coro_id=4
[2025/01/14 17:45:10] [debug] [task] destroy task=0x6c2dd80 (task_id=0)
[2025/01/14 17:45:11] [debug] [task] created task=0x6d05eb0 id=0 OK
[2025/01/14 17:45:11] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:11] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:11] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:11] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:11] [debug] [out flush] cb_destroy coro_id=5
[2025/01/14 17:45:11] [debug] [task] destroy task=0x6d05eb0 (task_id=0)
[2025/01/14 17:45:12] [debug] [task] created task=0x6d1f960 id=0 OK
[2025/01/14 17:45:12] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:12] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:12] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:12] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:12] [debug] [out flush] cb_destroy coro_id=6
[2025/01/14 17:45:12] [debug] [task] destroy task=0x6d1f960 (task_id=0)
[2025/01/14 17:45:13] [debug] [task] created task=0x6eb6400 id=0 OK
[2025/01/14 17:45:13] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:13] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:13] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:13] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:13] [debug] [out flush] cb_destroy coro_id=7
[2025/01/14 17:45:13] [debug] [task] destroy task=0x6eb6400 (task_id=0)
[2025/01/14 17:45:14] [debug] [task] created task=0x6f907a0 id=0 OK
[2025/01/14 17:45:14] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:14] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:14] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:14] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:14] [debug] [out flush] cb_destroy coro_id=8
[2025/01/14 17:45:14] [debug] [task] destroy task=0x6f907a0 (task_id=0)
[2025/01/14 17:45:15] [debug] [task] created task=0x7068af0 id=0 OK
[2025/01/14 17:45:15] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:15] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:15] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:15] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:15] [debug] [out flush] cb_destroy coro_id=9
[2025/01/14 17:45:15] [debug] [task] destroy task=0x7068af0 (task_id=0)
[2025/01/14 17:45:16] [debug] [task] created task=0x70f2530 id=0 OK
[2025/01/14 17:45:16] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:16] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:16] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:16] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:16] [debug] [out flush] cb_destroy coro_id=10
[2025/01/14 17:45:16] [debug] [task] destroy task=0x70f2530 (task_id=0)
[2025/01/14 17:45:17] [debug] [task] created task=0x7107d60 id=0 OK
[2025/01/14 17:45:17] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:17] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:17] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:17] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:17] [debug] [out flush] cb_destroy coro_id=11
[2025/01/14 17:45:17] [debug] [task] destroy task=0x7107d60 (task_id=0)
[2025/01/14 17:45:18] [debug] [task] created task=0x72f1480 id=0 OK
[2025/01/14 17:45:18] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:18] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:18] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:18] [debug] [upstream] KA connection #35 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:18] [debug] [out flush] cb_destroy coro_id=12
[2025/01/14 17:45:18] [debug] [task] destroy task=0x72f1480 (task_id=0)
^C[2025/01/14 17:45:18] [engine] caught signal (SIGINT)
[2025/01/14 17:45:18] [debug] [task] created task=0x73c9900 id=0 OK
[2025/01/14 17:45:18] [ warn] [engine] service will shutdown in max 5 seconds
[2025/01/14 17:45:18] [ info] [input] pausing dummy.0
[2025/01/14 17:45:18] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 has been assigned (recycled)
[2025/01/14 17:45:18] [debug] [http_client] not using http_proxy for header
[2025/01/14 17:45:18] [debug] [output:loki:loki.0] logs-prod-006.grafana.net:443, HTTP status=204
[2025/01/14 17:45:18] [debug] [upstream] KA connection #36 to logs-prod-006.grafana.net:443 is now available
[2025/01/14 17:45:18] [debug] [out flush] cb_destroy coro_id=13
[2025/01/14 17:45:18] [debug] [task] destroy task=0x73c9900 (task_id=0)
[2025/01/14 17:45:19] [ info] [engine] service has stopped (0 pending tasks)
[2025/01/14 17:45:19] [ info] [input] pausing dummy.0
==132953== 
==132953== HEAP SUMMARY:
==132953==     in use at exit: 0 bytes in 0 blocks
==132953==   total heap usage: 20,718 allocs, 20,718 frees, 14,506,821 bytes allocated
==132953== 
==132953== All heap blocks were freed -- no leaks are possible
==132953== 
==132953== For lists of detected and suppressed errors, rerun with: -s
==132953== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@0x006EA1E5
Copy link
Author

Screenshot of Grafana Loki, showing the remote logs with structured metadata fields a and b:
image

@0x006EA1E5
Copy link
Author

0x006EA1E5 commented Jan 17, 2025

I have now added a docker compose at docker_compose/loki-grafana-structured_metadata_map.

n.b., to run this for the branch, we of course need to build the image so that fluent/fluent-bit:latest contains the local changes. I did this via docker build -t fluent/fluent-bit --target=production -f dockerfiles/Dockerfile . as described in dockerfiles/README.md.

Running this, we can go to the Grafana instance running at http://localhost:3000/ and see the logs with the expected structured_metadata:
image

I have a slightly different / updated fluentbit config for this:

service:
  log_level: debug

pipeline:
  inputs:
    - name: dummy
      tag: logs
      dummy: |
        {
          "message": "simple log generated",
          "logger": "my.logger",
          "level": "INFO",
          "hostname": "localhost",
          "my_map_of_attributes_1": {
            "key_1": "hello, world!",
            "key_2": "goodbye, world!"
          },
          "my_map_of_maps_1": {
            "root_key": {
              "sub_key_1": "hello, world!",
              "sub_key_2": "goodbye, world!"
            }
          }
        }

  outputs:
    - name: loki
      match: logs
      host: loki
      remove_keys: hostname,my_map_of_attributes_1,my_map_of_maps_1
      label_keys: $level,$logger
      labels: service_name=test
      structured_metadata: $hostname
      structured_metadata_map_keys: $my_map_of_attributes_1,$my_map_of_maps_1['root_key']
      line_format: key_value
      drop_single_key: on

* Adds stuctured_metadata_map_keys config to dynamically populate stuctured_metadata from a map

Signed-off-by: Greg Eales <[email protected]>
Add docker-compose to test loki backend

Signed-off-by: Greg Eales <[email protected]>
@0x006EA1E5 0x006EA1E5 force-pushed the loki_out-structured_metadata_map branch from da03432 to 02c8797 Compare January 17, 2025 18:34
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
3 participants