Skip to content

out_chronicle: Support label and namespace mapping#11836

Open
cosmo0920 wants to merge 3 commits into
masterfrom
cosmo0920-label-and-namespace-mapping-chronicle
Open

out_chronicle: Support label and namespace mapping#11836
cosmo0920 wants to merge 3 commits into
masterfrom
cosmo0920-label-and-namespace-mapping-chronicle

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented May 22, 2026

To follow the requested structure of unstructuredlogentries format on https://docs.cloud.google.com/chronicle/docs/reference/ingestion-api#unstructuredlogentries,
we need to add a metadata like namespace and labels which should be defined by users.

Closes #11833.


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/fluent-bit-docs#2582


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.

Summary by CodeRabbit

  • New Features

    • Chronicle output now supports a configurable namespace (static or extracted from records) and repeatable labels (static or extracted). Metadata is resolved once per batch and reused; payloads split when namespace/labels change. namespace and labels are only emitted when present.
  • Tests

    • Added runtime tests verifying namespace extraction and fallback, dynamic label presence/omission, and batch-splitting when metadata changes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The Google Chronicle output plugin gains config-driven namespace and labels support: accessors resolve namespace and label values per-record, metadata is resolved once per batch (batch-split on changes), and optional namespace and labels are conditionally emitted in the Chronicle payload.

Changes

Chronicle namespace and labels metadata feature

Layer / File(s) Summary
Type definitions for namespace and labels
plugins/out_chronicle/chronicle.h
New struct flb_chronicle_label holds label key/value pairs and optional record accessors. struct flb_chronicle extended with namespace SDS, namespace record accessor, and label property list and list container.
Configuration lifecycle and validation
plugins/out_chronicle/chronicle_conf.c
Label helpers validate key/value pairs, optionally create record accessors for dynamic values (when value contains $), and manage lifecycle. Namespace validated non-empty; namespace_ra created from namespace_key if configured. Labels and namespace accessors destroyed during config teardown.
Metadata resolution and output formatting
plugins/out_chronicle/chronicle.c
chronicle_metadata_resolve() resolves namespace (via accessor or static fallback) and label values, populating a temporary resolved-label list. During formatting, metadata resolved once per batch; batch adopts first resolved metadata and splits when subsequent records differ. Root msgpack map size adjusted dynamically to account for optional namespace and labels array. Resolved namespace and labels conditionally packed into payload; all temporary resources freed on completion or error.
Config map extension
plugins/out_chronicle/chronicle.c
Adds namespace, namespace_key (falls back to namespace), and repeatable label configuration entries in the plugin config_map.
Validation tests for namespace and labels
tests/runtime/out_chronicle.c
Formatter callbacks and integration tests validate namespace and labels presence, fallback behavior, omission when source data is missing, and batch-splitting when metadata changes across records. Tests registered in TEST_LIST.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • edsiper

Poem

🐰 A rabbit hops through code and logs so bright,
With namespaces stitched and labels taking flight,
Static carrots, dynamic greens — all in a row,
Batches split neat where metadata won’t flow,
Hoppy builds and tidy packs — hop, pipeline, go!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'out_chronicle: Support label and namespace mapping' directly summarizes the main change—adding label and namespace support to the Chronicle output plugin.
Linked Issues check ✅ Passed The PR implements namespace configuration with record accessors and repeatable label key-value pairs matching issue #11833 requirements for out-of-band metadata injection into the Chronicle API.
Out of Scope Changes check ✅ Passed All changes are scoped to namespace/label support in the Chronicle output plugin; no unrelated modifications detected in the changeset.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-label-and-namespace-mapping-chronicle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/runtime/out_chronicle.c (1)

153-170: ⚡ Quick win

Assert label key/value pairs together to avoid false positives.

The current checks validate keys and values independently, so a mismatched pairing could still pass. Prefer asserting the expected pair objects (or parsing JSON and validating structured fields).

