rainerscript: add append_json() function#6385
Conversation
Summary of ChangesHello @20syldev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances RainerScript's JSON manipulation capabilities by introducing a new Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new and useful append_json function to RainerScript. The implementation is mostly sound, but I've identified several critical and high-severity issues related to memory management, particularly in error-handling paths. There are multiple potential memory leaks if json-c library calls fail, and a potential crash due to an unhandled NULL return from var2CString. I've also included suggestions for a minor refactoring to reduce code duplication and for expanding the test suite to cover more use cases for this new function.
There was a problem hiding this comment.
Code Review
This pull request introduces a new append_json() function to RainerScript, which is a valuable addition for dynamic JSON manipulation. The implementation is mostly correct, but there are a few critical issues related to memory management and error handling when using the json-c library that could lead to memory leaks or incorrect behavior under error conditions (like out-of-memory). The provided comments offer suggestions to improve the robustness of the implementation by using safer json-c functions and adding proper error handling. Additionally, expanding the test suite to cover more use cases and edge cases for the new function is recommended.
4fdd4f2 to
9c661f9
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a useful append_json function to RainerScript for manipulating JSON data. The implementation is mostly solid, with accompanying documentation and tests. However, I've identified a couple of critical memory leak issues in the object-handling logic due to missing error checks, which could lead to instability under certain conditions. I've also provided a suggestion to improve the array-handling code for better maintainability. Addressing these points will make the new function more robust.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
9c661f9 to
6e2bb38
Compare
|
@20syldev looks like this needs a rebase (not merge) |
6e2bb38 to
20d0e11
Compare
Done! |
There was a problem hiding this comment.
Code Review
This pull request introduces a new append_json() function to RainerScript, which is a great addition for dynamically manipulating JSON data. The implementation is mostly correct and includes documentation and tests.
My review focuses on improving the robustness and maintainability of the C implementation in grammar/rainerscript.c. I've identified a critical issue where silent failures during JSON object creation could lead to data loss. I've also suggested refactoring the error handling to align with the project's established conventions and improving variable scoping for better readability.
The documentation and test cases are well-written and cover the intended functionality. Addressing the feedback will make the new function more reliable.
20d0e11 to
be58266
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new RainerScript function, append_json(), which allows users to dynamically add elements to JSON arrays and properties to JSON objects. The implementation is accompanied by documentation and tests. The overall approach is sound, creating a new JSON object to ensure immutability of the original. However, I've identified two potential memory leaks in the object-handling logic due to the use of a deprecated json-c function that doesn't report errors. My review includes suggestions to fix these issues by using the recommended _ex version of the function and adding proper error handling, consistently applying the finalize_it: label for error management as per rsyslog policies.
rgerhards
left a comment
There was a problem hiding this comment.
I can make the adjustments myself, but would appreciate if you could do them.
There was a problem hiding this comment.
Code Review
This pull request introduces a new append_json() function to RainerScript, allowing users to add elements to JSON arrays and properties to JSON objects. The implementation is well-structured and includes documentation and tests. My review focuses on improving the robustness and safety of the new C function. The main suggestions are to use json_object_deep_copy to prevent side-effects from shared mutable objects, to make type checking more explicit and robust, and to ensure error handling aligns with rsyslog policies.
|
Please let me know if any of the issues I marked as “Resolved” are possible, as I haven't figured out how to do it with libfastjson. |
rgerhards
left a comment
There was a problem hiding this comment.
I added comments to the AI review. Once this is through, I can do a manual round of review.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new and useful RainerScript function, append_json(), for dynamically building JSON arrays and objects. The implementation is well-structured, and the inclusion of documentation and tests is commendable. I've identified a critical compilation issue due to a likely function name typo, a high-severity issue related to a potential memory leak from an unchecked return value (with a reminder to align with rsyslog error handling policies), and a medium-severity suggestion to refactor some duplicated code for better maintainability. Addressing these points will make this a solid contribution.
|
@20syldev my bad, I had a wrong merge order. I'll see that I can rebase it. |
No problem |
Users need to parse delimited strings (CSV, tags, paths) into arrays for iteration or JSON output without external processing. Impact: New RainerScript function available to all users. Before: No native way to split strings into arrays in RainerScript. After: split(string, separator) returns a JSON array of substrings. Technical overview: Implements doFunct_split() in grammar/rainerscript.c Registers "split" in scriptFunct table with 2 required args Adds CNFFUNC_SPLIT enum in rainerscript.h Uses unified strstr-based iteration for all separator lengths Handles edge cases: empty input, leading/trailing/consecutive delimiters Includes error handling for json-c memory allocation failures Returns empty JSON array on null/empty input or separator Includes documentation (rs-split.rst) and test scripts
2221741 to
ef050ae
Compare
|
CI fail is a know and unrelated flake |
Great, I was wondering about that. Thanks for the merge! |
|
@rgerhards Hi, I just noticed that the commit message was copied incorrectly for append_json. Here is the correct one: Title: Description: |
|
sry for that, but now it's too late. It is impossible to change commit afterwards. |
Okay, I understand! |
Summary
Users need to dynamically build JSON arrays and objects by adding elements without external processing or complex workarounds.
Notes
rscript_append_json.shandrscript_append_json-vg.shdoc/source/rainerscript/functions/rs-append_json.rstImpact: New RainerScript function available to all users.
append_json(array, element)orappend_json(object, key, value)returns a new JSON structure with the element/property added.