Skip to content

out_datadog: added support for site configuration field #10582

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

Closed
wants to merge 2 commits into from

Conversation

lucastemb
Copy link

@lucastemb lucastemb commented Jul 11, 2025

Add site Parameter to Fluent Bit Plugin for Regional Data Routing

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.

  • [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

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

    • Added support for a new "site" configuration option in the Datadog output plugin, allowing users to specify the Datadog site for telemetry data (e.g., 'datadoghq.com', 'datadoghq.eu').
    • The plugin now constructs the endpoint hostname automatically based on the provided "site" value, unless a custom host is set.
  • Bug Fixes

    • Improved memory management to ensure the "site" configuration is properly released during cleanup.

@lucastemb
Copy link
Author

Example Config File:

[SERVICE]
    Flush        1
    Log_Level    trace
    Parsers_File parsers.conf

[INPUT]
    Name        dummy
    Tag         dummy
    Dummy       {"message": "Testing support for site confiruation ", "test": "AGNTLOG-206", "container_id": "abc123def456", "container_name": "/ecs-web-service", "container_image": "nginx:1.24-alpine", "ecs_cluster": "arn:aws:ecs:us-west-2:123456789012:cluster/production-cluster", "ecs_task_definition": "web-service:42", "ecs_task_arn": "arn:aws:ecs:us-west-2:123456789012:task/production-cluster/abc123def456-7890-1234-5678-901234567890"}

[OUTPUT]
    Name        datadog
    Match       *
    apikey      ${DD_API_KEY}
    dd_hostname foobar
    provider    ecs
    dd_source   fluent-bit
    dd_service  test-service
    dd_tags     env:test,version:1.0
    compress    gzip 
    site        us3.datadoghq.com```

@lucastemb
Copy link
Author

Valgrind Output:

==1318749== 
==1318749== HEAP SUMMARY:
==1318749==     in use at exit: 0 bytes in 0 blocks
==1318749==   total heap usage: 10,659 allocs, 10,659 frees, 27,179,822 bytes allocated
==1318749== 
==1318749== All heap blocks were freed -- no leaks are possible
==1318749== 
==1318749== For lists of detected and suppressed errors, rerun with: -s
==1318749== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@lucastemb
Copy link
Author

Debug Log Output:

[2025/07/11 18:38:45] [ info] Configuration:
[2025/07/11 18:38:45] [ info]  flush time     | 1.000000 seconds
[2025/07/11 18:38:45] [ info]  grace          | 5 seconds
[2025/07/11 18:38:45] [ info]  daemon         | 0
[2025/07/11 18:38:45] [ info] ___________
[2025/07/11 18:38:45] [ info]  inputs:
[2025/07/11 18:38:45] [ info]      dummy
[2025/07/11 18:38:45] [ info] ___________
[2025/07/11 18:38:45] [ info]  filters:
[2025/07/11 18:38:45] [ info] ___________
[2025/07/11 18:38:45] [ info]  outputs:
[2025/07/11 18:38:45] [ info]      datadog.0
[2025/07/11 18:38:45] [ info] ___________
[2025/07/11 18:38:45] [ info]  collectors:
[2025/07/11 18:38:45] [ info] [fluent bit] version=4.0.5, commit=9def01d7de, pid=1326162
[2025/07/11 18:38:45] [debug] [engine] coroutine stack size: 24576 bytes (24.0K)
[2025/07/11 18:38:45] [ info] [storage] ver=1.5.3, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2025/07/11 18:38:45] [ info] [simd    ] disabled
[2025/07/11 18:38:45] [ info] [cmetrics] version=1.0.4
[2025/07/11 18:38:45] [ info] [ctraces ] version=0.6.6
[2025/07/11 18:38:45] [ info] [input:dummy:dummy.0] initializing
[2025/07/11 18:38:45] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2025/07/11 18:38:45] [debug] [dummy:dummy.0] created event channels: read=28 write=29
[2025/07/11 18:38:45] [debug] [datadog:datadog.0] created event channels: read=30 write=31
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] scheme: http://
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] site parameter set to: us3.datadoghq.com
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] uri: /api/v2/logs
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] using site for host construction: us3.datadoghq.com
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] created base hostname: http-intake.logs.
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] about to concatenate site: us3.datadoghq.com (length: 17)
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] after concatenation: http-intake.logs.us3.datadoghq.com
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] host constructed from site: http-intake.logs.us3.datadoghq.com
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] port: 80
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] json_date_key: timestamp
[2025/07/11 18:38:45] [debug] [output:datadog:datadog.0] compress_gzip: 1
[2025/07/11 18:38:45] [ info] [sp] stream processor started
[2025/07/11 18:38:45] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
[2025/07/11 18:38:45] [trace] [sched] 0 timer coroutines destroyed
[2025/07/11 18:38:45] [trace] [sched] 0 timer coroutines destroyed
[2025/07/11 18:38:46] [trace] [input chunk] update output instances with new chunk size diff=403, records=1, input=dummy.0
[2025/07/11 18:38:46] [trace] [sched] 0 timer coroutines destroyed
[2025/07/11 18:38:46] [trace] [sched] 0 timer coroutines destroyed
[2025/07/11 18:38:46] [trace] [sched] 0 timer coroutines destroyed
[2025/07/11 18:38:46] [trace] [sched] 0 timer coroutines destroyed
[2025/07/11 18:38:47] [trace] [task 0x5e9f010] created (id=0)
[2025/07/11 18:38:47] [debug] [task] created task=0x5e9f010 id=0 OK
[2025/07/11 18:38:47] [trace] [input chunk] update output instances with new chunk size diff=403, records=1, input=dummy.0
[2025/07/11 18:38:47] [trace] [upstream] get new connection for http-intake.logs.us3.datadoghq.com:80, net setup:
net.connect_timeout        = 10 seconds
net.source_address         = any
net.keepalive              = enabled
net.keepalive_idle_timeout = 30 seconds
net.max_worker_connections = 0
[2025/07/11 18:38:47] [trace] [net] connection #38 in process to http-intake.logs.us3.datadoghq.com:80

Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

A new "site" configuration parameter was introduced to the Datadog output plugin. The parameter is added to the configuration map and the plugin's context struct. The plugin now constructs the Datadog host using the "site" value if no explicit host is provided, with appropriate parsing, storage, and memory management for the new field.

Changes

Cohort / File(s) Change Summary
Config Map Addition
plugins/out_datadog/datadog.c
Added "site" as a new optional string entry in the config map, with description and mapping to context struct.
Context Struct Update
plugins/out_datadog/datadog.h
Added site field (type flb_sds_t) to flb_out_datadog struct for storing the "site" configuration value.
Configuration Logic and Memory Management
plugins/out_datadog/datadog_conf.c
Parses and stores the "site" parameter, constructs host from "site" if no explicit host is set, adds debug logging, and frees the "site" string during context destruction.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigLoader
    participant DatadogPlugin

    User->>ConfigLoader: Provide config with optional 'site' and/or 'host'
    ConfigLoader->>DatadogPlugin: Initialize plugin context
    ConfigLoader->>DatadogPlugin: Set 'site' field if provided
    alt Host not provided
        DatadogPlugin->>DatadogPlugin: Construct host as "http-intake.logs." + site
    else Host provided
        DatadogPlugin->>DatadogPlugin: Use explicit host value
    end
    DatadogPlugin->>DatadogPlugin: Store constructed or provided host
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A new "site" field hops into view,
Datadog hosts now built anew!
If no host you specify,
"http-intake.logs." will unify
With your chosen site—how neat!
The plugin’s logic is now complete,
A bunny’s job, quick and fleet! 🐇

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
plugins/out_datadog/datadog_conf.c (1)

150-191: Host construction logic is correct but consider reducing debug verbosity.

The implementation properly handles all three scenarios:

  1. Site-based host construction when no explicit host is provided
  2. Default host fallback when neither explicit host nor site is specified
  3. Explicit host parameter taking precedence

The error handling for memory allocation failures is appropriate, and the string concatenation logic is sound.

Consider reducing the debug logging verbosity as some statements provide redundant information:

-            flb_plg_debug(ctx->ins, "created base hostname: %s", tmp_sds);
-            flb_plg_debug(ctx->ins, "about to concatenate site: %s (length: %zu)", ctx->site, flb_sds_len(ctx->site));
-            flb_plg_debug(ctx->ins, "after concatenation: %s", tmp_sds);
             flb_plg_debug(ctx->ins, "host constructed from site: %s", ctx->host);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b9741c and 7ccfc95.

📒 Files selected for processing (3)
  • plugins/out_datadog/datadog.c (1 hunks)
  • plugins/out_datadog/datadog.h (1 hunks)
  • plugins/out_datadog/datadog_conf.c (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
plugins/out_datadog/datadog_conf.c (2)
src/flb_output.c (1)
  • flb_output_get_property (1091-1094)
src/flb_sds.c (3)
  • flb_sds_create (78-90)
  • flb_sds_cat (120-141)
  • flb_sds_destroy (389-399)
🔇 Additional comments (3)
plugins/out_datadog/datadog.h (1)

64-64: LGTM: Clean struct addition for site parameter.

The new site field is properly typed as flb_sds_t and positioned appropriately with other configuration fields. The field integrates well with the existing struct layout.

plugins/out_datadog/datadog.c (1)

584-587: LGTM: Well-defined configuration parameter.

The site configuration parameter is properly defined with:

  • Correct type (FLB_CONFIG_MAP_STR) for string input
  • Appropriate optional flag (FLB_FALSE) since explicit host can override it
  • Proper struct field mapping via offsetof
  • Clear description with practical examples of Datadog site values
plugins/out_datadog/datadog_conf.c (1)

264-266: LGTM: Proper memory cleanup for site field.

The cleanup logic correctly follows the established pattern with a null check before calling flb_sds_destroy(), ensuring no memory leaks for the site parameter.

Comment on lines +102 to +109
/* Parse site parameter early so it's available for host construction */
tmp = flb_output_get_property("site", ins);
if (tmp){
ctx->site = flb_sds_create(tmp);
flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site);
} else {
flb_plg_debug(ctx->ins, "no site parameter found");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check after flb_sds_create().

The code should check if flb_sds_create() returns NULL to handle memory allocation failures gracefully.

Apply this diff to add proper error handling:

 /* Parse site parameter early so it's available for host construction */
 tmp = flb_output_get_property("site", ins);
 if (tmp){
     ctx->site = flb_sds_create(tmp);
+    if (!ctx->site) {
+        flb_errno();
+        flb_datadog_conf_destroy(ctx);
+        return NULL;
+    }
     flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site);
 } else {
     flb_plg_debug(ctx->ins, "no site parameter found");
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/* Parse site parameter early so it's available for host construction */
tmp = flb_output_get_property("site", ins);
if (tmp){
ctx->site = flb_sds_create(tmp);
flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site);
} else {
flb_plg_debug(ctx->ins, "no site parameter found");
}
/* Parse site parameter early so it's available for host construction */
tmp = flb_output_get_property("site", ins);
if (tmp){
ctx->site = flb_sds_create(tmp);
if (!ctx->site) {
flb_errno();
flb_datadog_conf_destroy(ctx);
return NULL;
}
flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site);
} else {
flb_plg_debug(ctx->ins, "no site parameter found");
}
🤖 Prompt for AI Agents
In plugins/out_datadog/datadog_conf.c around lines 102 to 109, after calling
flb_sds_create(tmp) to assign ctx->site, add a null check to verify if ctx->site
is NULL. If it is NULL, handle the memory allocation failure gracefully by
logging an error message and returning an appropriate error code or cleaning up
as needed to prevent dereferencing a null pointer.

@lucastemb lucastemb marked this pull request as draft August 4, 2025 14:34
@lucastemb lucastemb closed this Aug 4, 2025
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.

1 participant