Skip to content

Improving the capture of nested data from set_stats#395

Open
Simon-cto wants to merge 5 commits into
rundeck-plugins:mainfrom
Simon-cto:AnsibleSetStatsFilterPlugin_nested
Open

Improving the capture of nested data from set_stats#395
Simon-cto wants to merge 5 commits into
rundeck-plugins:mainfrom
Simon-cto:AnsibleSetStatsFilterPlugin_nested

Conversation

@Simon-cto
Copy link
Copy Markdown
Contributor

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.

@Simon-cto
Copy link
Copy Markdown
Contributor Author

@ltamaster can you take a look at this and see if it can be merged?

Thanks

@Simon-cto
Copy link
Copy Markdown
Contributor Author

@fdevans can you take a look at this and see if it can be merged?

Thanks

@Simon-cto
Copy link
Copy Markdown
Contributor Author

@ltamaster or @fdevans can you please take a look at this pending issue?

Thanks

@Simon-cto
Copy link
Copy Markdown
Contributor Author

@ltamaster, @fdevans, @Jesus-Osuna-M could one of you please take a look at this ?

Thanks a lot

@fdevans fdevans requested review from a team and Copilot March 18, 2026 20:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 73 to 76
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()
@fdevans
Copy link
Copy Markdown
Contributor

fdevans commented Mar 24, 2026

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants