From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C38BFA0547; Fri, 10 Sep 2021 13:34:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3AD3B40DDE; Fri, 10 Sep 2021 13:34:55 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 5F40E406B4 for ; Fri, 10 Sep 2021 13:34:53 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10102"; a="284762470" X-IronPort-AV: E=Sophos;i="5.85,282,1624345200"; d="scan'208";a="284762470" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2021 04:34:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,282,1624345200"; d="scan'208";a="480141824" Received: from silpixa00400884.ir.intel.com ([10.243.22.82]) by orsmga008.jf.intel.com with ESMTP; 10 Sep 2021 04:34:51 -0700 From: Radu Nicolau To: Ciara Power Cc: dev@dpdk.org, bruce.richardson@intel.com, Radu Nicolau , Declan Doherty Date: Fri, 10 Sep 2021 12:27:52 +0100 Message-Id: <20210910112752.872337-1-radu.nicolau@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210903105725.243477-1-radu.nicolau@intel.com> References: <20210903105725.243477-1-radu.nicolau@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] telemetry: add support for dicts of dicts X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add support for dicts of dicts to telemetry library. Signed-off-by: Declan Doherty Signed-off-by: Radu Nicolau --- 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