diff options
41 files changed, 998 insertions, 1225 deletions
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7e47f12da4..72c789582a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,7 +52,7 @@ jobs: - name: Configure run: | autoreconf -ivf - ./configure --without-aclk-ng + ./configure # XXX: Work-around for bug with libbson-1.0 in Ubuntu 18.04 # See: https://bugs.launchpad.net/ubuntu/+source/libmongoc/+bug/1790771 # https://jira.mongodb.org/browse/CDRIVER-2818 diff --git a/CMakeLists.txt b/CMakeLists.txt index ce737436ee..c5d4bc8f52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -730,12 +730,22 @@ set(BACKENDS_PLUGIN_FILES set(CLAIM_PLUGIN_FILES claim/claim.c claim/claim.h - aclk/legacy/aclk_rrdhost_state.h - aclk/legacy/aclk_common.c - aclk/legacy/aclk_common.h ) -set(ACLK_PLUGIN_FILES +set(ACLK_ALWAYS_BUILD + aclk/aclk_rrdhost_state.h + aclk/aclk_api.c + aclk/aclk_api.h + aclk/aclk_proxy.c + aclk/aclk_proxy.h + ) + +set(ACLK_COMMON_FILES + aclk/aclk_collector_list.c + aclk/aclk_collector_list.h + ) + +set(ACLK_LEGACY_FILES aclk/legacy/agent_cloud_link.c aclk/legacy/agent_cloud_link.h aclk/legacy/aclk_query.c @@ -750,6 +760,40 @@ set(ACLK_PLUGIN_FILES aclk/legacy/aclk_stats.h aclk/legacy/aclk_rx_msgs.c aclk/legacy/aclk_rx_msgs.h + aclk/legacy/aclk_common.c + aclk/legacy/aclk_common.h + ) + +set(ACLK_NG_FILES + aclk/aclk.c + aclk/aclk.h + aclk/aclk_util.c + aclk/aclk_util.h + aclk/aclk_stats.c + aclk/aclk_stats.h + aclk/aclk_query.c + aclk/aclk_query.h + aclk/aclk_query_queue.c + aclk/aclk_query_queue.h + aclk/aclk_otp.c + aclk/aclk_otp.h + aclk/aclk_tx_msgs.c + aclk/aclk_tx_msgs.h + aclk/aclk_rx_msgs.c + aclk/aclk_rx_msgs.h + aclk/https_client.c + aclk/https_client.h + mqtt_websockets/src/mqtt_wss_client.c + mqtt_websockets/src/include/mqtt_wss_client.h + mqtt_websockets/src/mqtt_wss_log.c + mqtt_websockets/src/include/mqtt_wss_log.h + mqtt_websockets/src/ws_client.c + mqtt_websockets/src/include/ws_client.h + mqtt_websockets/c-rbuf/src/ringbuffer.c + mqtt_websockets/c-rbuf/include/ringbuffer.h + mqtt_websockets/c-rbuf/src/ringbuffer_internal.h + mqtt_websockets/MQTT-C/src/mqtt.c + mqtt_websockets/MQTT-C/include/mqtt.h ) set(SPAWN_PLUGIN_FILES @@ -759,7 +803,7 @@ set(SPAWN_PLUGIN_FILES spawn/spawn.h ) -set(ACLK_STATIC_LIBS +set(ACLK_LEGACY_STATIC_LIBS ${CMAKE_SOURCE_DIR}/externaldeps/mosquitto/libmosquitto.a ${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/libwebsockets.a ) @@ -967,21 +1011,21 @@ ENDIF() set(NETDATA_COMMON_LIBRARIES ${NETDATA_COMMON_LIBRARIES} m ${CMAKE_THREAD_LIBS_INIT}) -set(ACLK_CAN_BUILD 1) +set(ACLK_LEGACY_CAN_BUILD 1) if(NOT EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/mosquitto/libmosquitto.a") message(WARNING "Static build of mosquitto not found. Disabling ACLK") - set(ACLK_CAN_BUILD 0) + set(ACLK_LEGACY_CAN_BUILD 0) ENDIF() if(NOT EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/libwebsockets.a") message(WARNING "Static build of libwebsockets not found. Disabling ACLK") - set(ACLK_CAN_BUILD 0) + set(ACLK_LEGACY_CAN_BUILD 0) ENDIF() -IF(ACLK_CAN_BUILD) - message(STATUS "agent-cloud-link: enabled") - list(APPEND NETDATA_FILES ${ACLK_PLUGIN_FILES}) - list(APPEND NETDATA_COMMON_LIBRARIES ${ACLK_STATIC_LIBS}) +IF(ACLK_LEGACY_CAN_BUILD) + message(STATUS "agent-cloud-link Legacy: enabled") + list(APPEND NETDATA_FILES ${ACLK_LEGACY_FILES}) + list(APPEND NETDATA_COMMON_LIBRARIES ${ACLK_LEGACY_STATIC_LIBS}) include_directories(BEFORE ${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/include) IF(LINUX AND CAP_FOUND) list(APPEND NETDATA_COMMON_LIBRARIES ${CAP_LIBRARIES}) @@ -989,9 +1033,16 @@ IF(ACLK_CAN_BUILD) list(APPEND NETDATA_COMMON_CFLAGS ${CAP_CFLAGS_OTHER}) ENDIF() ELSE() - message(STATUS "agent-cloud-link: disabled") + message(STATUS "agent-cloud-link Legacy: disabled") ENDIF() +list(APPEND NETDATA_FILES ${ACLK_ALWAYS_BUILD}) +list(APPEND NETDATA_FILES ${ACLK_NG_FILES}) +list(APPEND NETDATA_FILES ${ACLK_COMMON_FILES}) +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/MQTT-C/include) +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/src/include) +include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/c-rbuf/include) + # ----------------------------------------------------------------------------- # netdata diff --git a/Makefile.am b/Makefile.am index da23b4b15d..1c98e30b6a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -114,7 +114,7 @@ SUBDIRS += \ spawn \ $(NULL) -if !ACLK_NG +if ENABLE_ACLK SUBDIRS += \ aclk/legacy \ $(NULL) @@ -540,7 +540,7 @@ PARSER_FILES = \ $(NULL) if ACLK_NG -ACLK_FILES = \ +ACLK_NG_FILES = \ aclk/aclk.c \ aclk/aclk.h \ aclk/aclk_util.c \ @@ -551,8 +551,6 @@ ACLK_FILES = \ aclk/aclk_query.h \ aclk/aclk_query_queue.c \ aclk/aclk_query_queue.h \ - aclk/aclk_collector_list.c \ - aclk/aclk_collector_list.h \ aclk/aclk_otp.c \ aclk/aclk_otp.h \ aclk/aclk_tx_msgs.c \ @@ -573,17 +571,25 @@ ACLK_FILES = \ mqtt_websockets/MQTT-C/src/mqtt.c \ mqtt_websockets/MQTT-C/include/mqtt.h \ $(NULL) -else #ACLK_NG -ACLK_FILES = \ - aclk/legacy/aclk_rrdhost_state.h \ - aclk/legacy/aclk_common.c \ - aclk/legacy/aclk_common.h \ - aclk/legacy/aclk_stats.c \ - aclk/legacy/aclk_stats.h \ - $(NULL) +endif #ACLK_NG if ENABLE_ACLK -ACLK_FILES += \ +ACLK_COMMON_FILES = \ + aclk/aclk_collector_list.c \ + aclk/aclk_collector_list.h \ + $(NULL) +endif + +ACLK_ALWAYS_BUILD_FILES = \ + aclk/aclk_rrdhost_state.h \ + aclk/aclk_api.c \ + aclk/aclk_api.h \ + aclk/aclk_proxy.c \ + aclk/aclk_proxy.h \ + $(NULL) + +if ACLK_LEGACY +ACLK_LEGACY_FILES = \ aclk/legacy/agent_cloud_link.c \ aclk/legacy/agent_cloud_link.h \ aclk/legacy/aclk_query.c \ @@ -596,9 +602,12 @@ ACLK_FILES += \ aclk/legacy/aclk_lws_wss_client.h \ aclk/legacy/aclk_lws_https_client.c \ aclk/legacy/aclk_lws_https_client.h \ + aclk/legacy/aclk_common.c \ + aclk/legacy/aclk_common.h \ + aclk/legacy/aclk_stats.c \ + aclk/legacy/aclk_stats.h \ $(NULL) -endif #ENABLE_ACLK -endif #ACLK_NG +endif #ACLK_LEGACY SPAWN_PLUGIN_FILES = \ spawn/spawn.c \ @@ -710,7 +719,10 @@ NETDATA_FILES = \ $(WEB_PLUGIN_FILES) \ $(CLAIM_FILES) \ $(PARSER_FILES) \ - $(ACLK_FILES) \ + $(ACLK_ALWAYS_BUILD_FILES) \ + $(ACLK_COMMON_FILES) \ + $(ACLK_LEGACY_FILES) \ + $(ACLK_NG_FILES) \ $(SPAWN_PLUGIN_FILES) \ $(NULL) @@ -770,16 +782,14 @@ netdata_LDADD = \ $(NETDATA_COMMON_LIBS) \ $(NULL) -if !ACLK_NG -if ENABLE_ACLK +if ACLK_LEGACY netdata_LDADD += \ $(abs_top_srcdir)/externaldeps/mosquitto/libmosquitto.a \ $(OPTIONAL_LIBCAP_LIBS) \ $(OPTIONAL_LWS_LIBS) \ $(NETDATA_COMMON_LIBS) \ $(NULL) -endif #ENABLE_ACLK -endif #ACLK_NG +endif #ACLK_LEGACY if ENABLE_CXX_LINKER netdata_LINK = $(CXXLD) $(CXXFLAGS) $(LDFLAGS) -o $@ diff --git a/aclk/aclk.c b/aclk/aclk.c index 3e538a5f4c..7e8c1c32e0 100644 --- a/aclk/aclk.c +++ b/aclk/aclk.c @@ -13,6 +13,8 @@ #include "aclk_collector_list.h" #include "https_client.h" +#include "aclk_proxy.h" + #ifdef ACLK_LOG_CONVERSATION_DIR #include <sys/types.h> #include <sys/stat.h> @@ -21,19 +23,10 @@ #define ACLK_STABLE_TIMEOUT 3 // Minimum delay to mark AGENT as stable -//TODO remove most (as in 99.999999999%) of this crap -int aclk_connected = 0; -int aclk_disable_runtime = 0; -int aclk_disable_single_updates = 0; -int aclk_kill_link = 0; - int aclk_pubacks_per_conn = 0; // How many PubAcks we got since MQTT conn est. time_t aclk_block_until = 0; -usec_t aclk_session_us = 0; // Used by the mqtt layer -time_t aclk_session_sec = 0; // Used by the mqtt layer - aclk_env_t *aclk_env = NULL; mqtt_wss_client mqttwss_client; @@ -43,22 +36,12 @@ netdata_mutex_t aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER; #define ACLK_SHARED_STATE_UNLOCK netdata_mutex_unlock(&aclk_shared_state_mutex) struct aclk_shared_state aclk_shared_state = { - .agent_state = AGENT_INITIALIZING, + .agent_state = ACLK_HOST_INITIALIZING, .last_popcorn_interrupt = 0, .mqtt_shutdown_msg_id = -1, .mqtt_shutdown_msg_rcvd = 0 }; -void aclk_single_update_disable() -{ - aclk_disable_single_updates = 1; -} - -void aclk_single_update_enable() -{ - aclk_disable_single_updates = 0; -} - //ENDTODO static RSA *aclk_private_key = NULL; @@ -301,7 +284,7 @@ static int handle_connection(mqtt_wss_client client) inline static int aclk_popcorn_check_bump() { ACLK_SHARED_STATE_LOCK; - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) { + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) { aclk_shared_state.last_popcorn_interrupt = now_realtime_sec(); ACLK_SHARED_STATE_UNLOCK; return 1; @@ -340,7 +323,7 @@ static inline void mqtt_connected_actions(mqtt_wss_client client) aclk_pubacks_per_conn = 0; ACLK_SHARED_STATE_LOCK; - if (aclk_shared_state.agent_state != AGENT_INITIALIZING) { + if (aclk_shared_state.agent_state != ACLK_HOST_INITIALIZING) { error("Sending `connect` payload immediately as popcorning was finished already."); queue_connect_payloads(); } @@ -360,13 +343,13 @@ static int wait_popcorning_finishes(mqtt_wss_client client, struct aclk_query_th int need_wait; while (!netdata_exit) { ACLK_SHARED_STATE_LOCK; - if (likely(aclk_shared_state.agent_state != AGENT_INITIALIZING)) { + if (likely(aclk_shared_state.agent_state != ACLK_HOST_INITIALIZING)) { ACLK_SHARED_STATE_UNLOCK; return 0; } elapsed = now_realtime_sec() - aclk_shared_state.last_popcorn_interrupt; if (elapsed >= ACLK_STABLE_TIMEOUT) { - aclk_shared_state.agent_state = AGENT_STABLE; + aclk_shared_state.agent_state = ACLK_HOST_STABLE; ACLK_SHARED_STATE_UNLOCK; error("ACLK localhost popocorn finished"); if (unlikely(!query_threads->thread_list)) @@ -721,10 +704,10 @@ exit: // fix this in both old and new ACLK extern void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host); -void aclk_alarm_reload(void) +void ng_aclk_alarm_reload(void) { ACLK_SHARED_STATE_LOCK; - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) { + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) { ACLK_SHARED_STATE_UNLOCK; return; } @@ -733,7 +716,7 @@ void aclk_alarm_reload(void) aclk_queue_query(aclk_query_new(METADATA_ALARMS)); } -int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae) +int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae) { BUFFER *local_buffer; json_object *msg; @@ -742,7 +725,7 @@ int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae) return 0; ACLK_SHARED_STATE_LOCK; - if (unlikely(aclk_shared_state.agent_state == AGENT_INITIALIZING)) { + if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) { ACLK_SHARED_STATE_UNLOCK; return 0; } @@ -764,7 +747,7 @@ int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae) return 0; } -int aclk_update_chart(RRDHOST *host, char *chart_name, int create) +int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create) { struct aclk_query *query; @@ -788,7 +771,7 @@ int aclk_update_chart(RRDHOST *host, char *chart_name, int create) * Add a new collector to the list * If it exists, update the chart count */ -void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name) +void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name) { struct aclk_query *query; struct _collector *tmp_collector; @@ -831,7 +814,7 @@ void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *modu * This function will release the memory used and schedule * a cloud update */ -void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name) +void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name) { struct aclk_query *query; struct _collector *tmp_collector; @@ -871,27 +854,3 @@ void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *modu query->data.metadata_alarms.initial_on_connect = 0; aclk_queue_query(query); } - -struct label *add_aclk_host_labels(struct label *label) { -#ifdef ENABLE_ACLK - ACLK_PROXY_TYPE aclk_proxy; - char *proxy_str; - aclk_get_proxy(&aclk_proxy); - - switch(aclk_proxy) { - case PROXY_TYPE_SOCKS5: - proxy_str = "SOCKS5"; - break; - case PROXY_TYPE_HTTP: - proxy_str = "HTTP"; - break; - default: - proxy_str = "none"; - break; - } - label = add_label_to_list(label, "_aclk_impl", "Next Generation", LABEL_SOURCE_AUTO); - return add_label_to_list(label, "_aclk_proxy", proxy_str, LABEL_SOURCE_AUTO); -#else - return label; -#endif -} diff --git a/aclk/aclk.h b/aclk/aclk.h index 3245f70af2..ab5332dc14 100644 --- a/aclk/aclk.h +++ b/aclk/aclk.h @@ -2,57 +2,24 @@ #ifndef ACLK_H #define ACLK_H -typedef struct aclk_rrdhost_state { - char *claimed_id; // Claimed ID if host has one otherwise NULL -} aclk_rrdhost_state; - #include "daemon/common.h" #include "aclk_util.h" - -// version for aclk legacy (old cloud arch) -#define ACLK_VERSION 2 - -// Define ACLK Feature Version Boundaries Here -#define ACLK_V_COMPRESSION 2 +#include "aclk_rrdhost_state.h" // How many MQTT PUBACKs we need to get to consider connection // stable for the purposes of TBEB (truncated binary exponential backoff) #define ACLK_PUBACKS_CONN_STABLE 3 -// TODO get rid of this shit -extern int aclk_disable_runtime; -extern int aclk_disable_single_updates; -extern int aclk_kill_link; -extern int aclk_connected; - extern time_t aclk_block_until; -extern usec_t aclk_session_us; -extern time_t aclk_session_sec; - extern aclk_env_t *aclk_env; void *aclk_main(void *ptr); -void aclk_single_update_disable(); -void aclk_single_update_enable(); - -#define NETDATA_ACLK_HOOK \ - { .name = "ACLK_Main", \ - .config_section = NULL, \ - .config_name = NULL, \ - .enabled = 1, \ - .thread = NULL, \ - .init_routine = NULL, \ - .start_routine = aclk_main }, extern netdata_mutex_t aclk_shared_state_mutex; #define ACLK_SHARED_STATE_LOCK netdata_mutex_lock(&aclk_shared_state_mutex) #define ACLK_SHARED_STATE_UNLOCK netdata_mutex_unlock(&aclk_shared_state_mutex) -typedef enum aclk_agent_state { - AGENT_INITIALIZING, - AGENT_STABLE -} ACLK_AGENT_STATE; extern struct aclk_shared_state { ACLK_AGENT_STATE agent_state; time_t last_popcorn_interrupt; @@ -65,20 +32,15 @@ extern struct aclk_shared_state { int mqtt_shutdown_msg_rcvd; } aclk_shared_state; -void aclk_alarm_reload(void); -int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae); +void ng_aclk_alarm_reload(void); +int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae); -// TODO this is for bacward compatibility with ACLK legacy -#define ACLK_CMD_CHART 1 -#define ACLK_CMD_CHARTDEL 0 /* Informs ACLK about created/deleted chart * @param create 0 - if chart was deleted, other if chart created */ -int aclk_update_chart(RRDHOST *host, char *chart_name, int create); - -void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name); -void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name); +int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create); -struct label *add_aclk_host_labels(struct label *label); +void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name); +void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name); #endif /* ACLK_H */ diff --git a/aclk/aclk_api.c b/aclk/aclk_api.c new file mode 100644 index 0000000000..9360ce349a --- /dev/null +++ b/aclk/aclk_api.c @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#include "libnetdata/libnetdata.h" +#include "database/rrd.h" + +#ifdef ACLK_NG +#include "aclk.h" +#endif +#ifdef ACLK_LEGACY +#include "legacy/agent_cloud_link.h" +#endif + +int aclk_connected = 0; +int aclk_kill_link = 0; + +usec_t aclk_session_us = 0; +time_t aclk_session_sec = 0; + +int aclk_disable_runtime = 0; +int aclk_disable_single_updates = 0; + +int aclk_stats_enabled; + +#ifdef ACLK_LEGACY +int aclk_ng = 0; +#else +int aclk_ng = 1; +#endif + +#define ACLK_IMPL_KEY_NAME "aclk implementation" + +#ifdef ENABLE_ACLK +void *aclk_starter(void *ptr) { + char *aclk_impl_req = config_get(CONFIG_SECTION_CLOUD, ACLK_IMPL_KEY_NAME, "legacy"); + + if (!strcasecmp(aclk_impl_req, "ng")) { + aclk_ng = 1; + } else if (!strcasecmp(aclk_impl_req, "legacy")) { + aclk_ng = 0; + } else { + 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"); + } + +#ifndef ACLK_NG + if (aclk_ng) { + error("Configuration requests ACLK-NG but it is not available in this agent. Switching to Legacy."); + aclk_ng = 0; + } +#endif + +#ifndef ACLK_LEGACY + if (!aclk_ng) { + error("Configuration requests ACLK Legacy but it is not available in this agent. Switching to NG."); + aclk_ng = 1; + } +#endif + +#ifdef ACLK_NG + if (aclk_ng) + return aclk_main(ptr); +#endif +#ifdef ACLK_LEGACY + if (!aclk_ng) + return legacy_aclk_main(ptr); +#endif + error_report("No ACLK could be started"); + return NULL; +} + +void aclk_single_update_disable() +{ + aclk_disable_single_updates = 1; +} + +void aclk_single_update_enable() +{ + aclk_disable_single_updates = 0; +} + +void aclk_alarm_reload(void) +{ +#ifdef ACLK_NG + if (aclk_ng) + ng_aclk_alarm_reload(); +#endif +#ifdef ACLK_LEGACY + if (!aclk_ng) + legacy_aclk_alarm_reload(); +#endif +} + +int aclk_update_chart(RRDHOST *host, char *chart_name, int create) +{ +#ifdef ACLK_NG + if (aclk_ng) + return ng_aclk_update_chart(host, chart_name, create); +#endif +#ifdef ACLK_LEGACY + if (!aclk_ng) + return legacy_aclk_update_chart(host, chart_name, create); +#endif + error_report("No usable aclk_update_chart implementation"); + return 1; +} + +int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae) +{ +#ifdef ACLK_NG + if (aclk_ng) + return ng_aclk_update_alarm(host, ae); +#endif +#ifdef ACLK_LEGACY + if (!aclk_ng) + return legacy_aclk_update_alarm(host, ae); +#endif + error_report("No usable aclk_update_alarm implementation"); + return 1; +} + +void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name) +{ +#ifdef ACLK_NG + if (aclk_ng) + return ng_aclk_add_collector(host, plugin_name, module_name); +#endif +#ifdef ACLK_LEGACY + if (!aclk_ng) + return legacy_aclk_add_collector(host, plugin_name, module_name); +#endif + error_report("No usable aclk_add_collector implementation"); +} + +void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name) +{ +#ifdef ACLK_NG + if (aclk_ng) + return ng_aclk_del_collector(host, plugin_name, module_name); +#endif +#ifdef ACLK_LEGACY + if (!aclk_ng) + return legacy_aclk_del_collector(host, plugin_name, module_name); +#endif + error_report("No usable aclk_del_collector implementation"); +} + +#endif /* ENABLE_ACLK */ + +struct label *add_aclk_host_labels(struct label *label) { +#ifdef ACLK_NG + label = add_label_to_list(label, "_aclk_ng_available", "true", LABEL_SOURCE_AUTO); +#else + label = add_label_to_list(label, "_aclk_ng_available", "false", LABEL_SOURCE_AUTO); +#endif +#ifdef ACLK_LEGACY + label = add_label_to_list(label, "_aclk_legacy_available", "true", LABEL_SOURCE_AUTO); +#else + label = add_label_to_list(label, "_aclk_legacy_available", "false", LABEL_SOURCE_AUTO); +#endif +#ifdef ENABLE_ACLK + ACLK_PROXY_TYPE aclk_proxy; + char *proxy_str; + aclk_get_proxy(&aclk_proxy); + + switch(aclk_proxy) { + case PROXY_TYPE_SOCKS5: + proxy_str = "SOCKS5"; + break; + case PROXY_TYPE_HTTP: + proxy_str = "HTTP"; + break; + default: + proxy_str = "none"; + break; + } + + label = add_label_to_list(label, "_aclk_impl", aclk_ng ? "Next Generation" : "Legacy", LABEL_SOURCE_AUTO); + label = add_label_to_list(label, "_aclk_proxy", proxy_str, LABEL_SOURCE_AUTO); +#endif + return label; +} diff --git a/aclk/aclk_api.h b/aclk/aclk_api.h new file mode 100644 index 0000000000..b76530c5ea --- /dev/null +++ b/aclk/aclk_api.h @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#ifndef ACLK_API_H +#define ACLK_API_H + +#include "libnetdata/libnetdata.h" + +#include "aclk_proxy.h" + +// TODO get rid global vars as soon as +// ACLK Legacy is removed +extern int aclk_connected; +extern int aclk_kill_link; + +extern usec_t aclk_session_us; +extern time_t aclk_session_sec; + +extern int aclk_disable_runtime; +extern int aclk_disable_single_updates; + +extern int aclk_stats_enabled; + +extern int aclk_ng; + +#ifdef ENABLE_ACLK +void *aclk_starter(void *ptr); + +void aclk_single_update_disable(); +void aclk_single_update_enable(); + +void aclk_alarm_reload(void); + +int aclk_update_chart(RRDHOST *host, char *chart_name, int create); +int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae); + +void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name); +void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name); + +#define NETDATA_ACLK_HOOK \ + { .name = "ACLK_Main", \ + .config_section = NULL, \ + .config_name = NULL, \ + .enabled = 1, \ + .thread = NULL, \ + .init_routine = NULL, \ + .start_routine = aclk_starter }, + +#endif + +struct label *add_aclk_host_labels(struct label *label); + +#endif /* ACLK_API_H */ |