[PATCH v2 00/13] telemetry JSON escaping and other enhancements
fengchengwen
fengchengwen at huawei.com
Wed Jul 27 03:51:04 CEST 2022
Hi Bruce,
I think escape the string at begin (following function) seem more simple:
rte_tel_data_string
rte_tel_data_add_array_string
rte_tel_data_add_dict_string
int
rte_tel_data_string(struct rte_tel_data *d, const char *str)
{
d->type = RTE_TEL_STRING;
d->data_len = strlcpy(d->data.str, str, sizeof(d->data.str));
// e.g. do escape here!
if (d->data_len >= RTE_TEL_MAX_SINGLE_STRING_LEN) {
d->data_len = RTE_TEL_MAX_SINGLE_STRING_LEN - 1;
return E2BIG; /* not necessarily and error, just truncation */
}
return 0;
}
Advantages:
1. simpler implementation
2. application are directly visible the result (by judge API retval) without waiting for JSON encapsulation.
Disadvantages:
1. not friend for new output format, but currently telemetry deep depend on json, so I think it's OK for it.
On 2022/7/26 0:35, Bruce Richardson wrote:
> This patchset contains fixes for the problem of handling characters
> returned by telemetry callbacks which require escaping when encoded in
> JSON format. It also includes unit tests to validate the correct
> encoding in such scenarios and a number of smaller enhancements to
> telemetry and telemetry testing.
>
> RFC->V2:
> * limited characters allowed in dictionary element names and command
> names to side-step the encoding problems there.
> * added support for proper escaping of dictionary string values
> * added more testing and test cases
> * added other misc telemetry cleanups and refactoring
>
> Bruce Richardson (13):
> test/telemetry_json: print success or failure per subtest
> telemetry: fix escaping of invalid json characters
> test/telemetry_json: add test for string character escaping
> telemetry: add escaping of strings in arrays
> test/telemetry-json: add test for escaping strings in arrays
> telemetry: limit characters allowed in dictionary names
> telemetry: add escaping of strings in dicts
> test/telemetry_json: add test for string escaping in objects
> telemetry: limit command characters
> test/telemetry_data: refactor for maintainability
> test/telemetry_data: add test cases for character escaping
> telemetry: eliminate duplicate code for json output
> telemetry: make help command more helpful
>
> app/test/test_telemetry_data.c | 138 +++++++++++++++++++--------
> app/test/test_telemetry_json.c | 98 +++++++++++++++++--
> doc/guides/rel_notes/deprecation.rst | 8 --
> lib/telemetry/rte_telemetry.h | 8 ++
> lib/telemetry/telemetry.c | 51 +++++-----
> lib/telemetry/telemetry_data.c | 32 +++++++
> lib/telemetry/telemetry_json.h | 72 ++++++++++++--
> 7 files changed, 318 insertions(+), 89 deletions(-)
>
> --
> 2.34.1
>
>
> .
>
More information about the dev
mailing list