telemetry: add support for dicts of dicts
Checks
Commit Message
Add support for dicts of dicts to telemetry library.
Signed-off-by: Declan Doherty <declan.doherty@intel.com>
Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
lib/telemetry/telemetry.c | 43 +++++++++++++++++++++++++++++++---
lib/telemetry/telemetry_data.c | 2 +-
2 files changed, 41 insertions(+), 4 deletions(-)
Comments
Hi Radu,
>-----Original Message-----
>From: Nicolau, Radu <radu.nicolau@intel.com>
>Sent: Friday 3 September 2021 11:57
>To: Power, Ciara <ciara.power@intel.com>
>Cc: dev@dpdk.org; Nicolau, Radu <radu.nicolau@intel.com>; Doherty, Declan
><declan.doherty@intel.com>
>Subject: [PATCH] telemetry: add support for dicts of dicts
>
>Add support for dicts of dicts to telemetry library.
>
>Signed-off-by: Declan Doherty <declan.doherty@intel.com>
>Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
>---
> lib/telemetry/telemetry.c | 43 +++++++++++++++++++++++++++++++---
> lib/telemetry/telemetry_data.c | 2 +-
> 2 files changed, 41 insertions(+), 4 deletions(-)
>
>diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index
>8665db8d03..3f83476112 100644
>--- a/lib/telemetry/telemetry.c
>+++ b/lib/telemetry/telemetry.c
>@@ -24,7 +24,7 @@
> #include "telemetry_internal.h"
>
> #define MAX_CMD_LEN 56
>-#define MAX_HELP_LEN 64
>+#define MAX_HELP_LEN 128
> #define MAX_OUTPUT_LEN (1024 * 16)
> #define MAX_CONNECTIONS 10
>
>@@ -157,8 +157,8 @@ container_to_json(const struct rte_tel_data *d, char
>*out_buf, size_t buf_len)
> size_t used = 0;
> unsigned int i;
>
>- if (d->type != RTE_TEL_ARRAY_U64 && d->type != RTE_TEL_ARRAY_INT
>- && d->type != RTE_TEL_ARRAY_STRING)
>+ if (d->type != RTE_TEL_DICT && d->type != RTE_TEL_ARRAY_U64 &&
>+ 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); @@ -177,6
>+177,43 @@ container_to_json(const struct rte_tel_data *d, char *out_buf,
>size_t buf_len)
> used = rte_tel_json_add_array_string(out_buf,
> buf_len, used,
> d->data.array[i].sval);
>+ if (d->type == RTE_TEL_DICT)
>+ for (i = 0; i < d->data_len; i++) {
>+ const struct tel_dict_entry *v = &d->data.dict[i];
>+ switch (v->type) {
>+ case RTE_TEL_STRING_VAL:
>+ used = rte_tel_json_add_obj_str(out_buf,
>+ buf_len, used,
>+ v->name, v->value.sval);
>+ break;
>+ case RTE_TEL_INT_VAL:
>+ used = rte_tel_json_add_obj_int(out_buf,
>+ buf_len, used,
>+ v->name, v->value.ival);
>+ break;
>+ case RTE_TEL_U64_VAL:
>+ used = rte_tel_json_add_obj_u64(out_buf,
>+ buf_len, used,
>+ v->name, v->value.u64val);
>+ break;
>+ case RTE_TEL_CONTAINER:
>+ {
>+ char temp[buf_len];
>+ const struct container *cont =
>+ &v->value.container;
>+ if (container_to_json(cont->data,
>+ temp, buf_len) != 0)
>+ used = rte_tel_json_add_obj_json(
>+ out_buf,
>+ buf_len, used,
>+ v->name, temp);
>+ if (!cont->keep)
>+ rte_tel_data_free(cont->data);
>+ break;
>+ }
>+ }
>+ }
>+
> return used;
> }
>
>diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
>index 77b0fe09a5..54a7c79fff 100644
>--- a/lib/telemetry/telemetry_data.c
>+++ b/lib/telemetry/telemetry_data.c
>@@ -153,7 +153,7 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d,
>const char *name, {
> struct tel_dict_entry *e = &d->data.dict[d->data_len];
>
>- if (d->type != RTE_TEL_DICT || (val->type != RTE_TEL_ARRAY_U64
>+ if ((d->type != RTE_TEL_DICT && val->type != RTE_TEL_ARRAY_U64
> && val->type != RTE_TEL_ARRAY_INT
> && val->type != RTE_TEL_ARRAY_STRING))
> return -EINVAL;
>--
>2.25.1
Thanks for this, it will be a good addition to Telemetry.
I think tests should be added with this feature.
Different combinations of data are tested in the test_telemetry_data.c file, tests for these nested dicts would be valuable there.
Thanks,
Ciara
On 9/6/2021 5:25 PM, Power, Ciara wrote:
> Hi Radu,
>
>
>> -----Original Message-----
>> From: Nicolau, Radu <radu.nicolau@intel.com>
>> Sent: Friday 3 September 2021 11:57
>> To: Power, Ciara <ciara.power@intel.com>
>> Cc: dev@dpdk.org; Nicolau, Radu <radu.nicolau@intel.com>; Doherty, Declan
>> <declan.doherty@intel.com>
>> Subject: [PATCH] telemetry: add support for dicts of dicts
>>
>> Add support for dicts of dicts to telemetry library.
>>
>> Signed-off-by: Declan Doherty <declan.doherty@intel.com>
>> Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
>> ---
>> 5.1
>
> Thanks for this, it will be a good addition to Telemetry.
>
> I think tests should be added with this feature.
> Different combinations of data are tested in the test_telemetry_data.c file, tests for these nested dicts would be valuable there.
>
> Thanks,
> Ciara
Hi Ciara, thanks for reviewing, I will add the tests.
@@ -24,7 +24,7 @@
#include "telemetry_internal.h"
#define MAX_CMD_LEN 56
-#define MAX_HELP_LEN 64
+#define MAX_HELP_LEN 128
#define MAX_OUTPUT_LEN (1024 * 16)
#define MAX_CONNECTIONS 10
@@ -157,8 +157,8 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
size_t used = 0;
unsigned int i;
- if (d->type != RTE_TEL_ARRAY_U64 && d->type != RTE_TEL_ARRAY_INT
- && d->type != RTE_TEL_ARRAY_STRING)
+ if (d->type != RTE_TEL_DICT && d->type != RTE_TEL_ARRAY_U64 &&
+ 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);
@@ -177,6 +177,43 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
used = rte_tel_json_add_array_string(out_buf,
buf_len, used,
d->data.array[i].sval);
+ if (d->type == RTE_TEL_DICT)
+ for (i = 0; i < d->data_len; i++) {
+ const struct tel_dict_entry *v = &d->data.dict[i];
+ switch (v->type) {
+ case RTE_TEL_STRING_VAL:
+ used = rte_tel_json_add_obj_str(out_buf,
+ buf_len, used,
+ v->name, v->value.sval);
+ break;
+ case RTE_TEL_INT_VAL:
+ used = rte_tel_json_add_obj_int(out_buf,
+ buf_len, used,
+ v->name, v->value.ival);
+ break;
+ case RTE_TEL_U64_VAL:
+ used = rte_tel_json_add_obj_u64(out_buf,
+ buf_len, used,
+ v->name, v->value.u64val);
+ break;
+ case RTE_TEL_CONTAINER:
+ {
+ char temp[buf_len];
+ const struct container *cont =
+ &v->value.container;
+ if (container_to_json(cont->data,
+ temp, buf_len) != 0)
+ used = rte_tel_json_add_obj_json(
+ out_buf,
+ buf_len, used,
+ v->name, temp);
+ if (!cont->keep)
+ rte_tel_data_free(cont->data);
+ break;
+ }
+ }
+ }
+
return used;
}
@@ -153,7 +153,7 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
{
struct tel_dict_entry *e = &d->data.dict[d->data_len];
- if (d->type != RTE_TEL_DICT || (val->type != RTE_TEL_ARRAY_U64
+ if ((d->type != RTE_TEL_DICT && val->type != RTE_TEL_ARRAY_U64
&& val->type != RTE_TEL_ARRAY_INT
&& val->type != RTE_TEL_ARRAY_STRING))
return -EINVAL;