Accept a data query timeout parameter from the cloud (#12823)
* Add the ability to parse a "timeout" parameter in the incoming command * Cancel the incoming query if already in the queue for too long
Stelios Fragkakis committed
May 5, 2022 at 11:49 UTC
d46fb8d1eca1fb40fc79423a9e6adb5638766014
3 files changed
+16
-1
aclk/aclk_query.c
+9
@@ -111,6 +111,15 @@ static int http_api_v2(struct aclk_query_thread *query_thr, aclk_query_t query)
111
w->tv_in = query->created_tv;
112
now_realtime_timeval(&w->tv_ready);
113
114
+ if (query->timeout && (dt_usec(&query->created_tv, &w->tv_ready) / 1000.0) > query->timeout) {
115
+ log_access("QUERY CANCELED: QUEUE TIME EXCEEDED %0.2f ms (LIMIT %d ms)",
116
+ dt_usec(&query->created_tv, &w->tv_ready) / 1000.0, query->timeout);
117
+ retval = 1;
118
+ w->response.code = HTTP_RESP_BACKEND_FETCH_FAILED;
119
+ aclk_http_msg_v2_err(query_thr->client, query->callback_topic, query->msg_id, w->response.code, CLOUD_EC_SND_TIMEOUT, CLOUD_EMSG_SND_TIMEOUT, NULL, 0);
120
+ goto cleanup;
121
+ }
122
+
123
RRDHOST *temp_host = NULL;
124
if (!strncmp(query->data.http_api_v2.query, NODE_ID_QUERY, strlen(NODE_ID_QUERY))) {
125
char *node_uuid = query->data.http_api_v2.query + strlen(NODE_ID_QUERY);
aclk/aclk_query_queue.h
+1
-1
@@ -67,7 +67,7 @@ struct aclk_query {
67
68
struct timeval created_tv;
69
usec_t created;
70
-
70
+ int timeout;
71
aclk_query_t next;
72
73
// TODO maybe remove?
aclk/aclk_rx_msgs.c
+6
@@ -17,6 +17,7 @@ struct aclk_request {
17
char *callback_topic;
18
char *payload;
19
int version;
20
+ int timeout;
21
int min_version;
22
int max_version;
23
};
@@ -57,6 +58,10 @@ static int cloud_to_agent_parse(JSON_ENTRY *e)
58
data->version = e->data.number;
59
break;
60
}
61
+ if (!strcmp(e->name, "timeout")) {
62
+ data->timeout = e->data.number;
63
+ break;
64
+ }
65
if (!strcmp(e->name, "min-version")) {
66
data->min_version = e->data.number;
67
break;
@@ -160,6 +165,7 @@ static int aclk_handle_cloud_http_request_v2(struct aclk_request *cloud_to_agent
165
166
// aclk_queue_query takes ownership of data pointer
167
query->callback_topic = cloud_to_agent->callback_topic;
168
+ query->timeout = cloud_to_agent->timeout;
169
// for clarity and code readability as when we process the request
170
// it would be strange to get URL from `dedup_id`
171
query->data.http_api_v2.query = query->dedup_id;