Skip to content

Conversation

@jvandenbroek
Copy link

@jvandenbroek jvandenbroek commented Nov 13, 2025

This adds support for Source_Address_Key when Format is set to none.

Addresses my earlier comment in this PR: #7673 (comment)


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
[INPUT]
    Name        udp
    Listen      0.0.0.0
    Port        5170
    Format      none
    Source_Address_Key source_host

[OUTPUT]
    Name        stdout
    Match       *
  • Debug log output from testing the change
[2025/11/13 17:20:42.324041892] [ info] Configuration:
[2025/11/13 17:20:42.324070936] [ info]  flush time     | 1.000000 seconds
[2025/11/13 17:20:42.324075966] [ info]  grace          | 5 seconds
[2025/11/13 17:20:42.324079452] [ info]  daemon         | 0
[2025/11/13 17:20:42.324083169] [ info] ___________
[2025/11/13 17:20:42.324086475] [ info]  inputs:
[2025/11/13 17:20:42.324089701] [ info]      udp
[2025/11/13 17:20:42.324093077] [ info] ___________
[2025/11/13 17:20:42.324097255] [ info]  filters:
[2025/11/13 17:20:42.324100441] [ info] ___________
[2025/11/13 17:20:42.324104358] [ info]  outputs:
[2025/11/13 17:20:42.324108055] [ info]      stdout.0
[2025/11/13 17:20:42.324111472] [ info] ___________
[2025/11/13 17:20:42.324114898] [ info]  collectors:
[2025/11/13 17:20:42.324341100] [ info] [fluent bit] version=4.2.1, commit=f1ba23a2e8, pid=1581429
[2025/11/13 17:20:42.324348413] [debug] [engine] coroutine stack size: 24576 bytes (24.0K)
[2025/11/13 17:20:42.324366747] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2025/11/13 17:20:42.324372628] [ info] [simd    ] disabled
[2025/11/13 17:20:42.324374872] [ info] [cmetrics] version=1.0.5
[2025/11/13 17:20:42.324378890] [ info] [ctraces ] version=0.6.6
[2025/11/13 17:20:42.324420347] [ info] [input:udp:udp.0] initializing
[2025/11/13 17:20:42.324423223] [ info] [input:udp:udp.0] storage_strategy='memory' (memory only)
[2025/11/13 17:20:42.324429644] [debug] [udp:udp.0] created event channels: read=26 write=27
[2025/11/13 17:20:42.324466653] [debug] [downstream] listening on 0.0.0.0:5170
[2025/11/13 17:20:42.324478385] [debug] [stdout:stdout.0] created event channels: read=29 write=30
[2025/11/13 17:20:42.324590003] [ info] [sp] stream processor started
[2025/11/13 17:20:42.324606915] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2025/11/13 17:20:42.324627814] [ info] [output:stdout:stdout.0] worker #0 started
[2025/11/13 17:21:35.432746309] [debug] [task] created task=0x7feee802aa60 id=0 OK
[2025/11/13 17:21:35.432759764] [debug] [output:stdout:stdout.0] task_id=0 assigned to thread #0
[0] udp.0: [[1763050895.017758118, {}], {"log"=>"test message", "source_host"=>"udp://127.0.0.1:40466"}]
[2025/11/13 17:21:35.445284487] [debug] [out flush] cb_destroy coro_id=0
[2025/11/13 17:21:35.445313711] [debug] [task] destroy task=0x7feee802aa60 (task_id=0)
  • Attached Valgrind output that shows no leaks or memory corruption was found

Unfortunately Valgrind fails on my Manjaro system, which seems to be expected because Valgrind uses Arch's glibc. But I doubt these simple changes, which were already implemented for the json part, would cause any issues. Maybe someone could test this?

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Initially added documentation which corresponds to fluent/fluent-bit-docs#1165

Backporting

  • [N/A] 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.

Summary by CodeRabbit

  • New Features

    • UDP NONE-format logs can optionally include the source (remote) address when enabled in configuration, appending it to log records without changing default behavior.
  • Tests

    • Added test coverage verifying UDP NONE-format logging includes the configured source address alongside the log payload.

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Walkthrough

Conditionally include the remote UDP source address in NONE-format log records when source_address_key is configured by retrieving the remote address and appending it to the encoded payload alongside the log value.

Changes

