mirror of
https://github.com/netdata/netdata.git
synced 2025-04-17 03:02:41 +00:00
Remove aclk_api.[ch] (#13540)
* get rid of aclk_starter middleman * get rid of aclk_api.[ch]
This commit is contained in:
parent
efd9989bc6
commit
971fe35547
13 changed files with 89 additions and 152 deletions
|
@ -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
|
||||
|
|
|
@ -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 = \
|
||||
|
|
60
aclk/aclk.c
60
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
|
||||
}
|
||||
|
|
22
aclk/aclk.h
22
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 */
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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 */
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "aclk_util.h"
|
||||
#include "aclk_proxy.h"
|
||||
|
||||
#include "daemon/common.h"
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue