Improving the capture of nested data from set_stats#395
Conversation
|
@ltamaster can you take a look at this and see if it can be merged? Thanks |
|
@fdevans can you take a look at this and see if it can be merged? Thanks |
|
@ltamaster or @fdevans can you please take a look at this pending issue? Thanks |
|
@ltamaster, @fdevans, @Jesus-Osuna-M could one of you please take a look at this ? Thanks a lot |
There was a problem hiding this comment.
Pull request overview
Updates the Ansible set_stats log filter to support capturing nested (object/array/null) values by serializing JSON elements instead of assuming all values are string primitives.
Changes:
- Replace
JsonElement#getAsString()extraction with Gson-based JSON serialization for captured values. - Add Gson imports and instantiate a Gson serializer during event handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| while(keys.hasNext()) { | ||
| String key = keys.next() | ||
| String value = obj.get(key).getAsString() | ||
| String value = gson.toJson(obj.get(key)) | ||
| allData[key] = value |
| String jsonString = match.group(1) | ||
| JsonObject obj = JsonParser.parseString(jsonString).getAsJsonObject() | ||
| Iterator<String> keys = obj.keySet().iterator() | ||
| Gson gson = new GsonBuilder().create() |
|
@Simon-cto - If you are able to review and address the CoPilot comments we can consider moving this forward in the review process internally. Thanks for the PR! |
The first implementation of the set_stats logs filter only works with string values, if you provide an array or a dict the log filter fails since the method getAsString() only works for JsonPrimitive objects.
This commit uses the Gson class and its toJson() method to serialize the value, no matter if it's a JsonPrimitive, JsonObject, JsonArray or JsonNull.