Skip to content

out_logdna: add hostname as primary field and runtime tests - #11517

Open
agup006 wants to merge 1 commit into
masterfrom
codex/add-hostname-field-to-fluentbit-log-dna-plugin
Open

out_logdna: add hostname as primary field and runtime tests#11517
agup006 wants to merge 1 commit into
masterfrom
codex/add-hostname-field-to-fluentbit-log-dna-plugin

Conversation

@agup006

@agup006 agup006 commented Mar 3, 2026

Copy link
Copy Markdown
Member

Motivation

  • Ensure LogDNA output treats hostname like other well-known primary fields so a record-level hostname can be used when present.
  • Provide a predictable fallback to the configured/environment hostname when a record does not include hostname.

Description

  • Updated record_append_primary_keys in plugins/out_logdna/logdna.c to recognize the hostname key in records and append it to the payload when present.
  • When a record does not contain hostname, inject the plugin-configured/environment hostname from ctx->_hostname into the record payload.
  • Added a runtime test file tests/runtime/out_logdna.c with two cases: record_hostname_field (verifies record-level hostname passthrough) and default_hostname_field (verifies default hostname injection from output config).
  • Registered the new runtime test target in tests/runtime/CMakeLists.txt so the test binary flb-rt-out_logdna is built with runtime tests enabled.

Testing

  • Configured the build with cmake -DFLB_DEV=On -DFLB_TESTS_RUNTIME=On -DFLB_TESTS_INTERNAL=On ../ and built the runtime test target flb-rt-out_logdna successfully.
  • Executed the runtime test binary with bin/flb-rt-out_logdna, which ran both test cases and reported success.
  • Ran the test binary under Valgrind with valgrind --leak-check=full bin/flb-rt-out_logdna and observed no memory leaks or errors (all tests passed).
  • All automated runtime tests added/affected by this change passed.

Codex Task

Summary by CodeRabbit

  • New Features

    • Log records sent to LogDNA now promote hostname information to a top-level field.
    • Record-provided hostnames take precedence, with a configured hostname used as a fallback.
    • When configured, promoted hostnames are excluded from the message body to prevent duplication.
  • Tests

    • Added coverage for record-provided hostnames, fallback hostnames, and duplicate prevention.

@coderabbitai

coderabbitai Bot commented Mar 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The LogDNA output plugin now promotes record-level hostname values, falls back to the configured hostname, excludes promoted hostnames from line when enabled, and includes runtime tests for these cases.

Changes

LogDNA hostname handling

Layer / File(s) Summary
Hostname payload composition
plugins/out_logdna/logdna.c
The formatter promotes the first record hostname as a top-level primary key, excludes it from line when configured, and emits the configured hostname when the record has none.
Hostname runtime validation
tests/runtime/out_logdna.c
Runtime tests cover record promotion, configured fallback, non-duplication in line, escaped message preservation, and test registration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: edsiper, cosmo0920

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: adding hostname as a primary field and adding runtime tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/add-hostname-field-to-fluentbit-log-dna-plugin

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.

@agup006
agup006 marked this pull request as ready for review March 3, 2026 21:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

58-68: Assert setup/push return values to prevent false-positive passes.

The tests currently don’t verify several API call results (flb_service_set, flb_input_set, flb_output_set, flb_lib_push, and ffd creation). If one fails, the test can pass without actually validating behavior.

