summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohann CAHIER <johann.cahier@iot.bzh>2019-05-15 17:19:26 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-05-21 01:56:44 +0000
commit8c0851b6fdf7690ae25a6fbd83e0f2795a8cdf8b (patch)
tree8f4bf2d95ad3791a729d9d1536071870f0f5d09d
parent23a7f78a50e91537a3ae6f13181d9f5edf2eb1bb (diff)
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 <johann.cahier@iot.bzh>
-rw-r--r--src/plugins/influxdb-writer.c50
1 files changed, 24 insertions, 26 deletions
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, " ");