From 8c0851b6fdf7690ae25a6fbd83e0f2795a8cdf8b Mon Sep 17 00:00:00 2001 From: Johann CAHIER Date: Wed, 15 May 2019 17:19:26 +0200 Subject: Fix influxdb-writer reporting of multiple value When the verb 'write' is called with a set of multiple values, the request sent to to influxdb will include the first value N times. Also cleaned/factorized a bit the code... Bug-AGL: SPEC-2416 Change-Id: Iafee9b472e8ef451bb048aaf487c94f3b0ae1c57 Signed-off-by: Johann CAHIER --- src/plugins/influxdb-writer.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c index 9090a32..2815b19 100644 --- a/src/plugins/influxdb-writer.c +++ b/src/plugins/influxdb-writer.c @@ -50,37 +50,35 @@ void influxdb_write_curl_cb(void *closure, int status, CURL *curl, const char *r } } + +static void serialize_list_to_query(char *query, struct list *node) { + bool first = true; + + while(node != NULL) { + if(first) { + concatenate(query, node->key, " "); + first = false; + } else { + concatenate(query, node->key, ","); + } + + if(json_object_is_type(node->value, json_type_string)) + concatenate(query, json_object_get_string(node->value), "="); + else + concatenate(query, json_object_to_json_string(node->value), "="); + node = node->next; + } +} + + static size_t format_write_args(char *query, struct series_t *serie) { char *ts; - struct list *tags = serie->serie_columns.tags; - struct list *fields = serie->serie_columns.fields; strncat(query, serie->name, strlen(serie->name)); - if(tags) { - while(tags != NULL) { - concatenate(query, tags->key, ","); - if(json_object_is_type(tags->value, json_type_string)) - concatenate(query, json_object_get_string(tags->value), "="); - else - concatenate(query, json_object_to_json_string(tags->value), "="); - tags = tags->next; - } - } - if(fields) { - int i = 0; - for(struct list *it = fields; it != NULL; it = it->next) { - if(!i) - concatenate(query, fields->key, " "); - else - concatenate(query, fields->key, ","); - if(json_object_is_type(fields->value, json_type_string)) - concatenate(query, json_object_get_string(fields->value), "="); - else - concatenate(query, json_object_to_json_string(fields->value), "="); - i++; - } - } + + serialize_list_to_query(query, serie->serie_columns.tags); + serialize_list_to_query(query, serie->serie_columns.fields); asprintf(&ts, "%lu", serie->timestamp); concatenate(query, ts, " "); -- cgit 1.2.3-korg