[PATCH dpdk v2] telemetry: fix adding dicts in container arrays

Robin Jarry
2026-01-08T10:50:52Z

Currently, adding TEL_DICT containers in TEL_ARRAY_CONTAINER containers
is not supported by rte_tel_data_add_array_container. It wrongfully
returns -EINVAL where it should allow it.

This is supported by the JSON formatter.

Allow the same value types than rte_tel_data_add_dict_container().

Add test case to verify it works as expected.

Fixes: c933bb5177ca ("telemetry: support array values in data object")
Cc: stable@dpdk.org

Signed-off-by: Robin Jarry <rjarry@redhat.com>
---

Notes:
v2: added test case

app/test/test_telemetry_data.c | 21 +++++++++++++++++++++
lib/telemetry/telemetry_data.c | 6 +++---
2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index 59898ff5e983..e904b5a7f210 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -405,6 +405,26 @@ test_array_with_array_uint_hex_values_nopadding(void)
return CHECK_OUTPUT("[[\"0x888\"],[\"0x8888\"]]");
}

+static int
+test_array_with_dict_values(void)
+{
+ rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER);
+
+ struct rte_tel_data *d1 = rte_tel_data_alloc();
+ rte_tel_data_start_dict(d1);
+ rte_tel_data_add_dict_string(d1, "name", "foo");
+ rte_tel_data_add_dict_uint(d1, "size", 42);
+ rte_tel_data_add_array_container(&response_data, d1, 0);
+
+ struct rte_tel_data *d2 = rte_tel_data_alloc();
+ rte_tel_data_start_dict(d2);
+ rte_tel_data_add_dict_string(d2, "name", "bar");
+ rte_tel_data_add_dict_uint(d2, "size", 666);
+ rte_tel_data_add_array_container(&response_data, d2, 0);
+
+ return CHECK_OUTPUT("[{\"name\":\"foo\",\"size\":42},{\"name\":\"bar\",\"size\":666}]");
+}
+
static int
test_case_array_u64(void)
{
@@ -597,6 +617,7 @@ telemetry_data_autotest(void)
test_array_with_array_string_values,
test_array_with_array_uint_hex_values_padding,
test_array_with_array_uint_hex_values_nopadding,
+ test_array_with_dict_values,
test_string_char_escaping,
test_array_char_escaping,
test_dict_char_escaping,
diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
index 0354a0654804..0a006559ab42 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -96,10 +96,10 @@ int
rte_tel_data_add_array_container(struct rte_tel_data *d,
struct rte_tel_data *val, int keep)
{
- if (d->type != TEL_ARRAY_CONTAINER ||
- (val->type != TEL_ARRAY_UINT
+ if (d->type != TEL_ARRAY_CONTAINER || (val->type != TEL_ARRAY_UINT
&& val->type != TEL_ARRAY_INT
- && val->type != TEL_ARRAY_STRING))
+ && val->type != TEL_ARRAY_STRING
+ && val->type != TEL_DICT))
return -EINVAL;
if (d->data_len >= RTE_TEL_MAX_ARRAY_ENTRIES)
return -ENOSPC;
--
2.52.0