Cohort / File(s) Change Summary
UDP input logic
plugins/in_udp/udp_conn.c
Add source_address local variable; when source_address_key is set, call flb_connection_get_remote_address and, if available, append (key, address) to the NONE-format encoded payload; preserve original behavior when not configured.
Tests
tests/runtime/in_udp.c
Add flb_test_format_none_with_source_address and register it in TEST_LIST; test sends a UDP message with format "none" and source_address_key (e.g., source_host) and asserts the output payload contains both the log and the source key.

Sequence Diagram(s)

sequenceDiagram
    participant Sender as UDP Sender
    participant Conn as udp_conn (plugin)
    participant Encoder as NONE Encoder
    participant Out as Output

    Sender->>Conn: send UDP packet
    Conn->>Conn: parse packet into log_value
    alt source_address_key configured
        Conn->>Conn: flb_connection_get_remote_address()
        Conn-->>Encoder: encode(log_value, source_address_key, source_address)
    else not configured
        Conn-->>Encoder: encode(log_value)
    end
    Encoder->>Out: emit encoded payload (JSON or NONE-format record)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Small, localized conditional change in plugins/in_udp/udp_conn.c.
  • New test added in tests/runtime/in_udp.c following existing patterns.
  • Review focus:
    • Correct retrieval and formatting of remote address.
    • Proper handling when remote address is absent.
    • Test timing/wait logic and assertions.

Poem

🐰 A packet by moonlight hops my way,
I whisper its origin in the log today.
No fuss, just a key with a tiny host name,
I stitch it to records — hop! — and it's part of the frame. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 accurately summarizes the main change: adding capability to insert source IP in UDP input when format is set to 'none', which directly aligns with the changeset modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6e89c4 and c560873.

📒 Files selected for processing (2)
  • plugins/in_udp/udp_conn.c (2 hunks)
  • tests/runtime/in_udp.c (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/runtime/in_udp.c
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/in_udp/udp_conn.c (1)
src/flb_log_event_encoder.c (2)
  • flb_log_event_encoder_begin_record (246-254)
  • flb_log_event_encoder_set_current_timestamp (289-292)
🔇 Additional comments (3)
plugins/in_udp/udp_conn.c (3)

267-267: LGTM! Variable declaration is appropriate.

The source_address variable is correctly declared at function scope to hold the remote address string when needed.


296-309: Excellent implementation following established patterns.

The conditional logic correctly handles both scenarios:

  • When source address is available, it appends both the log content and the source address
  • When not available, it appends only the log content

This implementation is consistent with the ARRAY type handling in process_pack (lines 174-187), which promotes maintainability.


286-286: No issues found—memory management is correct.

The function returns a pointer to internal connection memory (connection->user_friendly_remote_host), which is managed by the connection structure itself. The caller should not and does not need to free this memory. The NULL initialization and conditional retrieval pattern are appropriate.


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.

Signed-off-by: Joost van den Broek <jvandenbroek@gmail.com>
@jvandenbroek jvandenbroek force-pushed the source-address-udp-format-none branch from e6e89c4 to c560873 Compare November 13, 2025 17:17
Copy link
Contributor

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

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

I've left a few notes related to the test code but those are just information, it's good as is.

ssize_t w_size;

char *buf = "message\n";
size_t size = strlen(buf);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please separate the definition of this variable from the assignment of it.

int num;
ssize_t w_size;

char *buf = "message\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please declare this variable as a const char *

ctx = test_ctx_create(&cb_data);
if (!TEST_CHECK(ctx != NULL)) {
TEST_MSG("test_ctx_create failed");
exit(EXIT_FAILURE);
Copy link
Contributor

Choose a reason for hiding this comment

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

I could be wrong but I think failed test cases shouldn't exit but instead just return

}

/* waiting to flush */
flb_time_msleep(1500);
Copy link
Contributor

Choose a reason for hiding this comment

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

As a general rule, basing non timing related tests on timing is problematic, particularly when CI runs on nodes that are somewhat loaded as it tends to create false positives.

struct sockaddr_in addr;
flb_sockfd_t fd;
int ret;
int num;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using meaningful variable names is preferred to these generic names because even though this is a simple test case neglecting to do so leads to using these types of names in more complex (and meaningful) pieces of code which means someone who reads the code later on might have a harder time understanding it or even miss the point and end up introducing a bug.

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