Skip to content

Commit

Permalink
telemetry: fix empty JSON dictionaries
Browse files Browse the repository at this point in the history
[ upstream commit 324ec1df541711ca829f4d99b7e2d32ffe38d3ca ]

Fix to allow telemetry to handle empty dictionaries correctly.

This patch resolves an issue where empty dictionaries are reported
by telemetry as '[]' rather than '{}'. Initializing the output
buffer based on the container type resolves the issue.

Fixes: c933bb5 ("telemetry: support array values in data object")

Signed-off-by: Jonathan Erb <[email protected]>
Acked-by: Ciara Power <[email protected]>
  • Loading branch information
Jonathan Erb authored and kevintraynor committed Mar 5, 2024
1 parent 1af693e commit a5224aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ John OLoughlin <[email protected]>
John Ousterhout <[email protected]>
John W. Linville <[email protected]>
Jonas Pfefferle <[email protected]> <[email protected]>
Jonathan Erb <[email protected]>
(??)Jonathan Erb <[email protected]> <[email protected]>
Jonathan Tsai <[email protected]>
Jon DeVree <[email protected]>
Jon Loeliger <[email protected]>
Expand Down
6 changes: 5 additions & 1 deletion lib/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
d->type != RTE_TEL_ARRAY_INT && d->type != RTE_TEL_ARRAY_STRING)
return snprintf(out_buf, buf_len, "null");

used = rte_tel_json_empty_array(out_buf, buf_len, 0);
if (d->type == RTE_TEL_DICT)
used = rte_tel_json_empty_obj(out_buf, buf_len, 0);
else
used = rte_tel_json_empty_array(out_buf, buf_len, 0);

if (d->type == RTE_TEL_ARRAY_U64)
for (i = 0; i < d->data_len; i++)
used = rte_tel_json_add_array_u64(out_buf,
Expand Down

0 comments on commit a5224aa

Please sign in to comment.