Remove aclk_api.[ch] (#13540)

* get rid of aclk_starter middleman
* get rid of aclk_api.[ch]
This commit is contained in:
Timotej S 2022-08-24 10:41:14 +02:00 committed by GitHub
parent efd9989bc6
commit 971fe35547
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 89 additions and 152 deletions

View File

@ -860,15 +860,13 @@ set(CLAIM_PLUGIN_FILES
set(ACLK_ALWAYS_BUILD set(ACLK_ALWAYS_BUILD
aclk/aclk_rrdhost_state.h aclk/aclk_rrdhost_state.h
aclk/aclk_api.c
aclk/aclk_api.h
aclk/aclk_proxy.c aclk/aclk_proxy.c
aclk/aclk_proxy.h aclk/aclk_proxy.h
aclk/aclk.c
aclk/aclk.h
) )
set(ACLK_FILES set(ACLK_FILES
aclk/aclk.c
aclk/aclk.h
aclk/aclk_util.c aclk/aclk_util.c
aclk/aclk_util.h aclk/aclk_util.h
aclk/aclk_stats.c aclk/aclk_stats.c

View File

@ -676,8 +676,6 @@ PARSER_FILES = \
if ENABLE_ACLK if ENABLE_ACLK
ACLK_FILES = \ ACLK_FILES = \
aclk/aclk.c \
aclk/aclk.h \
aclk/aclk_util.c \ aclk/aclk_util.c \
aclk/aclk_util.h \ aclk/aclk_util.h \
aclk/aclk_stats.c \ aclk/aclk_stats.c \
@ -860,10 +858,10 @@ endif #ENABLE_ACLK
ACLK_ALWAYS_BUILD_FILES = \ ACLK_ALWAYS_BUILD_FILES = \
aclk/aclk_rrdhost_state.h \ aclk/aclk_rrdhost_state.h \
aclk/aclk_api.c \
aclk/aclk_api.h \
aclk/aclk_proxy.c \ aclk/aclk_proxy.c \
aclk/aclk_proxy.h \ aclk/aclk_proxy.h \
aclk/aclk.c \
aclk/aclk.h \
$(NULL) $(NULL)
SPAWN_PLUGIN_FILES = \ SPAWN_PLUGIN_FILES = \

View File

@ -2,6 +2,7 @@
#include "aclk.h" #include "aclk.h"
#ifdef ENABLE_ACLK
#include "aclk_stats.h" #include "aclk_stats.h"
#include "mqtt_wss_client.h" #include "mqtt_wss_client.h"
#include "aclk_otp.h" #include "aclk_otp.h"
@ -23,11 +24,23 @@
#define ACLK_STABLE_TIMEOUT 3 // Minimum delay to mark AGENT as stable #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_pubacks_per_conn = 0; // How many PubAcks we got since MQTT conn est.
int aclk_rcvd_cloud_msgs = 0; int aclk_rcvd_cloud_msgs = 0;
int aclk_connection_counter = 0; int aclk_connection_counter = 0;
int disconnect_req = 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_mqtt = 0;
time_t last_conn_time_appl = 0; time_t last_conn_time_appl = 0;
time_t last_disconnect_time = 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; time_t aclk_block_until = 0;
#ifdef ENABLE_ACLK
mqtt_wss_client mqttwss_client; mqtt_wss_client mqttwss_client;
netdata_mutex_t aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER; 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); 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); BUFFER *wb = buffer_create(1024);
struct tm *tmptr, tmbuf; struct tm *tmptr, tmbuf;
char *ret; char *ret;
@ -1010,8 +1028,10 @@ char *ng_aclk_state(void)
ret = strdupz(buffer_tostring(wb)); ret = strdupz(buffer_tostring(wb));
buffer_free(wb); buffer_free(wb);
return ret; return ret;
#endif /* ENABLE_ACLK */
} }
#ifdef ENABLE_ACLK
static void fill_alert_status_for_host_json(json_object *obj, RRDHOST *host) static void fill_alert_status_for_host_json(json_object *obj, RRDHOST *host)
{ {
struct proto_alert_status status; struct proto_alert_status status;
@ -1087,9 +1107,13 @@ static json_object *timestamp_to_json(const time_t *t)
} }
return NULL; 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(); json_object *tmp, *grp, *msg = json_object_new_object();
tmp = json_object_new_boolean(1); 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)); char *str = strdupz(json_object_to_json_string_ext(msg, JSON_C_TO_STRING_PLAIN));
json_object_put(msg); json_object_put(msg);
return str; 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
} }

