Skip to content

tests: runtime: isolate Loki mock server configuration#12132

Open
edsiper wants to merge 1 commit into
masterfrom
agent/loki-mock-server-configuration
Open

tests: runtime: isolate Loki mock server configuration#12132
edsiper wants to merge 1 commit into
masterfrom
agent/loki-mock-server-configuration

Conversation

@edsiper

@edsiper edsiper commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

  • give the Loki tenant-policy mock HTTP server its own flb_config
  • keep the mock downstream and connection queues out of the running Fluent Bit engine configuration
  • make partial initialization and teardown safe for both the split-request and partial-handling fixtures

Root cause

The runtime test started Fluent Bit and then registered the mock HTTP server downstream in ctx->config. The mock server event-loop thread modified downstream connection and destruction queues while the engine thread iterated and processed the same structures. Helgrind therefore reported races in downstream setup, timeout processing, connection release, and pending destruction.

This is a test-fixture ownership issue, not a Loki plugin or allocator bug.

Lifecycle

The mock fixture now:

  1. initializes an independent configuration before the HTTP server
  2. stops and joins its server thread
  3. stops and destroys the HTTP server
  4. destroys the event loop
  5. calls flb_config_exit() only after mock activity has ended

Initialization state is tracked so every failure path releases only initialized resources.

Validation

  • cmake -S . -B build -DFLB_TESTS_RUNTIME=On -DFLB_TESTS_INTERNAL=On
  • cmake --build build -j8
  • ctest --test-dir build -R '^flb-rt-out_loki$' --output-on-failure — passed
  • build/bin/flb-rt-out_loki tenant_id_key_splits_requests tenant_id_key_partial_success tenant_id_key_partial_error — passed
  • tenant_id_key_splits_requests repeated 30 times — 30/30 passed
  • Memcheck focused run — zero errors and zero leaks
  • Helgrind focused run — mock-server downstream races removed; remaining reports are unrelated engine lifecycle and third-party libp11-kit reports
  • GCC 13.3.0 with FLB_JEMALLOC=On — built and flb-rt-out_loki passed
  • HEAD and full PR-range commit-prefix checks — passed

No production code or bundled library code is changed.

Summary by CodeRabbit

  • Tests
    • Improved test mock server startup and shutdown reliability.
    • Added deterministic cleanup for server, event loop, configuration, and thread resources.
    • Enhanced failure handling during test server initialization.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ff289c2-8fa5-4eeb-ac86-42ed5d133a46

📥 Commits

Reviewing files that changed from the base of the PR and between c830fb6 and 2e2de87.

📒 Files selected for processing (1)
  • tests/runtime/out_loki.c

📝 Walkthrough

Walkthrough

The Loki runtime test mock server now owns its flb_config, tracks initialization stages, and performs deterministic cleanup across startup failures and shutdown. Test call sites use the revised server-start function signature.

Changes

Tenant policy server lifecycle

Layer / File(s) Summary
Owned state and staged cleanup
tests/runtime/out_loki.c
The mock server tracks its configuration and HTTP initialization state, and teardown conditionally stops, destroys, and frees resources in stages.
Startup ownership and call sites
tests/runtime/out_loki.c
Startup creates and wires the internal configuration, routes failures through cleanup, and test callers use the new function signature.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: cosmo0920

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: isolating the Loki mock server configuration in runtime tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/loki-mock-server-configuration

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.

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