diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2022-08-24 10:41:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 10:41:14 +0200 |
commit | 971fe355478c015a858a4428bf408ca2c2395c42 (patch) | |
tree | 32b1b1dffc40c0880a4576604e8776099040d380 | |
parent | efd9989bc6edb5f32ef60cd53d237929a93f425f (diff) |
Remove aclk_api.[ch] (#13540)
* get rid of aclk_starter middleman
* get rid of aclk_api.[ch]
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | aclk/aclk.c | 60 | ||||
-rw-r--r-- | aclk/aclk.h | 22 | ||||
-rw-r--r-- | aclk/aclk_api.c | 88 | ||||
-rw-r--r-- | aclk/aclk_api.h | 45 | ||||
-rw-r--r-- | aclk/aclk_util.c | 1 | ||||
-rw-r--r-- | claim/claim.c | 3 | ||||
-rw-r--r-- | daemon/buildinfo.c | 1 | ||||
-rw-r--r-- | daemon/common.h | 2 | ||||
-rw-r--r-- | daemon/static_threads.c | 4 | ||||
-rw-r--r-- | database/rrdcontext.c | 2 | ||||
-rw-r--r-- | web/api/web_api_v1.c | 1 |
13 files changed, 89 insertions, 152 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9752f37187..901023fd1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -860,15 +860,13 @@ set(CLAIM_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 + aclk/aclk.c + aclk/aclk.h ) set(ACLK_FILES - aclk/aclk.c - aclk/aclk.h aclk/aclk_util.c aclk/aclk_util.h aclk/aclk_stats.c diff --git a/Makefile.am b/Makefile.am index 7f8adf6afd..153731f978 100644 --- a/Makefile.am +++ b/Makefile.am @@ -676,8 +676,6 @@ PARSER_FILES = \ if ENABLE_ACLK ACLK_FILES = \ - aclk/aclk.c \ - aclk/aclk.h \ aclk/aclk_util.c \ aclk/aclk_util.h \ aclk/aclk_stats.c \ @@ -860,10 +858,10 @@ endif #ENABLE_ACLK 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 \ + aclk/aclk.c \ + aclk/aclk.h \ $(NULL) SPAWN_PLUGIN_FILES = \ diff --git a/aclk/aclk.c b/aclk/aclk.c index 7b3641b1e2..cfd85ad3a3 100644 --- a/aclk/aclk.c +++ b/aclk/aclk.c @@ -2,6 +2,7 @@ #include "aclk.h" +#ifdef ENABLE_ACLK #include "aclk_stats.h" #include "mqtt_wss_client.h" #include "aclk_otp.h" @@ -23,11 +24,23 @@ #define ACLK_STABLE_TIMEOUT 3 // Minimum delay to mark AGENT as stable +#endif /* ENABLE_ACLK */ + int aclk_pubacks_per_conn = 0; // How many PubAcks we got since MQTT conn est. int aclk_rcvd_cloud_msgs = 0; int aclk_connection_counter = 0; int disconnect_req = 0; +int aclk_connected = 0; +int use_mqtt_5 = 0; +int aclk_ctx_based = 0; +int aclk_disable_runtime = 0; +int aclk_stats_enabled; +int aclk_kill_link = 0; + +usec_t aclk_session_us = 0; +time_t aclk_session_sec = 0; + time_t last_conn_time_mqtt = 0; time_t last_conn_time_appl = 0; time_t last_disconnect_time = 0; @@ -38,6 +51,7 @@ int aclk_alert_reloaded = 0; //1 on health log exchange, and again on health_rel time_t aclk_block_until = 0; +#ifdef ENABLE_ACLK mqtt_wss_client mqttwss_client; netdata_mutex_t aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER; @@ -923,9 +937,13 @@ static void fill_chart_status_for_host(BUFFER *wb, RRDHOST *host) ); freez(stats); } +#endif /* ENABLE_ACLK */ -char *ng_aclk_state(void) +char *aclk_state(void) { +#ifndef ENABLE_ACLK + return strdupz("ACLK Available: No"); +#else BUFFER *wb = buffer_create(1024); struct tm *tmptr, tmbuf; char *ret; @@ -1010,8 +1028,10 @@ char *ng_aclk_state(void) ret = strdupz(buffer_tostring(wb)); buffer_free(wb); return ret; +#endif /* ENABLE_ACLK */ } +#ifdef ENABLE_ACLK static void fill_alert_status_for_host_json(json_object *obj, RRDHOST *host) { struct proto_alert_status status; @@ -1087,9 +1107,13 @@ static json_object *timestamp_to_json(const time_t *t) } return NULL; } +#endif /* ENABLE_ACLK */ -char *ng_aclk_state_json(void) +char *aclk_state_json(void) { +#ifndef ENABLE_ACLK + return strdupz("{\"aclk-available\":false}"); +#else json_object *tmp, *grp, *msg = json_object_new_object(); tmp = json_object_new_boolean(1); @@ -1203,4 +1227,36 @@ char *ng_aclk_state_json(void) char *str = strdupz(json_object_to_json_string_ext(msg, JSON_C_TO_STRING_PLAIN)); json_object_put(msg); return str; +#endif /* ENABLE_ACLK */ +} + +void add_aclk_host_labels(void) { + DICTIONARY *labels = localhost->host_labels; + +#ifdef ENABLE_ACLK + rrdlabels_add(labels, "_aclk_available", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_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; + } + + int mqtt5 = config_get_boolean(CONFIG_SECTION_CLOUD, "mqtt5", CONFIG_BOOLEAN_YES); + + rrdlabels_add(labels, "_mqtt_version", mqtt5 ? "5" : "3", RRDLABEL_SRC_AUTO); + rrdlabels_add(labels, "_aclk_proxy", proxy_str, RRDLABEL_SRC_AUTO); + rrdlabels_add(labels, "_aclk_ng_new_cloud_protocol", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); +#else + rrdlabels_add(labels, "_aclk_available", "false", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); +#endif } diff --git a/aclk/aclk.h b/aclk/aclk.h index 5065ac2bfc..061977c0b8 100644 --- a/aclk/aclk.h +++ b/aclk/aclk.h @@ -3,17 +3,32 @@ #define ACLK_H #include "daemon/common.h" + +#ifdef ENABLE_ACLK #include "aclk_util.h" #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 +#endif /* ENABLE_ACLK */ + +extern int aclk_connected; +extern int aclk_alert_reloaded; +extern int use_mqtt_5; +extern int aclk_ctx_based; +extern int aclk_disable_runtime; +extern int aclk_stats_enabled; +extern int aclk_kill_link; + +extern usec_t aclk_session_us; +extern time_t aclk_session_sec; extern time_t aclk_block_until; extern int disconnect_req; +#ifdef ENABLE_ACLK void *aclk_main(void *ptr); extern netdata_mutex_t aclk_shared_state_mutex; @@ -34,7 +49,10 @@ void aclk_send_node_instances(void); void aclk_send_bin_msg(char *msg, size_t msg_len, enum aclk_topics subtopic, const char *msgname); -char *ng_aclk_state(void); -char *ng_aclk_state_json(void); +#endif /* ENABLE_ACLK */ + +char *aclk_state(void); +char *aclk_state_json(void); +void add_aclk_host_labels(void); #endif /* ACLK_H */ diff --git a/aclk/aclk_api.c b/aclk/aclk_api.c deleted file mode 100644 index 141d267af2..0000000000 --- a/aclk/aclk_api.c +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -#include "libnetdata/libnetdata.h" -#include "database/rrd.h" - -#ifdef ENABLE_ACLK -#include "aclk.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_stats_enabled; -int use_mqtt_5 = 0; -int aclk_ctx_based = 0; - -#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, "ng"); - - if (!strcasecmp(aclk_impl_req, "ng")) { - return aclk_main(ptr); - } else if (!strcasecmp(aclk_impl_req, "legacy")) { - error("Legacy ACLK is not supported anymore key \"" ACLK_IMPL_KEY_NAME "\" in section \"" CONFIG_SECTION_CLOUD "\" ignored. Using ACLK-NG."); - } else { - error("Unknown value \"%s\" of key \"" ACLK_IMPL_KEY_NAME "\" in section \"" CONFIG_SECTION_CLOUD "\". Using ACLK-NG. This config key will be deprecated.", aclk_impl_req); - } - return aclk_main(ptr); -} -#endif /* ENABLE_ACLK */ - -void add_aclk_host_labels(void) { - DICTIONARY *labels = localhost->host_labels; - -#ifdef ENABLE_ACLK - rrdlabels_add(labels, "_aclk_ng_available", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); -#else - rrdlabels_add(labels, "_aclk_ng_available", "false", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); -#endif - rrdlabels_add(labels, "_aclk_legacy_available", "false", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); -#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; - } - - - int mqtt5 = config_get_boolean(CONFIG_SECTION_CLOUD, "mqtt5", CONFIG_BOOLEAN_YES); - - rrdlabels_add(labels, "_mqtt_version", mqtt5 ? "5" : "3", RRDLABEL_SRC_AUTO); - rrdlabels_add(labels, "_aclk_impl", "Next Generation", RRDLABEL_SRC_AUTO); - rrdlabels_add(labels, "_aclk_proxy", proxy_str, RRDLABEL_SRC_AUTO); - rrdlabels_add(labels, "_aclk_ng_new_cloud_protocol", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); -#endif -} - -char *aclk_state(void) { -#ifndef ENABLE_ACLK - return strdupz("ACLK Available: No"); -#else - return ng_aclk_state(); -#endif -} - -char *aclk_state_json(void) { -#ifndef ENABLE_ACLK - return strdupz("{\"aclk-available\":false}"); -#else - return ng_aclk_state_json(); -#endif -} diff --git a/aclk/aclk_api.h b/aclk/aclk_api.h deleted file mode 100644 index 36a6d603f3..0000000000 --- a/aclk/aclk_api.h +++ /dev/null @@ -1,45 +0,0 @@ -// 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_stats_enabled; -extern int aclk_alert_reloaded; - -extern int use_mqtt_5; -extern int aclk_ctx_based; - -#ifdef ENABLE_ACLK -void *aclk_starter(void *ptr); - -void aclk_host_state_update(RRDHOST *host, int connect); - -#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 - -void add_aclk_host_labels(void); -char *aclk_state(void); -char *aclk_state_json(void); - -#endif /* ACLK_API_H */ diff --git a/aclk/aclk_util.c b/aclk/aclk_util.c index ec021aec55..01eaedc8e0 100644 --- a/aclk/aclk_util.c +++ b/aclk/aclk_util.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "aclk_util.h" +#include "aclk_proxy.h" #include "daemon/common.h" diff --git a/claim/claim.c b/claim/claim.c index 59c21aa35a..b0d40ecf86 100644 --- a/claim/claim.c +++ b/claim/claim.c @@ -2,7 +2,8 @@ #include "claim.h" #include "registry/registry_internals.h" -#include "aclk/aclk_api.h" +#include "aclk/aclk.h" +#include "aclk/aclk_proxy.h" char *claiming_pending_arguments = NULL; diff --git a/daemon/buildinfo.c b/daemon/buildinfo.c index 456cf74867..2f837ea309 100644 --- a/daemon/buildinfo.c +++ b/daemon/buildinfo.c @@ -317,7 +317,6 @@ void print_build_info_json(void) { printf(" \"cloud-disabled\": false,\n"); #endif printf(" \"aclk\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD)); - printf(" \"aclk-new-cloud-proto\": %s,\n", FEAT_JSON_BOOL(1)); printf(" \"tls-host-verify\": %s,\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY)); printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML)); diff --git a/daemon/common.h b/daemon/common.h index 2a45ffe70e..f3d868661e 100644 --- a/daemon/common.h +++ b/daemon/common.h @@ -69,7 +69,7 @@ #include "claim/claim.h" // netdata agent cloud link -#include "aclk/aclk_api.h" +#include "aclk/aclk.h" // global GUID map functions diff --git a/daemon/static_threads.c b/daemon/static_threads.c index 96e2799064..2575bd4ca6 100644 --- a/daemon/static_threads.c +++ b/daemon/static_threads.c @@ -2,7 +2,7 @@ #include "common.h" -extern void *aclk_starter(void *ptr); +extern void *aclk_main(void *ptr); extern void *analytics_main(void *ptr); extern void *checks_main(void *ptr); extern void *cpuidlejitter_main(void *ptr); @@ -131,7 +131,7 @@ const struct netdata_static_thread static_threads_common[] = { .enabled = 1, .thread = NULL, .init_routine = NULL, - .start_routine = aclk_starter + .start_routine = aclk_main }, #endif diff --git a/database/rrdcontext.c b/database/rrdcontext.c index ab9cc5e4cb..3444178e5d 100644 --- a/database/rrdcontext.c +++ b/database/rrdcontext.c @@ -4,7 +4,7 @@ #include "sqlite/sqlite_context.h" #include "aclk/schema-wrappers/context.h" #include "aclk/aclk_contexts_api.h" -#include "aclk/aclk_api.h" +#include "aclk/aclk.h" int rrdcontext_enabled = CONFIG_BOOLEAN_YES; diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index f01594e87e..a21c3dabff 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -1215,7 +1215,6 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb) #ifdef ENABLE_ACLK buffer_strcat(wb, "\t\"cloud-available\": true,\n"); - buffer_strcat(wb, "\t\"aclk-new-cloud-protocol\": true,\n"); #else buffer_strcat(wb, "\t\"cloud-available\": false,\n"); #endif |