aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohann CAHIER <johann.cahier@iot.bzh>2019-05-21 09:49:04 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-05-24 15:16:39 +0000
commitc07d9d2f20d26ef21aede121a60c92b9f0af109e (patch)
tree7ab4c87e12f46f6637f48870b8a938b39e200c14
parent5dd410aab93c4ea5c3c04662585c072172ea5547 (diff)
Fix InfluxDB request formathalibut_7.99.1halibut/7.99.17.99.1
As per: https://docs.influxdata.com/influxdb/v1.7/write_protocols/ separator should be a comma between metric name and metadatas (tags). Bug-AGL: SPEC-2416 Change-Id: Iedfa21ec8e61aa406600711b38e5ac2b0e87d776 Signed-off-by: Johann CAHIER <johann.cahier@iot.bzh>
-rw-r--r--src/plugins/influxdb-writer.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/plugins/influxdb-writer.c b/src/plugins/influxdb-writer.c
index a7ce8fc..e22c2bd 100644
--- a/src/plugins/influxdb-writer.c
+++ b/src/plugins/influxdb-writer.c
@@ -50,16 +50,19 @@ 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) {
+// query: destination buffer
+// node: head node of the list
+// list_sep: separator to append in front of the list
+// item_sep: separator to append between items of the list
+static void serialize_list_to_query(char *query, struct list *node, const char *list_sep, const char *item_sep) {
bool first = true;
while(node != NULL) {
if(first) {
- concatenate(query, node->key, " ");
+ concatenate(query, node->key, list_sep);
first = false;
} else {
- concatenate(query, node->key, ",");
+ concatenate(query, node->key, item_sep);
}
if(json_object_is_type(node->value, json_type_string))
@@ -77,13 +80,15 @@ static size_t format_write_args(char *query, struct series_t *serie)
strncat(query, serie->name, strlen(serie->name));
- 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, " ");
+ serialize_list_to_query(query, serie->serie_columns.tags, ",", ",");
+ serialize_list_to_query(query, serie->serie_columns.fields, " ", ",");
- return strlen(query);
+ if (asprintf(&ts, "%lu", serie->timestamp) > 0) {
+ concatenate(query, ts, " ");
+ free(ts);
+ return strlen(query);
+ }
+ return -1;
}
CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *metricsJ)
@@ -121,7 +126,7 @@ CURL *make_curl_write_post(afb_api_t apiHandle, const char *url, json_object *me
}
else {
len_write = format_write_args(write, serie);
- if(len_write) {
+ if(len_write > 0) {
post_data[i] = malloc(len_write + 1);
strcpy(post_data[i], write);
memset(write, 0, len_write);