From: Florian Forster Date: Fri, 17 Jul 2020 10:43:13 +0000 (+0200) Subject: format_json: More cleanups. X-Git-Tag: 6.0.0-rc0~144^2~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8b4eb4b720a3a119268274d4e02e9c405921818;p=thirdparty%2Fcollectd.git format_json: More cleanups. * Struct "metric_t": unnecessary fields "type", "plugin", "ds" have been removed. The field "value_ds_type" has been renamed to "value_type". * The reference counted, multiple instance "meta_data_list_head_t" type has been removed. Manually doing the reference counting all over the place is error prone and it seems like premature optimization. * The "_destroy" functions must handle NULL gracefully. Removed NULL-checks around their invocation to improve readability. # Conflicts: # src/daemon/metrics_list_test.c --- diff --git a/src/utils/format_json/format_json.c b/src/utils/format_json/format_json.c index 32f35e873..d3f97f190 100644 --- a/src/utils/format_json/format_json.c +++ b/src/utils/format_json/format_json.c @@ -421,7 +421,7 @@ int format_json_metric(char *buffer_p, size_t *ret_buffer_fill, /* {{{ */ will be replaced by a [ */ BUFFER_ADD(",{"); BUFFER_ADD_KEYVAL("name", metric_p->identity->name); - if (metric_p->value_ds_type == DS_TYPE_GAUGE) { + if (metric_p->value_type == DS_TYPE_GAUGE) { if (isfinite(metric_p->value.gauge)) BUFFER_ADD(JSON_GAUGE_FORMAT, metric_p->value.gauge); else @@ -439,14 +439,14 @@ int format_json_metric(char *buffer_p, size_t *ret_buffer_fill, /* {{{ */ BUFFER_ADD(JSON_GAUGE_FORMAT, rate); else BUFFER_ADD("null"); - } else if (metric_p->value_ds_type == DS_TYPE_COUNTER) + } else if (metric_p->value_type == DS_TYPE_COUNTER) BUFFER_ADD("%" PRIu64, (uint64_t)metric_p->value.counter); - else if (metric_p->value_ds_type == DS_TYPE_DERIVE) + else if (metric_p->value_type == DS_TYPE_DERIVE) BUFFER_ADD("%" PRIi64, metric_p->value.derive); - else if (metric_p->value_ds_type == DS_TYPE_ABSOLUTE) + else if (metric_p->value_type == DS_TYPE_ABSOLUTE) BUFFER_ADD("%" PRIu64, metric_p->value.absolute); else { - ERROR("format_json: Unknown data source type: %i", metric_p->value_ds_type); + ERROR("format_json: Unknown data source type: %i", metric_p->value_type); buffer_p[*ret_buffer_fill] = '0'; return -1; } @@ -456,7 +456,7 @@ int format_json_metric(char *buffer_p, size_t *ret_buffer_fill, /* {{{ */ BUFFER_ADD_KEYVAL("plugin", metric_p->plugin); BUFFER_ADD_KEYVAL("type", metric_p->type); BUFFER_ADD_KEYVAL("dsname", metric_p->ds->name); - BUFFER_ADD_KEYVAL("dstype", DS_TYPE_TO_STRING(metric_p->value_ds_type)); + BUFFER_ADD_KEYVAL("dstype", DS_TYPE_TO_STRING(metric_p->value_type)); if (metric_p->identity->root_p != NULL) { c_avl_iterator_t *iter_p = c_avl_get_iterator(metric_p->identity->root_p);