@cryptotaxi247 / netdata-1 / commits / 971fe3554

Remove aclk_api.[ch] (#13540)

* get rid of aclk_starter middleman * get rid of aclk_api.[ch]

Timotej S committed Aug 24, 2022 at 10:41 UTC 971fe355478c015a858a4428bf408ca2c2395c42
13 files changed +89 -152
CMakeLists.txt
+2 -4
@@ -860,15 +860,13 @@ set(CLAIM_PLUGIN_FILES
860
861 set(ACLK_ALWAYS_BUILD
862 aclk/aclk_rrdhost_state.h
863 - aclk/aclk_api.c
864 - aclk/aclk_api.h
863 aclk/aclk_proxy.c
864 aclk/aclk_proxy.h
865 + aclk/aclk.c
866 + aclk/aclk.h
867 )
868
869 set(ACLK_FILES
870 - aclk/aclk.c
871 - aclk/aclk.h
870 aclk/aclk_util.c
871 aclk/aclk_util.h
872 aclk/aclk_stats.c
Makefile.am
+2 -4
@@ -676,8 +676,6 @@ PARSER_FILES = \
676
677 if ENABLE_ACLK
678 ACLK_FILES = \
679 - aclk/aclk.c \
680 - aclk/aclk.h \
679 aclk/aclk_util.c \
680 aclk/aclk_util.h \
681 aclk/aclk_stats.c \
@@ -860,10 +858,10 @@ endif #ENABLE_ACLK
858
859 ACLK_ALWAYS_BUILD_FILES = \
860 aclk/aclk_rrdhost_state.h \
863 - aclk/aclk_api.c \
864 - aclk/aclk_api.h \
861 aclk/aclk_proxy.c \
862 aclk/aclk_proxy.h \
863 + aclk/aclk.c \
864 + aclk/aclk.h \
865 $(NULL)
866
867 SPAWN_PLUGIN_FILES = \
aclk/aclk.c
+58 -2
@@ -2,6 +2,7 @@
2
3 #include "aclk.h"
4
5 +#ifdef ENABLE_ACLK
6 #include "aclk_stats.h"
7 #include "mqtt_wss_client.h"
8 #include "aclk_otp.h"
@@ -23,11 +24,23 @@
24
25 #define ACLK_STABLE_TIMEOUT 3 // Minimum delay to mark AGENT as stable
26
27 +#endif /* ENABLE_ACLK */
28 +
29 int aclk_pubacks_per_conn = 0; // How many PubAcks we got since MQTT conn est.
30 int aclk_rcvd_cloud_msgs = 0;
31 int aclk_connection_counter = 0;
32 int disconnect_req = 0;
33
34 +int aclk_connected = 0;
35 +int use_mqtt_5 = 0;
36 +int aclk_ctx_based = 0;
37 +int aclk_disable_runtime = 0;
38 +int aclk_stats_enabled;
39 +int aclk_kill_link = 0;
40 +
41 +usec_t aclk_session_us = 0;
42 +time_t aclk_session_sec = 0;
43 +
44 time_t last_conn_time_mqtt = 0;
45 time_t last_conn_time_appl = 0;
46 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
51
52 time_t aclk_block_until = 0;
53
54 +#ifdef ENABLE_ACLK
55 mqtt_wss_client mqttwss_client;
56
57 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)
937 );
938 freez(stats);
939 }
940 +#endif /* ENABLE_ACLK */
941
927 -char *ng_aclk_state(void)
942 +char *aclk_state(void)
943 {
944 +#ifndef ENABLE_ACLK
945 + return strdupz("ACLK Available: No");
946 +#else
947 BUFFER *wb = buffer_create(1024);
948 struct tm *tmptr, tmbuf;
949 char *ret;
@@ -1010,8 +1028,10 @@ char *ng_aclk_state(void)
1028 ret = strdupz(buffer_tostring(wb));
1029 buffer_free(wb);
1030 return ret;
1031 +#endif /* ENABLE_ACLK */
1032 }
1033
1034 +#ifdef ENABLE_ACLK
1035 static void fill_alert_status_for_host_json(json_object *obj, RRDHOST *host)
1036 {
1037 struct proto_alert_status status;
@@ -1087,9 +1107,13 @@ static json_object *timestamp_to_json(const time_t *t)
1107 }
1108 return NULL;
1109 }
1110 +#endif /* ENABLE_ACLK */
1111
1091 -char *ng_aclk_state_json(void)
1112 +char *aclk_state_json(void)
1113 {
1114 +#ifndef ENABLE_ACLK
1115 + return strdupz("{\"aclk-available\":false}");
1116 +#else
1117 json_object *tmp, *grp, *msg = json_object_new_object();
1118
1119 tmp = json_object_new_boolean(1);
@@ -1203,4 +1227,36 @@ char *ng_aclk_state_json(void)
1227 char *str = strdupz(json_object_to_json_string_ext(msg, JSON_C_TO_STRING_PLAIN));
1228 json_object_put(msg);
1229 return str;
1230 +#endif /* ENABLE_ACLK */
1231 +}
1232 +
1233 +void add_aclk_host_labels(void) {
1234 + DICTIONARY *labels = localhost->host_labels;
1235 +
1236 +#ifdef ENABLE_ACLK
1237 + rrdlabels_add(labels, "_aclk_available", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
1238 + ACLK_PROXY_TYPE aclk_proxy;
1239 + char *proxy_str;
1240 + aclk_get_proxy(&aclk_proxy);
1241 +
1242 + switch(aclk_proxy) {
1243 + case PROXY_TYPE_SOCKS5:
1244 + proxy_str = "SOCKS5";
1245 + break;
1246 + case PROXY_TYPE_HTTP:
1247 + proxy_str = "HTTP";
1248 + break;
1249 + default:
1250 + proxy_str = "none";
1251 + break;
1252 + }
1253 +
1254 + int mqtt5 = config_get_boolean(CONFIG_SECTION_CLOUD, "mqtt5", CONFIG_BOOLEAN_YES);
1255 +
1256 + rrdlabels_add(labels, "_mqtt_version", mqtt5 ? "5" : "3", RRDLABEL_SRC_AUTO);
1257 + rrdlabels_add(labels, "_aclk_proxy", proxy_str, RRDLABEL_SRC_AUTO);
1258 + rrdlabels_add(labels, "_aclk_ng_new_cloud_protocol", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
1259 +#else
1260 + rrdlabels_add(labels, "_aclk_available", "false", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
1261 +#endif
1262 }
aclk/aclk.h
+20 -2
@@ -3,17 +3,32 @@
3 #define ACLK_H
4
5 #include "daemon/common.h"
6 +
7 +#ifdef ENABLE_ACLK
8 #include "aclk_util.h"
9 #include "aclk_rrdhost_state.h"
10
11 // How many MQTT PUBACKs we need to get to consider connection
12 // stable for the purposes of TBEB (truncated binary exponential backoff)
13 #define ACLK_PUBACKS_CONN_STABLE 3
14 +#endif /* ENABLE_ACLK */
15 +
16 +extern int aclk_connected;
17 +extern int aclk_alert_reloaded;
18 +extern int use_mqtt_5;
19 +extern int aclk_ctx_based;
20 +extern int aclk_disable_runtime;
21 +extern int aclk_stats_enabled;
22 +extern int aclk_kill_link;
23 +
24 +extern usec_t aclk_session_us;
25 +extern time_t aclk_session_sec;
26
27 extern time_t aclk_block_until;
28
29 extern int disconnect_req;
30
31 +#ifdef ENABLE_ACLK
32 void *aclk_main(void *ptr);
33
34 extern netdata_mutex_t aclk_shared_state_mutex;
@@ -34,7 +49,10 @@ void aclk_send_node_instances(void);
49
50 void aclk_send_bin_msg(char *msg, size_t msg_len, enum aclk_topics subtopic, const char *msgname);
51
37 -char *ng_aclk_state(void);
38 -char *ng_aclk_state_json(void);
52 +#endif /* ENABLE_ACLK */
53 +
54 +char *aclk_state(void);
55 +char *aclk_state_json(void);
56 +void add_aclk_host_labels(void);
57
58 #endif /* ACLK_H */
aclk/aclk_api.c deleted
-88
@@ -1,88 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -#include "libnetdata/libnetdata.h"
3 -#include "database/rrd.h"
4 -
5 -#ifdef ENABLE_ACLK
6 -#include "aclk.h"
7 -#endif
8 -
9 -int aclk_connected = 0;
10 -int aclk_kill_link = 0;
11 -
12 -usec_t aclk_session_us = 0;
13 -time_t aclk_session_sec = 0;
14 -
15 -int aclk_disable_runtime = 0;
16 -
17 -int aclk_stats_enabled;
18 -int use_mqtt_5 = 0;
19 -int aclk_ctx_based = 0;
20 -
21 -#define ACLK_IMPL_KEY_NAME "aclk implementation"
22 -
23 -#ifdef ENABLE_ACLK
24 -void *aclk_starter(void *ptr) {
25 - char *aclk_impl_req = config_get(CONFIG_SECTION_CLOUD, ACLK_IMPL_KEY_NAME, "ng");
26 -
27 - if (!strcasecmp(aclk_impl_req, "ng")) {
28 - return aclk_main(ptr);
29 - } else if (!strcasecmp(aclk_impl_req, "legacy")) {
30 - error("Legacy ACLK is not supported anymore key \"" ACLK_IMPL_KEY_NAME "\" in section \"" CONFIG_SECTION_CLOUD "\" ignored. Using ACLK-NG.");
31 - } else {
32 - 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);
33 - }
34 - return aclk_main(ptr);
35 -}
36 -#endif /* ENABLE_ACLK */
37 -
38 -void add_aclk_host_labels(void) {
39 - DICTIONARY *labels = localhost->host_labels;
40 -
41 -#ifdef ENABLE_ACLK
42 - rrdlabels_add(labels, "_aclk_ng_available", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
43 -#else
44 - rrdlabels_add(labels, "_aclk_ng_available", "false", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
45 -#endif
46 - rrdlabels_add(labels, "_aclk_legacy_available", "false", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
47 -#ifdef ENABLE_ACLK
48 - ACLK_PROXY_TYPE aclk_proxy;
49 - char *proxy_str;
50 - aclk_get_proxy(&aclk_proxy);
51 -
52 - switch(aclk_proxy) {
53 - case PROXY_TYPE_SOCKS5:
54 - proxy_str = "SOCKS5";
55 - break;
56 - case PROXY_TYPE_HTTP:
57 - proxy_str = "HTTP";
58 - break;
59 - default:
60 - proxy_str = "none";
61 - break;
62 - }
63 -
64 -
65 - int mqtt5 = config_get_boolean(CONFIG_SECTION_CLOUD, "mqtt5", CONFIG_BOOLEAN_YES);
66 -
67 - rrdlabels_add(labels, "_mqtt_version", mqtt5 ? "5" : "3", RRDLABEL_SRC_AUTO);
68 - rrdlabels_add(labels, "_aclk_impl", "Next Generation", RRDLABEL_SRC_AUTO);
69 - rrdlabels_add(labels, "_aclk_proxy", proxy_str, RRDLABEL_SRC_AUTO);
70 - rrdlabels_add(labels, "_aclk_ng_new_cloud_protocol", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK);
71 -#endif
72 -}
73 -
74 -char *aclk_state(void) {
75 -#ifndef ENABLE_ACLK
76 - return strdupz("ACLK Available: No");
77 -#else
78 - return ng_aclk_state();
79 -#endif
80 -}
81 -
82 -char *aclk_state_json(void) {
83 -#ifndef ENABLE_ACLK
84 - return strdupz("{\"aclk-available\":false}");
85 -#else
86 - return ng_aclk_state_json();
87 -#endif
88 -}
aclk/aclk_api.h deleted
-45
@@ -1,45 +0,0 @@
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 -
19 -extern int aclk_stats_enabled;
20 -extern int aclk_alert_reloaded;
21 -
22 -extern int use_mqtt_5;
23 -extern int aclk_ctx_based;
24 -
25 -#ifdef ENABLE_ACLK
26 -void *aclk_starter(void *ptr);
27 -
28 -void aclk_host_state_update(RRDHOST *host, int connect);
29 -
30 -#define NETDATA_ACLK_HOOK \
31 - { .name = "ACLK_Main", \
32 - .config_section = NULL, \
33 - .config_name = NULL, \
34 - .enabled = 1, \
35 - .thread = NULL, \
36 - .init_routine = NULL, \
37 - .start_routine = aclk_starter },
38 -
39 -#endif
40 -
41 -void add_aclk_host_labels(void);
42 -char *aclk_state(void);
43 -char *aclk_state_json(void);
44 -
45 -#endif /* ACLK_API_H */
aclk/aclk_util.c
+1
@@ -1,6 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "aclk_util.h"
4 +#include "aclk_proxy.h"
5
6 #include "daemon/common.h"
7
claim/claim.c
+2 -1
@@ -2,7 +2,8 @@
2
3 #include "claim.h"
4 #include "registry/registry_internals.h"
5 -#include "aclk/aclk_api.h"
5 +#include "aclk/aclk.h"
6 +#include "aclk/aclk_proxy.h"
7
8 char *claiming_pending_arguments = NULL;
9
daemon/buildinfo.c
-1
@@ -317,7 +317,6 @@ void print_build_info_json(void) {
317 printf(" \"cloud-disabled\": false,\n");
318 #endif
319 printf(" \"aclk\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD));
320 - printf(" \"aclk-new-cloud-proto\": %s,\n", FEAT_JSON_BOOL(1));
320
321 printf(" \"tls-host-verify\": %s,\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY));
322 printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML));
daemon/common.h
+1 -1
@@ -69,7 +69,7 @@
69 #include "claim/claim.h"
70
71 // netdata agent cloud link
72 -#include "aclk/aclk_api.h"
72 +#include "aclk/aclk.h"
73
74 // global GUID map functions
75
daemon/static_threads.c
+2 -2
@@ -2,7 +2,7 @@
2
3 #include "common.h"
4
5 -extern void *aclk_starter(void *ptr);
5 +extern void *aclk_main(void *ptr);
6 extern void *analytics_main(void *ptr);
7 extern void *checks_main(void *ptr);
8 extern void *cpuidlejitter_main(void *ptr);
@@ -131,7 +131,7 @@ const struct netdata_static_thread static_threads_common[] = {
131 .enabled = 1,
132 .thread = NULL,
133 .init_routine = NULL,
134 - .start_routine = aclk_starter
134 + .start_routine = aclk_main
135 },
136 #endif
137
database/rrdcontext.c
+1 -1
@@ -4,7 +4,7 @@
4 #include "sqlite/sqlite_context.h"
5 #include "aclk/schema-wrappers/context.h"
6 #include "aclk/aclk_contexts_api.h"
7 -#include "aclk/aclk_api.h"
7 +#include "aclk/aclk.h"
8
9 int rrdcontext_enabled = CONFIG_BOOLEAN_YES;
10
web/api/web_api_v1.c
-1
@@ -1215,7 +1215,6 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
1215
1216 #ifdef ENABLE_ACLK
1217 buffer_strcat(wb, "\t\"cloud-available\": true,\n");
1218 - buffer_strcat(wb, "\t\"aclk-new-cloud-protocol\": true,\n");
1218 #else
1219 buffer_strcat(wb, "\t\"cloud-available\": false,\n");
1220 #endif