* [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts
@ 2021-09-03 10:57 Radu Nicolau
2021-09-06 16:25 ` Power, Ciara
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Radu Nicolau @ 2021-09-03 10:57 UTC (permalink / raw)
To: Ciara Power; +Cc: dev, Radu Nicolau, Declan Doherty
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts
2021-09-03 10:57 [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts Radu Nicolau
@ 2021-09-06 16:25 ` Power, Ciara
2021-09-07 10:01 ` Nicolau, Radu
2021-09-10 11:27 ` [dpdk-dev] [PATCH v2] " Radu Nicolau
2021-09-14 16:05 ` [dpdk-dev] [PATCH v3] " Radu Nicolau
2 siblings, 1 reply; 8+ messages in thread
From: Power, Ciara @ 2021-09-06 16:25 UTC (permalink / raw)
To: Nicolau, Radu; +Cc: dev, Doherty, Declan, Richardson, Bruce
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts
2021-09-06 16:25 ` Power, Ciara
@ 2021-09-07 10:01 ` Nicolau, Radu
0 siblings, 0 replies; 8+ messages in thread
From: Nicolau, Radu @ 2021-09-07 10:01 UTC (permalink / raw)
To: Power, Ciara; +Cc: dev, Doherty, Declan, Richardson, Bruce
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [dpdk-dev] [PATCH v2] telemetry: add support for dicts of dicts
2021-09-03 10:57 [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts Radu Nicolau
2021-09-06 16:25 ` Power, Ciara
@ 2021-09-10 11:27 ` Radu Nicolau
2021-09-14 15:41 ` Power, Ciara
2021-09-14 16:05 ` [dpdk-dev] [PATCH v3] " Radu Nicolau
2 siblings, 1 reply; 8+ messages in thread
From: Radu Nicolau @ 2021-09-10 11:27 UTC (permalink / raw)
To: Ciara Power; +Cc: dev, bruce.richardson, Radu Nicolau, Declan Doherty
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>
---
app/test/test_telemetry_data.c | 29 +++++++++++++++++++++++
lib/telemetry/telemetry.c | 43 +++++++++++++++++++++++++++++++---
lib/telemetry/telemetry_data.c | 3 ++-
3 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index f34d691265..18b93db8ef 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -200,6 +200,34 @@ test_dict_with_array_string_values(void)
"[\"bbbb\"]}}");
}
+static int
+test_dict_with_dict_values(void)
+{
+ struct rte_tel_data *dict_of_dicts = rte_tel_data_alloc();
+ rte_tel_data_start_dict(dict_of_dicts);
+
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ memset(&response_data, 0, sizeof(response_data));
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_array_string(child_data, "aaaa");
+ rte_tel_data_add_array_string(child_data2, "bbbb");
+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_0",
+ child_data, 0);
+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_1",
+ child_data2, 0);
+ rte_tel_data_add_dict_container(&response_data, "dict_of_dicts",
+ dict_of_dicts, 0);
+
+ return TEST_OUTPUT("{\"/test\":{\"dict_of_dicts\":{\"dict_0\":"
+ "[\"aaaa\"],\"dict_1\":[\"bbbb\"]}}}");
+}
+
static int
test_array_with_array_string_values(void)
{
@@ -355,6 +383,7 @@ test_telemetry_data(void)
test_dict_with_array_int_values,
test_dict_with_array_u64_values,
test_dict_with_array_string_values,
+ test_dict_with_dict_values,
test_array_with_array_int_values,
test_array_with_array_u64_values,
test_array_with_array_string_values };
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..e14ae3c4d4 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -155,7 +155,8 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
if (d->type != RTE_TEL_DICT || (val->type != RTE_TEL_ARRAY_U64
&& val->type != RTE_TEL_ARRAY_INT
- && val->type != RTE_TEL_ARRAY_STRING))
+ && val->type != RTE_TEL_ARRAY_STRING
+ && val->type != RTE_TEL_DICT))
return -EINVAL;
if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES)
return -ENOSPC;
--
2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH v2] telemetry: add support for dicts of dicts
2021-09-10 11:27 ` [dpdk-dev] [PATCH v2] " Radu Nicolau
@ 2021-09-14 15:41 ` Power, Ciara
0 siblings, 0 replies; 8+ messages in thread
From: Power, Ciara @ 2021-09-14 15:41 UTC (permalink / raw)
To: Nicolau, Radu; +Cc: dev, Richardson, Bruce, Doherty, Declan
Hi Radu,
Thanks for adding the test, one more comment inline that I have just noticed.
>-----Original Message-----
>From: Nicolau, Radu <radu.nicolau@intel.com>
>Sent: Friday 10 September 2021 12:28
>To: Power, Ciara <ciara.power@intel.com>
>Cc: dev@dpdk.org; Richardson, Bruce <bruce.richardson@intel.com>; Nicolau,
>Radu <radu.nicolau@intel.com>; Doherty, Declan
><declan.doherty@intel.com>
>Subject: [PATCH v2] 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>
>---
> app/test/test_telemetry_data.c | 29 +++++++++++++++++++++++
> lib/telemetry/telemetry.c | 43 +++++++++++++++++++++++++++++++---
> lib/telemetry/telemetry_data.c | 3 ++-
> 3 files changed, 71 insertions(+), 4 deletions(-)
>
>diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
>index f34d691265..18b93db8ef 100644
>--- a/app/test/test_telemetry_data.c
>+++ b/app/test/test_telemetry_data.c
>@@ -200,6 +200,34 @@ test_dict_with_array_string_values(void)
> "[\"bbbb\"]}}");
> }
>
>+static int
>+test_dict_with_dict_values(void)
>+{
>+ struct rte_tel_data *dict_of_dicts = rte_tel_data_alloc();
>+ rte_tel_data_start_dict(dict_of_dicts);
>+
>+ struct rte_tel_data *child_data = rte_tel_data_alloc();
>+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
>+
>+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
>+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
>+
>+ memset(&response_data, 0, sizeof(response_data));
>+ rte_tel_data_start_dict(&response_data);
>+
>+ rte_tel_data_add_array_string(child_data, "aaaa");
>+ rte_tel_data_add_array_string(child_data2, "bbbb");
>+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_0",
>+ child_data, 0);
>+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_1",
>+ child_data2, 0);
>+ rte_tel_data_add_dict_container(&response_data, "dict_of_dicts",
>+ dict_of_dicts, 0);
>+
>+ return TEST_OUTPUT("{\"/test\":{\"dict_of_dicts\":{\"dict_0\":"
>+ "[\"aaaa\"],\"dict_1\":[\"bbbb\"]}}}");
>+}
>+
> static int
> test_array_with_array_string_values(void)
> {
>@@ -355,6 +383,7 @@ test_telemetry_data(void)
> test_dict_with_array_int_values,
> test_dict_with_array_u64_values,
> test_dict_with_array_string_values,
>+ test_dict_with_dict_values,
> test_array_with_array_int_values,
> test_array_with_array_u64_values,
> test_array_with_array_string_values }; 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
This change will not do much - it will allow a longer help text to be given for the command on registration,
but when the user actually asks for help text for a command, there is a restriction on the size of the string value that is added to the dict reply,
which will truncate the help text:
In telemetry_data.c/rte_tel_data_add_dict_string:
vbytes = strlcpy(e->value.sval, val, RTE_TEL_MAX_STRING_LEN);
where RTE_TEL_MAX_STRING_LEN is 64
Maybe we could just increase RTE_TEL_MAX_STRING_LEN to 128 and replace use of MAX_HELP_LEN with that, to keep them aligned.
Thanks,
Ciara
^ permalink raw reply [flat|nested] 8+ messages in thread
* [dpdk-dev] [PATCH v3] telemetry: add support for dicts of dicts
2021-09-03 10:57 [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts Radu Nicolau
2021-09-06 16:25 ` Power, Ciara
2021-09-10 11:27 ` [dpdk-dev] [PATCH v2] " Radu Nicolau
@ 2021-09-14 16:05 ` Radu Nicolau
2021-09-15 8:30 ` Power, Ciara
2 siblings, 1 reply; 8+ messages in thread
From: Radu Nicolau @ 2021-09-14 16:05 UTC (permalink / raw)
To: Ciara Power; +Cc: dev, bruce.richardson, Radu Nicolau, Declan Doherty
Add support for dicts of dicts to telemetry library.
Increase the max string size to 128.
Signed-off-by: Declan Doherty <declan.doherty@intel.com>
Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
app/test/test_telemetry_data.c | 29 ++++++++++++++++++++
lib/telemetry/rte_telemetry.h | 2 +-
lib/telemetry/telemetry.c | 48 +++++++++++++++++++++++++++++-----
lib/telemetry/telemetry_data.c | 3 ++-
4 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index f34d691265..18b93db8ef 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -200,6 +200,34 @@ test_dict_with_array_string_values(void)
"[\"bbbb\"]}}");
}
+static int
+test_dict_with_dict_values(void)
+{
+ struct rte_tel_data *dict_of_dicts = rte_tel_data_alloc();
+ rte_tel_data_start_dict(dict_of_dicts);
+
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ memset(&response_data, 0, sizeof(response_data));
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_array_string(child_data, "aaaa");
+ rte_tel_data_add_array_string(child_data2, "bbbb");
+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_0",
+ child_data, 0);
+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_1",
+ child_data2, 0);
+ rte_tel_data_add_dict_container(&response_data, "dict_of_dicts",
+ dict_of_dicts, 0);
+
+ return TEST_OUTPUT("{\"/test\":{\"dict_of_dicts\":{\"dict_0\":"
+ "[\"aaaa\"],\"dict_1\":[\"bbbb\"]}}}");
+}
+
static int
test_array_with_array_string_values(void)
{
@@ -355,6 +383,7 @@ test_telemetry_data(void)
test_dict_with_array_int_values,
test_dict_with_array_u64_values,
test_dict_with_array_string_values,
+ test_dict_with_dict_values,
test_array_with_array_int_values,
test_array_with_array_u64_values,
test_array_with_array_string_values };
diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index 8776998b54..9d1bdb2e0e 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -11,7 +11,7 @@
#define _RTE_TELEMETRY_H_
/** Maximum length for string used in object. */
-#define RTE_TEL_MAX_STRING_LEN 64
+#define RTE_TEL_MAX_STRING_LEN 128
/** Maximum length of string. */
#define RTE_TEL_MAX_SINGLE_STRING_LEN 8192
/** Maximum number of dictionary entries. */
diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 8665db8d03..8304fbf6e9 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -24,7 +24,6 @@
#include "telemetry_internal.h"
#define MAX_CMD_LEN 56
-#define MAX_HELP_LEN 64
#define MAX_OUTPUT_LEN (1024 * 16)
#define MAX_CONNECTIONS 10
@@ -36,7 +35,7 @@ client_handler(void *socket);
struct cmd_callback {
char cmd[MAX_CMD_LEN];
telemetry_cb fn;
- char help[MAX_HELP_LEN];
+ char help[RTE_TEL_MAX_STRING_LEN];
};
#ifndef RTE_EXEC_ENV_WINDOWS
@@ -75,7 +74,7 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help)
int i = 0;
if (strlen(cmd) >= MAX_CMD_LEN || fn == NULL || cmd[0] != '/'
- || strlen(help) >= MAX_HELP_LEN)
+ || strlen(help) >= RTE_TEL_MAX_STRING_LEN)
return -EINVAL;
rte_spinlock_lock(&callback_sl);
@@ -95,7 +94,7 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help)
strlcpy(callbacks[i].cmd, cmd, MAX_CMD_LEN);
callbacks[i].fn = fn;
- strlcpy(callbacks[i].help, help, MAX_HELP_LEN);
+ strlcpy(callbacks[i].help, help, RTE_TEL_MAX_STRING_LEN);
num_callbacks++;
rte_spinlock_unlock(&callback_sl);
@@ -157,8 +156,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 +176,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..e14ae3c4d4 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -155,7 +155,8 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
if (d->type != RTE_TEL_DICT || (val->type != RTE_TEL_ARRAY_U64
&& val->type != RTE_TEL_ARRAY_INT
- && val->type != RTE_TEL_ARRAY_STRING))
+ && val->type != RTE_TEL_ARRAY_STRING
+ && val->type != RTE_TEL_DICT))
return -EINVAL;
if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES)
return -ENOSPC;
--
2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH v3] telemetry: add support for dicts of dicts
2021-09-14 16:05 ` [dpdk-dev] [PATCH v3] " Radu Nicolau
@ 2021-09-15 8:30 ` Power, Ciara
2021-09-23 12:17 ` Thomas Monjalon
0 siblings, 1 reply; 8+ messages in thread
From: Power, Ciara @ 2021-09-15 8:30 UTC (permalink / raw)
To: Nicolau, Radu; +Cc: dev, Richardson, Bruce, Doherty, Declan
Hi Radu,
>-----Original Message-----
>From: Nicolau, Radu <radu.nicolau@intel.com>
>Sent: Tuesday 14 September 2021 17:05
>To: Power, Ciara <ciara.power@intel.com>
>Cc: dev@dpdk.org; Richardson, Bruce <bruce.richardson@intel.com>; Nicolau,
>Radu <radu.nicolau@intel.com>; Doherty, Declan
><declan.doherty@intel.com>
>Subject: [PATCH v3] telemetry: add support for dicts of dicts
>
>Add support for dicts of dicts to telemetry library.
>Increase the max string size to 128.
>
>Signed-off-by: Declan Doherty <declan.doherty@intel.com>
>Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
>---
> app/test/test_telemetry_data.c | 29 ++++++++++++++++++++
>lib/telemetry/rte_telemetry.h | 2 +-
> lib/telemetry/telemetry.c | 48 +++++++++++++++++++++++++++++-----
> lib/telemetry/telemetry_data.c | 3 ++-
> 4 files changed, 74 insertions(+), 8 deletions(-)
>
Thanks,
Acked-by: Ciara Power <ciara.power@intel.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH v3] telemetry: add support for dicts of dicts
2021-09-15 8:30 ` Power, Ciara
@ 2021-09-23 12:17 ` Thomas Monjalon
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Monjalon @ 2021-09-23 12:17 UTC (permalink / raw)
To: Nicolau, Radu; +Cc: dev, Richardson, Bruce, Doherty, Declan, Power, Ciara
15/09/2021 10:30, Power, Ciara:
> >From: Nicolau, Radu <radu.nicolau@intel.com>
> >
> >Add support for dicts of dicts to telemetry library.
> >Increase the max string size to 128.
> >
> >Signed-off-by: Declan Doherty <declan.doherty@intel.com>
> >Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> >---
> > app/test/test_telemetry_data.c | 29 ++++++++++++++++++++
> >lib/telemetry/rte_telemetry.h | 2 +-
> > lib/telemetry/telemetry.c | 48 +++++++++++++++++++++++++++++-----
> > lib/telemetry/telemetry_data.c | 3 ++-
> > 4 files changed, 74 insertions(+), 8 deletions(-)
>
> Thanks,
>
> Acked-by: Ciara Power <ciara.power@intel.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-09-23 12:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 10:57 [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts Radu Nicolau
2021-09-06 16:25 ` Power, Ciara
2021-09-07 10:01 ` Nicolau, Radu
2021-09-10 11:27 ` [dpdk-dev] [PATCH v2] " Radu Nicolau
2021-09-14 15:41 ` Power, Ciara
2021-09-14 16:05 ` [dpdk-dev] [PATCH v3] " Radu Nicolau
2021-09-15 8:30 ` Power, Ciara
2021-09-23 12:17 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).