@cryptotaxi247 / netdata-1 / commits / 59af90b08

Allows ACLK NG and Legacy to coexist (#11225)

Timotej S committed Jun 14, 2021 at 10:38 UTC 59af90b08c705a66bdca7551b43257781db47711
41 files changed +998 -1225
.github/workflows/tests.yml
+1 -1
@@ -52,7 +52,7 @@ jobs:
52 - name: Configure
53 run: |
54 autoreconf -ivf
55 - ./configure --without-aclk-ng
55 + ./configure
56 # XXX: Work-around for bug with libbson-1.0 in Ubuntu 18.04
57 # See: https://bugs.launchpad.net/ubuntu/+source/libmongoc/+bug/1790771
58 # https://jira.mongodb.org/browse/CDRIVER-2818
CMakeLists.txt
+64 -13
@@ -730,12 +730,22 @@ set(BACKENDS_PLUGIN_FILES
730 set(CLAIM_PLUGIN_FILES
731 claim/claim.c
732 claim/claim.h
733 - aclk/legacy/aclk_rrdhost_state.h
734 - aclk/legacy/aclk_common.c
735 - aclk/legacy/aclk_common.h
733 )
734
738 -set(ACLK_PLUGIN_FILES
735 +set(ACLK_ALWAYS_BUILD
736 + aclk/aclk_rrdhost_state.h
737 + aclk/aclk_api.c
738 + aclk/aclk_api.h
739 + aclk/aclk_proxy.c
740 + aclk/aclk_proxy.h
741 + )
742 +
743 +set(ACLK_COMMON_FILES
744 + aclk/aclk_collector_list.c
745 + aclk/aclk_collector_list.h
746 + )
747 +
748 +set(ACLK_LEGACY_FILES
749 aclk/legacy/agent_cloud_link.c
750 aclk/legacy/agent_cloud_link.h
751 aclk/legacy/aclk_query.c
@@ -750,6 +760,40 @@ set(ACLK_PLUGIN_FILES
760 aclk/legacy/aclk_stats.h
761 aclk/legacy/aclk_rx_msgs.c
762 aclk/legacy/aclk_rx_msgs.h
763 + aclk/legacy/aclk_common.c
764 + aclk/legacy/aclk_common.h
765 + )
766 +
767 +set(ACLK_NG_FILES
768 + aclk/aclk.c
769 + aclk/aclk.h
770 + aclk/aclk_util.c
771 + aclk/aclk_util.h
772 + aclk/aclk_stats.c
773 + aclk/aclk_stats.h
774 + aclk/aclk_query.c
775 + aclk/aclk_query.h
776 + aclk/aclk_query_queue.c
777 + aclk/aclk_query_queue.h
778 + aclk/aclk_otp.c
779 + aclk/aclk_otp.h
780 + aclk/aclk_tx_msgs.c
781 + aclk/aclk_tx_msgs.h
782 + aclk/aclk_rx_msgs.c
783 + aclk/aclk_rx_msgs.h
784 + aclk/https_client.c
785 + aclk/https_client.h
786 + mqtt_websockets/src/mqtt_wss_client.c
787 + mqtt_websockets/src/include/mqtt_wss_client.h
788 + mqtt_websockets/src/mqtt_wss_log.c
789 + mqtt_websockets/src/include/mqtt_wss_log.h
790 + mqtt_websockets/src/ws_client.c
791 + mqtt_websockets/src/include/ws_client.h
792 + mqtt_websockets/c-rbuf/src/ringbuffer.c
793 + mqtt_websockets/c-rbuf/include/ringbuffer.h
794 + mqtt_websockets/c-rbuf/src/ringbuffer_internal.h
795 + mqtt_websockets/MQTT-C/src/mqtt.c
796 + mqtt_websockets/MQTT-C/include/mqtt.h
797 )
798
799 set(SPAWN_PLUGIN_FILES
@@ -759,7 +803,7 @@ set(SPAWN_PLUGIN_FILES
803 spawn/spawn.h
804 )
805
762 -set(ACLK_STATIC_LIBS
806 +set(ACLK_LEGACY_STATIC_LIBS
807 ${CMAKE_SOURCE_DIR}/externaldeps/mosquitto/libmosquitto.a
808 ${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/libwebsockets.a
809 )
@@ -967,21 +1011,21 @@ ENDIF()
1011
1012 set(NETDATA_COMMON_LIBRARIES ${NETDATA_COMMON_LIBRARIES} m ${CMAKE_THREAD_LIBS_INIT})
1013
970 -set(ACLK_CAN_BUILD 1)
1014 +set(ACLK_LEGACY_CAN_BUILD 1)
1015 if(NOT EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/mosquitto/libmosquitto.a")
1016 message(WARNING "Static build of mosquitto not found. Disabling ACLK")
973 - set(ACLK_CAN_BUILD 0)
1017 + set(ACLK_LEGACY_CAN_BUILD 0)
1018 ENDIF()
1019
1020 if(NOT EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/libwebsockets.a")
1021 message(WARNING "Static build of libwebsockets not found. Disabling ACLK")
978 - set(ACLK_CAN_BUILD 0)
1022 + set(ACLK_LEGACY_CAN_BUILD 0)
1023 ENDIF()
1024
981 -IF(ACLK_CAN_BUILD)
982 - message(STATUS "agent-cloud-link: enabled")
983 - list(APPEND NETDATA_FILES ${ACLK_PLUGIN_FILES})
984 - list(APPEND NETDATA_COMMON_LIBRARIES ${ACLK_STATIC_LIBS})
1025 +IF(ACLK_LEGACY_CAN_BUILD)
1026 + message(STATUS "agent-cloud-link Legacy: enabled")
1027 + list(APPEND NETDATA_FILES ${ACLK_LEGACY_FILES})
1028 + list(APPEND NETDATA_COMMON_LIBRARIES ${ACLK_LEGACY_STATIC_LIBS})
1029 include_directories(BEFORE ${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/include)
1030 IF(LINUX AND CAP_FOUND)
1031 list(APPEND NETDATA_COMMON_LIBRARIES ${CAP_LIBRARIES})
@@ -989,9 +1033,16 @@ IF(ACLK_CAN_BUILD)
1033 list(APPEND NETDATA_COMMON_CFLAGS ${CAP_CFLAGS_OTHER})
1034 ENDIF()
1035 ELSE()
992 - message(STATUS "agent-cloud-link: disabled")
1036 + message(STATUS "agent-cloud-link Legacy: disabled")
1037 ENDIF()
1038
1039 +list(APPEND NETDATA_FILES ${ACLK_ALWAYS_BUILD})
1040 +list(APPEND NETDATA_FILES ${ACLK_NG_FILES})
1041 +list(APPEND NETDATA_FILES ${ACLK_COMMON_FILES})
1042 +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/MQTT-C/include)
1043 +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/src/include)
1044 +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/c-rbuf/include)
1045 +
1046 # -----------------------------------------------------------------------------
1047 # netdata
1048
Makefile.am
+30 -20
@@ -114,7 +114,7 @@ SUBDIRS += \
114 spawn \
115 $(NULL)
116
117 -if !ACLK_NG
117 +if ENABLE_ACLK
118 SUBDIRS += \
119 aclk/legacy \
120 $(NULL)
@@ -540,7 +540,7 @@ PARSER_FILES = \
540 $(NULL)
541
542 if ACLK_NG
543 -ACLK_FILES = \
543 +ACLK_NG_FILES = \
544 aclk/aclk.c \
545 aclk/aclk.h \
546 aclk/aclk_util.c \
@@ -551,8 +551,6 @@ ACLK_FILES = \
551 aclk/aclk_query.h \
552 aclk/aclk_query_queue.c \
553 aclk/aclk_query_queue.h \
554 - aclk/aclk_collector_list.c \
555 - aclk/aclk_collector_list.h \
554 aclk/aclk_otp.c \
555 aclk/aclk_otp.h \
556 aclk/aclk_tx_msgs.c \
@@ -573,17 +571,25 @@ ACLK_FILES = \
571 mqtt_websockets/MQTT-C/src/mqtt.c \
572 mqtt_websockets/MQTT-C/include/mqtt.h \
573 $(NULL)
576 -else #ACLK_NG
577 -ACLK_FILES = \
578 - aclk/legacy/aclk_rrdhost_state.h \
579 - aclk/legacy/aclk_common.c \
580 - aclk/legacy/aclk_common.h \
581 - aclk/legacy/aclk_stats.c \
582 - aclk/legacy/aclk_stats.h \
583 - $(NULL)
574 +endif #ACLK_NG
575
576 if ENABLE_ACLK
586 -ACLK_FILES += \
577 +ACLK_COMMON_FILES = \
578 + aclk/aclk_collector_list.c \
579 + aclk/aclk_collector_list.h \
580 + $(NULL)
581 +endif
582 +
583 +ACLK_ALWAYS_BUILD_FILES = \
584 + aclk/aclk_rrdhost_state.h \
585 + aclk/aclk_api.c \
586 + aclk/aclk_api.h \
587 + aclk/aclk_proxy.c \
588 + aclk/aclk_proxy.h \
589 + $(NULL)
590 +
591 +if ACLK_LEGACY
592 +ACLK_LEGACY_FILES = \
593 aclk/legacy/agent_cloud_link.c \
594 aclk/legacy/agent_cloud_link.h \
595 aclk/legacy/aclk_query.c \
@@ -596,9 +602,12 @@ ACLK_FILES += \
602 aclk/legacy/aclk_lws_wss_client.h \
603 aclk/legacy/aclk_lws_https_client.c \
604 aclk/legacy/aclk_lws_https_client.h \
605 + aclk/legacy/aclk_common.c \
606 + aclk/legacy/aclk_common.h \
607 + aclk/legacy/aclk_stats.c \
608 + aclk/legacy/aclk_stats.h \
609 $(NULL)
600 -endif #ENABLE_ACLK
601 -endif #ACLK_NG
610 +endif #ACLK_LEGACY
611
612 SPAWN_PLUGIN_FILES = \
613 spawn/spawn.c \
@@ -710,7 +719,10 @@ NETDATA_FILES = \
719 $(WEB_PLUGIN_FILES) \
720 $(CLAIM_FILES) \
721 $(PARSER_FILES) \
713 - $(ACLK_FILES) \
722 + $(ACLK_ALWAYS_BUILD_FILES) \
723 + $(ACLK_COMMON_FILES) \
724 + $(ACLK_LEGACY_FILES) \
725 + $(ACLK_NG_FILES) \
726 $(SPAWN_PLUGIN_FILES) \
727 $(NULL)
728
@@ -770,16 +782,14 @@ netdata_LDADD = \
782 $(NETDATA_COMMON_LIBS) \
783 $(NULL)
784
773 -if !ACLK_NG
774 -if ENABLE_ACLK
785 +if ACLK_LEGACY
786 netdata_LDADD += \
787 $(abs_top_srcdir)/externaldeps/mosquitto/libmosquitto.a \
788 $(OPTIONAL_LIBCAP_LIBS) \
789 $(OPTIONAL_LWS_LIBS) \
790 $(NETDATA_COMMON_LIBS) \
791 $(NULL)
781 -endif #ENABLE_ACLK
782 -endif #ACLK_NG
792 +endif #ACLK_LEGACY
793
794 if ENABLE_CXX_LINKER
795 netdata_LINK = $(CXXLD) $(CXXFLAGS) $(LDFLAGS) -o $@
aclk/aclk.c
+14 -55
@@ -13,6 +13,8 @@
13 #include "aclk_collector_list.h"
14 #include "https_client.h"
15
16 +#include "aclk_proxy.h"
17 +
18 #ifdef ACLK_LOG_CONVERSATION_DIR
19 #include <sys/types.h>
20 #include <sys/stat.h>
@@ -21,19 +23,10 @@
23
24 #define ACLK_STABLE_TIMEOUT 3 // Minimum delay to mark AGENT as stable
25
24 -//TODO remove most (as in 99.999999999%) of this crap
25 -int aclk_connected = 0;
26 -int aclk_disable_runtime = 0;
27 -int aclk_disable_single_updates = 0;
28 -int aclk_kill_link = 0;
29 -
26 int aclk_pubacks_per_conn = 0; // How many PubAcks we got since MQTT conn est.
27
28 time_t aclk_block_until = 0;
29
34 -usec_t aclk_session_us = 0; // Used by the mqtt layer
35 -time_t aclk_session_sec = 0; // Used by the mqtt layer
36 -
30 aclk_env_t *aclk_env = NULL;
31
32 mqtt_wss_client mqttwss_client;
@@ -43,22 +36,12 @@ netdata_mutex_t aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER;
36 #define ACLK_SHARED_STATE_UNLOCK netdata_mutex_unlock(&aclk_shared_state_mutex)
37
38 struct aclk_shared_state aclk_shared_state = {
46 - .agent_state = AGENT_INITIALIZING,
39 + .agent_state = ACLK_HOST_INITIALIZING,
40 .last_popcorn_interrupt = 0,
41 .mqtt_shutdown_msg_id = -1,
42 .mqtt_shutdown_msg_rcvd = 0
43 };
44
52 -void aclk_single_update_disable()
53 -{
54 - aclk_disable_single_updates = 1;
55 -}
56 -
57 -void aclk_single_update_enable()
58 -{
59 - aclk_disable_single_updates = 0;
60 -}
61 -
45 //ENDTODO
46
47 static RSA *aclk_private_key = NULL;
@@ -301,7 +284,7 @@ static int handle_connection(mqtt_wss_client client)
284 inline static int aclk_popcorn_check_bump()
285 {
286 ACLK_SHARED_STATE_LOCK;
304 - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) {
287 + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) {
288 aclk_shared_state.last_popcorn_interrupt = now_realtime_sec();
289 ACLK_SHARED_STATE_UNLOCK;
290 return 1;
@@ -340,7 +323,7 @@ static inline void mqtt_connected_actions(mqtt_wss_client client)
323 aclk_pubacks_per_conn = 0;
324
325 ACLK_SHARED_STATE_LOCK;
343 - if (aclk_shared_state.agent_state != AGENT_INITIALIZING) {
326 + if (aclk_shared_state.agent_state != ACLK_HOST_INITIALIZING) {
327 error("Sending `connect` payload immediately as popcorning was finished already.");
328 queue_connect_payloads();
329 }
@@ -360,13 +343,13 @@ static int wait_popcorning_finishes(mqtt_wss_client client, struct aclk_query_th
343 int need_wait;
344 while (!netdata_exit) {
345 ACLK_SHARED_STATE_LOCK;
363 - if (likely(aclk_shared_state.agent_state != AGENT_INITIALIZING)) {
346 + if (likely(aclk_shared_state.agent_state != ACLK_HOST_INITIALIZING)) {
347 ACLK_SHARED_STATE_UNLOCK;
348 return 0;
349 }
350 elapsed = now_realtime_sec() - aclk_shared_state.last_popcorn_interrupt;
351 if (elapsed >= ACLK_STABLE_TIMEOUT) {
369 - aclk_shared_state.agent_state = AGENT_STABLE;
352 + aclk_shared_state.agent_state = ACLK_HOST_STABLE;
353 ACLK_SHARED_STATE_UNLOCK;
354 error("ACLK localhost popocorn finished");
355 if (unlikely(!query_threads->thread_list))
@@ -721,10 +704,10 @@ exit:
704 // fix this in both old and new ACLK
705 extern void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host);
706
724 -void aclk_alarm_reload(void)
707 +void ng_aclk_alarm_reload(void)
708 {
709 ACLK_SHARED_STATE_LOCK;
727 - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) {
710 + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) {
711 ACLK_SHARED_STATE_UNLOCK;
712 return;
713 }
@@ -733,7 +716,7 @@ void aclk_alarm_reload(void)
716 aclk_queue_query(aclk_query_new(METADATA_ALARMS));
717 }
718
736 -int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
719 +int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
720 {
721 BUFFER *local_buffer;
722 json_object *msg;
@@ -742,7 +725,7 @@ int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
725 return 0;
726
727 ACLK_SHARED_STATE_LOCK;
745 - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) {
728 + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) {
729 ACLK_SHARED_STATE_UNLOCK;
730 return 0;
731 }
@@ -764,7 +747,7 @@ int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
747 return 0;
748 }
749
767 -int aclk_update_chart(RRDHOST *host, char *chart_name, int create)
750 +int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create)
751 {
752 struct aclk_query *query;
753
@@ -788,7 +771,7 @@ int aclk_update_chart(RRDHOST *host, char *chart_name, int create)
771 * Add a new collector to the list
772 * If it exists, update the chart count
773 */
791 -void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
774 +void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
775 {
776 struct aclk_query *query;
777 struct _collector *tmp_collector;
@@ -831,7 +814,7 @@ void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *modu
814 * This function will release the memory used and schedule
815 * a cloud update
816 */
834 -void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
817 +void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
818 {
819 struct aclk_query *query;
820 struct _collector *tmp_collector;
@@ -871,27 +854,3 @@ void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *modu
854 query->data.metadata_alarms.initial_on_connect = 0;
855 aclk_queue_query(query);
856 }
874 -
875 -struct label *add_aclk_host_labels(struct label *label) {
876 -#ifdef ENABLE_ACLK
877 - ACLK_PROXY_TYPE aclk_proxy;
878 - char *proxy_str;
879 - aclk_get_proxy(&aclk_proxy);
880 -
881 - switch(aclk_proxy) {
882 - case PROXY_TYPE_SOCKS5:
883 - proxy_str = "SOCKS5";
884 - break;
885 - case PROXY_TYPE_HTTP:
886 - proxy_str = "HTTP";
887 - break;
888 - default:
889 - proxy_str = "none";
890 - break;
891 - }
892 - label = add_label_to_list(label, "_aclk_impl", "Next Generation", LABEL_SOURCE_AUTO);
893 - return add_label_to_list(label, "_aclk_proxy", proxy_str, LABEL_SOURCE_AUTO);
894 -#else
895 - return label;
896 -#endif
897 -}
aclk/aclk.h
+6 -44
@@ -2,57 +2,24 @@
2 #ifndef ACLK_H
3 #define ACLK_H
4
5 -typedef struct aclk_rrdhost_state {
6 - char *claimed_id; // Claimed ID if host has one otherwise NULL
7 -} aclk_rrdhost_state;
8 -
5 #include "daemon/common.h"
6 #include "aclk_util.h"
11 -
12 -// version for aclk legacy (old cloud arch)
13 -#define ACLK_VERSION 2
14 -
15 -// Define ACLK Feature Version Boundaries Here
16 -#define ACLK_V_COMPRESSION 2
7 +#include "aclk_rrdhost_state.h"
8
9 // How many MQTT PUBACKs we need to get to consider connection
10 // stable for the purposes of TBEB (truncated binary exponential backoff)
11 #define ACLK_PUBACKS_CONN_STABLE 3
12
22 -// TODO get rid of this shit
23 -extern int aclk_disable_runtime;
24 -extern int aclk_disable_single_updates;
25 -extern int aclk_kill_link;
26 -extern int aclk_connected;
27 -
13 extern time_t aclk_block_until;
14
30 -extern usec_t aclk_session_us;
31 -extern time_t aclk_session_sec;
32 -
15 extern aclk_env_t *aclk_env;
16
17 void *aclk_main(void *ptr);
36 -void aclk_single_update_disable();
37 -void aclk_single_update_enable();
38 -
39 -#define NETDATA_ACLK_HOOK \
40 - { .name = "ACLK_Main", \
41 - .config_section = NULL, \
42 - .config_name = NULL, \
43 - .enabled = 1, \
44 - .thread = NULL, \
45 - .init_routine = NULL, \
46 - .start_routine = aclk_main },
18
19 extern netdata_mutex_t aclk_shared_state_mutex;
20 #define ACLK_SHARED_STATE_LOCK netdata_mutex_lock(&aclk_shared_state_mutex)
21 #define ACLK_SHARED_STATE_UNLOCK netdata_mutex_unlock(&aclk_shared_state_mutex)
22
52 -typedef enum aclk_agent_state {
53 - AGENT_INITIALIZING,
54 - AGENT_STABLE
55 -} ACLK_AGENT_STATE;
23 extern struct aclk_shared_state {
24 ACLK_AGENT_STATE agent_state;
25 time_t last_popcorn_interrupt;
@@ -65,20 +32,15 @@ extern struct aclk_shared_state {
32 int mqtt_shutdown_msg_rcvd;
33 } aclk_shared_state;
34
68 -void aclk_alarm_reload(void);
69 -int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
35 +void ng_aclk_alarm_reload(void);
36 +int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
37
71 -// TODO this is for bacward compatibility with ACLK legacy
72 -#define ACLK_CMD_CHART 1
73 -#define ACLK_CMD_CHARTDEL 0
38 /* Informs ACLK about created/deleted chart
39 * @param create 0 - if chart was deleted, other if chart created
40 */
77 -int aclk_update_chart(RRDHOST *host, char *chart_name, int create);
78 -
79 -void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
80 -void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
41 +int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create);
42
82 -struct label *add_aclk_host_labels(struct label *label);
43 +void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
44 +void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
45
46 #endif /* ACLK_H */
aclk/aclk_api.c new
+179
@@ -0,0 +1,179 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +#include "libnetdata/libnetdata.h"
3 +#include "database/rrd.h"
4 +
5 +#ifdef ACLK_NG
6 +#include "aclk.h"
7 +#endif
8 +#ifdef ACLK_LEGACY
9 +#include "legacy/agent_cloud_link.h"
10 +#endif
11 +
12 +int aclk_connected = 0;
13 +int aclk_kill_link = 0;
14 +
15 +usec_t aclk_session_us = 0;
16 +time_t aclk_session_sec = 0;
17 +
18 +int aclk_disable_runtime = 0;
19 +int aclk_disable_single_updates = 0;
20 +
21 +int aclk_stats_enabled;
22 +
23 +#ifdef ACLK_LEGACY
24 +int aclk_ng = 0;
25 +#else
26 +int aclk_ng = 1;
27 +#endif
28 +
29 +#define ACLK_IMPL_KEY_NAME "aclk implementation"
30 +
31 +#ifdef ENABLE_ACLK
32 +void *aclk_starter(void *ptr) {
33 + char *aclk_impl_req = config_get(CONFIG_SECTION_CLOUD, ACLK_IMPL_KEY_NAME, "legacy");
34 +
35 + if (!strcasecmp(aclk_impl_req, "ng")) {
36 + aclk_ng = 1;
37 + } else if (!strcasecmp(aclk_impl_req, "legacy")) {
38 + aclk_ng = 0;
39 + } else {
40 + error("Unknown value \"%s\" of key \"" ACLK_IMPL_KEY_NAME "\" in section \"" CONFIG_SECTION_CLOUD "\". Using ACLK %s.", aclk_impl_req, aclk_ng ? "NG" : "Legacy");
41 + }
42 +
43 +#ifndef ACLK_NG
44 + if (aclk_ng) {
45 + error("Configuration requests ACLK-NG but it is not available in this agent. Switching to Legacy.");
46 + aclk_ng = 0;
47 + }
48 +#endif
49 +
50 +#ifndef ACLK_LEGACY
51 + if (!aclk_ng) {
52 + error("Configuration requests ACLK Legacy but it is not available in this agent. Switching to NG.");
53 + aclk_ng = 1;
54 + }
55 +#endif
56 +
57 +#ifdef ACLK_NG
58 + if (aclk_ng)
59 + return aclk_main(ptr);
60 +#endif
61 +#ifdef ACLK_LEGACY
62 + if (!aclk_ng)
63 + return legacy_aclk_main(ptr);
64 +#endif
65 + error_report("No ACLK could be started");
66 + return NULL;
67 +}
68 +
69 +void aclk_single_update_disable()
70 +{
71 + aclk_disable_single_updates = 1;
72 +}
73 +
74 +void aclk_single_update_enable()
75 +{
76 + aclk_disable_single_updates = 0;
77 +}
78 +
79 +void aclk_alarm_reload(void)
80 +{
81 +#ifdef ACLK_NG
82 + if (aclk_ng)
83 + ng_aclk_alarm_reload();
84 +#endif
85 +#ifdef ACLK_LEGACY
86 + if (!aclk_ng)
87 + legacy_aclk_alarm_reload();
88 +#endif
89 +}
90 +
91 +int aclk_update_chart(RRDHOST *host, char *chart_name, int create)
92 +{
93 +#ifdef ACLK_NG
94 + if (aclk_ng)
95 + return ng_aclk_update_chart(host, chart_name, create);
96 +#endif
97 +#ifdef ACLK_LEGACY
98 + if (!aclk_ng)
99 + return legacy_aclk_update_chart(host, chart_name, create);
100 +#endif
101 + error_report("No usable aclk_update_chart implementation");
102 + return 1;
103 +}
104 +
105 +int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
106 +{
107 +#ifdef ACLK_NG
108 + if (aclk_ng)
109 + return ng_aclk_update_alarm(host, ae);
110 +#endif
111 +#ifdef ACLK_LEGACY
112 + if (!aclk_ng)
113 + return legacy_aclk_update_alarm(host, ae);
114 +#endif
115 + error_report("No usable aclk_update_alarm implementation");
116 + return 1;
117 +}
118 +
119 +void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
120 +{
121 +#ifdef ACLK_NG
122 + if (aclk_ng)
123 + return ng_aclk_add_collector(host, plugin_name, module_name);
124 +#endif
125 +#ifdef ACLK_LEGACY
126 + if (!aclk_ng)
127 + return legacy_aclk_add_collector(host, plugin_name, module_name);
128 +#endif
129 + error_report("No usable aclk_add_collector implementation");
130 +}
131 +
132 +void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
133 +{
134 +#ifdef ACLK_NG
135 + if (aclk_ng)
136 + return ng_aclk_del_collector(host, plugin_name, module_name);
137 +#endif
138 +#ifdef ACLK_LEGACY
139 + if (!aclk_ng)
140 + return legacy_aclk_del_collector(host, plugin_name, module_name);
141 +#endif
142 + error_report("No usable aclk_del_collector implementation");
143 +}
144 +
145 +#endif /* ENABLE_ACLK */
146 +
147 +struct label *add_aclk_host_labels(struct label *label) {
148 +#ifdef ACLK_NG
149 + label = add_label_to_list(label, "_aclk_ng_available", "true", LABEL_SOURCE_AUTO);
150 +#else
151 + label = add_label_to_list(label, "_aclk_ng_available", "false", LABEL_SOURCE_AUTO);
152 +#endif
153 +#ifdef ACLK_LEGACY
154 + label = add_label_to_list(label, "_aclk_legacy_available", "true", LABEL_SOURCE_AUTO);
155 +#else
156 + label = add_label_to_list(label, "_aclk_legacy_available", "false", LABEL_SOURCE_AUTO);
157 +#endif
158 +#ifdef ENABLE_ACLK
159 + ACLK_PROXY_TYPE aclk_proxy;
160 + char *proxy_str;
161 + aclk_get_proxy(&aclk_proxy);
162 +
163 + switch(aclk_proxy) {
164 + case PROXY_TYPE_SOCKS5:
165 + proxy_str = "SOCKS5";
166 + break;
167 + case PROXY_TYPE_HTTP:
168 + proxy_str = "HTTP";
169 + break;
170 + default:
171 + proxy_str = "none";
172 + break;
173 + }
174 +
175 + label = add_label_to_list(label, "_aclk_impl", aclk_ng ? "Next Generation" : "Legacy", LABEL_SOURCE_AUTO);
176 + label = add_label_to_list(label, "_aclk_proxy", proxy_str, LABEL_SOURCE_AUTO);
177 +#endif
178 + return label;
179 +}
aclk/aclk_api.h new
+51
@@ -0,0 +1,51 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +#ifndef ACLK_API_H
3 +#define ACLK_API_H
4 +
5 +#include "libnetdata/libnetdata.h"
6 +
7 +#include "aclk_proxy.h"
8 +
9 +// TODO get rid global vars as soon as
10 +// ACLK Legacy is removed
11 +extern int aclk_connected;
12 +extern int aclk_kill_link;
13 +
14 +extern usec_t aclk_session_us;
15 +extern time_t aclk_session_sec;
16 +
17 +extern int aclk_disable_runtime;
18 +extern int aclk_disable_single_updates;
19 +
20 +extern int aclk_stats_enabled;
21 +
22 +extern int aclk_ng;
23 +
24 +#ifdef ENABLE_ACLK
25 +void *aclk_starter(void *ptr);
26 +
27 +void aclk_single_update_disable();
28 +void aclk_single_update_enable();
29 +
30 +void aclk_alarm_reload(void);
31 +
32 +int aclk_update_chart(RRDHOST *host, char *chart_name, int create);
33 +int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
34 +
35 +void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
36 +void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
37 +
38 +#define NETDATA_ACLK_HOOK \
39 + { .name = "ACLK_Main", \
40 + .config_section = NULL, \
41 + .config_name = NULL, \
42 + .enabled = 1, \
43 + .thread = NULL, \
44 + .init_routine = NULL, \
45 + .start_routine = aclk_starter },
46 +
47 +#endif
48 +
49 +struct label *add_aclk_host_labels(struct label *label);
50 +
51 +#endif /* ACLK_API_H */
aclk/aclk_collector_list.h
+2
@@ -31,6 +31,8 @@ struct _collector {
31 struct _collector *next;
32 };
33
34 +extern struct _collector *collector_list;
35 +
36 struct _collector *_add_collector(const char *hostname, const char *plugin_name, const char *module_name);
37 struct _collector *_del_collector(const char *hostname, const char *plugin_name, const char *module_name);
38 void _reset_collector_list();
aclk/aclk_otp.c
+2
@@ -2,6 +2,8 @@
2 // SPDX-License-Identifier: GPL-3.0-or-later
3
4 #include "aclk_otp.h"
5 +#include "aclk_util.h"
6 +#include "aclk.h"
7
8 #include "daemon/common.h"
9
aclk/aclk_otp.h
+1
@@ -6,6 +6,7 @@
6 #include "daemon/common.h"
7
8 #include "https_client.h"
9 +#include "aclk_util.h"
10
11 int aclk_get_mqtt_otp(RSA *p_key, char **mqtt_id, char **mqtt_usr, char **mqtt_pass, url_t *target);
12 int aclk_get_env(aclk_env_t *env, const char *aclk_hostname, int aclk_port);
aclk/aclk_proxy.c new
+186
@@ -0,0 +1,186 @@
1 +#include "aclk_proxy.h"
2 +
3 +#include "daemon/common.h"
4 +
5 +#define ACLK_PROXY_ENV "env"
6 +#define ACLK_PROXY_CONFIG_VAR "proxy"
7 +
8 +struct {
9 + ACLK_PROXY_TYPE type;
10 + const char *url_str;
11 +} supported_proxy_types[] = {
12 + { .type = PROXY_TYPE_SOCKS5, .url_str = "socks5" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
13 + { .type = PROXY_TYPE_SOCKS5, .url_str = "socks5h" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
14 + { .type = PROXY_TYPE_HTTP, .url_str = "http" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
15 + { .type = PROXY_TYPE_UNKNOWN, .url_str = NULL },
16 +};
17 +
18 +const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type)
19 +{
20 + switch (*type) {
21 + case PROXY_DISABLED:
22 + return "disabled";
23 + case PROXY_TYPE_HTTP:
24 + return "HTTP";
25 + case PROXY_TYPE_SOCKS5:
26 + return "SOCKS";
27 + default:
28 + return "Unknown";
29 + }
30 +}
31 +
32 +static inline ACLK_PROXY_TYPE aclk_find_proxy(const char *string)
33 +{
34 + int i = 0;
35 + while (supported_proxy_types[i].url_str) {
36 + if (!strncmp(supported_proxy_types[i].url_str, string, strlen(supported_proxy_types[i].url_str)))
37 + return supported_proxy_types[i].type;
38 + i++;
39 + }
40 + return PROXY_TYPE_UNKNOWN;
41 +}
42 +
43 +ACLK_PROXY_TYPE aclk_verify_proxy(const char *string)
44 +{
45 + if (!string)
46 + return PROXY_TYPE_UNKNOWN;
47 +
48 + while (*string == 0x20)
49 + string++;
50 +
51 + if (!*string)
52 + return PROXY_TYPE_UNKNOWN;
53 +
54 + return aclk_find_proxy(string);
55 +}
56 +
57 +// helper function to censor user&password
58 +// for logging purposes
59 +void safe_log_proxy_censor(char *proxy)
60 +{
61 + size_t length = strlen(proxy);
62 + char *auth = proxy + length - 1;
63 + char *cur;
64 +
65 + while ((auth >= proxy) && (*auth != '@'))
66 + auth--;
67 +
68 + //if not found or @ is first char do nothing
69 + if (auth <= proxy)
70 + return;
71 +
72 + cur = strstr(proxy, ACLK_PROXY_PROTO_ADDR_SEPARATOR);
73 + if (!cur)
74 + cur = proxy;
75 + else
76 + cur += strlen(ACLK_PROXY_PROTO_ADDR_SEPARATOR);
77 +
78 + while (cur < auth) {
79 + *cur = 'X';
80 + cur++;
81 + }
82 +}
83 +
84 +static inline void safe_log_proxy_error(char *str, const char *proxy)
85 +{
86 + char *log = strdupz(proxy);
87 + safe_log_proxy_censor(log);
88 + error("%s Provided Value:\"%s\"", str, log);
89 + freez(log);
90 +}
91 +
92 +static inline int check_socks_enviroment(const char **proxy)
93 +{
94 + char *tmp = getenv("socks_proxy");
95 +
96 + if (!tmp)
97 + return 1;
98 +
99 + if (aclk_verify_proxy(tmp) == PROXY_TYPE_SOCKS5) {
100 + *proxy = tmp;
101 + return 0;
102 + }
103 +
104 + safe_log_proxy_error(
105 + "Environment var \"socks_proxy\" defined but of unknown format. Supported syntax: \"socks5[h]://[user:pass@]host:ip\".",
106 + tmp);
107 + return 1;
108 +}
109 +
110 +static inline int check_http_enviroment(const char **proxy)
111 +{
112 + char *tmp = getenv("http_proxy");
113 +
114 + if (!tmp)
115 + return 1;
116 +
117 + if (aclk_verify_proxy(tmp) == PROXY_TYPE_HTTP) {
118 + *proxy = tmp;
119 + return 0;
120 + }
121 +
122 + safe_log_proxy_error(
123 + "Environment var \"http_proxy\" defined but of unknown format. Supported syntax: \"http[s]://[user:pass@]host:ip\".",
124 + tmp);
125 + return 1;
126 +}
127 +
128 +const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type)
129 +{
130 + const char *proxy = config_get(CONFIG_SECTION_CLOUD, ACLK_PROXY_CONFIG_VAR, ACLK_PROXY_ENV);
131 + *type = PROXY_DISABLED;
132 +
133 + if (strcmp(proxy, "none") == 0)
134 + return proxy;
135 +
136 + if (strcmp(proxy, ACLK_PROXY_ENV) == 0) {
137 + if (check_socks_enviroment(&proxy) == 0) {
138 +#ifdef LWS_WITH_SOCKS5
139 + *type = PROXY_TYPE_SOCKS5;
140 + return proxy;
141 +#else
142 + safe_log_proxy_error("socks_proxy environment variable set to use SOCKS5 proxy "
143 + "but Libwebsockets used doesn't have SOCKS5 support built in. "
144 + "Ignoring and checking for other options.",
145 + proxy);
146 +#endif
147 + }
148 + if (check_http_enviroment(&proxy) == 0)
149 + *type = PROXY_TYPE_HTTP;
150 + return proxy;
151 + }
152 +
153 + *type = aclk_verify_proxy(proxy);
154 +#ifndef LWS_WITH_SOCKS5
155 + if (*type == PROXY_TYPE_SOCKS5) {
156 + safe_log_proxy_error(
157 + "Config var \"" ACLK_PROXY_CONFIG_VAR
158 + "\" set to use SOCKS5 proxy but Libwebsockets used is built without support for SOCKS proxy. ACLK will be disabled.",
159 + proxy);
160 + }
161 +#endif
162 + if (*type == PROXY_TYPE_UNKNOWN) {
163 + *type = PROXY_DISABLED;
164 + safe_log_proxy_error(
165 + "Config var \"" ACLK_PROXY_CONFIG_VAR
166 + "\" defined but of unknown format. Supported syntax: \"socks5[h]://[user:pass@]host:ip\".",
167 + proxy);
168 + }
169 +
170 + return proxy;
171 +}
172 +
173 +// helper function to read settings only once (static)
174 +// as claiming, challenge/response and ACLK
175 +// read the same thing, no need to parse again
176 +const char *aclk_get_proxy(ACLK_PROXY_TYPE *type)
177 +{
178 + static const char *proxy = NULL;
179 + static ACLK_PROXY_TYPE proxy_type = PROXY_NOT_SET;
180 +
181 + if (proxy_type == PROXY_NOT_SET)
182 + proxy = aclk_lws_wss_get_proxy_setting(&proxy_type);
183 +
184 + *type = proxy_type;
185 + return proxy;
186 +}
aclk/aclk_proxy.h new
+22
@@ -0,0 +1,22 @@
1 +#ifndef ACLK_PROXY_H
2 +#define ACLK_PROXY_H
3 +
4 +#include <config.h>
5 +
6 +#define ACLK_PROXY_PROTO_ADDR_SEPARATOR "://"
7 +
8 +typedef enum aclk_proxy_type {
9 + PROXY_TYPE_UNKNOWN = 0,
10 + PROXY_TYPE_SOCKS5,
11 + PROXY_TYPE_HTTP,
12 + PROXY_DISABLED,
13 + PROXY_NOT_SET,
14 +} ACLK_PROXY_TYPE;
15 +
16 +const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type);
17 +ACLK_PROXY_TYPE aclk_verify_proxy(const char *string);
18 +const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type);
19 +void safe_log_proxy_censor(char *proxy);
20 +const char *aclk_get_proxy(ACLK_PROXY_TYPE *type);
21 +
22 +#endif /* ACLK_PROXY_H */
aclk/aclk_rrdhost_state.h renamed
+6 -4
@@ -3,6 +3,7 @@
3
4 #include "libnetdata/libnetdata.h"
5
6 +#ifdef ACLK_LEGACY
7 typedef enum aclk_cmd {
8 ACLK_CMD_CLOUD,
9 ACLK_CMD_ONCONNECT,
@@ -20,23 +21,24 @@ typedef enum aclk_metadata_state {
21 ACLK_METADATA_CMD_QUEUED,
22 ACLK_METADATA_SENT
23 } ACLK_METADATA_STATE;
24 +#endif
25
26 typedef enum aclk_agent_state {
27 ACLK_HOST_INITIALIZING,
28 ACLK_HOST_STABLE
27 -} ACLK_POPCORNING_STATE;
29 +} ACLK_AGENT_STATE;
30
31 typedef struct aclk_rrdhost_state {
32 char *claimed_id; // Claimed ID if host has one otherwise NULL
33
32 -#ifdef ENABLE_ACLK
34 +#ifdef ACLK_LEGACY
35 // per child popcorning
34 - ACLK_POPCORNING_STATE state;
36 + ACLK_AGENT_STATE state;
37 ACLK_METADATA_STATE metadata;
38
39 time_t timestamp_created;
40 time_t t_last_popcorn_update;
39 -#endif /* ENABLE_ACLK */
41 +#endif /* ACLK_LEGACY */
42 } aclk_rrdhost_state;
43
44 #endif /* ACLK_RRDHOST_STATE_H */
aclk/aclk_rx_msgs.c
+5 -2
@@ -4,10 +4,13 @@
4
5 #include "aclk_stats.h"
6 #include "aclk_query_queue.h"
7 +#include "aclk.h"
8
9 #define ACLK_V2_PAYLOAD_SEPARATOR "\x0D\x0A\x0D\x0A"
10 #define ACLK_CLOUD_REQ_V2_PREFIX "GET /api/v1/"
11
12 +#define ACLK_V_COMPRESSION 2
13 +
14 struct aclk_request {
15 char *type_id;
16 char *msg_id;
@@ -18,7 +21,7 @@ struct aclk_request {
21 int max_version;
22 };
23
21 -int cloud_to_agent_parse(JSON_ENTRY *e)
24 +static int cloud_to_agent_parse(JSON_ENTRY *e)
25 {
26 struct aclk_request *data = e->callback_data;
27
@@ -108,7 +111,7 @@ static inline int aclk_v2_payload_get_query(const char *payload, char **query_ur
111 }
112
113 #define HTTP_CHECK_AGENT_INITIALIZED() ACLK_SHARED_STATE_LOCK;\
111 - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) {\
114 + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) {\
115 debug(D_ACLK, "Ignoring \"http\" cloud request; agent not in stable state");\
116 ACLK_SHARED_STATE_UNLOCK;\
117 return 1;\
aclk/aclk_stats.c
-2
@@ -4,8 +4,6 @@
4
5 netdata_mutex_t aclk_stats_mutex = NETDATA_MUTEX_INITIALIZER;
6
7 -int aclk_stats_enabled;
8 -
7 int query_thread_count;
8
9 // data ACLK stats need per query thread
aclk/aclk_stats.h
-2
@@ -13,8 +13,6 @@ extern netdata_mutex_t aclk_stats_mutex;
13 #define ACLK_STATS_LOCK netdata_mutex_lock(&aclk_stats_mutex)
14 #define ACLK_STATS_UNLOCK netdata_mutex_unlock(&aclk_stats_mutex)
15
16 -extern int aclk_stats_enabled;
17 -
16 struct aclk_stats_thread {
17 netdata_thread_t *thread;
18 int query_thread_count;
aclk/aclk_tx_msgs.c
+4
@@ -4,11 +4,15 @@
4 #include "daemon/common.h"
5 #include "aclk_util.h"
6 #include "aclk_stats.h"
7 +#include "aclk.h"
8
9 #ifndef __GNUC__
10 #pragma region aclk_tx_msgs helper functions
11 #endif
12
13 +// version for aclk legacy (old cloud arch)
14 +#define ACLK_VERSION 2
15 +
16 static void aclk_send_message_subtopic(mqtt_wss_client client, json_object *msg, enum aclk_topics subtopic)
17 {
18 uint16_t packet_id;
aclk/aclk_util.c
-185
@@ -2,8 +2,6 @@
2
3 #include "aclk_util.h"
4
5 -#include <stdio.h>
6 -
5 #include "daemon/common.h"
6
7 // CentOS 7 has older version that doesn't define this
@@ -315,189 +313,6 @@ unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int min, un
313 return delay;
314 }
315
318 -#define ACLK_PROXY_PROTO_ADDR_SEPARATOR "://"
319 -#define ACLK_PROXY_ENV "env"
320 -#define ACLK_PROXY_CONFIG_VAR "proxy"
321 -
322 -struct {
323 - ACLK_PROXY_TYPE type;
324 - const char *url_str;
325 -} supported_proxy_types[] = {
326 - { .type = PROXY_TYPE_SOCKS5, .url_str = "socks5" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
327 - { .type = PROXY_TYPE_SOCKS5, .url_str = "socks5h" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
328 - { .type = PROXY_TYPE_HTTP, .url_str = "http" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
329 - { .type = PROXY_TYPE_UNKNOWN, .url_str = NULL },
330 -};
331 -
332 -const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type)
333 -{
334 - switch (*type) {
335 - case PROXY_DISABLED:
336 - return "disabled";
337 - case PROXY_TYPE_HTTP:
338 - return "HTTP";
339 - case PROXY_TYPE_SOCKS5:
340 - return "SOCKS";
341 - default:
342 - return "Unknown";
343 - }
344 -}
345 -
346 -static inline ACLK_PROXY_TYPE aclk_find_proxy(const char *string)
347 -{
348 - int i = 0;
349 - while (supported_proxy_types[i].url_str) {
350 - if (!strncmp(supported_proxy_types[i].url_str, string, strlen(supported_proxy_types[i].url_str)))
351 - return supported_proxy_types[i].type;
352 - i++;
353 - }
354 - return PROXY_TYPE_UNKNOWN;
355 -}
356 -
357 -ACLK_PROXY_TYPE aclk_verify_proxy(const char *string)
358 -{
359 - if (!string)
360 - return PROXY_TYPE_UNKNOWN;
361 -
362 - while (*string == 0x20 && *string!=0) // Help coverity (compiler will remove)
363 - string++;
364 -
365 - if (!*string)
366 - return PROXY_TYPE_UNKNOWN;
367 -
368 - return aclk_find_proxy(string);
369 -}
370 -
371 -// helper function to censor user&password
372 -// for logging purposes
373 -void safe_log_proxy_censor(char *proxy)
374 -{
375 - size_t length = strlen(proxy);
376 - char *auth = proxy + length - 1;
377 - char *cur;
378 -
379 - while ((auth >= proxy) && (*auth != '@'))
380 - auth--;
381 -
382 - //if not found or @ is first char do nothing
383 - if (auth <= proxy)
384 - return;
385 -
386 - cur = strstr(proxy, ACLK_PROXY_PROTO_ADDR_SEPARATOR);
387 - if (!cur)
388 - cur = proxy;
389 - else
390 - cur += strlen(ACLK_PROXY_PROTO_ADDR_SEPARATOR);
391 -
392 - while (cur < auth) {
393 - *cur = 'X';
394 - cur++;
395 - }
396 -}
397 -
398 -static inline void safe_log_proxy_error(char *str, const char *proxy)
399 -{
400 - char *log = strdupz(proxy);
401 - safe_log_proxy_censor(log);
402 - error("%s Provided Value:\"%s\"", str, log);
403 - freez(log);
404 -}
405 -
406 -static inline int check_socks_enviroment(const char **proxy)
407 -{
408 - char *tmp = getenv("socks_proxy");
409 -
410 - if (!tmp)
411 - return 1;
412 -
413 - if (aclk_verify_proxy(tmp) == PROXY_TYPE_SOCKS5) {
414 - *proxy = tmp;
415 - return 0;
416 - }
417 -
418 - safe_log_proxy_error(
419 - "Environment var \"socks_proxy\" defined but of unknown format. Supported syntax: \"socks5[h]://[user:pass@]host:ip\".",
420 - tmp);
421 - return 1;
422 -}
423 -
424 -static inline int check_http_enviroment(const char **proxy)
425 -{
426 - char *tmp = getenv("http_proxy");
427 -
428 - if (!tmp)
429 - return 1;
430 -
431 - if (aclk_verify_proxy(tmp) == PROXY_TYPE_HTTP) {
432 - *proxy = tmp;
433 - return 0;
434 - }
435 -
436 - safe_log_proxy_error(
437 - "Environment var \"http_proxy\" defined but of unknown format. Supported syntax: \"http[s]://[user:pass@]host:ip\".",
438 - tmp);
439 - return 1;
440 -}
441 -
442 -const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type)
443 -{
444 - const char *proxy = config_get(CONFIG_SECTION_CLOUD, ACLK_PROXY_CONFIG_VAR, ACLK_PROXY_ENV);
445 - *type = PROXY_DISABLED;
446 -
447 - if (strcmp(proxy, "none") == 0)
448 - return proxy;
449 -
450 - if (strcmp(proxy, ACLK_PROXY_ENV) == 0) {
451 - if (check_socks_enviroment(&proxy) == 0) {
452 -#ifdef LWS_WITH_SOCKS5
453 - *type = PROXY_TYPE_SOCKS5;
454 - return proxy;
455 -#else
456 - safe_log_proxy_error("socks_proxy environment variable set to use SOCKS5 proxy "
457 - "but Libwebsockets used doesn't have SOCKS5 support built in. "
458 - "Ignoring and checking for other options.",
459 - proxy);
460 -#endif
461 - }
462 - if (check_http_enviroment(&proxy) == 0)
463 - *type = PROXY_TYPE_HTTP;
464 - return proxy;
465 - }
466 -
467 - *type = aclk_verify_proxy(proxy);
468 -#ifndef LWS_WITH_SOCKS5
469 - if (*type == PROXY_TYPE_SOCKS5) {
470 - safe_log_proxy_error(
471 - "Config var \"" ACLK_PROXY_CONFIG_VAR
472 - "\" set to use SOCKS5 proxy but Libwebsockets used is built without support for SOCKS proxy. ACLK will be disabled.",
473 - proxy);
474 - }
475 -#endif
476 - if (*type == PROXY_TYPE_UNKNOWN) {
477 - *type = PROXY_DISABLED;
478 - safe_log_proxy_error(
479 - "Config var \"" ACLK_PROXY_CONFIG_VAR
480 - "\" defined but of unknown format. Supported syntax: \"socks5[h]://[user:pass@]host:ip\".",
481 - proxy);
482 - }
483 -
484 - return proxy;
485 -}
486 -
487 -// helper function to read settings only once (static)
488 -// as claiming, challenge/response and ACLK
489 -// read the same thing, no need to parse again
490 -const char *aclk_get_proxy(ACLK_PROXY_TYPE *type)
491 -{
492 - static const char *proxy = NULL;
493 - static ACLK_PROXY_TYPE proxy_type = PROXY_NOT_SET;
494 -
495 - if (proxy_type == PROXY_NOT_SET)
496 - proxy = aclk_lws_wss_get_proxy_setting(&proxy_type);
497 -
498 - *type = proxy_type;
499 - return proxy;
500 -}
316
317 #define HTTP_PROXY_PREFIX "http://"
318 void aclk_set_proxy(char **ohost, int *port, enum mqtt_wss_proxy_type *type)
aclk/aclk_util.h
-14
@@ -78,20 +78,6 @@ int aclk_get_conv_log_next();
78 unsigned long int aclk_tbeb_delay(int reset, int base, unsigned long int min, unsigned long int max);
79 #define aclk_tbeb_reset(x) aclk_tbeb_delay(1, 0, 0, 0)
80
81 -typedef enum aclk_proxy_type {
82 - PROXY_TYPE_UNKNOWN = 0,
83 - PROXY_TYPE_SOCKS5,
84 - PROXY_TYPE_HTTP,
85 - PROXY_DISABLED,
86 - PROXY_NOT_SET,
87 -} ACLK_PROXY_TYPE;
88 -
89 -const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type);
90 -ACLK_PROXY_TYPE aclk_verify_proxy(const char *string);
91 -const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type);
92 -void safe_log_proxy_censor(char *proxy);
93 -const char *aclk_get_proxy(ACLK_PROXY_TYPE *type);
94 -
81 void aclk_set_proxy(char **ohost, int *port, enum mqtt_wss_proxy_type *type);
82
83 #endif /* ACLK_UTIL_H */
aclk/legacy/aclk_common.c
+2 -209
@@ -6,196 +6,13 @@
6 #include <libwebsockets.h>
7 #endif
8
9 -netdata_mutex_t aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER;
9 +netdata_mutex_t legacy_aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER;
10
11 -int aclk_disable_runtime = 0;
12 -int aclk_kill_link = 0;
13 -
14 -struct aclk_shared_state aclk_shared_state = {
11 +struct legacy_aclk_shared_state legacy_aclk_shared_state = {
12 .version_neg = 0,
13 .version_neg_wait_till = 0
14 };
15
19 -struct {
20 - ACLK_PROXY_TYPE type;
21 - const char *url_str;
22 -} supported_proxy_types[] = {
23 - { .type = PROXY_TYPE_SOCKS5, .url_str = "socks5" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
24 - { .type = PROXY_TYPE_SOCKS5, .url_str = "socks5h" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
25 - { .type = PROXY_TYPE_HTTP, .url_str = "http" ACLK_PROXY_PROTO_ADDR_SEPARATOR },
26 - { .type = PROXY_TYPE_UNKNOWN, .url_str = NULL },
27 -};
28 -
29 -const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type)
30 -{
31 - switch (*type) {
32 - case PROXY_DISABLED:
33 - return "disabled";
34 - case PROXY_TYPE_HTTP:
35 - return "HTTP";
36 - case PROXY_TYPE_SOCKS5:
37 - return "SOCKS";
38 - default:
39 - return "Unknown";
40 - }
41 -}
42 -
43 -static inline ACLK_PROXY_TYPE aclk_find_proxy(const char *string)
44 -{
45 - int i = 0;
46 - while (supported_proxy_types[i].url_str) {
47 - if (!strncmp(supported_proxy_types[i].url_str, string, strlen(supported_proxy_types[i].url_str)))
48 - return supported_proxy_types[i].type;
49 - i++;
50 - }
51 - return PROXY_TYPE_UNKNOWN;
52 -}
53 -
54 -ACLK_PROXY_TYPE aclk_verify_proxy(const char *string)
55 -{
56 - if (!string)
57 - return PROXY_TYPE_UNKNOWN;
58 -
59 - while (*string == 0x20 && *string!=0) // Help coverity (compiler will remove)
60 - string++;
61 -
62 - if (!*string)
63 - return PROXY_TYPE_UNKNOWN;
64 -
65 - return aclk_find_proxy(string);
66 -}
67 -
68 -// helper function to censor user&password
69 -// for logging purposes
70 -void safe_log_proxy_censor(char *proxy)
71 -{
72 - size_t length = strlen(proxy);
73 - char *auth = proxy + length - 1;
74 - char *cur;
75 -
76 - while ((auth >= proxy) && (*auth != '@'))
77 - auth--;
78 -
79 - //if not found or @ is first char do nothing
80 - if (auth <= proxy)
81 - return;
82 -
83 - cur = strstr(proxy, ACLK_PROXY_PROTO_ADDR_SEPARATOR);
84 - if (!cur)
85 - cur = proxy;
86 - else
87 - cur += strlen(ACLK_PROXY_PROTO_ADDR_SEPARATOR);
88 -
89 - while (cur < auth) {
90 - *cur = 'X';
91 - cur++;
92 - }
93 -}
94 -
95 -static inline void safe_log_proxy_error(char *str, const char *proxy)
96 -{
97 - char *log = strdupz(proxy);
98 - safe_log_proxy_censor(log);
99 - error("%s Provided Value:\"%s\"", str, log);
100 - freez(log);
101 -}
102 -
103 -static inline int check_socks_environment(const char **proxy)
104 -{
105 - char *tmp = getenv("socks_proxy");
106 -
107 - if (!tmp)
108 - return 1;
109 -
110 - if (aclk_verify_proxy(tmp) == PROXY_TYPE_SOCKS5) {
111 - *proxy = tmp;
112 - return 0;
113 - }
114 -
115 - safe_log_proxy_error(
116 - "Environment var \"socks_proxy\" defined but of unknown format. Supported syntax: \"socks5[h]://[user:pass@]host:ip\".",
117 - tmp);
118 - return 1;
119 -}
120 -
121 -static inline int check_http_environment(const char **proxy)
122 -{
123 - char *tmp = getenv("http_proxy");
124 -
125 - if (!tmp)
126 - return 1;
127 -
128 - if (aclk_verify_proxy(tmp) == PROXY_TYPE_HTTP) {
129 - *proxy = tmp;
130 - return 0;
131 - }
132 -
133 - safe_log_proxy_error(
134 - "Environment var \"http_proxy\" defined but of unknown format. Supported syntax: \"http[s]://[user:pass@]host:ip\".",
135 - tmp);
136 - return 1;
137 -}
138 -
139 -const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type)
140 -{
141 - const char *proxy = config_get(CONFIG_SECTION_CLOUD, ACLK_PROXY_CONFIG_VAR, ACLK_PROXY_ENV);
142 - *type = PROXY_DISABLED;
143 -
144 - if (strcmp(proxy, "none") == 0)
145 - return proxy;
146 -
147 - if (strcmp(proxy, ACLK_PROXY_ENV) == 0) {
148 - if (check_socks_environment(&proxy) == 0) {
149 -#ifdef LWS_WITH_SOCKS5
150 - *type = PROXY_TYPE_SOCKS5;
151 - return proxy;
152 -#else
153 - safe_log_proxy_error("socks_proxy environment variable set to use SOCKS5 proxy "
154 - "but Libwebsockets used doesn't have SOCKS5 support built in. "
155 - "Ignoring and checking for other options.",
156 - proxy);
157 -#endif
158 - }
159 - if (check_http_environment(&proxy) == 0)
160 - *type = PROXY_TYPE_HTTP;
161 - return proxy;
162 - }
163 -
164 - *type = aclk_verify_proxy(proxy);
165 -#ifndef LWS_WITH_SOCKS5
166 - if (*type == PROXY_TYPE_SOCKS5) {
167 - safe_log_proxy_error(
168 - "Config var \"" ACLK_PROXY_CONFIG_VAR
169 - "\" set to use SOCKS5 proxy but Libwebsockets used is built without support for SOCKS proxy. ACLK will be disabled.",
170 - proxy);
171 - }
172 -#endif
173 - if (*type == PROXY_TYPE_UNKNOWN) {
174 - *type = PROXY_DISABLED;
175 - safe_log_proxy_error(
176 - "Config var \"" ACLK_PROXY_CONFIG_VAR
177 - "\" defined but of unknown format. Supported syntax: \"socks5[h]://[user:pass@]host:ip\".",
178 - proxy);
179 - }
180 -
181 - return proxy;
182 -}
183 -
184 -// helper function to read settings only once (static)
185 -// as claiming, challenge/response and ACLK
186 -// read the same thing, no need to parse again
187 -const char *aclk_get_proxy(ACLK_PROXY_TYPE *type)
188 -{
189 - static const char *proxy = NULL;
190 - static ACLK_PROXY_TYPE proxy_type = PROXY_NOT_SET;
191 -
192 - if (proxy_type == PROXY_NOT_SET)
193 - proxy = aclk_lws_wss_get_proxy_setting(&proxy_type);
194 -
195 - *type = proxy_type;
196 - return proxy;
197 -}
198 -
16 int aclk_decode_base_url(char *url, char **aclk_hostname, int *aclk_port)
17 {
18 int pos = 0;
@@ -234,27 +51,3 @@ int aclk_decode_base_url(char *url, char **aclk_hostname, int *aclk_port)
51 info("Setting ACLK target host=%s port=%d from %s", *aclk_hostname, *aclk_port, url);
52 return 0;
53 }
237 -
238 -struct label *add_aclk_host_labels(struct label *label) {
239 -#ifdef ENABLE_ACLK
240 - ACLK_PROXY_TYPE aclk_proxy;
241 - char *proxy_str;
242 - aclk_get_proxy(&aclk_proxy);
243 -
244 - switch(aclk_proxy) {
245 - case PROXY_TYPE_SOCKS5:
246 - proxy_str = "SOCKS5";
247 - break;
248 - case PROXY_TYPE_HTTP:
249 - proxy_str = "HTTP";
250 - break;
251 - default:
252 - proxy_str = "none";
253 - break;
254 - }
255 - label = add_label_to_list(label, "_aclk_impl", "Legacy", LABEL_SOURCE_AUTO);
256 - return add_label_to_list(label, "_aclk_proxy", proxy_str, LABEL_SOURCE_AUTO);
257 -#else
258 - return label;
259 -#endif
260 -}
aclk/legacy/aclk_common.h
+6 -27
@@ -1,12 +1,12 @@
1 #ifndef ACLK_COMMON_H
2 #define ACLK_COMMON_H
3
4 -#include "aclk_rrdhost_state.h"
4 +#include "../aclk_rrdhost_state.h"
5 #include "daemon/common.h"
6
7 -extern netdata_mutex_t aclk_shared_state_mutex;
8 -#define ACLK_SHARED_STATE_LOCK netdata_mutex_lock(&aclk_shared_state_mutex)
9 -#define ACLK_SHARED_STATE_UNLOCK netdata_mutex_unlock(&aclk_shared_state_mutex)
7 +extern netdata_mutex_t legacy_aclk_shared_state_mutex;
8 +#define legacy_aclk_shared_state_LOCK netdata_mutex_lock(&legacy_aclk_shared_state_mutex)
9 +#define legacy_aclk_shared_state_UNLOCK netdata_mutex_unlock(&legacy_aclk_shared_state_mutex)
10
11 // minimum and maximum supported version of ACLK
12 // in this version of agent
@@ -33,7 +33,7 @@ extern netdata_mutex_t aclk_shared_state_mutex;
33 #define ACLK_IS_HOST_INITIALIZING(host) (host->aclk_state.state == ACLK_HOST_INITIALIZING)
34 #define ACLK_IS_HOST_POPCORNING(host) (ACLK_IS_HOST_INITIALIZING(host) && host->aclk_state.t_last_popcorn_update)
35
36 -extern struct aclk_shared_state {
36 +extern struct legacy_aclk_shared_state {
37 // optimization to avoid looping trough hosts
38 // every time Query Thread wakes up
39 RRDHOST *next_popcorn_host;
@@ -42,31 +42,10 @@ extern struct aclk_shared_state {
42 // protect by lock otherwise
43 int version_neg;
44 usec_t version_neg_wait_till;
45 -} aclk_shared_state;
46 -
47 -typedef enum aclk_proxy_type {
48 - PROXY_TYPE_UNKNOWN = 0,
49 - PROXY_TYPE_SOCKS5,
50 - PROXY_TYPE_HTTP,
51 - PROXY_DISABLED,
52 - PROXY_NOT_SET,
53 -} ACLK_PROXY_TYPE;
54 -
55 -extern int aclk_kill_link; // Tells the agent to tear down the link
56 -extern int aclk_disable_runtime;
45 +} legacy_aclk_shared_state;
46
47 const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type);
48
60 -#define ACLK_PROXY_PROTO_ADDR_SEPARATOR "://"
61 -#define ACLK_PROXY_ENV "env"
62 -#define ACLK_PROXY_CONFIG_VAR "proxy"
63 -
64 -ACLK_PROXY_TYPE aclk_verify_proxy(const char *string);
65 -const char *aclk_lws_wss_get_proxy_setting(ACLK_PROXY_TYPE *type);
66 -void safe_log_proxy_censor(char *proxy);
49 int aclk_decode_base_url(char *url, char **aclk_hostname, int *aclk_port);
68 -const char *aclk_get_proxy(ACLK_PROXY_TYPE *type);
69 -
70 -struct label *add_aclk_host_labels(struct label *label);
50
51 #endif //ACLK_COMMON_H
aclk/legacy/aclk_lws_https_client.c
-6
@@ -2,13 +2,7 @@
2
3 #define ACLK_LWS_HTTPS_CLIENT_INTERNAL
4 #include "aclk_lws_https_client.h"
5 -
6 -#ifndef ACLK_NG
5 #include "aclk_common.h"
8 -#else
9 -#include "../aclk.h"
10 -#endif
11 -
6 #include "aclk_lws_wss_client.h"
7
8 #define SMALL_BUFFER 16
aclk/legacy/aclk_lws_wss_client.c
+13 -12
@@ -6,6 +6,7 @@
6 #include "daemon/common.h"
7 #include "aclk_common.h"
8 #include "aclk_stats.h"
9 +#include "../aclk_proxy.h"
10
11 extern int aclk_shutting_down;
12
@@ -450,9 +451,9 @@ static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reas
451 if (n>=0) {
452 data->written += n;
453 if (aclk_stats_enabled) {
453 - ACLK_STATS_LOCK;
454 - aclk_metrics_per_sample.write_q_consumed += n;
455 - ACLK_STATS_UNLOCK;
454 + LEGACY_ACLK_STATS_LOCK;
455 + legacy_aclk_metrics_per_sample.write_q_consumed += n;
456 + LEGACY_ACLK_STATS_UNLOCK;
457 }
458 }
459 //error("lws_write(req=%u,written=%u) %zu of %zu",bytes_left, rc, data->written,data->data_size,rc);
@@ -473,9 +474,9 @@ static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reas
474 retval = 1;
475 aclk_lws_mutex_unlock(&engine_instance->read_buf_mutex);
476 if (aclk_stats_enabled) {
476 - ACLK_STATS_LOCK;
477 - aclk_metrics_per_sample.read_q_added += len;
478 - ACLK_STATS_UNLOCK;
477 + LEGACY_ACLK_STATS_LOCK;
478 + legacy_aclk_metrics_per_sample.read_q_added += len;
479 + LEGACY_ACLK_STATS_UNLOCK;
480 }
481
482 // to future myself -> do not call this while read lock is active as it will eventually
@@ -553,9 +554,9 @@ int aclk_lws_wss_client_write(void *buf, size_t count)
554 aclk_lws_mutex_unlock(&engine_instance->write_buf_mutex);
555
556 if (aclk_stats_enabled) {
556 - ACLK_STATS_LOCK;
557 - aclk_metrics_per_sample.write_q_added += count;
558 - ACLK_STATS_UNLOCK;
557 + LEGACY_ACLK_STATS_LOCK;
558 + legacy_aclk_metrics_per_sample.write_q_added += count;
559 + LEGACY_ACLK_STATS_UNLOCK;
560 }
561
562 lws_callback_on_writable(engine_instance->lws_wsi);
@@ -584,9 +585,9 @@ int aclk_lws_wss_client_read(void *buf, size_t count)
585 engine_instance->data_to_read = 0;
586
587 if (aclk_stats_enabled) {
587 - ACLK_STATS_LOCK;
588 - aclk_metrics_per_sample.read_q_consumed += data_to_be_read;
589 - ACLK_STATS_UNLOCK;
588 + LEGACY_ACLK_STATS_LOCK;
589 + legacy_aclk_metrics_per_sample.read_q_consumed += data_to_be_read;
590 + LEGACY_ACLK_STATS_UNLOCK;
591 }
592
593 abort:
aclk/legacy/aclk_query.c
+46 -45
@@ -2,15 +2,16 @@
2 #include "aclk_query.h"
3 #include "aclk_stats.h"
4 #include "aclk_rx_msgs.h"
5 +#include "agent_cloud_link.h"
6
7 #define WEB_HDR_ACCEPT_ENC "Accept-Encoding:"
8
8 -pthread_cond_t query_cond_wait = PTHREAD_COND_INITIALIZER;
9 -pthread_mutex_t query_lock_wait = PTHREAD_MUTEX_INITIALIZER;
10 -#define QUERY_THREAD_LOCK pthread_mutex_lock(&query_lock_wait)
11 -#define QUERY_THREAD_UNLOCK pthread_mutex_unlock(&query_lock_wait)
9 +#define ACLK_QUERY_THREAD_NAME "ACLK_Query"
10
13 -volatile int aclk_connected = 0;
11 +pthread_cond_t legacy_query_cond_wait = PTHREAD_COND_INITIALIZER;
12 +pthread_mutex_t legacy_query_lock_wait = PTHREAD_MUTEX_INITIALIZER;
13 +#define LEGACY_QUERY_THREAD_LOCK pthread_mutex_lock(&legacy_query_lock_wait)
14 +#define LEGACY_QUERY_THREAD_UNLOCK pthread_mutex_unlock(&legacy_query_lock_wait)
15
16 #ifndef __GNUC__
17 #pragma region ACLK_QUEUE
@@ -188,7 +189,7 @@ aclk_query_find(char *topic, void *data, char *msg_id, char *query, ACLK_CMD cmd
189 * Add a query to execute, the result will be send to the specified topic
190 */
191
191 -int aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run_after, int internal, ACLK_CMD aclk_cmd)
192 +int legacy_aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run_after, int internal, ACLK_CMD aclk_cmd)
193 {
194 struct aclk_query *new_query, *tmp_query;
195
@@ -205,7 +206,7 @@ int aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run
206 if (unlikely(tmp_query)) {
207 if (tmp_query->run_after == run_after) {
208 ACLK_QUEUE_UNLOCK;
208 - QUERY_THREAD_WAKEUP;
209 + LEGACY_QUERY_THREAD_WAKEUP;
210 return 0;
211 }
212
@@ -220,9 +221,9 @@ int aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run
221 }
222
223 if (aclk_stats_enabled) {
223 - ACLK_STATS_LOCK;
224 - aclk_metrics_per_sample.queries_queued++;
225 - ACLK_STATS_UNLOCK;
224 + LEGACY_ACLK_STATS_LOCK;
225 + legacy_aclk_metrics_per_sample.queries_queued++;
226 + LEGACY_ACLK_STATS_UNLOCK;
227 }
228
229 new_query = callocz(1, sizeof(struct aclk_query));
@@ -255,7 +256,7 @@ int aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run
256 aclk_queue.aclk_query_tail = new_query;
257 aclk_queue.count++;
258 ACLK_QUEUE_UNLOCK;
258 - QUERY_THREAD_WAKEUP;
259 + LEGACY_QUERY_THREAD_WAKEUP;
260 return 0;
261 }
262
@@ -264,7 +265,7 @@ int aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run
265 aclk_queue.count++;
266
267 ACLK_QUEUE_UNLOCK;
267 - QUERY_THREAD_WAKEUP;
268 + LEGACY_QUERY_THREAD_WAKEUP;
269 return 0;
270 }
271
@@ -332,12 +333,12 @@ static char *aclk_encode_response(char *src, size_t content_size, int keep_newli
333 static usec_t aclk_web_api_request_v1(RRDHOST *host, struct web_client *w, char *url, usec_t q_created)
334 {
335 usec_t t = now_boottime_usec();
335 - aclk_metric_mat_update(&aclk_metrics_per_sample.cloud_q_recvd_to_processed, t - q_created);
336 + legacy_aclk_metric_mat_update(&legacy_aclk_metrics_per_sample.cloud_q_recvd_to_processed, t - q_created);
337
338 w->response.code = web_client_api_request_v1(host, w, url);
339 t = now_boottime_usec() - t;
340
340 - aclk_metric_mat_update(&aclk_metrics_per_sample.cloud_q_db_query_time, t);
341 + legacy_aclk_metric_mat_update(&legacy_aclk_metrics_per_sample.cloud_q_db_query_time, t);
342
343 return t;
344 }
@@ -375,7 +376,7 @@ static int aclk_execute_query(struct aclk_query *this_query)
376 buffer_flush(local_buffer);
377 local_buffer->contenttype = CT_APPLICATION_JSON;
378
378 - aclk_create_header(local_buffer, "http", this_query->msg_id, 0, 0, aclk_shared_state.version_neg);
379 + aclk_create_header(local_buffer, "http", this_query->msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
380 buffer_strcat(local_buffer, ",\n\t\"payload\": ");
381 char *encoded_response = aclk_encode_response(w->response.data->buffer, w->response.data->len, 0);
382 char *encoded_header = aclk_encode_response(w->response.header_output->buffer, w->response.header_output->len, 1);
@@ -510,7 +511,7 @@ static int aclk_execute_query_v2(struct aclk_query *this_query)
511 local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
512 local_buffer->contenttype = CT_APPLICATION_JSON;
513
513 - aclk_create_header(local_buffer, "http", this_query->msg_id, 0, 0, aclk_shared_state.version_neg);
514 + aclk_create_header(local_buffer, "http", this_query->msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
515 buffer_sprintf(local_buffer, ",\"t-exec\": %llu,\"t-rx\": %llu,\"http-code\": %d", t, this_query->created, w->response.code);
516 buffer_strcat(local_buffer, "}\x0D\x0A\x0D\x0A");
517 buffer_strcat(local_buffer, w->response.header_output->buffer);
@@ -607,7 +608,7 @@ static int aclk_process_query(struct aclk_query_thread *t_info)
608 case ACLK_CMD_ONCONNECT:
609 ACLK_HOST_PTR_COMPULSORY("ACLK_CMD_ONCONNECT");
610 #if ACLK_VERSION_MIN < ACLK_V_CHILDRENSTATE
610 - if (host != localhost && aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE) {
611 + if (host != localhost && legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE) {
612 error("We are not allowed to send connect message in ACLK version before %d", ACLK_V_CHILDRENSTATE);
613 break;
614 }
@@ -638,7 +639,7 @@ static int aclk_process_query(struct aclk_query_thread *t_info)
639
640 debug(D_ACLK, "EXECUTING a chart delete command");
641 //TODO: This send the info metadata for now
641 - aclk_send_info_metadata(ACLK_METADATA_SENT, host);
642 + legacy_aclk_send_info_metadata(ACLK_METADATA_SENT, host);
643 break;
644
645 case ACLK_CMD_ALARM:
@@ -673,10 +674,10 @@ static int aclk_process_query(struct aclk_query_thread *t_info)
674 debug(D_ACLK, "Query #%ld (%s) done", query_count, this_query->topic);
675
676 if (aclk_stats_enabled) {
676 - ACLK_STATS_LOCK;
677 - aclk_metrics_per_sample.queries_dispatched++;
678 - aclk_queries_per_thread[t_info->idx]++;
679 - ACLK_STATS_UNLOCK;
677 + LEGACY_ACLK_STATS_LOCK;
678 + legacy_aclk_metrics_per_sample.queries_dispatched++;
679 + legacy_aclk_queries_per_thread[t_info->idx]++;
680 + LEGACY_ACLK_STATS_UNLOCK;
681
682 if (likely(getrusage_called_this_tick[t_info->idx] < MAX_GETRUSAGE_CALLS_PER_TICK)) {
683 getrusage(RUSAGE_THREAD, &rusage_per_thread[t_info->idx]);
@@ -690,7 +691,7 @@ static int aclk_process_query(struct aclk_query_thread *t_info)
691 return 1;
692 }
693
693 -void aclk_query_threads_cleanup(struct aclk_query_threads *query_threads)
694 +void legacy_aclk_query_threads_cleanup(struct aclk_query_threads *query_threads)
695 {
696 if (query_threads && query_threads->thread_list) {
697 for (int i = 0; i < query_threads->count; i++) {
@@ -708,7 +709,7 @@ void aclk_query_threads_cleanup(struct aclk_query_threads *query_threads)
709 }
710
711 #define TASK_LEN_MAX 16
711 -void aclk_query_threads_start(struct aclk_query_threads *query_threads)
712 +void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads)
713 {
714 info("Starting %d query threads.", query_threads->count);
715
@@ -717,10 +718,10 @@ void aclk_query_threads_start(struct aclk_query_threads *query_threads)
718 for (int i = 0; i < query_threads->count; i++) {
719 query_threads->thread_list[i].idx = i; //thread needs to know its index for statistics
720
720 - if(unlikely(snprintf(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_THREAD_NAME, i) < 0))
721 + if(unlikely(snprintf(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
722 error("snprintf encoding error");
723 netdata_thread_create(
723 - &query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, aclk_query_main_thread,
724 + &query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, legacy_aclk_query_main_thread,
725 &query_threads->thread_list[i]);
726 }
727 }
@@ -730,10 +731,10 @@ void aclk_query_threads_start(struct aclk_query_threads *query_threads)
731 * returns actual/updated popcorning state
732 */
733
733 -ACLK_POPCORNING_STATE aclk_host_popcorn_check(RRDHOST *host)
734 +ACLK_AGENT_STATE aclk_host_popcorn_check(RRDHOST *host)
735 {
736 rrdhost_aclk_state_lock(host);
736 - ACLK_POPCORNING_STATE ret = host->aclk_state.state;
737 + ACLK_AGENT_STATE ret = host->aclk_state.state;
738 if (host->aclk_state.state != ACLK_HOST_INITIALIZING){
739 rrdhost_aclk_state_unlock(host);
740 return ret;
@@ -766,7 +767,7 @@ ACLK_POPCORNING_STATE aclk_host_popcorn_check(RRDHOST *host)
767 * of no new collectors coming in in order to mark the agent
768 * as stable (set agent_state = AGENT_STABLE)
769 */
769 -void *aclk_query_main_thread(void *ptr)
770 +void *legacy_aclk_query_main_thread(void *ptr)
771 {
772 struct aclk_query_thread *info = ptr;
773
@@ -785,10 +786,10 @@ void *aclk_query_main_thread(void *ptr)
786 sleep(1);
787 continue;
788 }
788 - ACLK_SHARED_STATE_LOCK;
789 - if (unlikely(!aclk_shared_state.version_neg)) {
790 - if (!aclk_shared_state.version_neg_wait_till || aclk_shared_state.version_neg_wait_till > now_monotonic_usec()) {
791 - ACLK_SHARED_STATE_UNLOCK;
789 + legacy_aclk_shared_state_LOCK;
790 + if (unlikely(!legacy_aclk_shared_state.version_neg)) {
791 + if (!legacy_aclk_shared_state.version_neg_wait_till || legacy_aclk_shared_state.version_neg_wait_till > now_monotonic_usec()) {
792 + legacy_aclk_shared_state_UNLOCK;
793 info("Waiting for ACLK Version Negotiation message from Cloud");
794 sleep(1);
795 continue;
@@ -796,14 +797,14 @@ void *aclk_query_main_thread(void *ptr)
797 errno = 0;
798 error("ACLK version negotiation failed. No reply to \"hello\" with \"version\" from cloud in time of %ds."
799 " Reverting to default ACLK version of %d.", VERSION_NEG_TIMEOUT, ACLK_VERSION_MIN);
799 - aclk_shared_state.version_neg = ACLK_VERSION_MIN;
800 - aclk_set_rx_handlers(aclk_shared_state.version_neg);
800 + legacy_aclk_shared_state.version_neg = ACLK_VERSION_MIN;
801 + aclk_set_rx_handlers(legacy_aclk_shared_state.version_neg);
802 }
802 - ACLK_SHARED_STATE_UNLOCK;
803 + legacy_aclk_shared_state_UNLOCK;
804
805 rrdhost_aclk_state_lock(localhost);
806 if (unlikely(localhost->aclk_state.metadata == ACLK_METADATA_REQUIRED)) {
806 - if (unlikely(aclk_queue_query("on_connect", localhost, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT))) {
807 + if (unlikely(legacy_aclk_queue_query("on_connect", localhost, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT))) {
808 rrdhost_aclk_state_unlock(localhost);
809 errno = 0;
810 error("ACLK failed to queue on_connect command");
@@ -814,25 +815,25 @@ void *aclk_query_main_thread(void *ptr)
815 }
816 rrdhost_aclk_state_unlock(localhost);
817
817 - ACLK_SHARED_STATE_LOCK;
818 - if (aclk_shared_state.next_popcorn_host && aclk_host_popcorn_check(aclk_shared_state.next_popcorn_host) == ACLK_HOST_STABLE) {
819 - aclk_queue_query("on_connect", aclk_shared_state.next_popcorn_host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT);
820 - aclk_shared_state.next_popcorn_host = NULL;
818 + legacy_aclk_shared_state_LOCK;
819 + if (legacy_aclk_shared_state.next_popcorn_host && aclk_host_popcorn_check(legacy_aclk_shared_state.next_popcorn_host) == ACLK_HOST_STABLE) {
820 + legacy_aclk_queue_query("on_connect", legacy_aclk_shared_state.next_popcorn_host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT);
821 + legacy_aclk_shared_state.next_popcorn_host = NULL;
822 aclk_update_next_child_to_popcorn();
823 }
823 - ACLK_SHARED_STATE_UNLOCK;
824 + legacy_aclk_shared_state_UNLOCK;
825
826 while (aclk_process_query(info)) {
827 // Process all commands
828 };
829
829 - QUERY_THREAD_LOCK;
830 + LEGACY_QUERY_THREAD_LOCK;
831
832 // TODO: Need to check if there are queries awaiting already
832 - if (unlikely(pthread_cond_wait(&query_cond_wait, &query_lock_wait)))
833 + if (unlikely(pthread_cond_wait(&legacy_query_cond_wait, &legacy_query_lock_wait)))
834 sleep_usec(USEC_PER_SEC * 1);
835
835 - QUERY_THREAD_UNLOCK;
836 + LEGACY_QUERY_THREAD_UNLOCK;
837 }
838
839 return NULL;
aclk/legacy/aclk_query.h
+8 -11
@@ -10,14 +10,11 @@
10
11 #define MAX_GETRUSAGE_CALLS_PER_TICK 5 // Maximum number of times getrusage can be called per tick, per thread.
12
13 -extern pthread_cond_t query_cond_wait;
14 -extern pthread_mutex_t query_lock_wait;
13 +extern pthread_cond_t legacy_query_cond_wait;
14 +extern pthread_mutex_t legacy_query_lock_wait;
15 extern uint8_t *getrusage_called_this_tick;
16 -#define QUERY_THREAD_WAKEUP pthread_cond_signal(&query_cond_wait)
17 -#define QUERY_THREAD_WAKEUP_ALL pthread_cond_broadcast(&query_cond_wait)
18 -
19 -extern volatile int aclk_connected;
20 -
16 +#define LEGACY_QUERY_THREAD_WAKEUP pthread_cond_signal(&legacy_query_cond_wait)
17 +#define LEGACY_QUERY_THREAD_WAKEUP_ALL pthread_cond_broadcast(&legacy_query_cond_wait)
18 struct aclk_query_thread {
19 netdata_thread_t thread;
20 int idx;
@@ -34,11 +31,11 @@ struct aclk_cloud_req_v2 {
31 char *query_endpoint;
32 };
33
37 -void *aclk_query_main_thread(void *ptr);
38 -int aclk_queue_query(char *token, void *data, char *msg_type, char *query, int run_after, int internal, ACLK_CMD cmd);
34 +void *legacy_aclk_query_main_thread(void *ptr);
35 +int legacy_aclk_queue_query(char *token, void *data, char *msg_type, char *query, int run_after, int internal, ACLK_CMD cmd);
36
40 -void aclk_query_threads_start(struct aclk_query_threads *query_threads);
41 -void aclk_query_threads_cleanup(struct aclk_query_threads *query_threads);
37 +void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads);
38 +void legacy_aclk_query_threads_cleanup(struct aclk_query_threads *query_threads);
39 unsigned int aclk_query_size();
40
41 #endif //NETDATA_AGENT_CLOUD_LINK_H
aclk/legacy/aclk_rx_msgs.c
+38 -37
@@ -4,6 +4,7 @@
4 #include "aclk_common.h"
5 #include "aclk_stats.h"
6 #include "aclk_query.h"
7 +#include "agent_cloud_link.h"
8
9 #ifndef UUID_STR_LEN
10 #define UUID_STR_LEN 37
@@ -107,7 +108,7 @@ static int aclk_handle_cloud_request_v1(struct aclk_request *cloud_to_agent, cha
108 error(
109 "Received \"http\" message from Cloud with version %d, but ACLK version %d is used",
110 cloud_to_agent->version,
110 - aclk_shared_state.version_neg);
111 + legacy_aclk_shared_state.version_neg);
112 return 1;
113 }
114
@@ -126,14 +127,14 @@ static int aclk_handle_cloud_request_v1(struct aclk_request *cloud_to_agent, cha
127 return 1;
128 }
129
129 - if (unlikely(aclk_queue_query(cloud_to_agent->callback_topic, NULL, cloud_to_agent->msg_id, cloud_to_agent->payload, 0, 0, ACLK_CMD_CLOUD)))
130 + if (unlikely(legacy_aclk_queue_query(cloud_to_agent->callback_topic, NULL, cloud_to_agent->msg_id, cloud_to_agent->payload, 0, 0, ACLK_CMD_CLOUD)))
131 debug(D_ACLK, "ACLK failed to queue incoming \"http\" message");
132
133 if (aclk_stats_enabled) {
133 - ACLK_STATS_LOCK;
134 - aclk_metrics_per_sample.cloud_req_v1++;
135 - aclk_metrics_per_sample.cloud_req_ok++;
136 - ACLK_STATS_UNLOCK;
134 + LEGACY_ACLK_STATS_LOCK;
135 + legacy_aclk_metrics_per_sample.cloud_req_v1++;
136 + legacy_aclk_metrics_per_sample.cloud_req_ok++;
137 + LEGACY_ACLK_STATS_UNLOCK;
138 }
139
140 return 0;
@@ -181,11 +182,11 @@ static int aclk_handle_cloud_request_v2(struct aclk_request *cloud_to_agent, cha
182 }
183
184 // we do this here due to cloud_req being taken over by query thread
184 - // which if crazy quick can free it after aclk_queue_query
185 + // which if crazy quick can free it after legacy_aclk_queue_query
186 stat_idx = aclk_cloud_req_type_to_idx(cloud_req->query_endpoint);
187
187 - // aclk_queue_query takes ownership of data pointer
188 - if (unlikely(aclk_queue_query(
188 + // legacy_aclk_queue_query takes ownership of data pointer
189 + if (unlikely(legacy_aclk_queue_query(
190 cloud_to_agent->callback_topic, cloud_req, cloud_to_agent->msg_id, cloud_to_agent->payload, 0, 0,
191 ACLK_CMD_CLOUD_QUERY_2))) {
192 error("ACLK failed to queue incoming \"http\" v2 message");
@@ -193,11 +194,11 @@ static int aclk_handle_cloud_request_v2(struct aclk_request *cloud_to_agent, cha
194 }
195
196 if (aclk_stats_enabled) {
196 - ACLK_STATS_LOCK;
197 - aclk_metrics_per_sample.cloud_req_v2++;
198 - aclk_metrics_per_sample.cloud_req_ok++;
199 - aclk_metrics_per_sample.cloud_req_by_type[stat_idx]++;
200 - ACLK_STATS_UNLOCK;
197 + LEGACY_ACLK_STATS_LOCK;
198 + legacy_aclk_metrics_per_sample.cloud_req_v2++;
199 + legacy_aclk_metrics_per_sample.cloud_req_ok++;
200 + legacy_aclk_metrics_per_sample.cloud_req_by_type[stat_idx]++;
201 + LEGACY_ACLK_STATS_UNLOCK;
202 }
203
204 return 0;
@@ -258,19 +259,19 @@ static int aclk_handle_version_response(struct aclk_request *cloud_to_agent, cha
259
260 version = MIN(cloud_to_agent->max_version, ACLK_VERSION_MAX);
261
261 - ACLK_SHARED_STATE_LOCK;
262 - if (unlikely(now_monotonic_usec() > aclk_shared_state.version_neg_wait_till)) {
262 + legacy_aclk_shared_state_LOCK;
263 + if (unlikely(now_monotonic_usec() > legacy_aclk_shared_state.version_neg_wait_till)) {
264 errno = 0;
265 error("The \"version\" message came too late ignoring.");
266 goto err_cleanup;
267 }
267 - if (unlikely(aclk_shared_state.version_neg)) {
268 + if (unlikely(legacy_aclk_shared_state.version_neg)) {
269 errno = 0;
269 - error("Version has already been set to %d", aclk_shared_state.version_neg);
270 + error("Version has already been set to %d", legacy_aclk_shared_state.version_neg);
271 goto err_cleanup;
272 }
272 - aclk_shared_state.version_neg = version;
273 - ACLK_SHARED_STATE_UNLOCK;
273 + legacy_aclk_shared_state.version_neg = version;
274 + legacy_aclk_shared_state_UNLOCK;
275
276 info("Choosing version %d of ACLK", version);
277
@@ -279,7 +280,7 @@ static int aclk_handle_version_response(struct aclk_request *cloud_to_agent, cha
280 return 0;
281
282 err_cleanup:
282 - ACLK_SHARED_STATE_UNLOCK;
283 + legacy_aclk_shared_state_UNLOCK;
284 return 1;
285 }
286
@@ -288,31 +289,31 @@ typedef struct aclk_incoming_msg_type{
289 int(*fnc)(struct aclk_request *, char *);
290 }aclk_incoming_msg_type;
291
291 -aclk_incoming_msg_type aclk_incoming_msg_types_v1[] = {
292 +aclk_incoming_msg_type legacy_aclk_incoming_msg_types_v1[] = {
293 { .name = "http", .fnc = aclk_handle_cloud_request_v1 },
294 { .name = "version", .fnc = aclk_handle_version_response },
295 { .name = NULL, .fnc = NULL }
296 };
297
297 -aclk_incoming_msg_type aclk_incoming_msg_types_compression[] = {
298 +aclk_incoming_msg_type legacy_aclk_incoming_msg_types_compression[] = {
299 { .name = "http", .fnc = aclk_handle_cloud_request_v2 },
300 { .name = "version", .fnc = aclk_handle_version_response },
301 { .name = NULL, .fnc = NULL }
302 };
303
303 -struct aclk_incoming_msg_type *aclk_incoming_msg_types = aclk_incoming_msg_types_v1;
304 +struct aclk_incoming_msg_type *legacy_aclk_incoming_msg_types = legacy_aclk_incoming_msg_types_v1;
305
306 void aclk_set_rx_handlers(int version)
307 {
308 if(version >= ACLK_V_COMPRESSION) {
308 - aclk_incoming_msg_types = aclk_incoming_msg_types_compression;
309 + legacy_aclk_incoming_msg_types = legacy_aclk_incoming_msg_types_compression;
310 return;
311 }
312
312 - aclk_incoming_msg_types = aclk_incoming_msg_types_v1;
313 + legacy_aclk_incoming_msg_types = legacy_aclk_incoming_msg_types_v1;
314 }
315
315 -int aclk_handle_cloud_message(char *payload)
316 +int legacy_aclk_handle_cloud_message(char *payload)
317 {
318 struct aclk_request cloud_to_agent;
319 memset(&cloud_to_agent, 0, sizeof(struct aclk_request));
@@ -325,7 +326,7 @@ int aclk_handle_cloud_message(char *payload)
326
327 debug(D_ACLK, "ACLK incoming message (%s)", payload);
328
328 - int rc = json_parse(payload, &cloud_to_agent, cloud_to_agent_parse);
329 + int rc = json_parse(payload, &cloud_to_agent, legacy_cloud_to_agent_parse);
330
331 if (unlikely(rc != JSON_OK)) {
332 errno = 0;
@@ -339,22 +340,22 @@ int aclk_handle_cloud_message(char *payload)
340 goto err_cleanup;
341 }
342
342 - if (!aclk_shared_state.version_neg && strcmp(cloud_to_agent.type_id, "version")) {
343 + if (!legacy_aclk_shared_state.version_neg && strcmp(cloud_to_agent.type_id, "version")) {
344 error("Only \"version\" message is allowed before popcorning and version negotiation is finished. Ignoring");
345 goto err_cleanup;
346 }
347
347 - for (int i = 0; aclk_incoming_msg_types[i].name; i++) {
348 - if (strcmp(cloud_to_agent.type_id, aclk_incoming_msg_types[i].name) == 0) {
349 - if (likely(!aclk_incoming_msg_types[i].fnc(&cloud_to_agent, payload))) {
348 + for (int i = 0; legacy_aclk_incoming_msg_types[i].name; i++) {
349 + if (strcmp(cloud_to_agent.type_id, legacy_aclk_incoming_msg_types[i].name) == 0) {
350 + if (likely(!legacy_aclk_incoming_msg_types[i].fnc(&cloud_to_agent, payload))) {
351 // in case of success handler is supposed to clean up after itself
352 // or as in the case of aclk_handle_cloud_request take
353 // ownership of the pointers (done to avoid copying)
353 - // see what `aclk_queue_query` parameter `internal` does
354 + // see what `legacy_aclk_queue_query` parameter `internal` does
355
356 // NEVER CONTINUE THIS LOOP AFTER CALLING FUNCTION!!!
357 // msg handlers (namely aclk_handle_version_response)
357 - // can freely change what aclk_incoming_msg_types points to
358 + // can freely change what legacy_aclk_incoming_msg_types points to
359 // so either exit or restart this for loop
360 freez(cloud_to_agent.type_id);
361 return 0;
@@ -378,9 +379,9 @@ err_cleanup:
379
380 err_cleanup_nojson:
381 if (aclk_stats_enabled) {
381 - ACLK_STATS_LOCK;
382 - aclk_metrics_per_sample.cloud_req_err++;
383 - ACLK_STATS_UNLOCK;
382 + LEGACY_ACLK_STATS_LOCK;
383 + legacy_aclk_metrics_per_sample.cloud_req_err++;
384 + LEGACY_ACLK_STATS_UNLOCK;
385 }
386
387 return 1;
aclk/legacy/aclk_rx_msgs.h
+1 -1
@@ -6,7 +6,7 @@
6 #include "daemon/common.h"
7 #include "libnetdata/libnetdata.h"
8
9 -int aclk_handle_cloud_message(char *payload);
9 +int legacy_aclk_handle_cloud_message(char *payload);
10 void aclk_set_rx_handlers(int version);
11
12
aclk/legacy/aclk_stats.c
+64 -66
@@ -1,33 +1,31 @@
1 #include "aclk_stats.h"
2
3 -netdata_mutex_t aclk_stats_mutex = NETDATA_MUTEX_INITIALIZER;
3 +netdata_mutex_t legacy_aclk_stats_mutex = NETDATA_MUTEX_INITIALIZER;
4
5 -int aclk_stats_enabled;
6 -
7 -int query_thread_count;
5 +int legacy_query_thread_count;
6
7 // data ACLK stats need per query thread
10 -struct aclk_qt_data {
8 +struct legacy_aclk_qt_data {
9 RRDDIM *dim;
12 -} *aclk_qt_data = NULL;
10 +} *legacy_aclk_qt_data = NULL;
11
12 // ACLK per query thread cpu stats
15 -struct aclk_cpu_data {
13 +struct legacy_aclk_cpu_data {
14 RRDDIM *user;
15 RRDDIM *system;
16 RRDSET *st;
19 -} *aclk_cpu_data = NULL;
17 +} *legacy_aclk_cpu_data = NULL;
18
21 -uint32_t *aclk_queries_per_thread = NULL;
22 -uint32_t *aclk_queries_per_thread_sample = NULL;
19 +uint32_t *legacy_aclk_queries_per_thread = NULL;
20 +uint32_t *legacy_aclk_queries_per_thread_sample = NULL;
21 struct rusage *rusage_per_thread;
22 uint8_t *getrusage_called_this_tick = NULL;
23
26 -struct aclk_metrics aclk_metrics = {
24 +static struct legacy_aclk_metrics legacy_aclk_metrics = {
25 .online = 0,
26 };
27
30 -struct aclk_metrics_per_sample aclk_metrics_per_sample;
28 +struct legacy_aclk_metrics_per_sample legacy_aclk_metrics_per_sample;
29
30 struct aclk_mat_metrics aclk_mat_metrics = {
31 #ifdef NETDATA_INTERNAL_CHECKS
@@ -61,20 +59,20 @@ struct aclk_mat_metrics aclk_mat_metrics = {
59 "by query thread (just before passing to the database)." }
60 };
61
64 -void aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurement)
62 +void legacy_aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurement)
63 {
64 if (aclk_stats_enabled) {
67 - ACLK_STATS_LOCK;
65 + LEGACY_ACLK_STATS_LOCK;
66 if (metric->max < measurement)
67 metric->max = measurement;
68
69 metric->total += measurement;
70 metric->count++;
73 - ACLK_STATS_UNLOCK;
71 + LEGACY_ACLK_STATS_UNLOCK;
72 }
73 }
74
77 -static void aclk_stats_collect(struct aclk_metrics_per_sample *per_sample, struct aclk_metrics *permanent)
75 +static void aclk_stats_collect(struct legacy_aclk_metrics_per_sample *per_sample, struct legacy_aclk_metrics *permanent)
76 {
77 static RRDSET *st_aclkstats = NULL;
78 static RRDDIM *rd_online_status = NULL;
@@ -93,7 +91,7 @@ static void aclk_stats_collect(struct aclk_metrics_per_sample *per_sample, struc
91 rrdset_done(st_aclkstats);
92 }
93
96 -static void aclk_stats_query_queue(struct aclk_metrics_per_sample *per_sample)
94 +static void aclk_stats_query_queue(struct legacy_aclk_metrics_per_sample *per_sample)
95 {
96 static RRDSET *st_query_thread = NULL;
97 static RRDDIM *rd_queued = NULL;
@@ -115,7 +113,7 @@ static void aclk_stats_query_queue(struct aclk_metrics_per_sample *per_sample)
113 rrdset_done(st_query_thread);
114 }
115
118 -static void aclk_stats_write_q(struct aclk_metrics_per_sample *per_sample)
116 +static void aclk_stats_write_q(struct legacy_aclk_metrics_per_sample *per_sample)
117 {
118 static RRDSET *st = NULL;
119 static RRDDIM *rd_wq_add = NULL;
@@ -137,7 +135,7 @@ static void aclk_stats_write_q(struct aclk_metrics_per_sample *per_sample)
135 rrdset_done(st);
136 }
137
140 -static void aclk_stats_read_q(struct aclk_metrics_per_sample *per_sample)
138 +static void aclk_stats_read_q(struct legacy_aclk_metrics_per_sample *per_sample)
139 {
140 static RRDSET *st = NULL;
141 static RRDDIM *rd_rq_add = NULL;
@@ -159,7 +157,7 @@ static void aclk_stats_read_q(struct aclk_metrics_per_sample *per_sample)
157 rrdset_done(st);
158 }
159
162 -static void aclk_stats_cloud_req(struct aclk_metrics_per_sample *per_sample)
160 +static void aclk_stats_cloud_req(struct legacy_aclk_metrics_per_sample *per_sample)
161 {
162 static RRDSET *st = NULL;
163 static RRDDIM *rd_rq_ok = NULL;
@@ -181,7 +179,7 @@ static void aclk_stats_cloud_req(struct aclk_metrics_per_sample *per_sample)
179 rrdset_done(st);
180 }
181
184 -static void aclk_stats_cloud_req_version(struct aclk_metrics_per_sample *per_sample)
182 +static void aclk_stats_cloud_req_version(struct legacy_aclk_metrics_per_sample *per_sample)
183 {
184 static RRDSET *st = NULL;
185 static RRDDIM *rd_rq_v1 = NULL;
@@ -223,7 +221,7 @@ int aclk_cloud_req_type_to_idx(const char *name)
221 return 0;
222 }
223
226 -static void aclk_stats_cloud_req_cmd(struct aclk_metrics_per_sample *per_sample)
224 +static void aclk_stats_cloud_req_cmd(struct legacy_aclk_metrics_per_sample *per_sample)
225 {
226 static RRDSET *st;
227 static int initialized = 0;
@@ -258,16 +256,16 @@ static void aclk_stats_query_threads(uint32_t *queries_per_thread)
256 "netdata", "aclk_query_threads", NULL, "aclk", NULL, "Queries Processed Per Thread", "req/s",
257 "netdata", "stats", 200008, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
258
261 - for (int i = 0; i < query_thread_count; i++) {
259 + for (int i = 0; i < legacy_query_thread_count; i++) {
260 if (snprintf(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
261 error("snprintf encoding error");
264 - aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
262 + legacy_aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
263 }
264 } else
265 rrdset_next(st);
266
269 - for (int i = 0; i < query_thread_count; i++) {
270 - rrddim_set_by_pointer(st, aclk_qt_data[i].dim, queries_per_thread[i]);
267 + for (int i = 0; i < legacy_query_thread_count; i++) {
268 + rrddim_set_by_pointer(st, legacy_aclk_qt_data[i].dim, queries_per_thread[i]);
269 }
270
271 rrdset_done(st);
@@ -301,59 +299,59 @@ static void aclk_stats_cpu_threads(void)
299 char id[100 + 1];
300 char title[100 + 1];
301
304 - for (int i = 0; i < query_thread_count; i++) {
305 - if (unlikely(!aclk_cpu_data[i].st)) {
302 + for (int i = 0; i < legacy_query_thread_count; i++) {
303 + if (unlikely(!legacy_aclk_cpu_data[i].st)) {
304
305 snprintfz(id, 100, "aclk_thread%d_cpu", i);
306 snprintfz(title, 100, "Cpu Usage For Thread No %d", i);
307
310 - aclk_cpu_data[i].st = rrdset_create_localhost(
308 + legacy_aclk_cpu_data[i].st = rrdset_create_localhost(
309 "netdata", id, NULL, "aclk", NULL, title, "milliseconds/s",
310 "netdata", "stats", 200020 + i, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
311
314 - aclk_cpu_data[i].user = rrddim_add(aclk_cpu_data[i].st, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
315 - aclk_cpu_data[i].system = rrddim_add(aclk_cpu_data[i].st, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
312 + legacy_aclk_cpu_data[i].user = rrddim_add(legacy_aclk_cpu_data[i].st, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
313 + legacy_aclk_cpu_data[i].system = rrddim_add(legacy_aclk_cpu_data[i].st, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
314
315 } else
318 - rrdset_next(aclk_cpu_data[i].st);
316 + rrdset_next(legacy_aclk_cpu_data[i].st);
317 }
318
321 - for (int i = 0; i < query_thread_count; i++) {
322 - rrddim_set_by_pointer(aclk_cpu_data[i].st, aclk_cpu_data[i].user, rusage_per_thread[i].ru_utime.tv_sec * 1000000ULL + rusage_per_thread[i].ru_utime.tv_usec);
323 - rrddim_set_by_pointer(aclk_cpu_data[i].st, aclk_cpu_data[i].system, rusage_per_thread[i].ru_stime.tv_sec * 1000000ULL + rusage_per_thread[i].ru_stime.tv_usec);
324 - rrdset_done(aclk_cpu_data[i].st);
319 + for (int i = 0; i < legacy_query_thread_count; i++) {
320 + rrddim_set_by_pointer(legacy_aclk_cpu_data[i].st, legacy_aclk_cpu_data[i].user, rusage_per_thread[i].ru_utime.tv_sec * 1000000ULL + rusage_per_thread[i].ru_utime.tv_usec);
321 + rrddim_set_by_pointer(legacy_aclk_cpu_data[i].st, legacy_aclk_cpu_data[i].system, rusage_per_thread[i].ru_stime.tv_sec * 1000000ULL + rusage_per_thread[i].ru_stime.tv_usec);
322 + rrdset_done(legacy_aclk_cpu_data[i].st);
323 }
324 }
325
328 -void aclk_stats_thread_cleanup()
326 +void legacy_aclk_stats_thread_cleanup()
327 {
330 - freez(aclk_qt_data);
331 - freez(aclk_queries_per_thread);
332 - freez(aclk_queries_per_thread_sample);
333 - freez(aclk_cpu_data);
328 + freez(legacy_aclk_qt_data);
329 + freez(legacy_aclk_queries_per_thread);
330 + freez(legacy_aclk_queries_per_thread_sample);
331 + freez(legacy_aclk_cpu_data);
332 freez(rusage_per_thread);
333 }
334
337 -void *aclk_stats_main_thread(void *ptr)
335 +void *legacy_aclk_stats_main_thread(void *ptr)
336 {
337 struct aclk_stats_thread *args = ptr;
338
341 - query_thread_count = args->query_thread_count;
342 - aclk_qt_data = callocz(query_thread_count, sizeof(struct aclk_qt_data));
343 - aclk_cpu_data = callocz(query_thread_count, sizeof(struct aclk_cpu_data));
344 - aclk_queries_per_thread = callocz(query_thread_count, sizeof(uint32_t));
345 - aclk_queries_per_thread_sample = callocz(query_thread_count, sizeof(uint32_t));
346 - rusage_per_thread = callocz(query_thread_count, sizeof(struct rusage));
347 - getrusage_called_this_tick = callocz(query_thread_count, sizeof(uint8_t));
339 + legacy_query_thread_count = args->query_thread_count;
340 + legacy_aclk_qt_data = callocz(legacy_query_thread_count, sizeof(struct legacy_aclk_qt_data));
341 + legacy_aclk_cpu_data = callocz(legacy_query_thread_count, sizeof(struct legacy_aclk_cpu_data));
342 + legacy_aclk_queries_per_thread = callocz(legacy_query_thread_count, sizeof(uint32_t));
343 + legacy_aclk_queries_per_thread_sample = callocz(legacy_query_thread_count, sizeof(uint32_t));
344 + rusage_per_thread = callocz(legacy_query_thread_count, sizeof(struct rusage));
345 + getrusage_called_this_tick = callocz(legacy_query_thread_count, sizeof(uint8_t));
346
347 heartbeat_t hb;
348 heartbeat_init(&hb);
349 usec_t step_ut = localhost->rrd_update_every * USEC_PER_SEC;
350
353 - memset(&aclk_metrics_per_sample, 0, sizeof(struct aclk_metrics_per_sample));
351 + memset(&legacy_aclk_metrics_per_sample, 0, sizeof(struct legacy_aclk_metrics_per_sample));
352
355 - struct aclk_metrics_per_sample per_sample;
356 - struct aclk_metrics permanent;
353 + struct legacy_aclk_metrics_per_sample per_sample;
354 + struct legacy_aclk_metrics permanent;
355
356 while (!netdata_exit) {
357 netdata_thread_testcancel();
@@ -363,17 +361,17 @@ void *aclk_stats_main_thread(void *ptr)
361 heartbeat_next(&hb, step_ut);
362 if (netdata_exit) break;
363
366 - ACLK_STATS_LOCK;
364 + LEGACY_ACLK_STATS_LOCK;
365 // to not hold lock longer than necessary, especially not to hold it
366 // during database rrd* operations
369 - memcpy(&per_sample, &aclk_metrics_per_sample, sizeof(struct aclk_metrics_per_sample));
370 - memcpy(&permanent, &aclk_metrics, sizeof(struct aclk_metrics));
371 - memset(&aclk_metrics_per_sample, 0, sizeof(struct aclk_metrics_per_sample));
367 + memcpy(&per_sample, &legacy_aclk_metrics_per_sample, sizeof(struct legacy_aclk_metrics_per_sample));
368 + memcpy(&permanent, &legacy_aclk_metrics, sizeof(struct legacy_aclk_metrics));
369 + memset(&legacy_aclk_metrics_per_sample, 0, sizeof(struct legacy_aclk_metrics_per_sample));
370
373 - memcpy(aclk_queries_per_thread_sample, aclk_queries_per_thread, sizeof(uint32_t) * query_thread_count);
374 - memset(aclk_queries_per_thread, 0, sizeof(uint32_t) * query_thread_count);
375 - memset(getrusage_called_this_tick, 0, sizeof(uint8_t) * query_thread_count);
376 - ACLK_STATS_UNLOCK;
371 + memcpy(legacy_aclk_queries_per_thread_sample, legacy_aclk_queries_per_thread, sizeof(uint32_t) * legacy_query_thread_count);
372 + memset(legacy_aclk_queries_per_thread, 0, sizeof(uint32_t) * legacy_query_thread_count);
373 + memset(getrusage_called_this_tick, 0, sizeof(uint8_t) * legacy_query_thread_count);
374 + LEGACY_ACLK_STATS_UNLOCK;
375
376 aclk_stats_collect(&per_sample, &permanent);
377 aclk_stats_query_queue(&per_sample);
@@ -386,7 +384,7 @@ void *aclk_stats_main_thread(void *ptr)
384
385 aclk_stats_cloud_req_cmd(&per_sample);
386
389 - aclk_stats_query_threads(aclk_queries_per_thread_sample);
387 + aclk_stats_query_threads(legacy_aclk_queries_per_thread_sample);
388
389 aclk_stats_cpu_threads();
390
@@ -400,14 +398,14 @@ void *aclk_stats_main_thread(void *ptr)
398 return 0;
399 }
400
403 -void aclk_stats_upd_online(int online) {
401 +void legacy_aclk_stats_upd_online(int online) {
402 if(!aclk_stats_enabled)
403 return;
404
407 - ACLK_STATS_LOCK;
408 - aclk_metrics.online = online;
405 + LEGACY_ACLK_STATS_LOCK;
406 + legacy_aclk_metrics.online = online;
407
408 if(!online)
411 - aclk_metrics_per_sample.offline_during_sample = 1;
412 - ACLK_STATS_UNLOCK;
409 + legacy_aclk_metrics_per_sample.offline_during_sample = 1;
410 + LEGACY_ACLK_STATS_UNLOCK;
411 }
aclk/legacy/aclk_stats.h
+11 -13
@@ -9,12 +9,10 @@
9
10 #define ACLK_STATS_THREAD_NAME "ACLK_Stats"
11
12 -extern netdata_mutex_t aclk_stats_mutex;
12 +extern netdata_mutex_t legacy_aclk_stats_mutex;
13
14 -#define ACLK_STATS_LOCK netdata_mutex_lock(&aclk_stats_mutex)
15 -#define ACLK_STATS_UNLOCK netdata_mutex_unlock(&aclk_stats_mutex)
16 -
17 -extern int aclk_stats_enabled;
14 +#define LEGACY_ACLK_STATS_LOCK netdata_mutex_lock(&legacy_aclk_stats_mutex)
15 +#define LEGACY_ACLK_STATS_UNLOCK netdata_mutex_unlock(&legacy_aclk_stats_mutex)
16
17 struct aclk_stats_thread {
18 netdata_thread_t *thread;
@@ -22,7 +20,7 @@ struct aclk_stats_thread {
20 };
21
22 // preserve between samples
25 -struct aclk_metrics {
23 +struct legacy_aclk_metrics {
24 volatile uint8_t online;
25 };
26
@@ -53,7 +51,7 @@ extern struct aclk_mat_metrics {
51 struct aclk_metric_mat cloud_q_recvd_to_processed;
52 } aclk_mat_metrics;
53
56 -void aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurement);
54 +void legacy_aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurement);
55
56 #define ACLK_STATS_CLOUD_REQ_TYPE_CNT 7
57 // if you change update cloud_req_type_names
@@ -61,7 +59,7 @@ void aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurem
59 int aclk_cloud_req_type_to_idx(const char *name);
60
61 // reset to 0 on every sample
64 -extern struct aclk_metrics_per_sample {
62 +extern struct legacy_aclk_metrics_per_sample {
63 /* in the unlikely event of ACLK disconnecting
64 and reconnecting under 1 sampling rate
65 we want to make sure we record the disconnection
@@ -90,13 +88,13 @@ extern struct aclk_metrics_per_sample {
88 #endif
89 struct aclk_metric_mat_data cloud_q_db_query_time;
90 struct aclk_metric_mat_data cloud_q_recvd_to_processed;
93 -} aclk_metrics_per_sample;
91 +} legacy_aclk_metrics_per_sample;
92
95 -extern uint32_t *aclk_queries_per_thread;
93 +extern uint32_t *legacy_aclk_queries_per_thread;
94 extern struct rusage *rusage_per_thread;
95
98 -void *aclk_stats_main_thread(void *ptr);
99 -void aclk_stats_thread_cleanup();
100 -void aclk_stats_upd_online(int online);
96 +void *legacy_aclk_stats_main_thread(void *ptr);
97 +void legacy_aclk_stats_thread_cleanup();
98 +void legacy_aclk_stats_upd_online(int online);
99
100 #endif /* NETDATA_ACLK_STATS_H */
aclk/legacy/agent_cloud_link.c
+67 -294
@@ -6,6 +6,7 @@
6 #include "aclk_query.h"
7 #include "aclk_common.h"
8 #include "aclk_stats.h"
9 +#include "../aclk_collector_list.h"
10
11 #ifdef ENABLE_ACLK
12 #include <libwebsockets.h>
@@ -15,46 +16,20 @@ int aclk_shutting_down = 0;
16
17 // Other global state
18 static int aclk_subscribed = 0;
18 -static int aclk_disable_single_updates = 0;
19 static char *aclk_username = NULL;
20 static char *aclk_password = NULL;
21
22 static char *global_base_topic = NULL;
23 static int aclk_connecting = 0;
24 int aclk_force_reconnect = 0; // Indication from lower layers
25 -usec_t aclk_session_us = 0; // Used by the mqtt layer
26 -time_t aclk_session_sec = 0; // Used by the mqtt layer
25
26 static netdata_mutex_t aclk_mutex = NETDATA_MUTEX_INITIALIZER;
29 -static netdata_mutex_t collector_mutex = NETDATA_MUTEX_INITIALIZER;
27
28 #define ACLK_LOCK netdata_mutex_lock(&aclk_mutex)
29 #define ACLK_UNLOCK netdata_mutex_unlock(&aclk_mutex)
30
34 -#define COLLECTOR_LOCK netdata_mutex_lock(&collector_mutex)
35 -#define COLLECTOR_UNLOCK netdata_mutex_unlock(&collector_mutex)
36 -
31 void lws_wss_check_queues(size_t *write_len, size_t *write_len_bytes, size_t *read_len);
32 void aclk_lws_wss_destroy_context();
39 -/*
40 - * Maintain a list of collectors and chart count
41 - * If all the charts of a collector are deleted
42 - * then a new metadata dataset must be send to the cloud
43 - *
44 - */
45 -struct _collector {
46 - time_t created;
47 - uint32_t count; //chart count
48 - uint32_t hostname_hash;
49 - uint32_t plugin_hash;
50 - uint32_t module_hash;
51 - char *hostname;
52 - char *plugin_name;
53 - char *module_name;
54 - struct _collector *next;
55 -};
56 -
57 -struct _collector *collector_list = NULL;
33
34 char *create_uuid()
35 {
@@ -67,7 +42,7 @@ char *create_uuid()
42 return uuid_str;
43 }
44
70 -int cloud_to_agent_parse(JSON_ENTRY *e)
45 +int legacy_cloud_to_agent_parse(JSON_ENTRY *e)
46 {
47 struct aclk_request *data = e->callback_data;
48
@@ -247,202 +222,10 @@ char *get_topic(char *sub_topic, char *final_topic, int max_size)
222 return final_topic;
223 }
224
250 -#ifndef __GNUC__
251 -#pragma region ACLK Internal Collector Tracking
252 -#endif
253 -
254 -/*
255 - * Free a collector structure
256 - */
257 -
258 -static void _free_collector(struct _collector *collector)
259 -{
260 - if (likely(collector->plugin_name))
261 - freez(collector->plugin_name);
262 -
263 - if (likely(collector->module_name))
264 - freez(collector->module_name);
265 -
266 - if (likely(collector->hostname))
267 - freez(collector->hostname);
268 -
269 - freez(collector);
270 -}
271 -
272 -/*
273 - * This will report the collector list
274 - *
275 - */
276 -#ifdef ACLK_DEBUG
277 -static void _dump_collector_list()
278 -{
279 - struct _collector *tmp_collector;
280 -
281 - COLLECTOR_LOCK;
282 -
283 - info("DUMPING ALL COLLECTORS");
284 -
285 - if (unlikely(!collector_list || !collector_list->next)) {
286 - COLLECTOR_UNLOCK;
287 - info("DUMPING ALL COLLECTORS -- nothing found");
288 - return;
289 - }
290 -
291 - // Note that the first entry is "dummy"
292 - tmp_collector = collector_list->next;
293 -
294 - while (tmp_collector) {
295 - info(
296 - "COLLECTOR %s : [%s:%s] count = %u", tmp_collector->hostname,
297 - tmp_collector->plugin_name ? tmp_collector->plugin_name : "",
298 - tmp_collector->module_name ? tmp_collector->module_name : "", tmp_collector->count);
299 -
300 - tmp_collector = tmp_collector->next;
301 - }
302 - info("DUMPING ALL COLLECTORS DONE");
303 - COLLECTOR_UNLOCK;
304 -}
305 -#endif
306 -
307 -/*
308 - * This will cleanup the collector list
309 - *
310 - */
311 -static void _reset_collector_list()
312 -{
313 - struct _collector *tmp_collector, *next_collector;
314 -
315 - COLLECTOR_LOCK;
316 -
317 - if (unlikely(!collector_list || !collector_list->next)) {
318 - COLLECTOR_UNLOCK;
319 - return;
320 - }
321 -
322 - // Note that the first entry is "dummy"
323 - tmp_collector = collector_list->next;
324 - collector_list->count = 0;
325 - collector_list->next = NULL;
326 -
327 - // We broke the link; we can unlock
328 - COLLECTOR_UNLOCK;
329 -
330 - while (tmp_collector) {
331 - next_collector = tmp_collector->next;
332 - _free_collector(tmp_collector);
333 - tmp_collector = next_collector;
334 - }
335 -}
336 -
337 -/*
338 - * Find a collector (if it exists)
339 - * Must lock before calling this
340 - * If last_collector is not null, it will return the previous collector in the linked
341 - * list (used in collector delete)
342 - */
343 -static struct _collector *_find_collector(
344 - const char *hostname, const char *plugin_name, const char *module_name, struct _collector **last_collector)
345 -{
346 - struct _collector *tmp_collector, *prev_collector;
347 - uint32_t plugin_hash;
348 - uint32_t module_hash;
349 - uint32_t hostname_hash;
350 -
351 - if (unlikely(!collector_list)) {
352 - collector_list = callocz(1, sizeof(struct _collector));
353 - return NULL;
354 - }
355 -
356 - if (unlikely(!collector_list->next))
357 - return NULL;
358 -
359 - plugin_hash = plugin_name ? simple_hash(plugin_name) : 1;
360 - module_hash = module_name ? simple_hash(module_name) : 1;
361 - hostname_hash = simple_hash(hostname);
362 -
363 - // Note that the first entry is "dummy"
364 - tmp_collector = collector_list->next;
365 - prev_collector = collector_list;
366 - while (tmp_collector) {
367 - if (plugin_hash == tmp_collector->plugin_hash && module_hash == tmp_collector->module_hash &&
368 - hostname_hash == tmp_collector->hostname_hash && (!strcmp(hostname, tmp_collector->hostname)) &&
369 - (!plugin_name || !tmp_collector->plugin_name || !strcmp(plugin_name, tmp_collector->plugin_name)) &&
370 - (!module_name || !tmp_collector->module_name || !strcmp(module_name, tmp_collector->module_name))) {
371 - if (unlikely(last_collector))
372 - *last_collector = prev_collector;
373 -
374 - return tmp_collector;
375 - }
376 -
377 - prev_collector = tmp_collector;
378 - tmp_collector = tmp_collector->next;
379 - }
380 -
381 - return tmp_collector;
382 -}
383 -
384 -/*
385 - * Called to delete a collector
386 - * It will reduce the count (chart_count) and will remove it
387 - * from the linked list if the count reaches zero
388 - * The structure will be returned to the caller to free
389 - * the resources
390 - *
391 - */
392 -static struct _collector *_del_collector(const char *hostname, const char *plugin_name, const char *module_name)
393 -{
394 - struct _collector *tmp_collector, *prev_collector = NULL;
395 -
396 - tmp_collector = _find_collector(hostname, plugin_name, module_name, &prev_collector);
397 -
398 - if (likely(tmp_collector)) {
399 - --tmp_collector->count;
400 - if (unlikely(!tmp_collector->count))
401 - prev_collector->next = tmp_collector->next;
402 - }
403 - return tmp_collector;
404 -}
405 -
406 -/*
407 - * Add a new collector (plugin / module) to the list
408 - * If it already exists just update the chart count
409 - *
410 - * Lock before calling
411 - */
412 -static struct _collector *_add_collector(const char *hostname, const char *plugin_name, const char *module_name)
413 -{
414 - struct _collector *tmp_collector;
415 -
416 - tmp_collector = _find_collector(hostname, plugin_name, module_name, NULL);
417 -
418 - if (unlikely(!tmp_collector)) {
419 - tmp_collector = callocz(1, sizeof(struct _collector));
420 - tmp_collector->hostname_hash = simple_hash(hostname);
421 - tmp_collector->plugin_hash = plugin_name ? simple_hash(plugin_name) : 1;
422 - tmp_collector->module_hash = module_name ? simple_hash(module_name) : 1;
423 -
424 - tmp_collector->hostname = strdupz(hostname);
425 - tmp_collector->plugin_name = plugin_name ? strdupz(plugin_name) : NULL;
426 - tmp_collector->module_name = module_name ? strdupz(module_name) : NULL;
427 -
428 - tmp_collector->next = collector_list->next;
429 - collector_list->next = tmp_collector;
430 - }
431 - tmp_collector->count++;
432 - debug(
433 - D_ACLK, "ADD COLLECTOR %s [%s:%s] -- chart %u", hostname, plugin_name ? plugin_name : "*",
434 - module_name ? module_name : "*", tmp_collector->count);
435 - return tmp_collector;
436 -}
437 -
438 -#ifndef __GNUC__
439 -#pragma endregion
440 -#endif
441 -
225 /* Avoids the need to scan trough all RRDHOSTS
226 * every time any Query Thread Wakes Up
227 * (every time we need to check child popcorn expiry)
445 - * call with ACLK_SHARED_STATE_LOCK held
228 + * call with legacy_aclk_shared_state_LOCK held
229 */
230 void aclk_update_next_child_to_popcorn(void)
231 {
@@ -462,19 +245,19 @@ void aclk_update_next_child_to_popcorn(void)
245
246 any = 1;
247
465 - if (unlikely(!aclk_shared_state.next_popcorn_host)) {
466 - aclk_shared_state.next_popcorn_host = host;
248 + if (unlikely(!legacy_aclk_shared_state.next_popcorn_host)) {
249 + legacy_aclk_shared_state.next_popcorn_host = host;
250 rrdhost_aclk_state_unlock(host);
251 continue;
252 }
253
471 - if (aclk_shared_state.next_popcorn_host->aclk_state.t_last_popcorn_update > host->aclk_state.t_last_popcorn_update)
472 - aclk_shared_state.next_popcorn_host = host;
254 + if (legacy_aclk_shared_state.next_popcorn_host->aclk_state.t_last_popcorn_update > host->aclk_state.t_last_popcorn_update)
255 + legacy_aclk_shared_state.next_popcorn_host = host;
256
257 rrdhost_aclk_state_unlock(host);
258 }
259 if(!any)
477 - aclk_shared_state.next_popcorn_host = NULL;
260 + legacy_aclk_shared_state.next_popcorn_host = NULL;
261
262 rrd_unlock();
263 }
@@ -487,7 +270,7 @@ static int aclk_popcorn_check_bump(RRDHOST *host)
270 {
271 time_t now = now_monotonic_sec();
272 int updated = 0, ret;
490 - ACLK_SHARED_STATE_LOCK;
273 + legacy_aclk_shared_state_LOCK;
274 rrdhost_aclk_state_lock(host);
275
276 ret = ACLK_IS_HOST_INITIALIZING(host);
@@ -502,12 +285,12 @@ static int aclk_popcorn_check_bump(RRDHOST *host)
285 if (host != localhost && updated)
286 aclk_update_next_child_to_popcorn();
287
505 - ACLK_SHARED_STATE_UNLOCK;
288 + legacy_aclk_shared_state_UNLOCK;
289 return ret;
290 }
291
292 rrdhost_aclk_state_unlock(host);
510 - ACLK_SHARED_STATE_UNLOCK;
293 + legacy_aclk_shared_state_UNLOCK;
294 return ret;
295 }
296
@@ -523,13 +306,13 @@ static void aclk_start_host_popcorning(RRDHOST *host)
306 {
307 usec_t now = now_monotonic_sec();
308 info("Starting ACLK popcorn timer for host \"%s\" with GUID \"%s\"", host->hostname, host->machine_guid);
526 - ACLK_SHARED_STATE_LOCK;
309 + legacy_aclk_shared_state_LOCK;
310 rrdhost_aclk_state_lock(host);
311 if (host == localhost && !ACLK_IS_HOST_INITIALIZING(host)) {
312 errno = 0;
313 error("Localhost is allowed to do popcorning only once after startup!");
314 rrdhost_aclk_state_unlock(host);
532 - ACLK_SHARED_STATE_UNLOCK;
315 + legacy_aclk_shared_state_UNLOCK;
316 return;
317 }
318
@@ -539,16 +322,16 @@ static void aclk_start_host_popcorning(RRDHOST *host)
322 rrdhost_aclk_state_unlock(host);
323 if (host != localhost)
324 aclk_update_next_child_to_popcorn();
542 - ACLK_SHARED_STATE_UNLOCK;
325 + legacy_aclk_shared_state_UNLOCK;
326 }
327
328 static void aclk_stop_host_popcorning(RRDHOST *host)
329 {
547 - ACLK_SHARED_STATE_LOCK;
330 + legacy_aclk_shared_state_LOCK;
331 rrdhost_aclk_state_lock(host);
332 if (!ACLK_IS_HOST_POPCORNING(host)) {
333 rrdhost_aclk_state_unlock(host);
551 - ACLK_SHARED_STATE_UNLOCK;
334 + legacy_aclk_shared_state_UNLOCK;
335 return;
336 }
337
@@ -557,18 +340,18 @@ static void aclk_stop_host_popcorning(RRDHOST *host)
340 host->aclk_state.metadata = ACLK_METADATA_REQUIRED;
341 rrdhost_aclk_state_unlock(host);
342
560 - if(host == aclk_shared_state.next_popcorn_host) {
561 - aclk_shared_state.next_popcorn_host = NULL;
343 + if(host == legacy_aclk_shared_state.next_popcorn_host) {
344 + legacy_aclk_shared_state.next_popcorn_host = NULL;
345 aclk_update_next_child_to_popcorn();
346 }
564 - ACLK_SHARED_STATE_UNLOCK;
347 + legacy_aclk_shared_state_UNLOCK;
348 }
349
350 /*
351 * Add a new collector to the list
352 * If it exists, update the chart count
353 */
571 -void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
354 +void legacy_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
355 {
356 struct _collector *tmp_collector;
357 if (unlikely(!netdata_ready)) {
@@ -589,7 +372,7 @@ void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *modu
372 if(aclk_popcorn_check_bump(host))
373 return;
374
592 - if (unlikely(aclk_queue_query("collector", host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT)))
375 + if (unlikely(legacy_aclk_queue_query("collector", host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT)))
376 debug(D_ACLK, "ACLK failed to queue on_connect command on collector addition");
377 }
378
@@ -601,7 +384,7 @@ void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *modu
384 * This function will release the memory used and schedule
385 * a cloud update
386 */
604 -void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
387 +void legacy_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
388 {
389 struct _collector *tmp_collector;
390 if (unlikely(!netdata_ready)) {
@@ -628,7 +411,7 @@ void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *modu
411 if (aclk_popcorn_check_bump(host))
412 return;
413
631 - if (unlikely(aclk_queue_query("collector", host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT)))
414 + if (unlikely(legacy_aclk_queue_query("collector", host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT)))
415 debug(D_ACLK, "ACLK failed to queue on_connect command on collector deletion");
416 }
417
@@ -639,7 +422,7 @@ static void aclk_graceful_disconnect()
422
423 // Send a graceful disconnect message
424 BUFFER *b = buffer_create(512);
642 - aclk_create_header(b, "disconnect", NULL, 0, 0, aclk_shared_state.version_neg);
425 + aclk_create_header(b, "disconnect", NULL, 0, 0, legacy_aclk_shared_state.version_neg);
426 buffer_strcat(b, ",\n\t\"payload\": \"graceful\"}");
427 aclk_send_message(ACLK_METADATA_TOPIC, (char*)buffer_tostring(b), NULL);
428 buffer_free(b);
@@ -963,10 +746,10 @@ static void aclk_try_to_connect(char *hostname, int port)
746 aclk_connecting = 1;
747 create_publish_base_topic();
748
966 - ACLK_SHARED_STATE_LOCK;
967 - aclk_shared_state.version_neg = 0;
968 - aclk_shared_state.version_neg_wait_till = 0;
969 - ACLK_SHARED_STATE_UNLOCK;
749 + legacy_aclk_shared_state_LOCK;
750 + legacy_aclk_shared_state.version_neg = 0;
751 + legacy_aclk_shared_state.version_neg_wait_till = 0;
752 + legacy_aclk_shared_state_UNLOCK;
753
754 rc = mqtt_attempt_connection(hostname, port, aclk_username, aclk_password);
755 if (unlikely(rc)) {
@@ -981,10 +764,10 @@ static inline void aclk_hello_msg()
764
765 char *msg_id = create_uuid();
766
984 - ACLK_SHARED_STATE_LOCK;
985 - aclk_shared_state.version_neg = 0;
986 - aclk_shared_state.version_neg_wait_till = now_monotonic_usec() + USEC_PER_SEC * VERSION_NEG_TIMEOUT;
987 - ACLK_SHARED_STATE_UNLOCK;
767 + legacy_aclk_shared_state_LOCK;
768 + legacy_aclk_shared_state.version_neg = 0;
769 + legacy_aclk_shared_state.version_neg_wait_till = now_monotonic_usec() + USEC_PER_SEC * VERSION_NEG_TIMEOUT;
770 + legacy_aclk_shared_state_UNLOCK;
771
772 //Hello message is versioned separately from the rest of the protocol
773 aclk_create_header(buf, "hello", msg_id, 0, 0, ACLK_VERSION_NEG_VERSION);
@@ -1004,7 +787,7 @@ static inline void aclk_hello_msg()
787 *
788 * @return It always returns NULL
789 */
1007 -void *aclk_main(void *ptr)
790 +void *legacy_aclk_main(void *ptr)
791 {
792 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
793 struct aclk_query_threads query_threads;
@@ -1065,7 +848,7 @@ void *aclk_main(void *ptr)
848 stats_thread->thread = mallocz(sizeof(netdata_thread_t));
849 stats_thread->query_thread_count = query_threads.count;
850 netdata_thread_create(
1068 - stats_thread->thread, ACLK_STATS_THREAD_NAME, NETDATA_THREAD_OPTION_JOINABLE, aclk_stats_main_thread,
851 + stats_thread->thread, ACLK_STATS_THREAD_NAME, NETDATA_THREAD_OPTION_JOINABLE, legacy_aclk_stats_main_thread,
852 stats_thread);
853 }
854
@@ -1165,20 +948,20 @@ void *aclk_main(void *ptr)
948 }
949
950 if (unlikely(!query_threads.thread_list)) {
1168 - aclk_query_threads_start(&query_threads);
951 + legacy_aclk_query_threads_start(&query_threads);
952 }
953
954 time_t now = now_monotonic_sec();
955 if(aclk_connected && last_periodic_query_wakeup < now) {
1173 - // to make `aclk_queue_query()` param `run_after` work
956 + // to make `legacy_aclk_queue_query()` param `run_after` work
957 // also makes per child popcorning work
958 last_periodic_query_wakeup = now;
1176 - QUERY_THREAD_WAKEUP;
959 + LEGACY_QUERY_THREAD_WAKEUP;
960 }
961 } // forever
962 exited:
963 // Wakeup query thread to cleanup
1181 - QUERY_THREAD_WAKEUP_ALL;
964 + LEGACY_QUERY_THREAD_WAKEUP_ALL;
965
966 freez(aclk_username);
967 freez(aclk_password);
@@ -1192,18 +975,18 @@ exited:
975 if (agent_id && aclk_connected) {
976 freez(agent_id);
977 // Wakeup thread to cleanup
1195 - QUERY_THREAD_WAKEUP;
978 + LEGACY_QUERY_THREAD_WAKEUP;
979 aclk_graceful_disconnect();
980 }
981
1199 - aclk_query_threads_cleanup(&query_threads);
982 + legacy_aclk_query_threads_cleanup(&query_threads);
983
984 _reset_collector_list();
985 freez(collector_list);
986
987 if(aclk_stats_enabled) {
988 netdata_thread_join(*stats_thread->thread, NULL);
1206 - aclk_stats_thread_cleanup();
989 + legacy_aclk_stats_thread_cleanup();
990 freez(stats_thread->thread);
991 freez(stats_thread);
992 }
@@ -1306,12 +1089,12 @@ void aclk_connect()
1089 {
1090 info("Connection detected (%u queued queries)", aclk_query_size());
1091
1309 - aclk_stats_upd_online(1);
1092 + legacy_aclk_stats_upd_online(1);
1093
1094 aclk_connected = 1;
1095 aclk_reconnect_delay(0);
1096
1314 - QUERY_THREAD_WAKEUP;
1097 + LEGACY_QUERY_THREAD_WAKEUP;
1098 return;
1099 }
1100
@@ -1321,7 +1104,7 @@ void aclk_disconnect()
1104 if (likely(aclk_connected))
1105 info("Disconnect detected (%u queued queries)", aclk_query_size());
1106
1324 - aclk_stats_upd_online(0);
1107 + legacy_aclk_stats_upd_online(0);
1108
1109 aclk_subscribed = 0;
1110 rrdhost_aclk_state_lock(localhost);
@@ -1372,7 +1155,7 @@ inline void aclk_create_header(BUFFER *dest, char *type, char *msg_id, time_t ts
1155 */
1156 void health_active_log_alarms_2json(RRDHOST *host, BUFFER *wb);
1157
1375 -void aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted)
1158 +void legacy_aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted)
1159 {
1160 BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1161
@@ -1388,9 +1171,9 @@ void aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted)
1171 // session.
1172
1173 if (metadata_submitted == ACLK_METADATA_SENT)
1391 - aclk_create_header(local_buffer, "connect_alarms", msg_id, 0, 0, aclk_shared_state.version_neg);
1174 + aclk_create_header(local_buffer, "connect_alarms", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1175 else
1393 - aclk_create_header(local_buffer, "connect_alarms", msg_id, aclk_session_sec, aclk_session_us, aclk_shared_state.version_neg);
1176 + aclk_create_header(local_buffer, "connect_alarms", msg_id, aclk_session_sec, aclk_session_us, legacy_aclk_shared_state.version_neg);
1177 buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1178
1179
@@ -1418,7 +1201,7 @@ void aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted)
1201 * /api/v1/info
1202 * charts
1203 */
1421 -int aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *host)
1204 +int legacy_aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *host)
1205 {
1206 BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1207
@@ -1433,9 +1216,9 @@ int aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *hos
1216 // a fake on_connect message then use the real timestamp to indicate it is within the existing
1217 // session.
1218 if (metadata_submitted == ACLK_METADATA_SENT)
1436 - aclk_create_header(local_buffer, "update", msg_id, 0, 0, aclk_shared_state.version_neg);
1219 + aclk_create_header(local_buffer, "update", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1220 else
1438 - aclk_create_header(local_buffer, "connect", msg_id, aclk_session_sec, aclk_session_us, aclk_shared_state.version_neg);
1221 + aclk_create_header(local_buffer, "connect", msg_id, aclk_session_sec, aclk_session_us, legacy_aclk_shared_state.version_neg);
1222 buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1223
1224 buffer_sprintf(local_buffer, "{\n\t \"info\" : ");
@@ -1459,14 +1242,14 @@ int aclk_send_info_child_connection(RRDHOST *host, ACLK_CMD cmd)
1242 BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1243 local_buffer->contenttype = CT_APPLICATION_JSON;
1244
1462 - if(aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE)
1463 - fatal("This function should not be called if ACLK version is less than %d (current %d)", ACLK_V_CHILDRENSTATE, aclk_shared_state.version_neg);
1245 + if(legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE)
1246 + fatal("This function should not be called if ACLK version is less than %d (current %d)", ACLK_V_CHILDRENSTATE, legacy_aclk_shared_state.version_neg);
1247
1248 debug(D_ACLK, "Sending Child Disconnect");
1249
1250 char *msg_id = create_uuid();
1251
1469 - aclk_create_header(local_buffer, cmd == ACLK_CMD_CHILD_CONNECT ? "child_connect" : "child_disconnect", msg_id, 0, 0, aclk_shared_state.version_neg);
1252 + aclk_create_header(local_buffer, cmd == ACLK_CMD_CHILD_CONNECT ? "child_connect" : "child_disconnect", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1253
1254 buffer_strcat(local_buffer, ",\"payload\":");
1255
@@ -1489,7 +1272,7 @@ int aclk_send_info_child_connection(RRDHOST *host, ACLK_CMD cmd)
1272 void aclk_host_state_update(RRDHOST *host, ACLK_CMD cmd)
1273 {
1274 #if ACLK_VERSION_MIN < ACLK_V_CHILDRENSTATE
1492 - if (aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE)
1275 + if (legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE)
1276 return;
1277 #else
1278 #warning "This check became unnecessary. Remove"
@@ -1502,12 +1285,12 @@ void aclk_host_state_update(RRDHOST *host, ACLK_CMD cmd)
1285 case ACLK_CMD_CHILD_CONNECT:
1286 debug(D_ACLK, "Child Connected %s %s.", host->hostname, host->machine_guid);
1287 aclk_start_host_popcorning(host);
1505 - aclk_queue_query("add_child", host, NULL, NULL, 0, 1, ACLK_CMD_CHILD_CONNECT);
1288 + legacy_aclk_queue_query("add_child", host, NULL, NULL, 0, 1, ACLK_CMD_CHILD_CONNECT);
1289 break;
1290 case ACLK_CMD_CHILD_DISCONNECT:
1291 debug(D_ACLK, "Child Disconnected %s %s.", host->hostname, host->machine_guid);
1292 aclk_stop_host_popcorning(host);
1510 - aclk_queue_query("del_child", host, NULL, NULL, 0, 1, ACLK_CMD_CHILD_DISCONNECT);
1293 + legacy_aclk_queue_query("del_child", host, NULL, NULL, 0, 1, ACLK_CMD_CHILD_DISCONNECT);
1294 break;
1295 default:
1296 error("Unknown command for aclk_host_state_update %d.", (int)cmd);
@@ -1537,31 +1320,21 @@ void aclk_send_stress_test(size_t size)
1320 // or on request
1321 int aclk_send_metadata(ACLK_METADATA_STATE state, RRDHOST *host)
1322 {
1540 - aclk_send_info_metadata(state, host);
1323 + legacy_aclk_send_info_metadata(state, host);
1324
1325 if(host == localhost)
1543 - aclk_send_alarm_metadata(state);
1326 + legacy_aclk_send_alarm_metadata(state);
1327
1328 return 0;
1329 }
1330
1548 -void aclk_single_update_disable()
1549 -{
1550 - aclk_disable_single_updates = 1;
1551 -}
1552 -
1553 -void aclk_single_update_enable()
1554 -{
1555 - aclk_disable_single_updates = 0;
1556 -}
1557 -
1331 // Triggered by a health reload, sends the alarm metadata
1559 -void aclk_alarm_reload()
1332 +void legacy_aclk_alarm_reload()
1333 {
1334 if (unlikely(aclk_host_initializing(localhost)))
1335 return;
1336
1564 - if (unlikely(aclk_queue_query("on_connect", localhost, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT))) {
1337 + if (unlikely(legacy_aclk_queue_query("on_connect", localhost, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT))) {
1338 if (likely(aclk_connected)) {
1339 errno = 0;
1340 error("ACLK failed to queue on_connect command on alarm reload");
@@ -1585,7 +1358,7 @@ int aclk_send_single_chart(RRDHOST *host, char *chart)
1358 buffer_flush(local_buffer);
1359 local_buffer->contenttype = CT_APPLICATION_JSON;
1360
1588 - aclk_create_header(local_buffer, "chart", msg_id, 0, 0, aclk_shared_state.version_neg);
1361 + aclk_create_header(local_buffer, "chart", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1362 buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1363
1364 rrdset2json(st, local_buffer, NULL, NULL, 1);
@@ -1598,7 +1371,7 @@ int aclk_send_single_chart(RRDHOST *host, char *chart)
1371 return 0;
1372 }
1373
1601 -int aclk_update_chart(RRDHOST *host, char *chart_name, ACLK_CMD aclk_cmd)
1374 +int legacy_aclk_update_chart(RRDHOST *host, char *chart_name, int create)
1375 {
1376 #ifndef ENABLE_ACLK
1377 UNUSED(host);
@@ -1611,7 +1384,7 @@ int aclk_update_chart(RRDHOST *host, char *chart_name, ACLK_CMD aclk_cmd)
1384 if (!netdata_cloud_setting)
1385 return 0;
1386
1614 - if (aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE && host != localhost)
1387 + if (legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE && host != localhost)
1388 return 0;
1389
1390 if (aclk_host_initializing(localhost))
@@ -1623,7 +1396,7 @@ int aclk_update_chart(RRDHOST *host, char *chart_name, ACLK_CMD aclk_cmd)
1396 if (aclk_popcorn_check_bump(host))
1397 return 0;
1398
1626 - if (unlikely(aclk_queue_query("_chart", host, NULL, chart_name, 0, 1, aclk_cmd))) {
1399 + if (unlikely(legacy_aclk_queue_query("_chart", host, NULL, chart_name, 0, 1, create ? ACLK_CMD_CHART : ACLK_CMD_CHARTDEL))) {
1400 if (likely(aclk_connected)) {
1401 errno = 0;
1402 error("ACLK failed to queue chart_update command");
@@ -1634,7 +1407,7 @@ int aclk_update_chart(RRDHOST *host, char *chart_name, ACLK_CMD aclk_cmd)
1407 #endif
1408 }
1409
1637 -int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
1410 +int legacy_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
1411 {
1412 BUFFER *local_buffer = NULL;
1413
@@ -1661,7 +1434,7 @@ int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
1434 char *msg_id = create_uuid();
1435
1436 buffer_flush(local_buffer);
1664 - aclk_create_header(local_buffer, "status-change", msg_id, 0, 0, aclk_shared_state.version_neg);
1437 + aclk_create_header(local_buffer, "status-change", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1438 buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1439
1440 netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
@@ -1670,7 +1443,7 @@ int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
1443
1444 buffer_sprintf(local_buffer, "\n}");
1445
1673 - if (unlikely(aclk_queue_query(ACLK_ALARMS_TOPIC, NULL, msg_id, local_buffer->buffer, 0, 1, ACLK_CMD_ALARM))) {
1446 + if (unlikely(legacy_aclk_queue_query(ACLK_ALARMS_TOPIC, NULL, msg_id, local_buffer->buffer, 0, 1, ACLK_CMD_ALARM))) {
1447 if (likely(aclk_connected)) {
1448 errno = 0;
1449 error("ACLK failed to queue alarm_command on alarm_update");
aclk/legacy/agent_cloud_link.h
+10 -23
@@ -7,7 +7,6 @@
7 #include "mqtt.h"
8 #include "aclk_common.h"
9
10 -#define ACLK_THREAD_NAME "ACLK_Query"
10 #define ACLK_CHART_TOPIC "outbound/meta"
11 #define ACLK_ALARMS_TOPIC "outbound/alarms"
12 #define ACLK_METADATA_TOPIC "outbound/meta"
@@ -18,7 +17,6 @@
17
18 #define ACLK_INITIALIZATION_WAIT 60 // Wait for link to initialize in seconds (per msg)
19 #define ACLK_INITIALIZATION_SLEEP_WAIT 1 // Wait time @ spin lock for MQTT initialization in seconds
21 -#define ACLK_QOS 1
20 #define ACLK_PING_INTERVAL 60
21 #define ACLK_LOOP_TIMEOUT 5 // seconds to wait for operations in the library loop
22
@@ -42,16 +40,7 @@ struct aclk_request {
40
41 typedef enum aclk_init_action { ACLK_INIT, ACLK_REINIT } ACLK_INIT_ACTION;
42
45 -void *aclk_main(void *ptr);
46 -
47 -#define NETDATA_ACLK_HOOK \
48 - { .name = "ACLK_Main", \
49 - .config_section = NULL, \
50 - .config_name = NULL, \
51 - .enabled = 1, \
52 - .thread = NULL, \
53 - .init_routine = NULL, \
54 - .start_routine = aclk_main },
43 +void *legacy_aclk_main(void *ptr);
44
45 extern int aclk_send_message(char *sub_topic, char *message, char *msg_id);
46 extern int aclk_send_message_bin(char *sub_topic, const void *message, size_t len, char *msg_id);
@@ -62,29 +51,27 @@ char *create_uuid();
51
52 // callbacks for agent cloud link
53 int aclk_subscribe(char *topic, int qos);
65 -int cloud_to_agent_parse(JSON_ENTRY *e);
54 +int legacy_cloud_to_agent_parse(JSON_ENTRY *e);
55 void aclk_disconnect();
56 void aclk_connect();
57
58 int aclk_send_metadata(ACLK_METADATA_STATE state, RRDHOST *host);
70 -int aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *host);
71 -void aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted);
59 +int legacy_aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *host);
60 +void legacy_aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted);
61
62 int aclk_wait_for_initialization();
63 char *create_publish_base_topic();
64
65 int aclk_send_single_chart(RRDHOST *host, char *chart);
77 -int aclk_update_chart(RRDHOST *host, char *chart_name, ACLK_CMD aclk_cmd);
78 -int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
66 +int legacy_aclk_update_chart(RRDHOST *host, char *chart_name, int create);
67 +int legacy_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
68 void aclk_create_header(BUFFER *dest, char *type, char *msg_id, time_t ts_secs, usec_t ts_us, int version);
80 -int aclk_handle_cloud_message(char *payload);
81 -void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
82 -void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
83 -void aclk_alarm_reload();
69 +int legacy_aclk_handle_cloud_message(char *payload);
70 +void legacy_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
71 +void legacy_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
72 +void legacy_aclk_alarm_reload(void);
73 unsigned long int aclk_reconnect_delay(int mode);
74 extern void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host);
86 -void aclk_single_update_enable();
87 -void aclk_single_update_disable();
75
76 void aclk_host_state_update(RRDHOST *host, ACLK_CMD cmd);
77 int aclk_send_info_child_connection(RRDHOST *host, ACLK_CMD cmd);
aclk/legacy/mqtt.c
+6 -2
@@ -7,6 +7,10 @@
7 #include "aclk_stats.h"
8 #include "aclk_rx_msgs.h"
9
10 +#include "agent_cloud_link.h"
11 +
12 +#define ACLK_QOS 1
13 +
14 extern usec_t aclk_session_us;
15 extern time_t aclk_session_sec;
16
@@ -27,7 +31,7 @@ void mqtt_message_callback(struct mosquitto *mosq, void *obj, const struct mosqu
31 UNUSED(mosq);
32 UNUSED(obj);
33
30 - aclk_handle_cloud_message(msg->payload);
34 + legacy_aclk_handle_cloud_message(msg->payload);
35 }
36
37 void publish_callback(struct mosquitto *mosq, void *obj, int rc)
@@ -44,7 +48,7 @@ void publish_callback(struct mosquitto *mosq, void *obj, int rc)
48
49 info("Publish_callback: mid=%d latency=%" PRId64 "ms", rc, diff);
50
47 - aclk_metric_mat_update(&aclk_metrics_per_sample.latency, diff);
51 + legacy_aclk_metric_mat_update(&legacy_aclk_metrics_per_sample.latency, diff);
52 #endif
53 return;
54 }
aclk/legacy/mqtt.h
+1 -1
@@ -19,7 +19,7 @@ const char *_link_strerror(int rc);
19 int _link_set_lwt(char *topic, int qos);
20
21
22 -int aclk_handle_cloud_message(char *);
22 +int legacy_aclk_handle_cloud_message(char *);
23 extern char *get_topic(char *sub_topic, char *final_topic, int max_size);
24
25 #endif //NETDATA_MQTT_H
claim/claim.c
+1 -5
@@ -2,11 +2,7 @@
2
3 #include "claim.h"
4 #include "registry/registry_internals.h"
5 -#ifndef ACLK_NG
6 -#include "aclk/legacy/aclk_common.h"
7 -#else
8 -#include "aclk/aclk.h"
9 -#endif
5 +#include "aclk/aclk_api.h"
6
7 char *claiming_pending_arguments = NULL;
8
configure.ac
+81 -72
@@ -193,12 +193,20 @@ AC_ARG_ENABLE(
193 [ enable_cloud="detect" ]
194 )
195
196 +AC_ARG_WITH(
197 + [aclk-legacy],
198 + [AS_HELP_STRING([--with-aclk-legacy],
199 + [Requires Legacy ACLK to be used even in case ACLK-NG can run on this system])],
200 + [aclk_legacy="$withval"],
201 + [aclk_legacy="detect"]
202 +)
203 +
204 AC_ARG_WITH(
205 [aclk-ng],
206 [AS_HELP_STRING([--with-aclk-ng],
207 [Requires ACLK-NG to be used even in case ACLK Legacy can run on this system])],
208 [aclk_ng="$withval"],
201 - [aclk_ng="fallback"]
209 + [aclk_ng="detect"]
210 )
211
212 if test "${enable_cloud}" = "no"; then
@@ -634,11 +642,64 @@ AM_CONDITIONAL([ENABLE_CAPABILITY], [test "${with_libcap}" = "yes"])
642 # -----------------------------------------------------------------------------
643 # ACLK
644
637 -AC_MSG_CHECKING([if cloud functionality should be enabled])
645 +AC_MSG_CHECKING([if Cloud functionality should be enabled])
646 AC_MSG_RESULT([${enable_cloud}])
639 -if test "$enable_cloud" != "no" -a "$aclk_ng" != "yes"; then
640 - # just to have all messages that can fail ACLK build in one place
641 - # so it is easier to see why it can't be built
647 +if test "$aclk_ng" = "no"; then
648 + AC_DEFINE([ACLK_NG_DISABLED], [1], [ACLK NG was disabled by user request])
649 +fi
650 +if test "$aclk_legacy" = "no"; then
651 + AC_DEFINE([ACLK_LEGACY_DISABLED], [1], [ACLK Legacy was disabled by user request])
652 +fi
653 +
654 +if test "$enable_cloud" = "no" -a "$aclk_legacy" = "yes"; then
655 + AC_MSG_ERROR([--disable-cloud && --with-aclk-legacy not allowed together (such configuration is self contradicting)])
656 +fi
657 +
658 +if test "$enable_cloud" = "no" -a "$aclk_ng" = "yes"; then
659 + AC_MSG_ERROR([--disable-cloud && --with-aclk-ng not allowed together (such configuration is self contradicting)])
660 +fi
661 +
662 +if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
663 + AC_MSG_NOTICE([Checking if ACLK Next Generation can be built])
664 + can_enable_ng="yes"
665 + AC_MSG_CHECKING([if git submodules present for ACLK Next Generation])
666 + if test -f "mqtt_websockets/src/mqtt_wss_client.c"; then
667 + AC_MSG_RESULT([yes])
668 + else
669 + AC_MSG_RESULT([no])
670 + can_enable_ng="no"
671 + fi
672 + AC_MSG_CHECKING([if SSL available for ACLK Next Generation])
673 + if test -n "${SSL_LIBS}"; then
674 + AC_MSG_RESULT([yes])
675 + OPTIONAL_SSL_CFLAGS="${SSL_CFLAGS}"
676 + OPTIONAL_SSL_LIBS="${SSL_LIBS}"
677 + else
678 + AC_MSG_RESULT([no])
679 + fi
680 + AC_MSG_CHECKING([if JSON-C available for ACLK Next Generation])
681 + if test "$enable_jsonc" != "yes"; then
682 + AC_MSG_RESULT([no])
683 + can_enable_ng="no"
684 + else
685 + AC_MSG_RESULT([yes])
686 + fi
687 + AC_MSG_CHECKING([ACLK Next Generation can be built])
688 + AC_MSG_RESULT([${can_enable_ng}])
689 + if test "$can_enable_ng" = "no" -a "$aclk_ng" = "yes"; then
690 + AC_MSG_ERROR([You have requested --with-aclk-ng but it can't be built. See reasons in lines above])
691 + fi
692 + if test "$can_enable_ng" = "yes"; then
693 + aclk_ng="yes"
694 + enable_aclk="yes"
695 + AC_DEFINE([ACLK_NG], [1], [ACLK Next Generation Should be used])
696 + AC_DEFINE([ENABLE_ACLK], [1], [netdata ACLK])
697 + OPTIONAL_ACLK_NG_CFLAGS="-I \$(abs_top_srcdir)/mqtt_websockets/src/include -I \$(abs_top_srcdir)/mqtt_websockets/c-rbuf/include -I \$(abs_top_srcdir)/mqtt_websockets/MQTT-C/include"
698 + fi
699 +fi
700 +
701 +if test "$enable_cloud" != "no" -a "$aclk_legacy" != "no"; then
702 + AC_MSG_NOTICE([Checking if ACLK Legacy can be built])
703 if test -n "${SSL_LIBS}"; then
704 OPTIONAL_SSL_CFLAGS="${SSL_CFLAGS}"
705 OPTIONAL_SSL_LIBS="${SSL_LIBS}"
@@ -665,7 +726,7 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "yes"; then
726 AC_MSG_RESULT([${HAVE_libmosquitto_a}])
727
728 if test "${with_bundled_lws}" = "yes"; then
668 - AC_MSG_CHECKING([if libwebsockets static lib is present])
729 + AC_MSG_CHECKING([if libwebsockets static lib is present for ACLK Legacy])
730 if test -f "externaldeps/libwebsockets/libwebsockets.a"; then
731 LWS_CFLAGS="-I \$(abs_top_srcdir)/externaldeps/libwebsockets/include"
732 OPTIONAL_LWS_LIBS="\$(abs_top_srcdir)/externaldeps/libwebsockets/libwebsockets.a"
@@ -677,7 +738,7 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "yes"; then
738 # as currently this is default we prefer building netdata without ACLK
739 # instead of error fail
740 AC_MSG_RESULT([no])
680 - AC_MSG_WARN([You required static libwebsockets to be used but we can't use it. Disabling ACLK])
741 + AC_MSG_WARN([You required static libwebsockets to be used but we can't use it. Disabling ACLK Legacy])
742 fi
743 else
744 AC_CHECK_LIB([websockets],
@@ -686,7 +747,7 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "yes"; then
747 [AC_DEFINE([ACLK_NO_LWS], [1], [usable system libwebsockets was not found during build.])])
748 fi
749
689 - if test "${build_target}" = "linux" -a "${enable_cloud}" != "no"; then
750 + if test "${build_target}" = "linux"; then
751 if test "${have_libcap}" = "yes" -a "${with_libcap}" = "no"; then
752 AC_MSG_ERROR([agent-cloud-link can't be built without libcap. Disable it by --disable-cloud or enable libcap])
753 fi
@@ -696,85 +757,33 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "yes"; then
757 fi
758
759 # next 2 lines are just to have info for ACLK dependencies in common place
699 - AC_MSG_CHECKING([if json-c available for ACLK])
760 + AC_MSG_CHECKING([if json-c available for ACLK Legacy])
761 AC_MSG_RESULT([${enable_jsonc}])
762
702 - test "${enable_cloud}" = "yes" -a "${enable_jsonc}" = "no" && \
703 - AC_MSG_ERROR([You have asked for ACLK to be built but no json-c available. ACLK requires json-c])
704 -
705 - AC_MSG_CHECKING([if netdata agent-cloud-link can be enabled])
763 + AC_MSG_CHECKING([if netdata ACLK Legacy can be built])
764 if test "${HAVE_libmosquitto_a}" = "yes" -a -n "${OPTIONAL_LWS_LIBS}" -a -n "${SSL_LIBS}" -a "${enable_jsonc}" = "yes"; then
707 - can_enable_aclk="yes"
765 + can_build_legacy="yes"
766 else
709 - can_enable_aclk="no"
767 + can_build_legacy="no"
768 fi
711 - AC_MSG_RESULT([${can_enable_aclk}])
712 -
713 -# TODO fix this (you need to try fallback)
714 - test "${enable_cloud}" = "yes" -a "${can_enable_aclk}" = "no" && \
715 - AC_MSG_ERROR([User required agent-cloud-link but it can't be built!])
769 + AC_MSG_RESULT([${can_build_legacy}])
770
717 - AC_MSG_CHECKING([if netdata agent-cloud-link should/will be enabled])
718 - if test "${enable_cloud}" = "detect"; then
719 - enable_aclk=$can_enable_aclk
720 - else
721 - enable_aclk=$enable_cloud
771 + if test "$can_build_legacy" = "no" -a "$aclk_legacy" = "yes"; then
772 + AC_MSG_ERROR([You have requested --with-aclk-legacy but it can't be built. See reasons in lines above])
773 fi
774
724 - if test "${enable_aclk}" = "yes"; then
725 - AC_DEFINE([ENABLE_ACLK], [1], [netdata ACLK])
726 - fi
727 -
728 - AC_MSG_RESULT([${enable_aclk}])
729 -fi
730 -
731 -if test "$enable_cloud" = "no" -a "$aclk_ng" = "yes"; then
732 - AC_MSG_ERROR([--disable-cloud && --aclk-ng not allowed together (such configuration is self contradicting)])
733 -fi
734 -
735 -if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
736 - can_enable_ng="yes"
737 - AC_MSG_CHECKING([if git submodules present for ACLK Next Generation])
738 - if test -f "mqtt_websockets/src/mqtt_wss_client.c"; then
739 - AC_MSG_RESULT([yes])
740 - else
741 - AC_MSG_RESULT([no])
742 - can_enable_ng="no"
743 - fi
744 - AC_MSG_CHECKING([if SSL available for ACLK Next Generation])
745 - if test -n "${SSL_LIBS}"; then
746 - AC_MSG_RESULT([yes])
747 - OPTIONAL_SSL_CFLAGS="${SSL_CFLAGS}"
748 - OPTIONAL_SSL_LIBS="${SSL_LIBS}"
749 - else
750 - AC_MSG_RESULT([no])
751 - fi
752 - AC_MSG_CHECKING([if JSON-C available for ACLK Next Generation])
753 - if test "$enable_jsonc" != "yes"; then
754 - AC_MSG_RESULT([no])
755 - can_enable_ng="no"
756 - else
757 - AC_MSG_RESULT([yes])
758 - fi
759 - AC_MSG_CHECKING([ACLK Next Generation can be built])
760 - AC_MSG_RESULT([${can_enable_ng}])
761 - if test "$aclk_ng" = "yes" -a "$can_enable_ng" != "yes"; then
762 - AC_MSG_ERROR([ACLK-NG requested but can't be built])
763 - fi
764 - if test "$aclk_ng" != "yes" -a "$enable_aclk" == "no" -a "$can_enable_ng" = "yes"; then #default "fallback"
765 - AC_MSG_NOTICE([ACLK Legacy could not be built. Trying ACLK-NG as fallback.])
766 - aclk_ng="yes"
767 - fi
768 - if test "$aclk_ng" = "yes"; then
769 - AC_DEFINE([ACLK_NG], [1], [ACLK Next Generation Should be used])
775 + if test "$can_build_legacy" = "yes"; then
776 + AC_DEFINE([ACLK_LEGACY], [1], [ACLK Legacy Should be used])
777 AC_DEFINE([ENABLE_ACLK], [1], [netdata ACLK])
778 + aclk_legacy="yes"
779 enable_aclk="yes"
772 - OPTIONAL_ACLK_NG_CFLAGS="-I \$(abs_top_srcdir)/mqtt_websockets/src/include -I \$(abs_top_srcdir)/mqtt_websockets/c-rbuf/include -I \$(abs_top_srcdir)/mqtt_websockets/MQTT-C/include"
780 fi
781 fi
782 +
783 AC_SUBST([enable_cloud])
784 AC_SUBST([enable_aclk])
785 AM_CONDITIONAL([ACLK_NG], [test "${aclk_ng}" = "yes"])
786 +AM_CONDITIONAL([ACLK_LEGACY], [test "${aclk_legacy}" = "yes"])
787 AM_CONDITIONAL([ENABLE_ACLK], [test "${enable_aclk}" = "yes"])
788
789 # -----------------------------------------------------------------------------
daemon/buildinfo.c
+44 -39
@@ -9,13 +9,7 @@
9 #ifdef ENABLE_ACLK
10 #define FEAT_CLOUD 1
11 #define FEAT_CLOUD_MSG ""
12 -#ifdef ACLK_NG
13 -#define ACLK_IMPL "Next Generation"
14 -#else
15 -#define ACLK_IMPL "Legacy"
16 -#endif
12 #else
18 -#define ACLK_IMPL ""
13 #ifdef DISABLE_CLOUD
14 #define FEAT_CLOUD 0
15 #define FEAT_CLOUD_MSG "(by user request)"
@@ -69,29 +63,29 @@
63 #define FEAT_LIBCAP 0
64 #endif
65
72 -#ifndef ACLK_NG
73 -#ifdef ACLK_NO_LIBMOSQ
74 -#define FEAT_MOSQUITTO 0
75 -#else
76 -#define FEAT_MOSQUITTO 1
77 -#endif
78 -
79 -#ifdef ACLK_NO_LWS
80 -#define FEAT_LWS 0
81 -#define FEAT_LWS_MSG ""
82 -#else
83 -#ifdef ENABLE_ACLK
84 -#include <libwebsockets.h>
85 -#endif
86 -#ifdef BUNDLED_LWS
87 -#define FEAT_LWS 1
88 -#define FEAT_LWS_MSG "static"
89 -#else
90 -#define FEAT_LWS 1
91 -#define FEAT_LWS_MSG "shared-lib"
92 -#endif
93 -#endif
94 -#endif /* ACLK_NG */
66 +#ifndef ACLK_LEGACY_DISABLED
67 + #ifdef ACLK_NO_LIBMOSQ
68 + #define FEAT_MOSQUITTO 0
69 + #else
70 + #define FEAT_MOSQUITTO 1
71 + #endif
72 +
73 + #ifdef ACLK_NO_LWS
74 + #define FEAT_LWS 0
75 + #define FEAT_LWS_MSG ""
76 + #else
77 + #ifdef ACLK_LEGACY
78 + #include <libwebsockets.h>
79 + #endif
80 + #ifdef BUNDLED_LWS
81 + #define FEAT_LWS 1
82 + #define FEAT_LWS_MSG "static"
83 + #else
84 + #define FEAT_LWS 1
85 + #define FEAT_LWS_MSG "shared-lib"
86 + #endif
87 + #endif
88 +#endif /* ACLK_LEGACY_DISABLED */
89
90 #ifdef NETDATA_WITH_ZLIB
91 #define FEAT_ZLIB 1
@@ -199,6 +193,18 @@
193 #define FEAT_REMOTE_WRITE 0
194 #endif
195
196 +#ifdef ACLK_NG
197 +#define FEAT_ACLK_NG 1
198 +#else
199 +#define FEAT_ACLK_NG 0
200 +#endif
201 +
202 +#ifdef ACLK_LEGACY
203 +#define FEAT_ACLK_LEGACY 1
204 +#else
205 +#define FEAT_ACLK_LEGACY 0
206 +#endif
207 +
208 #define FEAT_YES_NO(x) ((x) ? "YES" : "NO")
209
210 void print_build_info(void) {
@@ -208,9 +214,8 @@ void print_build_info(void) {
214 printf(" dbengine: %s\n", FEAT_YES_NO(FEAT_DBENGINE));
215 printf(" Native HTTPS: %s\n", FEAT_YES_NO(FEAT_NATIVE_HTTPS));
216 printf(" Netdata Cloud: %s %s\n", FEAT_YES_NO(FEAT_CLOUD), FEAT_CLOUD_MSG);
211 -#if FEAT_CLOUD == 1
212 - printf(" Cloud Implementation: %s\n", ACLK_IMPL);
213 -#endif
217 + printf(" ACLK Next Generation: %s\n", FEAT_YES_NO(FEAT_ACLK_NG));
218 + printf(" ACLK Legacy: %s\n", FEAT_YES_NO(FEAT_ACLK_LEGACY));
219 printf(" TLS Host Verification: %s\n", FEAT_YES_NO(FEAT_TLS_HOST_VERIFY));
220
221 printf("Libraries:\n");
@@ -219,8 +224,8 @@ void print_build_info(void) {
224 printf(" libcap: %s\n", FEAT_YES_NO(FEAT_LIBCAP));
225 printf(" libcrypto: %s\n", FEAT_YES_NO(FEAT_CRYPTO));
226 printf(" libm: %s\n", FEAT_YES_NO(FEAT_LIBM));
222 -#ifndef ACLK_NG
223 -#if defined(ENABLE_ACLK)
227 +#ifndef ACLK_LEGACY_DISABLED
228 +#if defined(ACLK_LEGACY)
229 printf(" LWS: %s %s v%d.%d.%d\n", FEAT_YES_NO(FEAT_LWS), FEAT_LWS_MSG, LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH);
230 #else
231 printf(" LWS: %s %s\n", FEAT_YES_NO(FEAT_LWS), FEAT_LWS_MSG);
@@ -266,9 +271,9 @@ void print_build_info_json(void) {
271 #else
272 printf(" \"cloud-disabled\": false,\n");
273 #endif
269 -#if FEAT_CLOUD == 1
270 - printf(" \"cloud-implementation\": \"%s\",\n", ACLK_IMPL);
271 -#endif
274 + printf(" \"aclk-ng\": \"%s\",\n", FEAT_JSON_BOOL(FEAT_ACLK_NG));
275 + printf(" \"aclk-legacy\": \"%s\",\n", FEAT_JSON_BOOL(FEAT_ACLK_LEGACY));
276 +
277 printf(" \"tls-host-verify\": %s\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY));
278 printf(" },\n");
279
@@ -328,8 +333,8 @@ void analytics_build_info(BUFFER *b) {
333 if(FEAT_CRYPTO) buffer_strcat (b, "|libcrypto");
334 if(FEAT_LIBM) buffer_strcat (b, "|libm");
335
331 -#ifndef ACLK_NG
332 -#if defined(ENABLE_ACLK)
336 +#ifndef ACLK_LEGACY_DISABLED
337 +#if defined(ENABLE_ACLK) && defined(ACLK_LEGACY)
338 {
339 char buf[20];
340 snprintfz(buf, 19, "|LWS v%d.%d.%d", LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH);
daemon/common.h
+2 -4
@@ -66,10 +66,8 @@
66 #include "claim/claim.h"
67
68 // netdata agent cloud link
69 -#ifndef ACLK_NG
70 -#include "aclk/legacy/agent_cloud_link.h"
71 -#else
72 -#include "aclk/aclk.h"
69 +#ifdef ENABLE_ACLK
70 +#include "aclk/aclk_api.h"
71 #endif
72
73 // global GUID map functions
database/rrd.h
+1 -6
@@ -34,12 +34,7 @@ struct pg_cache_page_index;
34 #include "rrdcalc.h"
35 #include "rrdcalctemplate.h"
36 #include "streaming/rrdpush.h"
37 -
38 -#ifndef ACLK_NG
39 -#include "aclk/legacy/aclk_rrdhost_state.h"
40 -#else
41 -#include "aclk/aclk.h"
42 -#endif
37 +#include "aclk/aclk_rrdhost_state.h"
38
39 enum {
40 CONTEXT_FLAGS_ARCHIVE = 0x01,
database/rrdset.c
+2 -2
@@ -938,7 +938,7 @@ RRDSET *rrdset_create_custom(
938 rrdhost_cleanup_obsolete_charts(host);
939 #ifdef ENABLE_ACLK
940 if (host->obsolete_count)
941 - aclk_update_chart(st->rrdhost, "dummy-chart", ACLK_CMD_CHARTDEL);
941 + aclk_update_chart(st->rrdhost, "dummy-chart", 0);
942 #endif
943
944 rrdhost_unlock(host);
@@ -1384,7 +1384,7 @@ void rrdset_done(RRDSET *st) {
1384 #ifdef ENABLE_ACLK
1385 if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_ACLK))) {
1386 rrdset_flag_clear(st, RRDSET_FLAG_ACLK);
1387 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
1387 + aclk_update_chart(st->rrdhost, st->id, 1);
1388 }
1389 #endif
1390
netdata-installer.sh
+7 -6
@@ -215,7 +215,7 @@ USAGE: ${PROGRAM} [options]
215 --disable-ebpf Disable eBPF Kernel plugin (Default: enabled)
216 --disable-cloud Disable all Netdata Cloud functionality.
217 --require-cloud Fail the install if it can't build Netdata Cloud support.
218 - --aclk-ng Forces build of ACLK Next Generation which is fallback by default.
218 + --aclk-legacy Forces build of ACLK Legacy which is fallback by default.
219 --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
220 --disable-plugin-freeipmi
221 --disable-https Explicitly disable TLS support
@@ -320,9 +320,9 @@ while [ -n "${1}" ]; do
320 "--disable-go") NETDATA_DISABLE_GO=1 ;;
321 "--enable-ebpf") NETDATA_DISABLE_EBPF=0 ;;
322 "--disable-ebpf") NETDATA_DISABLE_EBPF=1 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-ebpf/} --disable-ebpf" ;;
323 - "--aclk-ng")
324 - NETDATA_ACLK_NG=1
325 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--with-aclk-ng/} --with-aclk-ng"
323 + "--aclk-ng") ;;
324 + "--aclk-legacy")
325 + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--with-aclk-legacy/} --with-aclk-legacy"
326 ;;
327 "--disable-cloud")
328 if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
@@ -572,7 +572,7 @@ copy_libmosquitto() {
572 }
573
574 bundle_libmosquitto() {
575 - if [ -n "${NETDATA_DISABLE_CLOUD}" ] || [ -n "${NETDATA_ACLK_NG}" ]; then
575 + if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
576 echo "Skipping libmosquitto"
577 return 0
578 fi
@@ -674,7 +674,8 @@ copy_libwebsockets() {
674 }
675
676 bundle_libwebsockets() {
677 - if [ -n "${NETDATA_DISABLE_CLOUD}" ] || [ -n "${USE_SYSTEM_LWS}" ] || [ -n "${NETDATA_ACLK_NG}" ]; then
677 + if [ -n "${NETDATA_DISABLE_CLOUD}" ] || [ -n "${USE_SYSTEM_LWS}" ]; then
678 + echo "Skipping libwebsockets"
679 return 0
680 fi
681
web/api/web_api_v1.c
+14 -2
@@ -980,10 +980,22 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
980 #ifdef ENABLE_ACLK
981 buffer_strcat(wb, "\t\"cloud-available\": true,\n");
982 #ifdef ACLK_NG
983 - buffer_strcat(wb, "\t\"aclk-implementation\": \"Next Generation\",\n");
983 + buffer_strcat(wb, "\t\"aclk-ng-available\": true,\n");
984 #else
985 - buffer_strcat(wb, "\t\"aclk-implementation\": \"legacy\",\n");
985 + buffer_strcat(wb, "\t\"aclk-ng-available\": false,\n");
986 #endif
987 +#ifdef ACLK_LEGACY
988 + buffer_strcat(wb, "\t\"aclk-legacy-available\": true,\n");
989 +#else
990 + buffer_strcat(wb, "\t\"aclk-legacy-available\": false,\n");
991 +#endif
992 + buffer_strcat(wb, "\t\"aclk-implementation\": \"");
993 + if (aclk_ng) {
994 + buffer_strcat(wb, "Next Generation");
995 + } else {
996 + buffer_strcat(wb, "legacy");
997 + }
998 + buffer_strcat(wb, "\",\n");
999 #else
1000 buffer_strcat(wb, "\t\"cloud-available\": false,\n");
1001 #endif