kv: add flb_kv_get_all_key_values function#11788
kv: add flb_kv_get_all_key_values function#11788iypetrov wants to merge 5 commits intofluent:masterfrom
Conversation
The goal of this enhancement is to extend the key-value store API to support retrieving all elements from the linked list in a single call. Currently, the only way to retrieve all elements is to guess the keys and repeatedly call `flb_kv_get_key_value`, which is especially problematic for plugin writers. Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
📝 WalkthroughWalkthroughThis pull request adds a public API, flb_kv_get_all_key_values, that returns all flb_kv entries from a mk_list as a newly allocated array and reports the element count; it includes implementation, header declaration, and a unit test with cleanup. ChangesKey-Value Array Retrieval API
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@include/fluent-bit/flb_kv.h`:
- Line 44: flb_kv_get_all_key_values currently returns a pointer array without
length metadata, making callers unsafe to iterate; modify its signature to
include an output count (e.g., add a size_t *out_count parameter) or change the
return to a small struct { struct flb_kv **items; size_t count; } so callers can
know the array length; update the function implementation and all call sites
that use flb_kv_get_all_key_values to set/read the count and to free/iterate
correctly (search for references to flb_kv_get_all_key_values to update usage).
In `@tests/internal/kv.c`:
- Around line 49-61: The test accesses pairs[0..2] without ensuring the
underlying list contains three items; change the check so after verifying pairs
is non-NULL you also assert mk_list_size(&list) == 3 (or equivalent size check
against the list used to build pairs) before indexing pairs[0], pairs[1], and
pairs[2]; reference the list used when calling flb_kv_item_set() and use that
size guard so the subsequent TEST_CHECK(strcmp(...)) validations only run when
the list actually has three entries.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 96ef314f-ede6-4b61-9703-2e217b4ad117
📒 Files selected for processing (3)
include/fluent-bit/flb_kv.hsrc/flb_kv.ctests/internal/kv.c
This out_count parameter is needed so the callers can safely iterate without external assumptions. Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
…t parameter Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/internal/kv.c (1)
44-46: ⚡ Quick winCheck each
flb_kv_item_setresult explicitlyPlease assert each insertion succeeds, so failures are reported at the source rather than only via downstream
count/content checks.Suggested patch
- flb_kv_item_set(&list, "host", "localhost"); - flb_kv_item_set(&list, "port", "8080"); - flb_kv_item_set(&list, "path", "/api"); + TEST_CHECK(flb_kv_item_set(&list, "host", "localhost") != NULL); + TEST_CHECK(flb_kv_item_set(&list, "port", "8080") != NULL); + TEST_CHECK(flb_kv_item_set(&list, "path", "/api") != NULL);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/internal/kv.c` around lines 44 - 46, Each flb_kv_item_set call should have its return value checked and asserted immediately so insertion failures are reported at the source; update the three calls to flb_kv_item_set(&list, "host", "localhost"), flb_kv_item_set(&list, "port", "8080"), and flb_kv_item_set(&list, "path", "/api") to capture their returns into distinct variables (e.g., ret_host/ret_port/ret_path) and add assertions that each return indicates success (match the test framework's success condition) before proceeding to later count/content checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/internal/kv.c`:
- Around line 44-46: Each flb_kv_item_set call should have its return value
checked and asserted immediately so insertion failures are reported at the
source; update the three calls to flb_kv_item_set(&list, "host", "localhost"),
flb_kv_item_set(&list, "port", "8080"), and flb_kv_item_set(&list, "path",
"/api") to capture their returns into distinct variables (e.g.,
ret_host/ret_port/ret_path) and add assertions that each return indicates
success (match the test framework's success condition) before proceeding to
later count/content checks.
Add
flb_kv_get_all_key_valuesfunction formk_list.Addresses #11776 (1/3 sub-task)
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:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-testlabel to test for all targets (requires maintainer to do).Documentation
Backporting
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.