Proposed hardening diff
 void flb_test_record_hostname_field()
 {
     int ret;
@@
     ctx = flb_create();
-    flb_service_set(ctx, "flush", "1", "grace", "1", NULL);
+    TEST_CHECK(ctx != NULL);
+    ret = flb_service_set(ctx, "flush", "1", "grace", "1", NULL);
+    TEST_CHECK(ret == 0);

     in_ffd = flb_input(ctx, (char *) "lib", NULL);
-    flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+    TEST_CHECK(in_ffd >= 0);
+    ret = flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+    TEST_CHECK(ret == 0);

     out_ffd = flb_output(ctx, (char *) "logdna", NULL);
-    flb_output_set(ctx, out_ffd,
-                   "match", "test",
-                   "api_key", "dummy-api-key",
-                   NULL);
+    TEST_CHECK(out_ffd >= 0);
+    ret = flb_output_set(ctx, out_ffd,
+                         "match", "test",
+                         "api_key", "dummy-api-key",
+                         NULL);
+    TEST_CHECK(ret == 0);
@@
-    flb_lib_push(ctx, in_ffd,
-                 (char *) "[12345678, {\"hostname\":\"record-host\",\"message\":\"hello\"}]",
-                 size);
+    ret = flb_lib_push(ctx, in_ffd,
+                       (char *) "[12345678, {\"hostname\":\"record-host\",\"message\":\"hello\"}]",
+                       size);
+    TEST_CHECK(ret > 0);
@@
 void flb_test_default_hostname_field()
 {
     int ret;
@@
     ctx = flb_create();
-    flb_service_set(ctx, "flush", "1", "grace", "1", NULL);
+    TEST_CHECK(ctx != NULL);
+    ret = flb_service_set(ctx, "flush", "1", "grace", "1", NULL);
+    TEST_CHECK(ret == 0);

     in_ffd = flb_input(ctx, (char *) "lib", NULL);
-    flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+    TEST_CHECK(in_ffd >= 0);
+    ret = flb_input_set(ctx, in_ffd, "tag", "test", NULL);
+    TEST_CHECK(ret == 0);

     out_ffd = flb_output(ctx, (char *) "logdna", NULL);
-    flb_output_set(ctx, out_ffd,
-                   "match", "test",
-                   "api_key", "dummy-api-key",
-                   "hostname", "config-host",
-                   NULL);
+    TEST_CHECK(out_ffd >= 0);
+    ret = flb_output_set(ctx, out_ffd,
+                         "match", "test",
+                         "api_key", "dummy-api-key",
+                         "hostname", "config-host",
+                         NULL);
+    TEST_CHECK(ret == 0);
@@
-    flb_lib_push(ctx, in_ffd,
-                 (char *) "[12345678, {\"message\":\"hello\"}]",
-                 size);
+    ret = flb_lib_push(ctx, in_ffd,
+                       (char *) "[12345678, {\"message\":\"hello\"}]",
+                       size);
+    TEST_CHECK(ret > 0);

Also applies to: 78-80, 95-107, 116-118

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/runtime/out_logdna.c` around lines 58 - 68, The test doesn't check
return values and can false-pass; add assertions after each creation/config call
to fail the test on error: verify ctx from flb_create is non-NULL, verify
in_ffd/out_ffd from flb_input and flb_output are non-NULL, and assert
flb_service_set, flb_input_set, flb_output_set and flb_lib_push return success
(non-error/expected return code) so failures abort the test; update all
occurrences around flb_create, flb_service_set, flb_input, flb_input_set,
flb_output, flb_output_set and flb_lib_push (including the other ranges noted)
to check and handle their return values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/runtime/out_logdna.c`:
- Around line 58-68: The test doesn't check return values and can false-pass;
add assertions after each creation/config call to fail the test on error: verify
ctx from flb_create is non-NULL, verify in_ffd/out_ffd from flb_input and
flb_output are non-NULL, and assert flb_service_set, flb_input_set,
flb_output_set and flb_lib_push return success (non-error/expected return code)
so failures abort the test; update all occurrences around flb_create,
flb_service_set, flb_input, flb_input_set, flb_output, flb_output_set and
flb_lib_push (including the other ranges noted) to check and handle their return
values.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7db0c7 and bb6e91e.

📒 Files selected for processing (3)
  • plugins/out_logdna/logdna.c
  • tests/runtime/CMakeLists.txt
  • tests/runtime/out_logdna.c

@cosmo0920

Copy link
Copy Markdown
Contributor

The patch seems good but DCO complains Signed-off glitch:
https://github.com/fluent/fluent-bit/pull/11517/checks?check_run_id=65626494515

Could you use the correct Signed-off signature?

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions Bot added the Stale label Jun 3, 2026
@agup006
agup006 force-pushed the codex/add-hostname-field-to-fluentbit-log-dna-plugin branch from bb6e91e to a55bd63 Compare August 10, 2026 17:08
Promote a record's "hostname" key to a top-level field, falling back to
the hostname resolved at configuration time when the record does not
carry one. This follows the same handling as the other primary keys, so
with exclude_promoted_keys enabled the value is not duplicated into the
line body.

Signed-off-by: Anurag Gupta <agup006@gmail.com>
@agup006
agup006 force-pushed the codex/add-hostname-field-to-fluentbit-log-dna-plugin branch from a55bd63 to 118f3ed Compare August 10, 2026 17:26
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

758-758: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use the required control-statement brace style.

Move each if opening brace to the next line.

  • tests/runtime/out_logdna.c#L758-L758: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L802-L802: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L820-L820: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L865-L865: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L883-L883: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L887-L887: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L891-L891: move the if opening brace to the next line.
  • tests/runtime/out_logdna.c#L936-L936: move the if opening brace to the next line.
🤖 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_logdna.c` at line 758, In tests/runtime/out_logdna.c,
update the control-statement brace style for the if statements at lines 758,
802, 820, 865, 883, 887, 891, and 936 by placing each opening brace on the
following line; preserve all conditions and bodies unchanged.

Source: Coding guidelines

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

Nitpick comments:
In `@tests/runtime/out_logdna.c`:
- Line 758: In tests/runtime/out_logdna.c, update the control-statement brace
style for the if statements at lines 758, 802, 820, 865, 883, 887, 891, and 936
by placing each opening brace on the following line; preserve all conditions and
bodies unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0599adaa-37ea-44ee-82e8-2a461043e5ed

📥 Commits

Reviewing files that changed from the base of the PR and between a1d6fb1 and 118f3ed.

📒 Files selected for processing (2)
  • plugins/out_logdna/logdna.c
  • tests/runtime/out_logdna.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/out_logdna/logdna.c

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.

2 participants