Suggested patch
-    p = strstr(out_json, "\"key\":\"env\"");
-    if (!TEST_CHECK(p != NULL)) {
-        TEST_MSG("Expected static label key not found. Got: %s", out_json);
-    }
-
-    p = strstr(out_json, "\"value\":\"production\"");
-    if (!TEST_CHECK(p != NULL)) {
-        TEST_MSG("Expected static label value not found. Got: %s", out_json);
-    }
-
-    p = strstr(out_json, "\"key\":\"cluster_name\"");
-    if (!TEST_CHECK(p != NULL)) {
-        TEST_MSG("Expected dynamic label key not found. Got: %s", out_json);
-    }
-
-    p = strstr(out_json, "\"value\":\"blue\"");
-    if (!TEST_CHECK(p != NULL)) {
-        TEST_MSG("Expected dynamic label value not found. Got: %s", out_json);
-    }
+    p = strstr(out_json, "\"key\":\"env\",\"value\":\"production\"");
+    if (!TEST_CHECK(p != NULL)) {
+        TEST_MSG("Expected static label pair not found. Got: %s", out_json);
+    }
+
+    p = strstr(out_json, "\"key\":\"cluster_name\",\"value\":\"blue\"");
+    if (!TEST_CHECK(p != NULL)) {
+        TEST_MSG("Expected dynamic label pair not found. Got: %s", out_json);
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/runtime/out_chronicle.c` around lines 153 - 170, The tests currently
look for keys and values separately using strstr(out_json, ...) which can yield
false positives if pairs are mismatched; update the checks in
tests/runtime/out_chronicle.c to assert the key/value pairs together (e.g.
search for the combined substring representing the pair such as
"\"key\":\"env\",\"value\":\"production\"" and similarly for cluster_name/blue)
or parse out_json into a JSON object and validate that for the same label object
the key equals "env" and value equals "production" (use the existing
TEST_CHECK/TEST_MSG pattern and the same variables p and out_json or the parsed
structure to report failures).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/out_chronicle/chronicle_conf.c`:
- Around line 71-74: The validation wrongly allows empty label values and
mis-detects record accessors by scanning for any '$' anywhere; update the check
around key, key_len, value, value_len to treat value_len == 0 as an error as
well (same failure path and log), and change the RA detection logic that
currently inspects value for any '$' to only treat it as a record accessor when
the first character of value is '$' (i.e., use value[0] == '$' or equivalent) so
static values containing '$' are accepted; update references in chronicle_conf.c
where key/key_len/value/value_len and the RA detection are used.

In `@plugins/out_chronicle/chronicle.c`:
- Around line 883-897: The code currently uses metadata_resolved as a one-time
gate so chronicle_metadata_resolve is called only for the first record in a
batch, causing later records to reuse the same namespace/resolved_labels; remove
that gating and call chronicle_metadata_resolve for each record (e.g., before
sending each log_event) using the same parameters (tag, tag_len,
*log_event.body, &namespace, &resolved_labels, &label_count), ensure you
destroy/free any previous namespace and resolved_labels
(flb_sds_destroy(namespace) and
chronicle_resolved_labels_destroy(&resolved_labels)) before reassigning to avoid
leaks, and handle the non-zero return path the same way it does now (cleanup and
return error) so each record gets its correct per-record namespace/labels.

In `@tests/runtime/out_chronicle.c`:
- Around line 138-143: The new formatter callbacks use strstr on
res_data/out_json without checking for NULL; add a null guard that checks if
res_data (or out_json) is NULL before calling strstr and handle the error path
cleanly (e.g., set_output_invoked to indicate failure, fail the test or return
early) so the test does not segfault; update both occurrences around the strstr
calls (the variables res_data/out_json and the pointer p) to bail out with a
clear test failure when NULL is encountered.

---

Nitpick comments:
In `@tests/runtime/out_chronicle.c`:
- Around line 153-170: The tests currently look for keys and values separately
using strstr(out_json, ...) which can yield false positives if pairs are
mismatched; update the checks in tests/runtime/out_chronicle.c to assert the
key/value pairs together (e.g. search for the combined substring representing
the pair such as "\"key\":\"env\",\"value\":\"production\"" and similarly for
cluster_name/blue) or parse out_json into a JSON object and validate that for
the same label object the key equals "env" and value equals "production" (use
the existing TEST_CHECK/TEST_MSG pattern and the same variables p and out_json
or the parsed structure to report failures).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b42c43d8-6d76-4b12-84bd-f9607f85f4a4

📥 Commits

Reviewing files that changed from the base of the PR and between f6126eb and 9df0472.

📒 Files selected for processing (4)
  • plugins/out_chronicle/chronicle.c
  • plugins/out_chronicle/chronicle.h
  • plugins/out_chronicle/chronicle_conf.c
  • tests/runtime/out_chronicle.c

Comment thread plugins/out_chronicle/chronicle_conf.c
Comment thread plugins/out_chronicle/chronicle.c
Comment thread tests/runtime/out_chronicle.c
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9df047220c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/out_chronicle/chronicle.c Outdated
@cosmo0920 cosmo0920 force-pushed the cosmo0920-label-and-namespace-mapping-chronicle branch from 519af6b to 38d78bb Compare May 22, 2026 05:12
@cosmo0920 cosmo0920 changed the title out_chronicle: label and namespace mapping chronicle out_chronicle: Support label and namespace mapping chronicle May 22, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/out_chronicle/chronicle.c`:
- Around line 975-987: The failure path after chronicle_metadata_resolve(...)
currently returns -1 without freeing any previously queued buffered entries;
update the error branch in chronicle_format (the block handling ret != 0) to
free the queued entry_list before returning by calling the same cleanup used on
successful/normal teardown (i.e., invoke the function that destroys/clears the
buffered entries — the one used elsewhere for entry_list cleanup) in addition to
the existing flb_sds_destroy( log_text / record_namespace / namespace ) and
chronicle_resolved_labels_destroy(&record_labels / &resolved_labels) calls so no
entry_list memory is leaked on metadata-resolution failure.

In `@tests/runtime/out_chronicle.c`:
- Around line 201-235: The test callback
cb_check_format_split_on_metadata_change currently forces the invocation count
to 1 via set_output_invoked(1), which hides whether a second split payload was
emitted; change the callback to increment the invocation counter (e.g., call
set_output_invoked(get_output_invoked()+1) or use an increment function) and add
assertions that when invoked a second time the res_data contains the second
payload markers ("tenant-b", "green", "record two"); update the test harness
assertions (where cb_check_format_split_on_metadata_change is used) to expect at
least two invocations instead of only one so the test fails if the second split
is dropped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f33ca8d8-3bee-451c-9297-c46e28027d74

📥 Commits

Reviewing files that changed from the base of the PR and between 9df0472 and 38d78bb.

📒 Files selected for processing (2)
  • plugins/out_chronicle/chronicle.c
  • tests/runtime/out_chronicle.c

Comment thread plugins/out_chronicle/chronicle.c
Comment thread tests/runtime/out_chronicle.c
@cosmo0920 cosmo0920 changed the title out_chronicle: Support label and namespace mapping chronicle out_chronicle: Support label and namespace mapping May 22, 2026
@cosmo0920 cosmo0920 force-pushed the cosmo0920-label-and-namespace-mapping-chronicle branch from 38d78bb to 475a48f Compare May 22, 2026 05:25
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/out_chronicle/chronicle.c`:
- Around line 902-903: chronicle_format() must initialize its output pointers to
deterministic defaults so callers (like cb_chronicle_flush()) don't attempt to
free garbage when chronicle_format() returns early; at the top of
chronicle_format(), set *out_data = NULL, *out_size = 0, and *out_offset = 0 (or
equivalent deterministic values) so payload_buf in cb_chronicle_flush() will be
NULL if an error occurs and flb_sds_destroy(payload_buf) is safe; ensure any
early-return error paths do not overwrite these defaults.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5db04ec5-1291-459d-808d-cff5d8ff67a2

📥 Commits

Reviewing files that changed from the base of the PR and between 38d78bb and 475a48f.

📒 Files selected for processing (4)
  • plugins/out_chronicle/chronicle.c
  • plugins/out_chronicle/chronicle.h
  • plugins/out_chronicle/chronicle_conf.c
  • tests/runtime/out_chronicle.c

Comment thread plugins/out_chronicle/chronicle.c
cosmo0920 added 2 commits May 22, 2026 14:43
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
…mappings

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/out_chronicle/chronicle.c`:
- Around line 837-851: flb_ra_translate_check may return an empty string which
should be treated like NULL; update the post-call check for the resolved
namespace (the result stored in *namespace after calling flb_ra_translate_check
with ctx->namespace_ra, tag, tag_len, map) to treat both NULL and empty-string
results as unresolved and trigger the existing fallback: if the translated value
is NULL or its first character is '\0' then fall back to
flb_sds_create(ctx->namespace) when ctx->namespace is set, otherwise call
flb_plg_warn(ctx->ins, "namespace_key '%s' did not resolve for this batch",
ctx->namespace_key). Ensure you reference ctx->namespace_ra,
flb_ra_translate_check, *namespace, and ctx->namespace in the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 553b6feb-9ecc-4bad-b88b-bdef1f5cac3d

📥 Commits

Reviewing files that changed from the base of the PR and between 475a48f and deaf050.

📒 Files selected for processing (4)
  • plugins/out_chronicle/chronicle.c
  • plugins/out_chronicle/chronicle.h
  • plugins/out_chronicle/chronicle_conf.c
  • tests/runtime/out_chronicle.c

Comment thread plugins/out_chronicle/chronicle.c
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
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.

[Feature Request] Support for native out-of-band Labels and Namespace mapping in google-chronicle destination plugin

1 participant