Report ACLK Connection Failure (#8456)
* report callback chain on conn failure
Timo committed
Mar 25, 2020 at 14:09 UTC
a43bd7cc5b7135e24fa36892e4fcc736fa8b0f30
2 files changed
+40
aclk/aclk_lws_wss_client.c
+36
@@ -264,12 +264,16 @@ int aclk_lws_wss_connect(char *host, int port)
264
{
265
struct lws_client_connect_info i;
266
struct lws_vhost *vhost;
267
+ int n;
268
269
if (!engine_instance) {
270
return aclk_lws_wss_client_init(host, port);
271
// PROTOCOL_INIT callback will call again.
272
}
273
274
+ for (n = 0; n < ACLK_LWS_CALLBACK_HISTORY; n++)
275
+ engine_instance->lws_callback_history[n] = 0;
276
+
277
if (engine_instance->lws_wsi) {
278
error("Already Connected. Only one connection supported at a time.");
279
return 0;
@@ -346,12 +350,42 @@ static const char *aclk_lws_callback_name(enum lws_callback_reasons reason)
350
return "unknown";
351
}
352
}
353
+
354
+void aclk_lws_wss_fail_report()
355
+{
356
+ int i;
357
+ int anything_to_send = 0;
358
+ BUFFER *buf;
359
+
360
+ if (netdata_anonymous_statistics_enabled <= 0)
361
+ return;
362
+
363
+ // guess - most of the callback will be 1-99 + ',' + \0
364
+ buf = buffer_create((ACLK_LWS_CALLBACK_HISTORY * 2) + 10);
365
+
366
+ for (i = 0; i < ACLK_LWS_CALLBACK_HISTORY; i++)
367
+ if (engine_instance->lws_callback_history[i]) {
368
+ buffer_sprintf(buf, "%s%d", (i ? "," : ""), engine_instance->lws_callback_history[i]);
369
+ anything_to_send = 1;
370
+ }
371
+
372
+ if (anything_to_send)
373
+ send_statistics("ACLK_CONN_FAIL", "FAIL", buffer_tostring(buf));
374
+
375
+ buffer_free(buf);
376
+}
377
+
378
static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
379
{
380
UNUSED(user);
381
struct lws_wss_packet_buffer *data;
382
int retval = 0;
383
static int lws_shutting_down = 0;
384
+ int i;
385
+
386
+ for (i = ACLK_LWS_CALLBACK_HISTORY - 1; i > 0; i--)
387
+ engine_instance->lws_callback_history[i] = engine_instance->lws_callback_history[i - 1];
388
+ engine_instance->lws_callback_history[0] = (int)reason;
389
390
if (unlikely(aclk_shutting_down && !lws_shutting_down)) {
391
lws_shutting_down = 1;
@@ -443,6 +477,8 @@ static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reas
477
return -1; // the callback response is ignored, hope the above remains true
478
case LWS_CALLBACK_WSI_DESTROY:
479
aclk_lws_wss_clear_io_buffers(engine_instance);
480
+ if (!engine_instance->websocket_connection_up)
481
+ aclk_lws_wss_fail_report();
482
engine_instance->lws_wsi = NULL;
483
engine_instance->websocket_connection_up = 0;
484
aclk_lws_connection_closed();
aclk/aclk_lws_wss_client.h
+4
@@ -16,6 +16,8 @@
16
17
#define ACLK_LWS_WSS_RECV_BUFF_SIZE_BYTES (128 * 1024)
18
19
+#define ACLK_LWS_CALLBACK_HISTORY 10
20
+
21
#ifdef ACLK_LWS_MOSQUITTO_IO_CALLS_MULTITHREADED
22
#define aclk_lws_mutex_init(x) netdata_mutex_init(x)
23
#define aclk_lws_mutex_lock(x) netdata_mutex_lock(x)
@@ -63,6 +65,8 @@ struct aclk_lws_wss_engine_instance {
65
66
int data_to_read;
67
int upstream_reconnect_request;
68
+
69
+ int lws_callback_history[ACLK_LWS_CALLBACK_HISTORY];
70
};
71
72
void aclk_lws_wss_client_destroy();