View File

@ -3,17 +3,32 @@
#define ACLK_H #define ACLK_H
#include "daemon/common.h" #include "daemon/common.h"
#ifdef ENABLE_ACLK
#include "aclk_util.h" #include "aclk_util.h"
#include "aclk_rrdhost_state.h" #include "aclk_rrdhost_state.h"
// How many MQTT PUBACKs we need to get to consider connection // How many MQTT PUBACKs we need to get to consider connection
// stable for the purposes of TBEB (truncated binary exponential backoff) // stable for the purposes of TBEB (truncated binary exponential backoff)
#define ACLK_PUBACKS_CONN_STABLE 3 #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 time_t aclk_block_until;
extern int disconnect_req; extern int disconnect_req;
#ifdef ENABLE_ACLK
void *aclk_main(void *ptr); void *aclk_main(void *ptr);
extern netdata_mutex_t aclk_shared_state_mutex; 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); void aclk_send_bin_msg(char *msg, size_t msg_len, enum aclk_topics subtopic, const char *msgname);
char *ng_aclk_state(void); #endif /* ENABLE_ACLK */
char *ng_aclk_state_json(void);
char *aclk_state(void);
char *aclk_state_json(void);
void add_aclk_host_labels(void);
#endif /* ACLK_H */ #endif /* ACLK_H */

View File

@ -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
}

View File

@ -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 */

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include "aclk_util.h" #include "aclk_util.h"
#include "aclk_proxy.h"
#include "daemon/common.h" #include "daemon/common.h"

View File

@ -2,7 +2,8 @@
#include "claim.h" #include "claim.h"
#include "registry/registry_internals.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; char *claiming_pending_arguments = NULL;

View File

@ -317,7 +317,6 @@ void print_build_info_json(void) {
printf(" \"cloud-disabled\": false,\n"); printf(" \"cloud-disabled\": false,\n");
#endif #endif
printf(" \"aclk\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD)); 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(" \"tls-host-verify\": %s,\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY));
printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML)); printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML));

View File

@ -69,7 +69,7 @@
#include "claim/claim.h" #include "claim/claim.h"
// netdata agent cloud link // netdata agent cloud link
#include "aclk/aclk_api.h" #include "aclk/aclk.h"
// global GUID map functions // global GUID map functions

View File

@ -2,7 +2,7 @@
#include "common.h" #include "common.h"
extern void *aclk_starter(void *ptr); extern void *aclk_main(void *ptr);
extern void *analytics_main(void *ptr); extern void *analytics_main(void *ptr);
extern void *checks_main(void *ptr); extern void *checks_main(void *ptr);
extern void *cpuidlejitter_main(void *ptr); extern void *cpuidlejitter_main(void *ptr);
@ -131,7 +131,7 @@ const struct netdata_static_thread static_threads_common[] = {
.enabled = 1, .enabled = 1,
.thread = NULL, .thread = NULL,
.init_routine = NULL, .init_routine = NULL,
.start_routine = aclk_starter .start_routine = aclk_main
}, },
#endif #endif

View File

@ -4,7 +4,7 @@
#include "sqlite/sqlite_context.h" #include "sqlite/sqlite_context.h"
#include "aclk/schema-wrappers/context.h" #include "aclk/schema-wrappers/context.h"
#include "aclk/aclk_contexts_api.h" #include "aclk/aclk_contexts_api.h"
#include "aclk/aclk_api.h" #include "aclk/aclk.h"
int rrdcontext_enabled = CONFIG_BOOLEAN_YES; int rrdcontext_enabled = CONFIG_BOOLEAN_YES;

View File

@ -1215,7 +1215,6 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
#ifdef ENABLE_ACLK #ifdef ENABLE_ACLK
buffer_strcat(wb, "\t\"cloud-available\": true,\n"); buffer_strcat(wb, "\t\"cloud-available\": true,\n");
buffer_strcat(wb, "\t\"aclk-new-cloud-protocol\": true,\n");
#else #else
buffer_strcat(wb, "\t\"cloud-available\": false,\n"); buffer_strcat(wb, "\t\"cloud-available\": false,\n");
#endif #endif