Skip to content

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

Open
agup006 wants to merge 1 commit intomasterfrom
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 intomasterfrom
codex/add-hostname-field-to-fluentbit-log-dna-plugin

Conversation

@agup006
Copy link
Member

@agup006 agup006 commented Mar 3, 2026

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

Release Notes

  • New Features

    • LogDNA output now includes hostname in log records, extracted from the log entry or falling back to a configured default hostname.
  • Tests

    • Added runtime tests to verify hostname field handling in LogDNA output plugin.

Signed-off-by: Codex <codex@openai.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

This PR adds hostname field support to the LogDNA output plugin, enabling hostname extraction from log records with automatic fallback to configured defaults. Comprehensive runtime tests validate both scenarios—hostname present in record and hostname from configuration.

Changes

Cohort / File(s) Summary
LogDNA Plugin Implementation
plugins/out_logdna/logdna.c
Adds hostname extraction from log records during payload construction. Implements fallback logic to use configured hostname (ctx->_hostname) if not found in record. Adjusts MessagePack map sizing to account for the new hostname key.
Test Infrastructure
tests/runtime/CMakeLists.txt
Registers new LogDNA output runtime test target (FLB_OUT_LOGDNA) in the Output Plugins test section.
Test Cases
tests/runtime/out_logdna.c
Introduces two runtime tests: flb_test_record_hostname_field validates hostname extraction from record data, and flb_test_default_hostname_field validates fallback to configured hostname when record lacks hostname field. Both tests configure Fluent Bit context, push test events, and verify correct hostname in JSON output.

Poem

🐰 Hops of joy, the hostname's here,
Records dance or defaults near,
No more lost in the log's great deep,
Each message now its home can keep! 🏠

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding hostname as a primary field to the LogDNA output plugin and introducing runtime tests for it.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • 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 and usage tips.

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

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

🧹 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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants