Skip to content

Conversation

nicknezis
Copy link

@nicknezis nicknezis commented Sep 16, 2025

  1. Added HTTP method field to plugin context (http.h)
  • Added int http_method; field to struct flb_out_http
  1. Added configuration option (http.c)
  • Added new config map entry for "http_method" with default value "POST"
  • Description: "Specify the HTTP method to use. Supported methods are POST and PUT"
  1. Added method parsing logic (http_conf.c)
  • Added parsing for the http_method configuration option
  • Supports case-insensitive "POST" and "PUT" values
  • Defaults to FLB_HTTP_POST if not specified
  • Validates input and shows error for unsupported methods
  1. Updated HTTP client calls (http.c)
  • Changed flb_http_client() call from hardcoded FLB_HTTP_POST to ctx->http_method
  • Renamed http_post() function to http_request() for clarity
  • Updated all function calls and log messages to be method-agnostic

Usage

Users can now configure the HTTP method in their Fluent Bit configuration:

[OUTPUT]
Name http
Match *
Host example.com
Port 443
URI /api/logs
http_method PUT
tls on

The plugin will validate the method and default to POST if not specified, maintaining backward compatibility.

Ticket: #10522

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 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 a configurable http_method (default: POST) to choose the HTTP method for the output plugin; supports POST and PUT.
    • Plugin now sends requests using the selected method and updated status messages to reflect "sending" instead of "posting".
  • Bug Fixes

    • Invalid http_method values cause startup to fail with a clear error to prevent misconfiguration.
  • Documentation

    • Documented the http_method option and supported methods (POST, PUT).

Copy link

coderabbitai bot commented Sep 16, 2025

Walkthrough

Adds a configurable HTTP method to the out_http plugin: new http_method config (default "POST", supports "PUT"), stored in ctx->http_method and used when creating HTTP clients; renames http_posthttp_request and post_all_requestssend_all_requests; updates trace text to "sending record ...".

Changes

Cohort / File(s) Summary
Config parsing: http_method option
plugins/out_http/http_conf.c
Adds parsing for http_method (case-insensitive). Maps "POST"FLB_HTTP_POST, "PUT"FLB_HTTP_PUT; invalid values log an error, free context and abort init. Stores selected method in ctx->http_method before upstream setup.
Request logic & helper renames
plugins/out_http/http.c
Adds http_method config_map entry (default "POST"). Replaces hard-coded FLB_HTTP_POST with ctx->http_method when creating HTTP clients. Renames http_posthttp_request and post_all_requestssend_all_requests, updates call sites and trace message to "sending record ...".
Public struct extension
plugins/out_http/http.h
Adds int http_method to struct flb_out_http (inserted after port) to expose the selected HTTP method to request code.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User as User Config
  participant Conf as out_http Conf
  participant Ctx as flb_out_http (ctx)
  participant Up as Upstream
  participant Net as HTTP Client

  User->>Conf: set http_method = "POST"/"PUT"
  Conf->>Ctx: parse & set ctx.http_method
  alt invalid method
    Conf-->>User: log error, abort init
  else valid method
    Conf->>Up: initialize upstream
    Note over Ctx,Net: On flush/send, use ctx.http_method
    Ctx->>Net: create/send HTTP request (method = ctx.http_method)
    Net-->>Ctx: response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

I thump my paw—configure, don't guess!
From POST to PUT I hop with finesse.
A field tucked in the burrowed struct,
Helpers renamed, logs now conduct.
Sending records onward—carrot inbound. 🥕🐇

Pre-merge checks and finishing touches

❌ 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%. 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 "Added PUT support" is concise, clear, and directly captures the primary change in the PR — enabling HTTP PUT (via a new http_method config, struct field, and method-agnostic request handling). It avoids noise and is specific enough for a reviewer scanning history to understand the main intent. Therefore it aligns with the title guidelines.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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 f8c0d4d and f7dfae3.

