diff options
author | Timo <6674623+underhood@users.noreply.github.com> | 2020-03-25 14:09:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 14:09:06 +0100 |
commit | a43bd7cc5b7135e24fa36892e4fcc736fa8b0f30 (patch) | |
tree | ee027e181da93cbf33c1b52a3813eec38c27f17b /aclk | |
parent | 198b735f30d1bdbbb8ca87dc1f0b25f9091bfe3b (diff) |
Report ACLK Connection Failure (#8456)
* report callback chain on conn failure
Diffstat (limited to 'aclk')
-rw-r--r-- | aclk/aclk_lws_wss_client.c | 36 | ||||
-rw-r--r-- | aclk/aclk_lws_wss_client.h | 4 |
2 files changed, 40 insertions, 0 deletions
diff --git a/aclk/aclk_lws_wss_client.c b/aclk/aclk_lws_wss_client.c index 06f8d2451a..a5ed3d5235 100644 --- a/aclk/aclk_lws_wss_client.c +++ b/aclk/aclk_lws_wss_client.c @@ -264,12 +264,16 @@ int aclk_lws_wss_connect(char *host, int port) { struct lws_client_connect_info i; struct lws_vhost *vhost; + int n; if (!engine_instance) { return aclk_lws_wss_client_init(host, port); // PROTOCOL_INIT callback will call again. } + for (n = 0; n < ACLK_LWS_CALLBACK_HISTORY; n++) + engine_instance->lws_callback_history[n] = 0; + if (engine_instance->lws_wsi) { error("Already Connected. Only one connection supported at a time."); return 0; @@ -346,12 +350,42 @@ static const char *aclk_lws_callback_name(enum lws_callback_reasons reason) return "unknown"; } } + +void aclk_lws_wss_fail_report() +{ + int i; + int anything_to_send = 0; + BUFFER *buf; + + if (netdata_anonymous_statistics_enabled <= 0) + return; + + // guess - most of the callback will be 1-99 + ',' + \0 + buf = buffer_create((ACLK_LWS_CALLBACK_HISTORY * 2) + 10); + + for (i = 0; i < ACLK_LWS_CALLBACK_HISTORY; i++) + if (engine_instance->lws_callback_history[i]) { + buffer_sprintf(buf, "%s%d", (i ? "," : ""), engine_instance->lws_callback_history[i]); + anything_to_send = 1; + } + + if (anything_to_send) + send_statistics("ACLK_CONN_FAIL", "FAIL", buffer_tostring(buf)); + + buffer_free(buf); +} + static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { UNUSED(user); struct lws_wss_packet_buffer *data; int retval = 0; static int lws_shutting_down = 0; + int i; + + for (i = ACLK_LWS_CALLBACK_HISTORY - 1; i > 0; i--) + engine_instance->lws_callback_history[i] = engine_instance->lws_callback_history[i - 1]; + engine_instance->lws_callback_history[0] = (int)reason; if (unlikely(aclk_shutting_down && !lws_shutting_down)) { lws_shutting_down = 1; @@ -443,6 +477,8 @@ static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reas return -1; // the callback response is ignored, hope the above remains true case LWS_CALLBACK_WSI_DESTROY: aclk_lws_wss_clear_io_buffers(engine_instance); + if (!engine_instance->websocket_connection_up) + aclk_lws_wss_fail_report(); engine_instance->lws_wsi = NULL; engine_instance->websocket_connection_up = 0; aclk_lws_connection_closed(); diff --git a/aclk/aclk_lws_wss_client.h b/aclk/aclk_lws_wss_client.h index 349e0c0ef6..26a7865393 100644 --- a/aclk/aclk_lws_wss_client.h +++ b/aclk/aclk_lws_wss_client.h @@ -16,6 +16,8 @@ #define ACLK_LWS_WSS_RECV_BUFF_SIZE_BYTES (128 * 1024) +#define ACLK_LWS_CALLBACK_HISTORY 10 + #ifdef ACLK_LWS_MOSQUITTO_IO_CALLS_MULTITHREADED #define aclk_lws_mutex_init(x) netdata_mutex_init(x) #define aclk_lws_mutex_lock(x) netdata_mutex_lock(x) @@ -63,6 +65,8 @@ struct aclk_lws_wss_engine_instance { int data_to_read; int upstream_reconnect_request; + + int lws_callback_history[ACLK_LWS_CALLBACK_HISTORY]; }; void aclk_lws_wss_client_destroy(); |