filter_kubernetes: Attach k8s metadata for internal logs#11998
filter_kubernetes: Attach k8s metadata for internal logs#11998cosmo0920 wants to merge 7 commits into
Conversation
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
… files Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds a file-based Kubernetes metadata path for the ChangesLocal Kubernetes metadata for fluentbit_logs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e6f2ca107
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
plugins/filter_kubernetes/kube_meta.c (1)
2426-2438: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle cache insertion failures before unpacking.
If
flb_hash_table_add()returns< 0,hash_meta_bufis still uninitialized in the cache-miss path, but both helpers continue tomsgpack_unpack_next(). Bail out or use a safely owned buffer before continuing.Proposed fix
id = flb_hash_table_add(ctx->hash_table, meta->cache_key, meta->cache_key_len, tmp_hash_meta_buf, hash_meta_size); - if (id >= 0) { - /* - * Release the original buffer created on extract_pod_meta() as a new - * copy has been generated into the hash table, then re-set - * the outgoing buffer and size. - */ - flb_free(tmp_hash_meta_buf); - flb_hash_table_get_by_id(ctx->hash_table, id, meta->cache_key, - &hash_meta_buf, &hash_meta_size); + if (id < 0) { + flb_free(tmp_hash_meta_buf); + *out_buf = NULL; + *out_size = 0; + return 0; } + + flb_free(tmp_hash_meta_buf); + flb_hash_table_get_by_id(ctx->hash_table, id, meta->cache_key, + &hash_meta_buf, &hash_meta_size); @@ id = flb_hash_table_add(ctx->namespace_hash_table, meta->cache_key, meta->cache_key_len, tmp_hash_meta_buf, hash_meta_size); - if (id >= 0) { - /* - * Release the original buffer created on extract_namespace_meta() - * as a new copy has been generated into the hash table, then reset - * the outgoing buffer and size. - */ - flb_free(tmp_hash_meta_buf); - flb_hash_table_get_by_id(ctx->namespace_hash_table, id, meta->cache_key, - &hash_meta_buf, &hash_meta_size); + if (id < 0) { + flb_free(tmp_hash_meta_buf); + *out_buf = NULL; + *out_size = 0; + return 0; } + + flb_free(tmp_hash_meta_buf); + flb_hash_table_get_by_id(ctx->namespace_hash_table, id, meta->cache_key, + &hash_meta_buf, &hash_meta_size);Also applies to: 2530-2542
🤖 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 `@plugins/filter_kubernetes/kube_meta.c` around lines 2426 - 2438, In the cache-miss handling in kube_meta.c, `flb_hash_table_add()` can fail and leave `hash_meta_buf` uninitialized, but the code still continues into `msgpack_unpack_next()`. Update the cache insertion flow in the affected helpers (including the matching path around the second occurrence) so that on `id < 0` you either return/bail out early or explicitly fall back to a safely owned buffer before unpacking. Use the `flb_hash_table_add()`, `flb_hash_table_get_by_id()`, and `msgpack_unpack_next()` call sites to ensure only valid buffer/size pairs are passed forward.
🤖 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.
Outside diff comments:
In `@plugins/filter_kubernetes/kube_meta.c`:
- Around line 2426-2438: In the cache-miss handling in kube_meta.c,
`flb_hash_table_add()` can fail and leave `hash_meta_buf` uninitialized, but the
code still continues into `msgpack_unpack_next()`. Update the cache insertion
flow in the affected helpers (including the matching path around the second
occurrence) so that on `id < 0` you either return/bail out early or explicitly
fall back to a safely owned buffer before unpacking. Use the
`flb_hash_table_add()`, `flb_hash_table_get_by_id()`, and
`msgpack_unpack_next()` call sites to ensure only valid buffer/size pairs are
passed forward.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e165a48c-b07b-42bc-a747-533197d23771
📒 Files selected for processing (8)
plugins/filter_kubernetes/kube_conf.hplugins/filter_kubernetes/kube_meta.cplugins/filter_kubernetes/kube_meta.hplugins/filter_kubernetes/kubernetes.cplugins/in_fluentbit_logs/fluentbit_logs.ctests/runtime/data/kubernetes/local/namespacetests/runtime/data/kubernetes/local/tokentests/runtime/filter_kubernetes.c
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
…EGV paths Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Plus, fixing shutdown lifecycle glitches on in_fluentbit_logs plugin.
Closes #11741.
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.
Summary by CodeRabbit
New Features
Bug Fixes
Tests