📒 Files selected for processing (1)
  • plugins/out_http/http.c (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/out_http/http.c

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.

@nicknezis
Copy link
Author

Added a small Documentation update here: fluent/fluent-bit-docs#2064

@nicknezis nicknezis marked this pull request as ready for review September 16, 2025 16:23
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
plugins/out_http/http.c (2)

176-180: Null-check the HTTP client to prevent a crash and leak.

flb_http_client(...) can return NULL; c->proxy.host is dereferenced later and cleanup: unconditionally destroys c. Guard the creation path and the cleanup.

Apply this diff:

-    /* Create HTTP client context */
-    c = flb_http_client(u_conn, ctx->http_method, ctx->uri,
+    /* Create HTTP client context */
+    c = flb_http_client(u_conn, ctx->http_method, ctx->uri,
                         payload_buf, payload_size,
                         ctx->host, ctx->port,
                         ctx->proxy, 0);
+    if (c == NULL) {
+        flb_plg_error(ctx->ins, "failed to create HTTP client for %s:%i",
+                      ctx->host, ctx->port);
+        if (payload_buf != body) {
+            flb_free(payload_buf);
+        }
+        flb_upstream_conn_release(u_conn);
+        return FLB_RETRY;
+    }

And in the cleanup section:

-    /* Destroy HTTP client context */
-    flb_http_client_destroy(c);
+    /* Destroy HTTP client context */
+    if (c != NULL) {
+        flb_http_client_destroy(c);
+    }

503-513: Bug: wrong NULL checks in header extraction (latent leak/skip).

The code checks headers[i] instead of headers[i*2]/headers[i*2+1]. On allocation failure it won’t trip the guard, possibly leaking a half-pair and skipping headers.

Apply this fix:

-        headers[i * 2] = strndup(k.ptr, k.size);
-
-        if (!headers[i]) {
+        headers[i * 2] = strndup(k.ptr, k.size);
+        if (!headers[i * 2]) {
             goto err;
         }
 
-        headers[i * 2 + 1] = strndup(v.ptr, v.size);
-
-        if (!headers[i]) {
+        headers[i * 2 + 1] = strndup(v.ptr, v.size);
+        if (!headers[i * 2 + 1]) {
             goto err;
         }
🧹 Nitpick comments (2)
plugins/out_http/http.c (2)

635-637: Make error message method-neutral.

Minor text nit; avoid “post” now that PUT is supported.

Apply:

-                          "failed to post requests body key \"%s\"", ctx->body_key);
+                          "failed to send requests with body key \"%s\"", ctx->body_key);

530-535: Optional: rename function to match semantics.

post_all_requests is misleading now; suggest send_all_requests.

Example:

-static int post_all_requests(struct flb_out_http *ctx,
+static int send_all_requests(struct flb_out_http *ctx,

And update its single call site in cb_http_flush.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60db310 and e7d0484.

📒 Files selected for processing (3)
  • plugins/out_http/http.c (5 hunks)
  • plugins/out_http/http.h (1 hunks)
  • plugins/out_http/http_conf.c (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
plugins/out_http/http_conf.c (2)
src/flb_output.c (1)
  • flb_output_get_property (1096-1099)
include/fluent-bit/flb_mem.h (1)
  • flb_free (126-128)
plugins/out_http/http.c (1)
src/flb_http_client.c (1)
  • flb_http_client (814-859)
🔇 Additional comments (5)
plugins/out_http/http.h (1)

70-72: Field addition looks good; preserves defaulting via conf.

Placing http_method near connection params is fine and keeps the struct cohesive. No ABI concerns within the tree since all offsets are recompiled.

plugins/out_http/http.c (4)

112-116: Rename to method-agnostic helper is sane.

Signature and intent match the new config; good extraction point.


599-602: Trace message now method-neutral — good.

Keeps logs accurate for POST/PUT.


650-659: Method-agnostic calls look correct.

http_request(...) used consistently for both JSON/msgpack paths.


760-764: Config map entry for http_method: approve (docs/UI); verify for POST leftovers

Config map entry is fine — manual conf parsing makes offsetof=0 acceptable and the description is clear. Approving changes.

Sandbox search failed ("No files were searched"). Run locally to confirm there are no remaining POST-specific code paths or log strings:

rg --debug -n --hidden -uu -S -g '!**/vendor/**' \
  -e 'http_post\(' \
  -e 'posting record' \
  -e 'failed to post' \
  -e '\bPOST\b' -i

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 (3)
plugins/out_http/http.c (3)

530-535: Return an aggregated status for multi-record sends.

send_all_requests() overwrites ret per record; a late success can mask earlier failures. Track an overall_ret (prefer FLB_RETRY over FLB_OK, FLB_ERROR over both) and return it.

Example patch (core idea):

-    int ret = 0;
+    int ret = 0;
+    int overall_ret = FLB_OK;
@@
-            ret = http_request(ctx, body, body_size, event_chunk->tag,
-                    flb_sds_len(event_chunk->tag), headers);
+            ret = http_request(ctx, body, body_size, event_chunk->tag,
+                               flb_sds_len(event_chunk->tag), headers);
+            if (ret == FLB_ERROR) {
+                overall_ret = FLB_ERROR;
+            }
+            else if (ret == FLB_RETRY && overall_ret == FLB_OK) {
+                overall_ret = FLB_RETRY;
+            }
@@
-    return ret;
+    return overall_ret;

598-602: Enrich trace with HTTP method.

Including the verb helps debug mixed POST/PUT flows.

Apply this diff:

-            flb_plg_trace(ctx->ins, "sending record %zu", record_count++);
+            flb_plg_trace(ctx->ins, "sending record %zu via %s",
+                          record_count++,
+                          ctx->http_method == FLB_HTTP_POST ? "POST" : "PUT");

631-637: Tweak error message grammar.

“failed to send requests body key” reads oddly.

Apply this diff:

-                          "failed to send requests body key \"%s\"", ctx->body_key);
+                          "failed to send requests using body key \"%s\"", ctx->body_key);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d98da11 and f8c0d4d.

📒 Files selected for processing (1)
  • plugins/out_http/http.c (7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/out_http/http.c (2)
src/flb_http_client.c (1)
  • flb_http_client (814-859)
src/flb_sds.c (1)
  • flb_sds_destroy (389-399)
🔇 Additional comments (2)
plugins/out_http/http.c (2)

650-659: LGTM: method-agnostic requests in flush path.

Replacing http_post() with http_request() for both JSON/GELF and msgpack paths looks correct; tag/length handling is intact.


760-764: Config surface LGTM — parsing & PUT support verified

plugins/out_http/http_conf.c parses http_method case‑insensitively (defaults to FLB_HTTP_POST; "PUT" → FLB_HTTP_PUT), FLB_HTTP_PUT is defined in include/fluent-bit/flb_http_client.h and handled by src/flb_http_client.c; callers use FLB_HTTP_PUT.

@cosmo0920
Copy link
Contributor

Could you add Signed-off line in your commit? We need to follow DCO rules and that workflow to be green.

@nicknezis
Copy link
Author

Could you add Signed-off line in your commit? We need to follow DCO rules and that workflow to be green.

I rebased onto master and signed the original commit. Hopefully it looks better now?

Signed-off-by: Nicholas Nezis <[email protected]>
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