[v2,1/2] telemetry: correct json empty dictionaries

Message ID 20231224220201.762377-1-jonathan.erb@threater.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2,1/2] telemetry: correct json empty dictionaries |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Jonathan Erb Dec. 24, 2023, 10:02 p.m. UTC
  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.

Signed-off-by: Jonathan Erb <jonathan.erb@threater.com>
---
 .mailmap                  | 2 +-
 lib/telemetry/telemetry.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson Jan. 8, 2024, 11:01 a.m. UTC | #1
On Sun, Dec 24, 2023 at 05:02:00PM -0500, Jonathan Erb wrote:
> 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.
> 
> Signed-off-by: Jonathan Erb <jonathan.erb@threater.com>

One minor comment below.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

> ---
>  .mailmap                  | 2 +-
>  lib/telemetry/telemetry.c | 6 +++++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/.mailmap b/.mailmap
> index ab0742a382..a3302ba7a1 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -675,7 +675,7 @@ John Ousterhout <ouster@cs.stanford.edu>
>  John Romein <romein@astron.nl>
>  John W. Linville <linville@tuxdriver.com>
>  Jonas Pfefferle <jpf@zurich.ibm.com> <pepperjo@japf.ch>
> -Jonathan Erb <jonathan.erb@threatblockr.com> <jonathan.erb@banduracyber.com>
> +Jonathan Erb <jonathan.erb@threater.com>

FYI, it's advisable to keep old email addresses in this file, since it is
then used to map the older email addresses to the new one. Just add your
new correct email address as the first one on the line.

>  Jonathan Tsai <jonathan1.tsai@intel.com>
>  Jon DeVree <nuxi@vault24.org>
>  Jon Loeliger <jdl@netgate.com>
> diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
> index 92982842a8..0788a32210 100644
> --- a/lib/telemetry/telemetry.c
> +++ b/lib/telemetry/telemetry.c
> @@ -169,7 +169,11 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
>  		d->type != TEL_ARRAY_INT && d->type != 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 == TEL_ARRAY_UINT)
>  		for (i = 0; i < d->data_len; i++)
>  			used = rte_tel_json_add_array_uint(out_buf,
> -- 
> 2.34.1
>
  
Power, Ciara Jan. 10, 2024, 5:49 p.m. UTC | #2
Hi Jonathan,

> -----Original Message-----
> From: Jonathan Erb <jonathan.erb@threater.com>
> Sent: Sunday, December 24, 2023 10:02 PM
> To: Power, Ciara <ciara.power@intel.com>
> Cc: dev@dpdk.org; Jonathan Erb <jonathan.erb@threater.com>
> Subject: [PATCH v2 1/2] telemetry: correct json empty dictionaries
> 
> 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.
> 
> Signed-off-by: Jonathan Erb <jonathan.erb@threater.com>
> ---
>  .mailmap                  | 2 +-
>  lib/telemetry/telemetry.c | 6 +++++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/.mailmap b/.mailmap
> index ab0742a382..a3302ba7a1 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -675,7 +675,7 @@ John Ousterhout <ouster@cs.stanford.edu>  John
> Romein <romein@astron.nl>  John W. Linville <linville@tuxdriver.com>  Jonas
> Pfefferle <jpf@zurich.ibm.com> <pepperjo@japf.ch> -Jonathan Erb
> <jonathan.erb@threatblockr.com> <jonathan.erb@banduracyber.com>
> +Jonathan Erb <jonathan.erb@threater.com>
>  Jonathan Tsai <jonathan1.tsai@intel.com>  Jon DeVree <nuxi@vault24.org>
> Jon Loeliger <jdl@netgate.com> diff --git a/lib/telemetry/telemetry.c
> b/lib/telemetry/telemetry.c index 92982842a8..0788a32210 100644
> --- a/lib/telemetry/telemetry.c
> +++ b/lib/telemetry/telemetry.c
> @@ -169,7 +169,11 @@ container_to_json(const struct rte_tel_data *d, char
> *out_buf, size_t buf_len)
>  		d->type != TEL_ARRAY_INT && d->type !=
> 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 == TEL_ARRAY_UINT)
>  		for (i = 0; i < d->data_len; i++)
>  			used = rte_tel_json_add_array_uint(out_buf,
> --
> 2.34.1

+1 for Bruce's suggestion to squash patch #2 into this one.

Thanks,
Acked-by: Ciara Power <ciara.power@intel.com>
  

Patch

diff --git a/.mailmap b/.mailmap
index ab0742a382..a3302ba7a1 100644
--- a/.mailmap
+++ b/.mailmap
@@ -675,7 +675,7 @@  John Ousterhout <ouster@cs.stanford.edu>
 John Romein <romein@astron.nl>
 John W. Linville <linville@tuxdriver.com>
 Jonas Pfefferle <jpf@zurich.ibm.com> <pepperjo@japf.ch>
-Jonathan Erb <jonathan.erb@threatblockr.com> <jonathan.erb@banduracyber.com>
+Jonathan Erb <jonathan.erb@threater.com>
 Jonathan Tsai <jonathan1.tsai@intel.com>
 Jon DeVree <nuxi@vault24.org>
 Jon Loeliger <jdl@netgate.com>
diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 92982842a8..0788a32210 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -169,7 +169,11 @@  container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len)
 		d->type != TEL_ARRAY_INT && d->type != 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 == TEL_ARRAY_UINT)
 		for (i = 0; i < d->data_len; i++)
 			used = rte_tel_json_add_array_uint(out_buf,