Skip to content

in_http: add support for fixed tag configuration parameter#11413

Open
kalavt wants to merge 3 commits intofluent:masterfrom
kalavt:feature/in_http_fixed_tag
Open

in_http: add support for fixed tag configuration parameter#11413
kalavt wants to merge 3 commits intofluent:masterfrom
kalavt:feature/in_http_fixed_tag

Conversation

@kalavt
Copy link

@kalavt kalavt commented Jan 29, 2026

Add Fixed Tag Configuration Parameter to in_http Plugin

Description

This PR adds support for a tag configuration parameter in the in_http input plugin, allowing users to specify a fixed tag for all incoming records. This addresses scenarios where users want consistent tagging without relying on URL paths or dynamic extraction from record content.

Problem Statement

Currently, the in_http plugin determines tags using the following logic:

  1. Extract from record content if tag_key is configured
  2. Use URL path from the HTTP request
  3. Fall back to default plugin instance name (e.g., http.0)

This creates issues when:

  • Users want a consistent fixed tag for all records
  • The default http.0 tag doesn't match their routing configuration
  • Dynamic URL-based tagging is not desired
  • To consistent with other plugins to eliminate misunderstandings

Solution

Added a new tag configuration parameter that allows users to specify a fixed tag. The updated tag selection priority is now:

  1. tag_key - Extract from record content (highest priority)
  2. URL path - From HTTP request path
  3. tag parameter - User-configured fixed tag (new)
  4. Default plugin tag - Plugin instance name (e.g., http.0)

Changes

Source Code

  • plugins/in_http/http.h: Added flb_sds_t tag field to struct flb_http
  • plugins/in_http/http.c: Added tag parameter to config_map
  • plugins/in_http/http_prot.c: Updated process_pack_record() to use ctx->tag as fallback
  • plugins/in_http/http_config.c: Added cleanup for ctx->tag in http_config_destroy()

Tests

  • tests/runtime/in_http.c: Added flb_test_http_fixed_tag() test case

Usage Example

[INPUT]
    Name http
    Port 9880
    Tag http_logs    # Fixed tag for all incoming records

[OUTPUT]
    Name kafka
    Match http_logs  # Now correctly matches the configured tag

Testing

All unit tests pass successfully:

Test http...                                    [ OK ]
Test successful_response_code_200...            [ OK ]
Test successful_response_code_204...            [ OK ]
Test failure_response_code_400_bad_json...      [ OK ]
Test failure_response_code_400_bad_disk_write... [ OK ]
Test tag_key_with_map_input...                  [ OK ]
Test tag_key_with_array_input...                [ OK ]
Test fixed_tag...                               [ OK ]  (new test)
Test oauth2_requires_token...                   [ OK ]
Test oauth2_accepts_valid_token...              [ OK ]

SUCCESS: All unit tests have passed.

Backward Compatibility

✅ This change is fully backward compatible. Existing configurations will continue to work as before since the tag parameter is optional and defaults to NULL.

Checklist

  • Code follows project coding style
  • Commit message follows project convention (in_http: description)
  • All existing unit tests pass
  • New unit test added for the feature
  • Code compiles without errors or new warnings
  • Memory cleanup properly implemented
  • Signed-off-by line included in commit

Summary by CodeRabbit

  • New Features

    • HTTP input can be configured with a fixed tag to apply to all incoming requests.
  • Bug Fixes

    • Fixed-tag configuration now reliably overrides URL/path-based tagging when present.
  • Tests

    • Added automated test validating fixed-tag routing, request handling, and output generation.

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Adds a configurable fixed_tag to the HTTP input plugin: new tag field on struct flb_http, a fixed_tag config map entry, cleanup in destroy, tag-resolution change to prefer the configured tag when no per-record tag exists, and an accompanying runtime test.

Changes

Cohort / File(s) Summary
Plugin header & struct
plugins/in_http/http.h
Added flb_sds_t tag member to struct flb_http (user-configured fixed_tag).
Plugin config map
plugins/in_http/http.c
Added FLB_CONFIG_MAP_STR entry "fixed_tag" wired via offsetof(struct flb_http, tag) to set a fixed tag overriding URL path-based tags.
Lifecycle / cleanup
plugins/in_http/http_config.c
Free ctx->tag in http_config_destroy using flb_sds_destroy() when non-NULL.
Tag resolution / protocol
plugins/in_http/http_prot.c
In process_pack_record, when no per-record tag is present, use ctx->tag if configured; minor comment wording tweak.
Tests
tests/runtime/in_http.c
Added flb_test_http_fixed_tag() and registered it in TEST_LIST; test posts JSON to / and verifies output routed by the fixed tag.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • edsiper
  • cosmo0920

Poem

🐰 I found a tag beneath the log,
I fixed it firm and gave a jog,
Requests hop in from near and far,
I stamp them neat — a steady star,
Tiny paws on data’s log.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 'in_http: add support for fixed tag configuration parameter' clearly and specifically describes the main change—adding a fixed tag configuration parameter to the in_http input plugin.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a7ced7459

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Renamed 'tag' config parameter to 'fixed_tag' to avoid collision with
global input tag property handled by flb_input_set_property.

Signed-off-by: Arbin <arbin.cheng@coins.ph>
@kalavt kalavt force-pushed the feature/in_http_fixed_tag branch from 2a7ced7 to 97fd309 Compare January 29, 2026 19:55
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

🤖 Fix all issues with AI agents
In `@tests/runtime/in_http.c`:
- Around line 987-996: flb_http_add_header is called before confirming the HTTP
client pointer c was successfully created; reorder the checks so you first
verify c != NULL (the result of flb_http_client) and handle the error (TEST_MSG
and early exit) before calling flb_http_add_header, keeping the same variable
names (c) and functions (flb_http_client, flb_http_add_header) to locate and
update the logic.

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

🤖 Fix all issues with AI agents
In `@tests/runtime/in_http.c`:
- Around line 944-1022: The test flb_test_http_fixed_tag sets a config with the
wrong key ("tag") so the plugin's "fixed_tag" option is never applied; update
the flb_input_set call in flb_test_http_fixed_tag to use the correct config key
name "fixed_tag" (i.e., replace the "tag" argument passed to flb_input_set with
"fixed_tag") so the fixed tag configuration is actually applied when the test
runs.

Fix two issues in flb_test_http_fixed_tag():
1. Check if HTTP client pointer c is not NULL before calling flb_http_add_header
   to prevent potential null pointer dereference
2. Use correct config key 'fixed_tag' instead of 'tag' to properly apply
   the fixed tag configuration

Signed-off-by: Arbin <arbin.cheng@coins.ph>
@kalavt kalavt force-pushed the feature/in_http_fixed_tag branch from 896ebea to 9cbabc7 Compare February 5, 2026 15:42
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