Removes ACLK Legacy (#11841)
* remove legacy from makefiles * remove ACLK Legacy from installer * remove ACLK Legacy from configure.ac * remove legacy from cmake * aclk api cleanup * remove legacy files from packaging * changes for CI from Austin
Timotej S committed
Jan 4, 2022 at 10:11 UTC
5736b4bcb179896280cb579ee1dbe0cfa464064c
41 files changed
+58
-5696
.github/workflows/build.yml
-4
@@ -223,10 +223,6 @@ jobs:
223
run: |
224
docker run --security-opt seccomp=unconfined -w /netdata sha256:${{ steps.load.outputs.image }} \
225
/bin/sh -c './netdata-installer.sh --dont-wait --dont-start-it --require-cloud'
226
- - name: netdata-installer on ${{ matrix.distro }}, require cloud, require ACLK-NG
227
- run: |
228
- docker run --security-opt seccomp=unconfined -w /netdata -e NETDATA_CONFIGURE_OPTIONS='--with-aclk-ng' \
229
- sha256:${{ steps.load.outputs.image }} /bin/sh -c './netdata-installer.sh --dont-wait --dont-start-it --require-cloud'
226
- name: netdata-installer on ${{ matrix.distro }}, require cloud, no JSON-C
227
if: matrix.rmjsonc != ''
228
run: |
CMakeLists.txt
+4
-53
@@ -773,26 +773,7 @@ set(ACLK_COMMON_FILES
773
aclk/aclk_collector_list.h
774
)
775
776
-set(ACLK_LEGACY_FILES
777
- aclk/legacy/agent_cloud_link.c
778
- aclk/legacy/agent_cloud_link.h
779
- aclk/legacy/aclk_query.c
780
- aclk/legacy/aclk_query.h
781
- aclk/legacy/aclk_lws_wss_client.c
782
- aclk/legacy/aclk_lws_wss_client.h
783
- aclk/legacy/aclk_lws_https_client.c
784
- aclk/legacy/aclk_lws_https_client.h
785
- aclk/legacy/mqtt.c
786
- aclk/legacy/mqtt.h
787
- aclk/legacy/aclk_stats.c
788
- aclk/legacy/aclk_stats.h
789
- aclk/legacy/aclk_rx_msgs.c
790
- aclk/legacy/aclk_rx_msgs.h
791
- aclk/legacy/aclk_common.c
792
- aclk/legacy/aclk_common.h
793
- )
794
-
795
-set(ACLK_NG_FILES
776
+set(ACLK_FILES
777
aclk/aclk.c
778
aclk/aclk.h
779
aclk/aclk_util.c
@@ -854,11 +835,6 @@ set(SPAWN_PLUGIN_FILES
835
spawn/spawn.h
836
)
837
857
-set(ACLK_LEGACY_STATIC_LIBS
858
- ${CMAKE_SOURCE_DIR}/externaldeps/mosquitto/libmosquitto.a
859
- ${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/libwebsockets.a
860
- )
861
-
838
set(EXPORTING_ENGINE_FILES
839
exporting/exporting_engine.c
840
exporting/exporting_engine.h
@@ -1070,31 +1046,6 @@ ENDIF()
1046
1047
set(NETDATA_COMMON_LIBRARIES ${NETDATA_COMMON_LIBRARIES} m ${CMAKE_THREAD_LIBS_INIT})
1048
1073
-set(ACLK_LEGACY_CAN_BUILD 1)
1074
-if(NOT EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/mosquitto/libmosquitto.a")
1075
- message(WARNING "Static build of mosquitto not found. Disabling ACLK")
1076
- set(ACLK_LEGACY_CAN_BUILD 0)
1077
-ENDIF()
1078
-
1079
-if(NOT EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/libwebsockets.a")
1080
- message(WARNING "Static build of libwebsockets not found. Disabling ACLK")
1081
- set(ACLK_LEGACY_CAN_BUILD 0)
1082
-ENDIF()
1083
-
1084
-IF(ACLK_LEGACY_CAN_BUILD)
1085
- message(STATUS "agent-cloud-link Legacy: enabled")
1086
- list(APPEND NETDATA_FILES ${ACLK_LEGACY_FILES})
1087
- list(APPEND NETDATA_COMMON_LIBRARIES ${ACLK_LEGACY_STATIC_LIBS})
1088
- include_directories(BEFORE ${CMAKE_SOURCE_DIR}/externaldeps/libwebsockets/include)
1089
- IF(LINUX AND CAP_FOUND)
1090
- list(APPEND NETDATA_COMMON_LIBRARIES ${CAP_LIBRARIES})
1091
- list(APPEND NETDATA_COMMON_INCLUDE_DIRS ${CAP_INCLUDE_DIRS})
1092
- list(APPEND NETDATA_COMMON_CFLAGS ${CAP_CFLAGS_OTHER})
1093
- ENDIF()
1094
-ELSE()
1095
- message(STATUS "agent-cloud-link Legacy: disabled")
1096
-ENDIF()
1097
-
1049
find_package(Protobuf REQUIRED)
1050
1051
function(PROTOBUF_ACLK_GENERATE_CPP SRCS HDRS)
@@ -1133,7 +1084,7 @@ function(PROTOBUF_ACLK_GENERATE_CPP SRCS HDRS)
1084
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
1085
endfunction()
1086
1136
-set(ACLK_NG_PROTO_DEFS
1087
+set(ACLK_PROTO_DEFS
1088
aclk/aclk-schemas/proto/aclk/v1/lib.proto
1089
aclk/aclk-schemas/proto/agent/v1/disconnect.proto
1090
aclk/aclk-schemas/proto/agent/v1/connection.proto
@@ -1147,13 +1098,13 @@ set(ACLK_NG_PROTO_DEFS
1098
aclk/aclk-schemas/proto/nodeinstance/create/v1/creation.proto
1099
aclk/aclk-schemas/proto/nodeinstance/info/v1/info.proto
1100
)
1150
-PROTOBUF_ACLK_GENERATE_CPP(ACLK_NG_PROTO_BUILT_SRCS ACLK_NG_PROTO_BUILT_HDRS ${ACLK_NG_PROTO_DEFS})
1101
+PROTOBUF_ACLK_GENERATE_CPP(ACLK_PROTO_BUILT_SRCS ACLK_PROTO_BUILT_HDRS ${ACLK_PROTO_DEFS})
1102
1103
list(APPEND NETDATA_COMMON_LIBRARIES ${PROTOBUF_LIBRARIES})
1104
list(APPEND NETDATA_COMMON_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
1105
list(APPEND NETDATA_COMMON_CFLAGS ${PROTOBUF_CFLAGS_OTHER})
1106
list(APPEND NETDATA_FILES ${ACLK_ALWAYS_BUILD})
1156
-list(APPEND NETDATA_FILES ${ACLK_NG_FILES} ${ACLK_NG_PROTO_BUILT_SRCS} ${ACLK_NG_PROTO_BUILT_HDRS})
1107
+list(APPEND NETDATA_FILES ${ACLK_FILES} ${ACLK_PROTO_BUILT_SRCS} ${ACLK_PROTO_BUILT_HDRS})
1108
list(APPEND NETDATA_FILES ${ACLK_COMMON_FILES})
1109
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/aclk/aclk-schemas)
1110
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/mqtt_websockets/MQTT-C/include)
Makefile.am
+12
-54
@@ -64,8 +64,6 @@ dist_noinst_DATA = \
64
packaging/bundle-ebpf.sh \
65
packaging/bundle-judy.sh \
66
packaging/bundle-libbpf.sh \
67
- packaging/bundle-lws.sh \
68
- packaging/bundle-mosquitto.sh \
67
packaging/check-kernel-config.sh \
68
packaging/ebpf.checksums \
69
packaging/ebpf.version \
@@ -80,10 +78,6 @@ dist_noinst_DATA = \
78
packaging/judy.version \
79
packaging/libbpf.checksums \
80
packaging/libbpf.version \
83
- packaging/libwebsockets.checksums \
84
- packaging/libwebsockets.version \
85
- packaging/mosquitto.checksums \
86
- packaging/mosquitto.version \
81
packaging/protobuf.checksums \
82
packaging/protobuf.version \
83
packaging/version \
@@ -121,12 +115,6 @@ SUBDIRS += \
115
ml \
116
$(NULL)
117
124
-if ENABLE_ACLK
125
-SUBDIRS += \
126
- aclk/legacy \
127
- $(NULL)
128
-endif
129
-
118
AM_CFLAGS = \
119
$(OPTIONAL_MATH_CFLAGS) \
120
$(OPTIONAL_NFACCT_CFLAGS) \
@@ -618,8 +606,8 @@ PARSER_FILES = \
606
parser/parser.h \
607
$(NULL)
608
621
-if ACLK_NG
622
-ACLK_NG_FILES = \
609
+if ENABLE_ACLK
610
+ACLK_FILES = \
611
aclk/aclk.c \
612
aclk/aclk.h \
613
aclk/aclk_util.c \
@@ -652,7 +640,7 @@ ACLK_NG_FILES = \
640
$(NULL)
641
642
if ENABLE_NEW_CLOUD_PROTOCOL
655
-ACLK_NG_FILES += \
643
+ACLK_FILES += \
644
aclk/aclk_charts_api.c \
645
aclk/aclk_charts_api.h \
646
aclk/aclk_alarm_api.c \
@@ -678,7 +666,7 @@ ACLK_NG_FILES += \
666
aclk/schema-wrappers/schema_wrapper_utils.h \
667
$(NULL)
668
681
-ACLK_NG_PROTO_DEFINITIONS = \
669
+ACLK_PROTO_DEFINITIONS = \
670
aclk/aclk-schemas/proto/aclk/v1/lib.proto \
671
aclk/aclk-schemas/proto/agent/v1/disconnect.proto \
672
aclk/aclk-schemas/proto/agent/v1/connection.proto \
@@ -693,9 +681,9 @@ ACLK_NG_PROTO_DEFINITIONS = \
681
aclk/aclk-schemas/proto/nodeinstance/info/v1/info.proto \
682
$(NULL)
683
696
-dist_noinst_DATA += $(ACLK_NG_PROTO_DEFINITIONS)
684
+dist_noinst_DATA += $(ACLK_PROTO_DEFINITIONS)
685
698
-ACLK_NG_PROTO_BUILT_FILES = aclk/aclk-schemas/proto/agent/v1/connection.pb.cc \
686
+ACLK_PROTO_BUILT_FILES = aclk/aclk-schemas/proto/agent/v1/connection.pb.cc \
687
aclk/aclk-schemas/proto/agent/v1/connection.pb.h \
688
aclk/aclk-schemas/proto/nodeinstance/connection/v1/connection.pb.cc \
689
aclk/aclk-schemas/proto/nodeinstance/connection/v1/connection.pb.h \
@@ -721,9 +709,9 @@ ACLK_NG_PROTO_BUILT_FILES = aclk/aclk-schemas/proto/agent/v1/connection.pb.cc \
709
aclk/aclk-schemas/proto/nodeinstance/info/v1/info.pb.h \
710
$(NULL)
711
724
-BUILT_SOURCES += $(ACLK_NG_PROTO_BUILT_FILES)
725
-nodist_netdata_SOURCES += $(ACLK_NG_PROTO_BUILT_FILES)
726
-CLEANFILES += $(ACLK_NG_PROTO_BUILT_FILES)
712
+BUILT_SOURCES += $(ACLK_PROTO_BUILT_FILES)
713
+nodist_netdata_SOURCES += $(ACLK_PROTO_BUILT_FILES)
714
+CLEANFILES += $(ACLK_PROTO_BUILT_FILES)
715
716
aclk/aclk-schemas/proto/agent/v1/connection.pb.cc \
717
aclk/aclk-schemas/proto/agent/v1/connection.pb.h: aclk/aclk-schemas/proto/agent/v1/connection.proto
@@ -775,7 +763,7 @@ aclk/aclk-schemas/proto/nodeinstance/info/v1/info.pb.h: aclk/aclk-schemas/proto/
763
764
endif #ENABLE_NEW_CLOUD_PROTOCOL
765
778
-endif #ACLK_NG
766
+endif #ENABLE_ACLK
767
768
if ENABLE_ACLK
769
ACLK_COMMON_FILES = \
@@ -792,27 +780,6 @@ ACLK_ALWAYS_BUILD_FILES = \
780
aclk/aclk_proxy.h \
781
$(NULL)
782
795
-if ACLK_LEGACY
796
-ACLK_LEGACY_FILES = \
797
- aclk/legacy/agent_cloud_link.c \
798
- aclk/legacy/agent_cloud_link.h \
799
- aclk/legacy/aclk_query.c \
800
- aclk/legacy/aclk_query.h \
801
- aclk/legacy/mqtt.c \
802
- aclk/legacy/mqtt.h \
803
- aclk/legacy/aclk_rx_msgs.c \
804
- aclk/legacy/aclk_rx_msgs.h \
805
- aclk/legacy/aclk_lws_wss_client.c \
806
- aclk/legacy/aclk_lws_wss_client.h \
807
- aclk/legacy/aclk_lws_https_client.c \
808
- aclk/legacy/aclk_lws_https_client.h \
809
- aclk/legacy/aclk_common.c \
810
- aclk/legacy/aclk_common.h \
811
- aclk/legacy/aclk_stats.c \
812
- aclk/legacy/aclk_stats.h \
813
- $(NULL)
814
-endif #ACLK_LEGACY
815
-
783
SPAWN_PLUGIN_FILES = \
784
spawn/spawn.c \
785
spawn/spawn_server.c \
@@ -929,8 +896,7 @@ NETDATA_FILES = \
896
$(PARSER_FILES) \
897
$(ACLK_ALWAYS_BUILD_FILES) \
898
$(ACLK_COMMON_FILES) \
932
- $(ACLK_LEGACY_FILES) \
933
- $(ACLK_NG_FILES) \
899
+ $(ACLK_FILES) \
900
$(SPAWN_PLUGIN_FILES) \
901
$(NULL)
902
@@ -994,7 +960,7 @@ netdata_LDADD = \
960
$(NETDATA_COMMON_LIBS) \
961
$(NULL)
962
997
-if ACLK_NG
963
+if ENABLE_ACLK
964
netdata_LDADD += $(OPTIONAL_PROTOBUF_LIBS) \
965
$(OPTIONAL_ATOMIC_LIBS) \
966
$(NULL)
@@ -1005,14 +971,6 @@ if ENABLE_ML_TESTS
971
$(NULL)
972
endif
973
1008
-if ACLK_LEGACY
1009
- netdata_LDADD += \
1010
- $(abs_top_srcdir)/externaldeps/mosquitto/libmosquitto.a \
1011
- $(OPTIONAL_LWS_LIBS) \
1012
- $(OPTIONAL_LIBCAP_LIBS) \
1013
- $(NULL)
1014
-endif #ACLK_LEGACY
1015
-
974
if ENABLE_CXX_LINKER
975
netdata_LINK = $(CXXLD) $(CXXFLAGS) $(LDFLAGS) -o $@
976
else
aclk/aclk.c
+6
-6
@@ -859,7 +859,7 @@ exit:
859
// fix this in both old and new ACLK
860
extern void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host);
861
862
-void ng_aclk_alarm_reload(void)
862
+void aclk_alarm_reload(void)
863
{
864
ACLK_SHARED_STATE_LOCK;
865
if (unlikely(aclk_shared_state.agent_state == ACLK_HOST_INITIALIZING)) {
@@ -871,7 +871,7 @@ void ng_aclk_alarm_reload(void)
871
aclk_queue_query(aclk_query_new(METADATA_ALARMS));
872
}
873
874
-int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
874
+int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
875
{
876
BUFFER *local_buffer;
877
json_object *msg;
@@ -902,7 +902,7 @@ int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
902
return 0;
903
}
904
905
-int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create)
905
+int aclk_update_chart(RRDHOST *host, char *chart_name, int create)
906
{
907
struct aclk_query *query;
908
@@ -926,7 +926,7 @@ int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create)
926
* Add a new collector to the list
927
* If it exists, update the chart count
928
*/
929
-void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
929
+void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
930
{
931
struct aclk_query *query;
932
struct _collector *tmp_collector;
@@ -969,7 +969,7 @@ void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *m
969
* This function will release the memory used and schedule
970
* a cloud update
971
*/
972
-void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
972
+void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
973
{
974
struct aclk_query *query;
975
struct _collector *tmp_collector;
@@ -1010,7 +1010,7 @@ void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *m
1010
aclk_queue_query(query);
1011
}
1012
1013
-void ng_aclk_host_state_update(RRDHOST *host, int cmd)
1013
+void aclk_host_state_update(RRDHOST *host, int cmd)
1014
{
1015
uuid_t node_id;
1016
int ret;
aclk/aclk.h
+6
-6
@@ -32,18 +32,18 @@ extern struct aclk_shared_state {
32
int mqtt_shutdown_msg_rcvd;
33
} aclk_shared_state;
34
35
-void ng_aclk_alarm_reload(void);
36
-int ng_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
35
+void aclk_alarm_reload(void);
36
+int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
37
38
/* Informs ACLK about created/deleted chart
39
* @param create 0 - if chart was deleted, other if chart created
40
*/
41
-int ng_aclk_update_chart(RRDHOST *host, char *chart_name, int create);
41
+int aclk_update_chart(RRDHOST *host, char *chart_name, int create);
42
43
-void ng_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
44
-void ng_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
43
+void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
44
+void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
45
46
-void ng_aclk_host_state_update(RRDHOST *host, int cmd);
46
+void aclk_host_state_update(RRDHOST *host, int cmd);
47
48
void aclk_send_node_instances(void);
49
aclk/aclk_api.c
+10
-147
@@ -2,12 +2,9 @@
2
#include "libnetdata/libnetdata.h"
3
#include "database/rrd.h"
4
5
-#ifdef ACLK_NG
5
+#ifdef ENABLE_ACLK
6
#include "aclk.h"
7
#endif
8
-#ifdef ACLK_LEGACY
9
-#include "legacy/agent_cloud_link.h"
10
-#endif
8
9
int aclk_connected = 0;
10
int aclk_kill_link = 0;
@@ -20,12 +17,6 @@ int aclk_disable_single_updates = 0;
17
18
int aclk_stats_enabled;
19
23
-#ifdef ACLK_NG
24
-int aclk_ng = 1;
25
-#else
26
-int aclk_ng = 0;
27
-#endif
28
-
20
#define ACLK_IMPL_KEY_NAME "aclk implementation"
21
22
#ifdef ENABLE_ACLK
@@ -33,41 +24,13 @@ void *aclk_starter(void *ptr) {
24
char *aclk_impl_req = config_get(CONFIG_SECTION_CLOUD, ACLK_IMPL_KEY_NAME, "ng");
25
26
if (!strcasecmp(aclk_impl_req, "ng")) {
36
- aclk_ng = 1;
27
+ return aclk_main(ptr);
28
} else if (!strcasecmp(aclk_impl_req, "legacy")) {
38
- aclk_ng = 0;
29
+ error("Legacy ACLK is not supported anymore key \"" ACLK_IMPL_KEY_NAME "\" in section \"" CONFIG_SECTION_CLOUD "\" ignored. Using ACLK-NG.");
30
} else {
40
- error("Unknown value \"%s\" of key \"" ACLK_IMPL_KEY_NAME "\" in section \"" CONFIG_SECTION_CLOUD "\". Trying default ACLK %s.", aclk_impl_req, aclk_ng ? "NG" : "Legacy");
41
- }
42
-
43
-#ifndef ACLK_NG
44
- if (aclk_ng) {
45
- error("Configuration requests ACLK-NG but it is not available in this agent. Switching to Legacy.");
46
- aclk_ng = 0;
47
- }
48
-#endif
49
-
50
-#ifndef ACLK_LEGACY
51
- if (!aclk_ng) {
52
- error("Configuration requests ACLK Legacy but it is not available in this agent. Switching to NG.");
53
- aclk_ng = 1;
54
- }
55
-#endif
56
-
57
-#ifdef ACLK_NG
58
- if (aclk_ng) {
59
- info("Starting ACLK-NG");
60
- return aclk_main(ptr);
61
- }
62
-#endif
63
-#ifdef ACLK_LEGACY
64
- if (!aclk_ng) {
65
- info("Starting ACLK Legacy");
66
- return legacy_aclk_main(ptr);
31
+ 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);
32
}
68
-#endif
69
- error_report("No ACLK could be started");
70
- return NULL;
33
+ return aclk_main(ptr);
34
}
35
36
void aclk_single_update_disable()
@@ -79,99 +42,15 @@ void aclk_single_update_enable()
42
{
43
aclk_disable_single_updates = 0;
44
}
82
-
83
-void aclk_alarm_reload(void)
84
-{
85
-#ifdef ACLK_NG
86
- if (aclk_ng)
87
- ng_aclk_alarm_reload();
88
-#endif
89
-#ifdef ACLK_LEGACY
90
- if (!aclk_ng)
91
- legacy_aclk_alarm_reload();
92
-#endif
93
-}
94
-
95
-int aclk_update_chart(RRDHOST *host, char *chart_name, int create)
96
-{
97
-#ifdef ACLK_NG
98
- if (aclk_ng)
99
- return ng_aclk_update_chart(host, chart_name, create);
100
-#endif
101
-#ifdef ACLK_LEGACY
102
- if (!aclk_ng)
103
- return legacy_aclk_update_chart(host, chart_name, create);
104
-#endif
105
- error_report("No usable aclk_update_chart implementation");
106
- return 1;
107
-}
108
-
109
-int aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
110
-{
111
-#ifdef ACLK_NG
112
- if (aclk_ng)
113
- return ng_aclk_update_alarm(host, ae);
114
-#endif
115
-#ifdef ACLK_LEGACY
116
- if (!aclk_ng)
117
- return legacy_aclk_update_alarm(host, ae);
118
-#endif
119
- error_report("No usable aclk_update_alarm implementation");
120
- return 1;
121
-}
122
-
123
-void aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
124
-{
125
-#ifdef ACLK_NG
126
- if (aclk_ng)
127
- return ng_aclk_add_collector(host, plugin_name, module_name);
128
-#endif
129
-#ifdef ACLK_LEGACY
130
- if (!aclk_ng)
131
- return legacy_aclk_add_collector(host, plugin_name, module_name);
132
-#endif
133
- error_report("No usable aclk_add_collector implementation");
134
-}
135
-
136
-void aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
137
-{
138
-#ifdef ACLK_NG
139
- if (aclk_ng)
140
- return ng_aclk_del_collector(host, plugin_name, module_name);
141
-#endif
142
-#ifdef ACLK_LEGACY
143
- if (!aclk_ng)
144
- return legacy_aclk_del_collector(host, plugin_name, module_name);
145
-#endif
146
- error_report("No usable aclk_del_collector implementation");
147
-}
148
-
149
-void aclk_host_state_update(RRDHOST *host, int connect)
150
-{
151
-#ifdef ACLK_NG
152
- if (aclk_ng)
153
- return ng_aclk_host_state_update(host, connect);
154
-#endif
155
-#ifdef ACLK_LEGACY
156
- if (!aclk_ng)
157
- return legacy_aclk_host_state_update(host, connect);
158
-#endif
159
- error_report("Couldn't use any version of aclk_host_state_update");
160
-}
161
-
45
#endif /* ENABLE_ACLK */
46
47
struct label *add_aclk_host_labels(struct label *label) {
165
-#ifdef ACLK_NG
48
+#ifdef ENABLE_ACLK
49
label = add_label_to_list(label, "_aclk_ng_available", "true", LABEL_SOURCE_AUTO);
50
#else
51
label = add_label_to_list(label, "_aclk_ng_available", "false", LABEL_SOURCE_AUTO);
52
#endif
170
-#ifdef ACLK_LEGACY
171
- label = add_label_to_list(label, "_aclk_legacy_available", "true", LABEL_SOURCE_AUTO);
172
-#else
53
label = add_label_to_list(label, "_aclk_legacy_available", "false", LABEL_SOURCE_AUTO);
174
-#endif
54
#ifdef ENABLE_ACLK
55
ACLK_PROXY_TYPE aclk_proxy;
56
char *proxy_str;
@@ -189,7 +68,7 @@ struct label *add_aclk_host_labels(struct label *label) {
68
break;
69
}
70
192
- label = add_label_to_list(label, "_aclk_impl", aclk_ng ? "Next Generation" : "Legacy", LABEL_SOURCE_AUTO);
71
+ label = add_label_to_list(label, "_aclk_impl", "Next Generation", LABEL_SOURCE_AUTO);
72
label = add_label_to_list(label, "_aclk_proxy", proxy_str, LABEL_SOURCE_AUTO);
73
#endif
74
return label;
@@ -199,30 +78,14 @@ char *aclk_state(void) {
78
#ifndef ENABLE_ACLK
79
return strdupz("ACLK Available: No");
80
#else
202
-#ifdef ACLK_NG
203
- if (aclk_ng)
204
- return ng_aclk_state();
205
-#endif
206
-#ifdef ACLK_LEGACY
207
- if (!aclk_ng)
208
- return legacy_aclk_state();
81
+ return ng_aclk_state();
82
#endif
210
-#endif /* ENABLE_ACLK */
211
- return NULL;
83
}
84
85
char *aclk_state_json(void) {
86
#ifndef ENABLE_ACLK
216
- return strdupz("{\"aclk-available\": false}");
87
+ return strdupz("{\"aclk-available\":false}");
88
#else
218
-#ifdef ACLK_NG
219
- if (aclk_ng)
220
- return ng_aclk_state_json();
221
-#endif
222
-#ifdef ACLK_LEGACY
223
- if (!aclk_ng)
224
- return legacy_aclk_state_json();
89
+ return ng_aclk_state_json();
90
#endif
226
-#endif /* ENABLE_ACLK */
227
- return NULL;
91
}
aclk/legacy/Makefile.am
deleted
-19
@@ -1,19 +0,0 @@
1
-# SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-AUTOMAKE_OPTIONS = subdir-objects
4
-MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
5
-
6
-CLEANFILES = \
7
- tests/install-fake-charts.d.sh \
8
- $(NULL)
9
-
10
-include $(top_srcdir)/build/subst.inc
11
-SUFFIXES = .in
12
-
13
-#sbin_SCRIPTS = \
14
-# tests/install-fake-charts.d.sh \
15
-# $(NULL)
16
-
17
-dist_noinst_SCRIPTS = tests/install-fake-charts.d.sh
18
-dist_noinst_DATA = tests/install-fake-charts.d.sh.in
19
-
aclk/legacy/aclk_common.c
deleted
-53
@@ -1,53 +0,0 @@
1
-#include "aclk_common.h"
2
-
3
-#include "daemon/common.h"
4
-
5
-#ifdef ENABLE_ACLK
6
-#include <libwebsockets.h>
7
-#endif
8
-
9
-netdata_mutex_t legacy_aclk_shared_state_mutex = NETDATA_MUTEX_INITIALIZER;
10
-
11
-struct legacy_aclk_shared_state legacy_aclk_shared_state = {
12
- .version_neg = 0,
13
- .version_neg_wait_till = 0
14
-};
15
-
16
-int aclk_decode_base_url(char *url, char **aclk_hostname, int *aclk_port)
17
-{
18
- int pos = 0;
19
- if (!strncmp("https://", url, 8)) {
20
- pos = 8;
21
- } else if (!strncmp("http://", url, 7)) {
22
- error("Cannot connect ACLK over %s -> unencrypted link is not supported", url);
23
- return 1;
24
- }
25
- int host_end = pos;
26
- while (url[host_end] != 0 && url[host_end] != '/' && url[host_end] != ':')
27
- host_end++;
28
- if (url[host_end] == 0) {
29
- *aclk_hostname = strdupz(url + pos);
30
- *aclk_port = 443;
31
- info("Setting ACLK target host=%s port=%d from %s", *aclk_hostname, *aclk_port, url);
32
- return 0;
33
- }
34
- if (url[host_end] == ':') {
35
- *aclk_hostname = callocz(host_end - pos + 1, 1);
36
- strncpy(*aclk_hostname, url + pos, host_end - pos);
37
- int port_end = host_end + 1;
38
- while (url[port_end] >= '0' && url[port_end] <= '9')
39
- port_end++;
40
- if (port_end - host_end > 6) {
41
- error("Port specified in %s is invalid", url);
42
- return 0;
43
- }
44
- *aclk_port = atoi(&url[host_end+1]);
45
- }
46
- if (url[host_end] == '/') {
47
- *aclk_port = 443;
48
- *aclk_hostname = callocz(1, host_end - pos + 1);
49
- strncpy(*aclk_hostname, url+pos, host_end - pos);
50
- }
51
- info("Setting ACLK target host=%s port=%d from %s", *aclk_hostname, *aclk_port, url);
52
- return 0;
53
-}
aclk/legacy/aclk_common.h
deleted
-51
@@ -1,51 +0,0 @@
1
-#ifndef ACLK_COMMON_H
2
-#define ACLK_COMMON_H
3
-
4
-#include "../aclk_rrdhost_state.h"
5
-#include "daemon/common.h"
6
-
7
-extern netdata_mutex_t legacy_aclk_shared_state_mutex;
8
-#define legacy_aclk_shared_state_LOCK netdata_mutex_lock(&legacy_aclk_shared_state_mutex)
9
-#define legacy_aclk_shared_state_UNLOCK netdata_mutex_unlock(&legacy_aclk_shared_state_mutex)
10
-
11
-// minimum and maximum supported version of ACLK
12
-// in this version of agent
13
-#define ACLK_VERSION_MIN 2
14
-#define ACLK_VERSION_MAX 3
15
-
16
-// Version negotiation messages have they own versioning
17
-// this is also used for LWT message as we set that up
18
-// before version negotiation
19
-#define ACLK_VERSION_NEG_VERSION 1
20
-
21
-// Maximum time to wait for version negotiation before aborting
22
-// and defaulting to oldest supported version
23
-#define VERSION_NEG_TIMEOUT 3
24
-
25
-#if ACLK_VERSION_MIN > ACLK_VERSION_MAX
26
-#error "ACLK_VERSION_MAX must be >= than ACLK_VERSION_MIN"
27
-#endif
28
-
29
-// Define ACLK Feature Version Boundaries Here
30
-#define ACLK_V_COMPRESSION 2
31
-#define ACLK_V_CHILDRENSTATE 3
32
-
33
-#define ACLK_IS_HOST_INITIALIZING(host) (host->aclk_state.state == ACLK_HOST_INITIALIZING)
34
-#define ACLK_IS_HOST_POPCORNING(host) (ACLK_IS_HOST_INITIALIZING(host) && host->aclk_state.t_last_popcorn_update)
35
-
36
-extern struct legacy_aclk_shared_state {
37
- // optimization to avoid looping through hosts
38
- // every time Query Thread wakes up
39
- RRDHOST *next_popcorn_host;
40
-
41
- // read only while ACLK connected
42
- // protect by lock otherwise
43
- int version_neg;
44
- usec_t version_neg_wait_till;
45
-} legacy_aclk_shared_state;
46
-
47
-const char *aclk_proxy_type_to_s(ACLK_PROXY_TYPE *type);
48
-
49
-int aclk_decode_base_url(char *url, char **aclk_hostname, int *aclk_port);
50
-
51
-#endif //ACLK_COMMON_H
aclk/legacy/aclk_lws_https_client.c
deleted
-244
@@ -1,244 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#define ACLK_LWS_HTTPS_CLIENT_INTERNAL
4
-#include "aclk_lws_https_client.h"
5
-#include "aclk_common.h"
6
-#include "aclk_lws_wss_client.h"
7
-
8
-#define SMALL_BUFFER 16
9
-
10
-struct simple_hcc_data {
11
- char *data;
12
- size_t data_size;
13
- size_t written;
14
- char lws_work_buffer[1024 + LWS_PRE];
15
- char *payload;
16
- int response_code;
17
- int done;
18
-};
19
-
20
-static int simple_https_client_callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
21
-{
22
- UNUSED(user);
23
- int n;
24
- char *ptr;
25
- char buffer[SMALL_BUFFER];
26
- struct simple_hcc_data *perconn_data = lws_get_opaque_user_data(wsi);
27
-
28
- switch (reason) {
29
- case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ:
30
- debug(D_ACLK, "LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ");
31
- if (perconn_data->data_size - 1 - perconn_data->written < len)
32
- return 1;
33
- memcpy(&perconn_data->data[perconn_data->written], in, len);
34
- perconn_data->written += len;
35
- return 0;
36
- case LWS_CALLBACK_RECEIVE_CLIENT_HTTP:
37
- debug(D_ACLK, "LWS_CALLBACK_RECEIVE_CLIENT_HTTP");
38
- if(!perconn_data) {
39
- error("Missing Per Connect Data");
40
- return -1;
41
- }
42
- n = sizeof(perconn_data->lws_work_buffer) - LWS_PRE;
43
- ptr = perconn_data->lws_work_buffer + LWS_PRE;
44
- if (lws_http_client_read(wsi, &ptr, &n) < 0)
45
- return -1;
46
- perconn_data->data[perconn_data->written] = '\0';
47
- return 0;
48
- case LWS_CALLBACK_WSI_DESTROY:
49
- debug(D_ACLK, "LWS_CALLBACK_WSI_DESTROY");
50
- if(perconn_data)
51
- perconn_data->done = 1;
52
- return 0;
53
- case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP:
54
- debug(D_ACLK, "LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP");
55
- if(perconn_data)
56
- perconn_data->response_code = lws_http_client_http_response(wsi);
57
- return 0;
58
- case LWS_CALLBACK_CLOSED_CLIENT_HTTP:
59
- debug(D_ACLK, "LWS_CALLBACK_CLOSED_CLIENT_HTTP");
60
- return 0;
61
- case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS:
62
- debug(D_ACLK, "LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS");
63
- return 0;
64
- case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
65
- debug(D_ACLK, "LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER");
66
- if(perconn_data && perconn_data->payload) {
67
- unsigned char **p = (unsigned char **)in, *end = (*p) + len;
68
- snprintfz(buffer, SMALL_BUFFER, "%zu", strlen(perconn_data->payload));
69
- if (lws_add_http_header_by_token(wsi,
70
- WSI_TOKEN_HTTP_CONTENT_LENGTH,
71
- (unsigned char *)buffer, strlen(buffer), p, end))
72
- return -1;
73
- if (lws_add_http_header_by_token(wsi,
74
- WSI_TOKEN_HTTP_CONTENT_TYPE,
75
- (unsigned char *)ACLK_CONTENT_TYPE_JSON,
76
- strlen(ACLK_CONTENT_TYPE_JSON), p, end))
77
- return -1;
78
- lws_client_http_body_pending(wsi, 1);
79
- lws_callback_on_writable(wsi);
80
- }
81
- return 0;
82
- case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE:
83
- debug(D_ACLK, "LWS_CALLBACK_CLIENT_HTTP_WRITEABLE");
84
- if(perconn_data && perconn_data->payload) {
85
- n = strlen(perconn_data->payload);
86
- if(perconn_data->data_size < (size_t)LWS_PRE + n + 1) {
87
- error("Buffer given is not big enough");
88
- return 1;
89
- }
90
-
91
- memcpy(&perconn_data->data[LWS_PRE], perconn_data->payload, n);
92
- if(n != lws_write(wsi, (unsigned char*)&perconn_data->data[LWS_PRE], n, LWS_WRITE_HTTP)) {
93
- error("lws_write error");
94
- perconn_data->data[0] = 0;
95
- return 1;
96
- }
97
- lws_client_http_body_pending(wsi, 0);
98
- // clean for subsequent reply read
99
- perconn_data->data[0] = 0;
100
- }
101
- return 0;
102
- case LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL:
103
- debug(D_ACLK, "LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL");
104
- return 0;
105
- case LWS_CALLBACK_WSI_CREATE:
106
- debug(D_ACLK, "LWS_CALLBACK_WSI_CREATE");
107
- return 0;
108
- case LWS_CALLBACK_PROTOCOL_INIT:
109
- debug(D_ACLK, "LWS_CALLBACK_PROTOCOL_INIT");
110
- return 0;
111
- case LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL:
112
- debug(D_ACLK, "LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL");
113
- return 0;
114
- case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED:
115
- debug(D_ACLK, "LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED");
116
- return 0;
117
- case LWS_CALLBACK_GET_THREAD_ID:
118
- debug(D_ACLK, "LWS_CALLBACK_GET_THREAD_ID");
119
- return 0;
120
- case LWS_CALLBACK_EVENT_WAIT_CANCELLED:
121
- debug(D_ACLK, "LWS_CALLBACK_EVENT_WAIT_CANCELLED");
122
- return 0;
123
- case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION:
124
- debug(D_ACLK, "LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION");
125
- return 0;
126
- case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH:
127
- debug(D_ACLK, "LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH");
128
- return 0;
129
- default:
130
- debug(D_ACLK, "Unknown callback %d", (int)reason);
131
- return 0;
132
- }
133
-}
134
-
135
-static const struct lws_protocols protocols[] = {
136
- {
137
- "http",
138
- simple_https_client_callback,
139
- 0,
140
- 0,
141
- 0,
142
- 0,
143
- 0
144
- },
145
- { NULL, NULL, 0, 0, 0, 0, 0 }
146
-};
147
-
148
-static void simple_hcc_log_divert(int level, const char *line)
149
-{
150
- UNUSED(level);
151
- error("Libwebsockets: %s", line);
152
-}
153
-
154
-int aclk_send_https_request(char *method, char *host, int port, char *url, char *b, size_t b_size, char *payload)
155
-{
156
- info("%s %s", __func__, method);
157
-
158
- struct lws_context_creation_info info;
159
- struct lws_client_connect_info i;
160
- struct lws_context *context;
161
-
162
- struct simple_hcc_data *data = callocz(1, sizeof(struct simple_hcc_data));
163
- data->data = b;
164
- data->data[0] = 0;
165
- data->data_size = b_size;
166
- data->payload = payload;
167
-
168
- int n = 0;
169
- time_t timestamp;
170
-
171
- struct lws_vhost *vhost;
172
-
173
- memset(&info, 0, sizeof info);
174
-
175
- info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
176
- info.port = CONTEXT_PORT_NO_LISTEN;
177
- info.protocols = protocols;
178
-
179
-
180
- context = lws_create_context(&info);
181
- if (!context) {
182
- error("Error creating LWS context");
183
- freez(data);
184
- return 1;
185
- }
186
-
187
- lws_set_log_level(LLL_ERR | LLL_WARN, simple_hcc_log_divert);
188
-
189
- lws_service(context, 0);
190
-
191
- memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */
192
- i.context = context;
193
-
194
-#ifdef ACLK_SSL_ALLOW_SELF_SIGNED
195
- i.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_INSECURE;
196
- info("Disabling SSL certificate checks");
197
-#else
198
- i.ssl_connection = LCCSCF_USE_SSL;
199
-#endif
200
-#if defined(HAVE_X509_VERIFY_PARAM_set1_host) && HAVE_X509_VERIFY_PARAM_set1_host == 0
201
-#warning DISABLING SSL HOSTNAME VALIDATION BECAUSE IT IS NOT AVAILABLE ON THIS SYSTEM.
202
- i.ssl_connection |= LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK;
203
-#endif
204
-
205
- i.port = port;
206
- i.address = host;
207
- i.path = url;
208
-
209
- i.host = i.address;
210
- i.origin = i.address;
211
- i.method = method;
212
- i.opaque_user_data = data;
213
- i.alpn = "http/1.1";
214
-
215
- i.protocol = protocols[0].name;
216
-
217
- vhost = lws_get_vhost_by_name(context, "default");
218
- if(!vhost)
219
- fatal("Could not find the default LWS vhost.");
220
-
221
- //set up proxy
222
- aclk_wss_set_proxy(vhost);
223
-
224
- lws_client_connect_via_info(&i);
225
-
226
- // libwebsockets handle connection timeouts already
227
- // this adds additional safety in case of bug in LWS
228
- timestamp = now_monotonic_sec();
229
- while( n >= 0 && !data->done && !netdata_exit) {
230
- n = lws_service(context, 0);
231
- if( now_monotonic_sec() - timestamp > SEND_HTTPS_REQUEST_TIMEOUT ) {
232
- data->data[0] = 0;
233
- data->done = 1;
234
- error("Servicing LWS took too long.");
235
- }
236
- }
237
-
238
- lws_context_destroy(context);
239
-
240
- n = data->response_code;
241
-
242
- freez(data);
243
- return (n < 200 || n >= 300);
244
-}
aclk/legacy/aclk_lws_https_client.h
deleted
-18
@@ -1,18 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef NETDATA_LWS_HTTPS_CLIENT_H
4
-#define NETDATA_LWS_HTTPS_CLIENT_H
5
-
6
-#include "daemon/common.h"
7
-#include "libnetdata/libnetdata.h"
8
-
9
-#define DATAMAXLEN 1024*16
10
-
11
-#ifdef ACLK_LWS_HTTPS_CLIENT_INTERNAL
12
-#define ACLK_CONTENT_TYPE_JSON "application/json"
13
-#define SEND_HTTPS_REQUEST_TIMEOUT 30
14
-#endif
15
-
16
-int aclk_send_https_request(char *method, char *host, int port, char *url, char *b, size_t b_size, char *payload);
17
-
18
-#endif /* NETDATA_LWS_HTTPS_CLIENT_H */
aclk/legacy/aclk_lws_wss_client.c
deleted
-622
@@ -1,622 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#include "aclk_lws_wss_client.h"
4
-
5
-#include "libnetdata/libnetdata.h"
6
-#include "daemon/common.h"
7
-#include "aclk_common.h"
8
-#include "aclk_stats.h"
9
-#include "../aclk_proxy.h"
10
-
11
-extern int aclk_shutting_down;
12
-
13
-static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
14
-
15
-struct aclk_lws_wss_perconnect_data {
16
- int todo;
17
-};
18
-
19
-static struct aclk_lws_wss_engine_instance *engine_instance = NULL;
20
-
21
-void lws_wss_check_queues(size_t *write_len, size_t *write_len_bytes, size_t *read_len)
22
-{
23
- if (write_len != NULL && write_len_bytes != NULL)
24
- {
25
- *write_len = 0;
26
- *write_len_bytes = 0;
27
- if (engine_instance != NULL)
28
- {
29
- aclk_lws_mutex_lock(&engine_instance->write_buf_mutex);
30
-
31
- struct lws_wss_packet_buffer *write_b;
32
- size_t w,wb;
33
- for(w=0, wb=0, write_b = engine_instance->write_buffer_head; write_b != NULL; write_b = write_b->next)
34
- {
35
- w++;
36
- wb += write_b->data_size - write_b->written;
37
- }
38
- *write_len = w;
39
- *write_len_bytes = wb;
40
- aclk_lws_mutex_unlock(&engine_instance->write_buf_mutex);
41
- }
42
- }
43
- else if (write_len != NULL)
44
- {
45
- *write_len = 0;
46
- if (engine_instance != NULL)
47
- {
48
- aclk_lws_mutex_lock(&engine_instance->write_buf_mutex);
49
-
50
- struct lws_wss_packet_buffer *write_b;
51
- size_t w;
52
- for(w=0, write_b = engine_instance->write_buffer_head; write_b != NULL; write_b = write_b->next)
53
- w++;
54
- *write_len = w;
55
- aclk_lws_mutex_unlock(&engine_instance->write_buf_mutex);
56
- }
57
- }
58
- if (read_len != NULL)
59
- {
60
- *read_len = 0;
61
- if (engine_instance != NULL)
62
- {
63
- aclk_lws_mutex_lock(&engine_instance->read_buf_mutex);
64
- *read_len = lws_ring_get_count_waiting_elements(engine_instance->read_ringbuffer, NULL);
65
- aclk_lws_mutex_unlock(&engine_instance->read_buf_mutex);
66
- }
67
- }
68
-}
69
-
70
-static inline struct lws_wss_packet_buffer *lws_wss_packet_buffer_new(void *data, size_t size)
71
-{
72
- struct lws_wss_packet_buffer *new = callocz(1, sizeof(struct lws_wss_packet_buffer));
73
- if (data) {
74
- new->data = mallocz(LWS_PRE + size);
75
- memcpy(new->data + LWS_PRE, data, size);
76
- new->data_size = size;
77
- new->written = 0;
78
- }
79
- return new;
80
-}
81
-
82
-static inline void lws_wss_packet_buffer_append(struct lws_wss_packet_buffer **list, struct lws_wss_packet_buffer *item)
83
-{
84
- struct lws_wss_packet_buffer *tail = *list;
85
- if (!*list) {
86
- *list = item;
87
- return;
88
- }
89
- while (tail->next) {
90
- tail = tail->next;
91
- }
92
- tail->next = item;
93
-}
94
-
95
-static inline struct lws_wss_packet_buffer *lws_wss_packet_buffer_pop(struct lws_wss_packet_buffer **list)
96
-{
97
- struct lws_wss_packet_buffer *ret = *list;
98
- if (ret != NULL)
99
- *list = ret->next;
100
-
101
- return ret;
102
-}
103
-
104
-static inline void lws_wss_packet_buffer_free(struct lws_wss_packet_buffer *item)
105
-{
106
- freez(item->data);
107
- freez(item);
108
-}
109
-
110
-static inline void _aclk_lws_wss_read_buffer_clear(struct lws_ring *ringbuffer)
111
-{
112
- size_t elems = lws_ring_get_count_waiting_elements(ringbuffer, NULL);
113
- if (elems > 0)
114
- lws_ring_consume(ringbuffer, NULL, NULL, elems);
115
-}
116
-
117
-static inline void _aclk_lws_wss_write_buffer_clear(struct lws_wss_packet_buffer **list)
118
-{
119
- struct lws_wss_packet_buffer *i;
120
- while ((i = lws_wss_packet_buffer_pop(list)) != NULL) {
121
- lws_wss_packet_buffer_free(i);
122
- }
123
- *list = NULL;
124
-}
125
-
126
-static inline void aclk_lws_wss_clear_io_buffers()
127
-{
128
- aclk_lws_mutex_lock(&engine_instance->read_buf_mutex);
129
- _aclk_lws_wss_read_buffer_clear(engine_instance->read_ringbuffer);
130
- aclk_lws_mutex_unlock(&engine_instance->read_buf_mutex);
131
- aclk_lws_mutex_lock(&engine_instance->write_buf_mutex);
132
- _aclk_lws_wss_write_buffer_clear(&engine_instance->write_buffer_head);
133
- aclk_lws_mutex_unlock(&engine_instance->write_buf_mutex);
134
-}
135
-
136
-static const struct lws_protocols protocols[] = { { "aclk-wss", aclk_lws_wss_callback,
137
- sizeof(struct aclk_lws_wss_perconnect_data), 32768*4, 0, 0, 32768*4 },
138
- { NULL, NULL, 0, 0, 0, 0, 0 } };
139
-
140
-static void aclk_lws_wss_log_divert(int level, const char *line)
141
-{
142
- switch (level) {
143
- case LLL_ERR:
144
- error("Libwebsockets Error: %s", line);
145
- break;
146
- case LLL_WARN:
147
- debug(D_ACLK, "Libwebsockets Warn: %s", line);
148
- break;
149
- default:
150
- error("Libwebsockets try to log with unknown log level (%d), msg: %s", level, line);
151
- }
152
-}
153
-
154
-static int aclk_lws_wss_client_init( char *target_hostname, int target_port)
155
-{
156
- static int lws_logging_initialized = 0;
157
-
158
- if (unlikely(!lws_logging_initialized)) {
159
- lws_set_log_level(LLL_ERR | LLL_WARN, aclk_lws_wss_log_divert);
160
- lws_logging_initialized = 1;
161
- }
162
-
163
- if (!target_hostname)
164
- return 1;
165
-
166
- engine_instance = callocz(1, sizeof(struct aclk_lws_wss_engine_instance));
167
-
168
- engine_instance->host = target_hostname;
169
- engine_instance->port = target_port;
170
-
171
-
172
- aclk_lws_mutex_init(&engine_instance->write_buf_mutex);
173
- aclk_lws_mutex_init(&engine_instance->read_buf_mutex);
174
-
175
- engine_instance->read_ringbuffer = lws_ring_create(1, ACLK_LWS_WSS_RECV_BUFF_SIZE_BYTES, NULL);
176
- if (!engine_instance->read_ringbuffer)
177
- goto failure_cleanup;
178
-
179
- return 0;
180
-
181
-failure_cleanup:
182
- freez(engine_instance);
183
- return 1;
184
-}
185
-
186
-void aclk_lws_wss_destroy_context()
187
-{
188
- if (!engine_instance)
189
- return;
190
- if (!engine_instance->lws_context)
191
- return;
192
- lws_context_destroy(engine_instance->lws_context);
193
- engine_instance->lws_context = NULL;
194
-}
195
-
196
-
197
-void aclk_lws_wss_client_destroy()
198
-{
199
- if (engine_instance == NULL)
200
- return;
201
-
202
- aclk_lws_wss_destroy_context();
203
- engine_instance->lws_wsi = NULL;
204
-
205
- aclk_lws_wss_clear_io_buffers();
206
-
207
-#ifdef ACLK_LWS_MOSQUITTO_IO_CALLS_MULTITHREADED
208
- pthread_mutex_destroy(&engine_instance->write_buf_mutex);
209
- pthread_mutex_destroy(&engine_instance->read_buf_mutex);
210
-#endif
211
-}
212
-
213
-#ifdef LWS_WITH_SOCKS5
214
-static int aclk_wss_set_socks(struct lws_vhost *vhost, const char *socks)
215
-{
216
- char *proxy = strstr(socks, ACLK_PROXY_PROTO_ADDR_SEPARATOR);
217
-
218
- if (!proxy)
219
- return -1;
220
-
221
- proxy += strlen(ACLK_PROXY_PROTO_ADDR_SEPARATOR);
222
-
223
- if (!*proxy)
224
- return -1;
225
-
226
- return lws_set_socks(vhost, proxy);
227
-}
228
-#endif
229
-
230
-void aclk_wss_set_proxy(struct lws_vhost *vhost)
231
-{
232
- const char *proxy;
233
- ACLK_PROXY_TYPE proxy_type;
234
- char *log;
235
-
236
- proxy = aclk_get_proxy(&proxy_type);
237
-
238
-#ifdef LWS_WITH_SOCKS5
239
- lws_set_socks(vhost, ":");
240
-#endif
241
- lws_set_proxy(vhost, ":");
242
-
243
- if (proxy_type == PROXY_TYPE_UNKNOWN) {
244
- error("Unknown proxy type");
245
- return;
246
- }
247
-
248
- if (proxy_type == PROXY_TYPE_SOCKS5 || proxy_type == PROXY_TYPE_HTTP) {
249
- log = strdupz(proxy);
250
- safe_log_proxy_censor(log);
251
- info("Connecting using %s proxy:\"%s\"", aclk_proxy_type_to_s(&proxy_type), log);
252
- freez(log);
253
- }
254
- if (proxy_type == PROXY_TYPE_SOCKS5) {
255
-#ifdef LWS_WITH_SOCKS5
256
- if (aclk_wss_set_socks(vhost, proxy))
257
- error("LWS failed to accept socks proxy.");
258
- return;
259
-#else
260
- fatal("We have no SOCKS5 support but we made it here. Programming error!");
261
-#endif
262
- }
263
- if (proxy_type == PROXY_TYPE_HTTP) {
264
- if (lws_set_proxy(vhost, proxy))
265
- error("LWS failed to accept http proxy.");
266
- return;
267
- }
268
- if (proxy_type != PROXY_DISABLED)
269
- error("Unknown proxy type");
270
-}
271
-
272
-// Return code indicates if connection attempt has started async.
273
-int aclk_lws_wss_connect(char *host, int port)
274
-{
275
- struct lws_client_connect_info i;
276
- struct lws_vhost *vhost;
277
- int n;
278
-
279
- if (!engine_instance) {
280
- if (aclk_lws_wss_client_init(host, port))
281
- return 1; // Propagate failure
282
- }
283
-
284
- if (!engine_instance->lws_context)
285
- {
286
- // First time through (on this connection), create the context
287
- struct lws_context_creation_info info;
288
- memset(&info, 0, sizeof(struct lws_context_creation_info));
289
- info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
290
- info.port = CONTEXT_PORT_NO_LISTEN;
291
- info.protocols = protocols;
292
- engine_instance->lws_context = lws_create_context(&info);
293
- if (!engine_instance->lws_context)
294
- {
295
- error("Failed to create lws_context, ACLK will not function");
296
- return 1;
297
- }
298
- return 0;
299
- // PROTOCOL_INIT callback will call again.
300
- }
301
-
302
- for (n = 0; n < ACLK_LWS_CALLBACK_HISTORY; n++)
303
- engine_instance->lws_callback_history[n] = 0;
304
-
305
- if (engine_instance->lws_wsi) {
306
- error("Already Connected. Only one connection supported at a time.");
307
- return 0;
308
- }
309
-
310
- memset(&i, 0, sizeof(i));
311
- i.context = engine_instance->lws_context;
312
- i.port = engine_instance->port;
313
- i.address = engine_instance->host;
314
- i.path = "/mqtt";
315
- i.host = engine_instance->host;
316
- i.protocol = "mqtt";
317
-
318
- // from LWS docu:
319
- // If option LWS_SERVER_OPTION_EXPLICIT_VHOSTS is given, no vhost is
320
- // created; you're expected to create your own vhosts afterwards using
321
- // lws_create_vhost(). Otherwise a vhost named "default" is also created
322
- // using the information in the vhost-related members, for compatibility.
323
- vhost = lws_get_vhost_by_name(engine_instance->lws_context, "default");
324
- if(!vhost)
325
- fatal("Could not find the default LWS vhost.");
326
-
327
- aclk_wss_set_proxy(vhost);
328
-
329
-#ifdef ACLK_SSL_ALLOW_SELF_SIGNED
330
- i.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_INSECURE;
331
- info("Disabling SSL certificate checks");
332
-#else
333
- i.ssl_connection = LCCSCF_USE_SSL;
334
-#endif
335
-#if defined(HAVE_X509_VERIFY_PARAM_set1_host) && HAVE_X509_VERIFY_PARAM_set1_host == 0
336
-#warning DISABLING SSL HOSTNAME VALIDATION BECAUSE IT IS NOT AVAILABLE ON THIS SYSTEM.
337
- i.ssl_connection |= LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK;
338
-#endif
339
- lws_client_connect_via_info(&i);
340
- return 0;
341
-}
342
-
343
-static inline int received_data_to_ringbuff(struct lws_ring *buffer, void *data, size_t len)
344
-{
345
- if (lws_ring_insert(buffer, data, len) != len) {
346
- error("ACLK_LWS_WSS_CLIENT: receive buffer full. Closing connection to prevent flooding.");
347
- return 0;
348
- }
349
- return 1;
350
-}
351
-
352
-#ifdef ACLK_TRP_DEBUG_VERBOSE
353
-static const char *aclk_lws_callback_name(enum lws_callback_reasons reason)
354
-{
355
- switch (reason) {
356
- case LWS_CALLBACK_CLIENT_WRITEABLE:
357
- return "LWS_CALLBACK_CLIENT_WRITEABLE";
358
- case LWS_CALLBACK_CLIENT_RECEIVE:
359
- return "LWS_CALLBACK_CLIENT_RECEIVE";
360
- case LWS_CALLBACK_PROTOCOL_INIT:
361
- return "LWS_CALLBACK_PROTOCOL_INIT";
362
- case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED:
363
- return "LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED";
364
- case LWS_CALLBACK_USER:
365
- return "LWS_CALLBACK_USER";
366
- case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
367
- return "LWS_CALLBACK_CLIENT_CONNECTION_ERROR";
368
- case LWS_CALLBACK_CLIENT_CLOSED:
369
- return "LWS_CALLBACK_CLIENT_CLOSED";
370
- case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE:
371
- return "LWS_CALLBACK_WS_PEER_INITIATED_CLOSE";
372
- case LWS_CALLBACK_WSI_DESTROY:
373
- return "LWS_CALLBACK_WSI_DESTROY";
374
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
375
- return "LWS_CALLBACK_CLIENT_ESTABLISHED";
376
- case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION:
377
- return "LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION";
378
- case LWS_CALLBACK_EVENT_WAIT_CANCELLED:
379
- return "LWS_CALLBACK_EVENT_WAIT_CANCELLED";
380
- default:
381
- // Not using an internal buffer here for thread-safety with unknown calling context.
382
- error("Unknown LWS callback %u", reason);
383
- return "unknown";
384
- }
385
-}
386
-#endif
387
-
388
-void aclk_lws_wss_fail_report()
389
-{
390
- int i;
391
- int anything_to_send = 0;
392
- BUFFER *buf;
393
-
394
- if (netdata_anonymous_statistics_enabled <= 0)
395
- return;
396
-
397
- // guess - most of the callback will be 1-99 + ',' + \0
398
- buf = buffer_create((ACLK_LWS_CALLBACK_HISTORY * 2) + 10);
399
-
400
- for (i = 0; i < ACLK_LWS_CALLBACK_HISTORY; i++)
401
- if (engine_instance->lws_callback_history[i]) {
402
- buffer_sprintf(buf, "%s%d", (i ? "," : ""), engine_instance->lws_callback_history[i]);
403
- anything_to_send = 1;
404
- }
405
-
406
- if (anything_to_send)
407
- send_statistics("ACLK_CONN_FAIL", "FAIL", buffer_tostring(buf));
408
-
409
- buffer_free(buf);
410
-}
411
-
412
-static int aclk_lws_wss_callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
413
-{
414
- UNUSED(user);
415
- struct lws_wss_packet_buffer *data;
416
- int retval = 0;
417
- static int lws_shutting_down = 0;
418
- int i;
419
-
420
- for (i = ACLK_LWS_CALLBACK_HISTORY - 1; i > 0; i--)
421
- engine_instance->lws_callback_history[i] = engine_instance->lws_callback_history[i - 1];
422
- engine_instance->lws_callback_history[0] = (int)reason;
423
-
424
- if (unlikely(aclk_shutting_down && !lws_shutting_down)) {
425
- lws_shutting_down = 1;
426
- retval = -1;
427
- engine_instance->upstream_reconnect_request = 0;
428
- }
429
-
430
- // Callback servicing is forced when we are closed from above.
431
- if (engine_instance->upstream_reconnect_request) {
432
- error("Closing lws connection due to libmosquitto error.");
433
- char *upstream_connection_error = "MQTT protocol error. Closing underlying wss connection.";
434
- lws_close_reason(
435
- wsi, LWS_CLOSE_STATUS_PROTOCOL_ERR, (unsigned char *)upstream_connection_error,
436
- strlen(upstream_connection_error));
437
- retval = -1;
438
- engine_instance->upstream_reconnect_request = 0;
439
- }
440
-
441
- // Don't log to info - volume is proportional to message flow on ACLK.
442
- switch (reason) {
443
- case LWS_CALLBACK_CLIENT_WRITEABLE:
444
- aclk_lws_mutex_lock(&engine_instance->write_buf_mutex);
445
- data = engine_instance->write_buffer_head;
446
- if (likely(data)) {
447
- size_t bytes_left = data->data_size - data->written;
448
- if ( bytes_left > FRAGMENT_SIZE)
449
- bytes_left = FRAGMENT_SIZE;
450
- int n = lws_write(wsi, data->data + LWS_PRE + data->written, bytes_left, LWS_WRITE_BINARY);
451
- if (n>=0) {
452
- data->written += n;
453
- if (aclk_stats_enabled) {
454
- LEGACY_ACLK_STATS_LOCK;
455
- legacy_aclk_metrics_per_sample.write_q_consumed += n;
456
- LEGACY_ACLK_STATS_UNLOCK;
457
- }
458
- }
459
- //error("lws_write(req=%u,written=%u) %zu of %zu",bytes_left, rc, data->written,data->data_size,rc);
460
- if (data->written == data->data_size)
461
- {
462
- lws_wss_packet_buffer_pop(&engine_instance->write_buffer_head);
463
- lws_wss_packet_buffer_free(data);
464
- }
465
- if (engine_instance->write_buffer_head)
466
- lws_callback_on_writable(engine_instance->lws_wsi);
467
- }
468
- aclk_lws_mutex_unlock(&engine_instance->write_buf_mutex);
469
- return retval;
470
-
471
- case LWS_CALLBACK_CLIENT_RECEIVE:
472
- aclk_lws_mutex_lock(&engine_instance->read_buf_mutex);
473
- if (!received_data_to_ringbuff(engine_instance->read_ringbuffer, in, len))
474
- retval = 1;
475
- aclk_lws_mutex_unlock(&engine_instance->read_buf_mutex);
476
- if (aclk_stats_enabled) {
477
- LEGACY_ACLK_STATS_LOCK;
478
- legacy_aclk_metrics_per_sample.read_q_added += len;
479
- LEGACY_ACLK_STATS_UNLOCK;
480
- }
481
-
482
- // to future myself -> do not call this while read lock is active as it will eventually
483
- // want to acquire same lock later in aclk_lws_wss_client_read() function
484
- aclk_lws_connection_data_received();
485
- return retval;
486
-
487
- case LWS_CALLBACK_WSI_CREATE:
488
- case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH:
489
- case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
490
- case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS:
491
- case LWS_CALLBACK_GET_THREAD_ID: // ?
492
- case LWS_CALLBACK_EVENT_WAIT_CANCELLED:
493
- case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION:
494
- // Expected and safe to ignore.
495
-#ifdef ACLK_TRP_DEBUG_VERBOSE
496
- debug(D_ACLK, "Ignoring expected callback from LWS: %s", aclk_lws_callback_name(reason));
497
-#endif
498
- return retval;
499
-
500
- default:
501
- // Pass to next switch, this case removes compiler warnings.
502
- break;
503
- }
504
- // Log to info - volume is proportional to connection attempts.
505
-#ifdef ACLK_TRP_DEBUG_VERBOSE
506
- info("Processing callback %s", aclk_lws_callback_name(reason));
507
-#endif
508
- switch (reason) {
509
- case LWS_CALLBACK_PROTOCOL_INIT:
510
- aclk_lws_wss_connect(engine_instance->host, engine_instance->port); // Makes the outgoing connection
511
- break;
512
- case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED:
513
- if (engine_instance->lws_wsi != NULL && engine_instance->lws_wsi != wsi)
514
- error("Multiple connections on same WSI? %p vs %p", engine_instance->lws_wsi, wsi);
515
- engine_instance->lws_wsi = wsi;
516
- break;
517
- case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
518
- error(
519
- "Could not connect MQTT over WSS server \"%s:%d\". LwsReason:\"%s\"", engine_instance->host,
520
- engine_instance->port, (in ? (char *)in : "not given"));
521
- // Fall-through
522
- case LWS_CALLBACK_CLIENT_CLOSED:
523
- case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE:
524
- engine_instance->lws_wsi = NULL; // inside libwebsockets lws_close_free_wsi is called after callback
525
- aclk_lws_connection_closed();
526
- return -1; // the callback response is ignored, hope the above remains true
527
- case LWS_CALLBACK_WSI_DESTROY:
528
- aclk_lws_wss_clear_io_buffers();
529
- if (!engine_instance->websocket_connection_up)
530
- aclk_lws_wss_fail_report();
531
- engine_instance->lws_wsi = NULL;
532
- engine_instance->websocket_connection_up = 0;
533
- aclk_lws_connection_closed();
534
- break;
535
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
536
- engine_instance->websocket_connection_up = 1;
537
- aclk_lws_connection_established(engine_instance->host, engine_instance->port);
538
- break;
539
-
540
- default:
541
-#ifdef ACLK_TRP_DEBUG_VERBOSE
542
- error("Unexpected callback from libwebsockets %s", aclk_lws_callback_name(reason));
543
-#endif
544
- break;
545
- }
546
- return retval; //0-OK, other connection should be closed!
547
-}
548
-
549
-int aclk_lws_wss_client_write(void *buf, size_t count)
550
-{
551
- if (engine_instance && engine_instance->lws_wsi && engine_instance->websocket_connection_up) {
552
- aclk_lws_mutex_lock(&engine_instance->write_buf_mutex);
553
- lws_wss_packet_buffer_append(&engine_instance->write_buffer_head, lws_wss_packet_buffer_new(buf, count));
554
- aclk_lws_mutex_unlock(&engine_instance->write_buf_mutex);
555
-
556
- if (aclk_stats_enabled) {
557
- LEGACY_ACLK_STATS_LOCK;
558
- legacy_aclk_metrics_per_sample.write_q_added += count;
559
- LEGACY_ACLK_STATS_UNLOCK;
560
- }
561
-
562
- lws_callback_on_writable(engine_instance->lws_wsi);
563
- return count;
564
- }
565
- return 0;
566
-}
567
-
568
-int aclk_lws_wss_client_read(void *buf, size_t count)
569
-{
570
- size_t data_to_be_read = count;
571
-
572
- aclk_lws_mutex_lock(&engine_instance->read_buf_mutex);
573
- size_t readable_byte_count = lws_ring_get_count_waiting_elements(engine_instance->read_ringbuffer, NULL);
574
- if (unlikely(readable_byte_count == 0)) {
575
- errno = EAGAIN;
576
- data_to_be_read = -1;
577
- goto abort;
578
- }
579
-
580
- if (readable_byte_count < data_to_be_read)
581
- data_to_be_read = readable_byte_count;
582
-
583
- data_to_be_read = lws_ring_consume(engine_instance->read_ringbuffer, NULL, buf, data_to_be_read);
584
- if (data_to_be_read == readable_byte_count)
585
- engine_instance->data_to_read = 0;
586
-
587
- if (aclk_stats_enabled) {
588
- LEGACY_ACLK_STATS_LOCK;
589
- legacy_aclk_metrics_per_sample.read_q_consumed += data_to_be_read;
590
- LEGACY_ACLK_STATS_UNLOCK;
591
- }
592
-
593
-abort:
594
- aclk_lws_mutex_unlock(&engine_instance->read_buf_mutex);
595
- return data_to_be_read;
596
-}
597
-
598
-void aclk_lws_wss_service_loop()
599
-{
600
- if (engine_instance)
601
- {
602
- /*if (engine_instance->lws_wsi) {
603
- lws_cancel_service(engine_instance->lws_context);
604
- lws_callback_on_writable(engine_instance->lws_wsi);
605
- }*/
606
- lws_service(engine_instance->lws_context, 0);
607
- }
608
-}
609
-
610
-// in case the MQTT connection disconnect while lws transport is still operational
611
-// we should drop connection and reconnect
612
-// this function should be called when that happens to notify lws of that situation
613
-void aclk_lws_wss_mqtt_layer_disconnect_notif()
614
-{
615
- if (!engine_instance)
616
- return;
617
- if (engine_instance->lws_wsi && engine_instance->websocket_connection_up) {
618
- engine_instance->upstream_reconnect_request = 1;
619
- lws_callback_on_writable(
620
- engine_instance->lws_wsi); //here we just do it to ensure we get callback called from lws, we don't need any actual data to be written.
621
- }
622
-}
aclk/legacy/aclk_lws_wss_client.h
deleted
-92
@@ -1,92 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef ACLK_LWS_WSS_CLIENT_H
4
-#define ACLK_LWS_WSS_CLIENT_H
5
-
6
-#include <libwebsockets.h>
7
-
8
-#include "libnetdata/libnetdata.h"
9
-
10
-// This is as define because ideally the ACLK at high level
11
-// can do mosquitto writes and reads only from one thread
12
-// which is cleaner implementation IMHO
13
-// in such case this mutexes are not necessary and life
14
-// is simpler
15
-#define ACLK_LWS_MOSQUITTO_IO_CALLS_MULTITHREADED 1
16
-
17
-#define ACLK_LWS_WSS_RECV_BUFF_SIZE_BYTES (128 * 1024)
18
-
19
-#define ACLK_LWS_CALLBACK_HISTORY 10
20
-
21
-#ifdef ACLK_LWS_MOSQUITTO_IO_CALLS_MULTITHREADED
22
-#define aclk_lws_mutex_init(x) netdata_mutex_init(x)
23
-#define aclk_lws_mutex_lock(x) netdata_mutex_lock(x)
24
-#define aclk_lws_mutex_unlock(x) netdata_mutex_unlock(x)
25
-#else
26
-#define aclk_lws_mutex_init(x)
27
-#define aclk_lws_mutex_lock(x)
28
-#define aclk_lws_mutex_unlock(x)
29
-#endif
30
-
31
-struct aclk_lws_wss_engine_callbacks {
32
- void (*connection_established_callback)();
33
- void (*data_rcvd_callback)();
34
- void (*data_writable_callback)();
35
- void (*connection_closed)();
36
-};
37
-
38
-struct lws_wss_packet_buffer {
39
- unsigned char *data;
40
- size_t data_size, written;
41
- struct lws_wss_packet_buffer *next;
42
-};
43
-
44
-struct aclk_lws_wss_engine_instance {
45
- //target host/port for connection
46
- char *host;
47
- int port;
48
-
49
- //internal data
50
- struct lws_context *lws_context;
51
- struct lws *lws_wsi;
52
-
53
-#ifdef ACLK_LWS_MOSQUITTO_IO_CALLS_MULTITHREADED
54
- netdata_mutex_t write_buf_mutex;
55
- netdata_mutex_t read_buf_mutex;
56
-#endif
57
-
58
- struct lws_wss_packet_buffer *write_buffer_head;
59
- struct lws_ring *read_ringbuffer;
60
-
61
- //flags to be read by engine user
62
- int websocket_connection_up;
63
-
64
- // currently this is by default disabled
65
-
66
- int data_to_read;
67
- int upstream_reconnect_request;
68
-
69
- int lws_callback_history[ACLK_LWS_CALLBACK_HISTORY];
70
-};
71
-
72
-void aclk_lws_wss_client_destroy();
73
-void aclk_lws_wss_destroy_context();
74
-
75
-int aclk_lws_wss_connect(char *host, int port);
76
-
77
-int aclk_lws_wss_client_write(void *buf, size_t count);
78
-int aclk_lws_wss_client_read(void *buf, size_t count);
79
-void aclk_lws_wss_service_loop();
80
-
81
-void aclk_lws_wss_mqtt_layer_disconnect_notif();
82
-
83
-// Notifications inside the layer above
84
-void aclk_lws_connection_established();
85
-void aclk_lws_connection_data_received();
86
-void aclk_lws_connection_closed();
87
-void lws_wss_check_queues(size_t *write_len, size_t *write_len_bytes, size_t *read_len);
88
-
89
-void aclk_wss_set_proxy(struct lws_vhost *vhost);
90
-
91
-#define FRAGMENT_SIZE 4096
92
-#endif
aclk/legacy/aclk_query.c
deleted
-843
@@ -1,843 +0,0 @@
1
-#include "aclk_common.h"
2
-#include "aclk_query.h"
3
-#include "aclk_stats.h"
4
-#include "aclk_rx_msgs.h"
5
-#include "agent_cloud_link.h"
6
-
7
-#define WEB_HDR_ACCEPT_ENC "Accept-Encoding:"
8
-
9
-#define ACLK_QUERY_THREAD_NAME "ACLK_Query"
10
-
11
-pthread_cond_t legacy_query_cond_wait = PTHREAD_COND_INITIALIZER;
12
-pthread_mutex_t legacy_query_lock_wait = PTHREAD_MUTEX_INITIALIZER;
13
-#define LEGACY_QUERY_THREAD_LOCK pthread_mutex_lock(&legacy_query_lock_wait)
14
-#define LEGACY_QUERY_THREAD_UNLOCK pthread_mutex_unlock(&legacy_query_lock_wait)
15
-
16
-#ifndef __GNUC__
17
-#pragma region ACLK_QUEUE
18
-#endif
19
-
20
-static netdata_mutex_t queue_mutex = NETDATA_MUTEX_INITIALIZER;
21
-#define ACLK_QUEUE_LOCK netdata_mutex_lock(&queue_mutex)
22
-#define ACLK_QUEUE_UNLOCK netdata_mutex_unlock(&queue_mutex)
23
-
24
-struct aclk_query {
25
- usec_t created;
26
- struct timeval tv_in;
27
- usec_t created_boot_time;
28
- time_t run_after; // Delay run until after this time
29
- ACLK_CMD cmd; // What command is this
30
- char *topic; // Topic to respond to
31
- char *data; // Internal data (NULL if request from the cloud)
32
- char *msg_id; // msg_id generated by the cloud (NULL if internal)
33
- char *query; // The actual query
34
- u_char deleted; // Mark deleted for garbage collect
35
- int idx; // index of query thread
36
- struct aclk_query *next;
37
-};
38
-
39
-struct aclk_query_queue {
40
- struct aclk_query *aclk_query_head;
41
- struct aclk_query *aclk_query_tail;
42
- unsigned int count;
43
-} aclk_queue = { .aclk_query_head = NULL, .aclk_query_tail = NULL, .count = 0 };
44
-
45
-
46
-unsigned int aclk_query_size()
47
-{
48
- int r;
49
- ACLK_QUEUE_LOCK;
50
- r = aclk_queue.count;
51
- ACLK_QUEUE_UNLOCK;
52
- return r;
53
-}
54
-
55
-/*
56
- * Free a query structure when done
57
- */
58
-static void aclk_query_free(struct aclk_query *this_query)
59
-{
60
- if (unlikely(!this_query))
61
- return;
62
-
63
- freez(this_query->topic);
64
- if (likely(this_query->query))
65
- freez(this_query->query);
66
- if(this_query->data && this_query->cmd == ACLK_CMD_CLOUD_QUERY_2) {
67
- struct aclk_cloud_req_v2 *del = (struct aclk_cloud_req_v2 *)this_query->data;
68
- freez(del->query_endpoint);
69
- freez(del->data);
70
- freez(del);
71
- }
72
- if (likely(this_query->msg_id))
73
- freez(this_query->msg_id);
74
- freez(this_query);
75
-}
76
-
77
-/*
78
- * Get the next query to process - NULL if nothing there
79
- * The caller needs to free memory by calling aclk_query_free()
80
- *
81
- * topic
82
- * query
83
- * The structure itself
84
- *
85
- */
86
-static struct aclk_query *aclk_queue_pop()
87
-{
88
- struct aclk_query *this_query;
89
-
90
- ACLK_QUEUE_LOCK;
91
-
92
- if (likely(!aclk_queue.aclk_query_head)) {
93
- ACLK_QUEUE_UNLOCK;
94
- return NULL;
95
- }
96
-
97
- this_query = aclk_queue.aclk_query_head;
98
-
99
- // Get rid of the deleted entries
100
- while (this_query && this_query->deleted) {
101
- aclk_queue.count--;
102
-
103
- aclk_queue.aclk_query_head = aclk_queue.aclk_query_head->next;
104
-
105
- if (likely(!aclk_queue.aclk_query_head)) {
106
- aclk_queue.aclk_query_tail = NULL;
107
- }
108
-
109
- aclk_query_free(this_query);
110
-
111
- this_query = aclk_queue.aclk_query_head;
112
- }
113
-
114
- if (likely(!this_query)) {
115
- ACLK_QUEUE_UNLOCK;
116
- return NULL;
117
- }
118
-
119
- if (!this_query->deleted && this_query->run_after > now_realtime_sec()) {
120
- info("Query %s will run in %ld seconds", this_query->query, this_query->run_after - now_realtime_sec());
121
- ACLK_QUEUE_UNLOCK;
122
- return NULL;
123
- }
124
-
125
- aclk_queue.count--;
126
- aclk_queue.aclk_query_head = aclk_queue.aclk_query_head->next;
127
-
128
- if (likely(!aclk_queue.aclk_query_head)) {
129
- aclk_queue.aclk_query_tail = NULL;
130
- }
131
-
132
- ACLK_QUEUE_UNLOCK;
133
- return this_query;
134
-}
135
-
136
-// Returns the entry after which we need to create a new entry to run at the specified time
137
-// If NULL is returned we need to add to HEAD
138
-// Need to have a QUERY lock before calling this
139
-
140
-static struct aclk_query *aclk_query_find_position(time_t time_to_run)
141
-{
142
- struct aclk_query *tmp_query, *last_query;
143
-
144
- // Quick check if we will add to the end
145
- if (likely(aclk_queue.aclk_query_tail)) {
146
- if (aclk_queue.aclk_query_tail->run_after <= time_to_run)
147
- return aclk_queue.aclk_query_tail;
148
- }
149
-
150
- last_query = NULL;
151
- tmp_query = aclk_queue.aclk_query_head;
152
-
153
- while (tmp_query) {
154
- if (tmp_query->run_after > time_to_run)
155
- return last_query;
156
- last_query = tmp_query;
157
- tmp_query = tmp_query->next;
158
- }
159
- return last_query;
160
-}
161
-
162
-// Need to have a QUERY lock before calling this
163
-static struct aclk_query *
164
-aclk_query_find(char *topic, void *data, char *msg_id, char *query, ACLK_CMD cmd, struct aclk_query **last_query)
165
-{
166
- struct aclk_query *tmp_query, *prev_query;
167
- UNUSED(cmd);
168
-
169
- tmp_query = aclk_queue.aclk_query_head;
170
- prev_query = NULL;
171
- while (tmp_query) {
172
- if (likely(!tmp_query->deleted)) {
173
- if (strcmp(tmp_query->topic, topic) == 0 && (!query || strcmp(tmp_query->query, query) == 0)) {
174
- if ((!data || data == tmp_query->data) &&
175
- (!msg_id || (msg_id && strcmp(msg_id, tmp_query->msg_id) == 0))) {
176
- if (likely(last_query))
177
- *last_query = prev_query;
178
- return tmp_query;
179
- }
180
- }
181
- }
182
- prev_query = tmp_query;
183
- tmp_query = tmp_query->next;
184
- }
185
- return NULL;
186
-}
187
-
188
-/*
189
- * Add a query to execute, the result will be send to the specified topic
190
- */
191
-
192
-int legacy_aclk_queue_query(char *topic, void *data, char *msg_id, char *query, int run_after, int internal, ACLK_CMD aclk_cmd)
193
-{
194
- struct aclk_query *new_query, *tmp_query;
195
-
196
- // Ignore all commands while we wait for the agent to initialize
197
- if (unlikely(!aclk_connected))
198
- return 1;
199
-
200
- run_after = now_realtime_sec() + run_after;
201
-
202
- ACLK_QUEUE_LOCK;
203
- struct aclk_query *last_query = NULL;
204
-
205
- tmp_query = aclk_query_find(topic, data, msg_id, query, aclk_cmd, &last_query);
206
- if (unlikely(tmp_query)) {
207
- if (tmp_query->run_after == run_after) {
208
- ACLK_QUEUE_UNLOCK;
209
- LEGACY_QUERY_THREAD_WAKEUP;
210
- return 0;
211
- }
212
-
213
- if (last_query)
214
- last_query->next = tmp_query->next;
215
- else
216
- aclk_queue.aclk_query_head = tmp_query->next;
217
-
218
- debug(D_ACLK, "Removing double entry");
219
- aclk_query_free(tmp_query);
220
- aclk_queue.count--;
221
- }
222
-
223
- if (aclk_stats_enabled) {
224
- LEGACY_ACLK_STATS_LOCK;
225
- legacy_aclk_metrics_per_sample.queries_queued++;
226
- LEGACY_ACLK_STATS_UNLOCK;
227
- }
228
-
229
- new_query = callocz(1, sizeof(struct aclk_query));
230
- new_query->cmd = aclk_cmd;
231
- if (internal) {
232
- new_query->topic = strdupz(topic);
233
- if (likely(query))
234
- new_query->query = strdupz(query);
235
- } else {
236
- new_query->topic = topic;
237
- new_query->query = query;
238
- new_query->msg_id = msg_id;
239
- }
240
-
241
- new_query->data = data;
242
- new_query->next = NULL;
243
- now_realtime_timeval(&new_query->tv_in);
244
- new_query->created = (new_query->tv_in.tv_sec * USEC_PER_SEC) + new_query->tv_in.tv_usec;
245
- new_query->created_boot_time = now_boottime_usec();
246
- new_query->run_after = run_after;
247
-
248
- debug(D_ACLK, "Added query (%s) (%s)", topic, query ? query : "");
249
-
250
- tmp_query = aclk_query_find_position(run_after);
251
-
252
- if (tmp_query) {
253
- new_query->next = tmp_query->next;
254
- tmp_query->next = new_query;
255
- if (tmp_query == aclk_queue.aclk_query_tail)
256
- aclk_queue.aclk_query_tail = new_query;
257
- aclk_queue.count++;
258
- ACLK_QUEUE_UNLOCK;
259
- LEGACY_QUERY_THREAD_WAKEUP;
260
- return 0;
261
- }
262
-
263
- new_query->next = aclk_queue.aclk_query_head;
264
- aclk_queue.aclk_query_head = new_query;
265
- aclk_queue.count++;
266
-
267
- ACLK_QUEUE_UNLOCK;
268
- LEGACY_QUERY_THREAD_WAKEUP;
269
- return 0;
270
-}
271
-
272
-#ifndef __GNUC__
273
-#pragma endregion
274
-#endif
275
-
276
-#ifndef __GNUC__
277
-#pragma region Helper Functions
278
-#endif
279
-
280
-/*
281
- * Take a buffer, encode it and rewrite it
282
- *
283
- */
284
-
285
-static char *aclk_encode_response(char *src, size_t content_size, int keep_newlines)
286
-{
287
- char *tmp_buffer = mallocz(content_size * 2);
288
- char *dst = tmp_buffer;
289
- while (content_size > 0) {
290
- switch (*src) {
291
- case '\n':
292
- if (keep_newlines)
293
- {
294
- *dst++ = '\\';
295
- *dst++ = 'n';
296
- }
297
- break;
298
- case '\t':
299
- break;
300
- case 0x01 ... 0x08:
301
- case 0x0b ... 0x1F:
302
- *dst++ = '\\';
303
- *dst++ = 'u';
304
- *dst++ = '0';
305
- *dst++ = '0';
306
- *dst++ = (*src < 0x0F) ? '0' : '1';
307
- *dst++ = to_hex(*src);
308
- break;
309
- case '\"':
310
- *dst++ = '\\';
311
- *dst++ = *src;
312
- break;
313
- default:
314
- *dst++ = *src;
315
- }
316
- src++;
317
- content_size--;
318
- }
319
- *dst = '\0';
320
-
321
- return tmp_buffer;
322
-}
323
-
324
-#ifndef __GNUC__
325
-#pragma endregion
326
-#endif
327
-
328
-#ifndef __GNUC__
329
-#pragma region ACLK_QUERY
330
-#endif
331
-
332
-
333
-static usec_t aclk_web_api_request_v1(RRDHOST *host, struct web_client *w, char *url, usec_t q_created)
334
-{
335
- usec_t t = now_boottime_usec();
336
- legacy_aclk_metric_mat_update(&legacy_aclk_metrics_per_sample.cloud_q_recvd_to_processed, t - q_created);
337
-
338
- w->response.code = web_client_api_request_v1(host, w, url);
339
- t = now_boottime_usec() - t;
340
-
341
- legacy_aclk_metric_mat_update(&legacy_aclk_metrics_per_sample.cloud_q_db_query_time, t);
342
-
343
- return t;
344
-}
345
-
346
-static int aclk_execute_query(struct aclk_query *this_query)
347
-{
348
- if (strncmp(this_query->query, "/api/v1/", 8) == 0) {
349
- struct web_client *w = (struct web_client *)callocz(1, sizeof(struct web_client));
350
- w->response.data = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
351
- w->response.header = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE);
352
- w->response.header_output = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE);
353
- strcpy(w->origin, "*"); // Simulate web_client_create_on_fd()
354
- w->cookie1[0] = 0; // Simulate web_client_create_on_fd()
355
- w->cookie2[0] = 0; // Simulate web_client_create_on_fd()
356
- w->acl = 0x1f;
357
-
358
- char *mysep = strchr(this_query->query, '?');
359
- if (mysep) {
360
- strncpyz(w->decoded_query_string, mysep, NETDATA_WEB_REQUEST_URL_SIZE);
361
- *mysep = '\0';
362
- } else
363
- strncpyz(w->decoded_query_string, this_query->query, NETDATA_WEB_REQUEST_URL_SIZE);
364
-
365
- mysep = strrchr(this_query->query, '/');
366
-
367
- // TODO: handle bad response perhaps in a different way. For now it does to the payload
368
- w->tv_in = this_query->tv_in;
369
- now_realtime_timeval(&w->tv_ready);
370
- aclk_web_api_request_v1(localhost, w, mysep ? mysep + 1 : "noop", this_query->created_boot_time);
371
- size_t size = w->response.data->len;
372
- size_t sent = size;
373
- w->response.data->date = w->tv_ready.tv_sec;
374
- web_client_build_http_header(w); // TODO: this function should offset from date, not tv_ready
375
- BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
376
- buffer_flush(local_buffer);
377
- local_buffer->contenttype = CT_APPLICATION_JSON;
378
-
379
- aclk_create_header(local_buffer, "http", this_query->msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
380
- buffer_strcat(local_buffer, ",\n\t\"payload\": ");
381
- char *encoded_response = aclk_encode_response(w->response.data->buffer, w->response.data->len, 0);
382
- char *encoded_header = aclk_encode_response(w->response.header_output->buffer, w->response.header_output->len, 1);
383
-
384
- buffer_sprintf(
385
- local_buffer, "{\n\"code\": %d,\n\"body\": \"%s\",\n\"headers\": \"%s\"\n}",
386
- w->response.code, encoded_response, encoded_header);
387
-
388
- buffer_sprintf(local_buffer, "\n}");
389
-
390
- debug(D_ACLK, "Response:%s", encoded_header);
391
-
392
- aclk_send_message(this_query->topic, local_buffer->buffer, this_query->msg_id);
393
-
394
- struct timeval tv;
395
- now_realtime_timeval(&tv);
396
-
397
- log_access("%llu: %d '[ACLK]:%d' '%s' (sent/all = %zu/%zu bytes %0.0f%%, prep/sent/total = %0.2f/%0.2f/%0.2f ms) %d '%s'",
398
- w->id
399
- , gettid()
400
- , this_query->idx
401
- , "DATA"
402
- , sent
403
- , size
404
- , size > sent ? -((size > 0) ? (((size - sent) / (double) size) * 100.0) : 0.0) : ((size > 0) ? (((sent - size ) / (double) size) * 100.0) : 0.0)
405
- , dt_usec(&w->tv_ready, &w->tv_in) / 1000.0
406
- , dt_usec(&tv, &w->tv_ready) / 1000.0
407
- , dt_usec(&tv, &w->tv_in) / 1000.0
408
- , w->response.code
409
- , strip_control_characters(this_query->query)
410
- );
411
-
412
- buffer_free(w->response.data);
413
- buffer_free(w->response.header);
414
- buffer_free(w->response.header_output);
415
- freez(w);
416
- buffer_free(local_buffer);
417
- freez(encoded_response);
418
- freez(encoded_header);
419
- return 0;
420
- }
421
- return 1;
422
-}
423
-
424
-static int aclk_execute_query_v2(struct aclk_query *this_query)
425
-{
426
- int retval = 0;
427
- usec_t t;
428
- BUFFER *local_buffer = NULL;
429
- struct aclk_cloud_req_v2 *cloud_req = (struct aclk_cloud_req_v2 *)this_query->data;
430
-
431
-#ifdef NETDATA_WITH_ZLIB
432
- int z_ret;
433
- BUFFER *z_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
434
- char *start, *end;
435
-#endif
436
-
437
- struct web_client *w = (struct web_client *)callocz(1, sizeof(struct web_client));
438
- w->response.data = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
439
- w->response.header = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE);
440
- w->response.header_output = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE);
441
- strcpy(w->origin, "*"); // Simulate web_client_create_on_fd()
442
- w->cookie1[0] = 0; // Simulate web_client_create_on_fd()
443
- w->cookie2[0] = 0; // Simulate web_client_create_on_fd()
444
- w->acl = 0x1f;
445
-
446
- char *mysep = strchr(this_query->query, '?');
447
- if (mysep) {
448
- url_decode_r(w->decoded_query_string, mysep, NETDATA_WEB_REQUEST_URL_SIZE + 1);
449
- *mysep = '\0';
450
- } else
451
- url_decode_r(w->decoded_query_string, this_query->query, NETDATA_WEB_REQUEST_URL_SIZE + 1);
452
-
453
- mysep = strrchr(this_query->query, '/');
454
-
455
- // execute the query
456
- w->tv_in = this_query->tv_in;
457
- now_realtime_timeval(&w->tv_ready);
458
- t = aclk_web_api_request_v1(cloud_req->host, w, mysep ? mysep + 1 : "noop", this_query->created_boot_time);
459
- size_t size = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->response.rlen:w->response.data->len;
460
- size_t sent = size;
461
-
462
-#ifdef NETDATA_WITH_ZLIB
463
- // check if gzip encoding can and should be used
464
- if ((start = strstr(cloud_req->data, WEB_HDR_ACCEPT_ENC))) {
465
- start += strlen(WEB_HDR_ACCEPT_ENC);
466
- end = strstr(start, "\x0D\x0A");
467
- start = strstr(start, "gzip");
468
-
469
- if (start && start < end) {
470
- w->response.zstream.zalloc = Z_NULL;
471
- w->response.zstream.zfree = Z_NULL;
472
- w->response.zstream.opaque = Z_NULL;
473
- if(deflateInit2(&w->response.zstream, web_gzip_level, Z_DEFLATED, 15 + 16, 8, web_gzip_strategy) == Z_OK) {
474
- w->response.zinitialized = 1;
475
- w->response.zoutput = 1;
476
- } else
477
- error("Failed to initialize zlib. Proceeding without compression.");
478
- }
479
- }
480
-
481
- if (w->response.data->len && w->response.zinitialized) {
482
- w->response.zstream.next_in = (Bytef *)w->response.data->buffer;
483
- w->response.zstream.avail_in = w->response.data->len;
484
- do {
485
- w->response.zstream.avail_out = NETDATA_WEB_RESPONSE_ZLIB_CHUNK_SIZE;
486
- w->response.zstream.next_out = w->response.zbuffer;
487
- z_ret = deflate(&w->response.zstream, Z_FINISH);
488
- if(z_ret < 0) {
489
- if(w->response.zstream.msg)
490
- error("Error compressing body. ZLIB error: \"%s\"", w->response.zstream.msg);
491
- else
492
- error("Unknown error during zlib compression.");
493
- retval = 1;
494
- goto cleanup;
495
- }
496
- int bytes_to_cpy = NETDATA_WEB_RESPONSE_ZLIB_CHUNK_SIZE - w->response.zstream.avail_out;
497
- buffer_need_bytes(z_buffer, bytes_to_cpy);
498
- memcpy(&z_buffer->buffer[z_buffer->len], w->response.zbuffer, bytes_to_cpy);
499
- z_buffer->len += bytes_to_cpy;
500
- } while(z_ret != Z_STREAM_END);
501
- // so that web_client_build_http_header
502
- // puts correct content length into header
503
- buffer_free(w->response.data);
504
- w->response.data = z_buffer;
505
- z_buffer = NULL;
506
- }
507
-#endif
508
-
509
- w->response.data->date = w->tv_ready.tv_sec;
510
- web_client_build_http_header(w);
511
- local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
512
- local_buffer->contenttype = CT_APPLICATION_JSON;
513
-
514
- aclk_create_header(local_buffer, "http", this_query->msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
515
- buffer_sprintf(local_buffer, ",\"t-exec\": %llu,\"t-rx\": %llu,\"http-code\": %d", t, this_query->created, w->response.code);
516
- buffer_strcat(local_buffer, "}\x0D\x0A\x0D\x0A");
517
- buffer_strcat(local_buffer, w->response.header_output->buffer);
518
-
519
- if (w->response.data->len) {
520
-#ifdef NETDATA_WITH_ZLIB
521
- if (w->response.zinitialized) {
522
- buffer_need_bytes(local_buffer, w->response.data->len);
523
- memcpy(&local_buffer->buffer[local_buffer->len], w->response.data->buffer, w->response.data->len);
524
- local_buffer->len += w->response.data->len;
525
- sent = sent - size + w->response.data->len;
526
- } else {
527
-#endif
528
- buffer_strcat(local_buffer, w->response.data->buffer);
529
-#ifdef NETDATA_WITH_ZLIB
530
- }
531
-#endif
532
- }
533
-
534
- aclk_send_message_bin(this_query->topic, local_buffer->buffer, local_buffer->len, this_query->msg_id);
535
-
536
- struct timeval tv;
537
- now_realtime_timeval(&tv);
538
-
539
- log_access("%llu: %d '[ACLK]:%d' '%s' (sent/all = %zu/%zu bytes %0.0f%%, prep/sent/total = %0.2f/%0.2f/%0.2f ms) %d '%s'",
540
- w->id
541
- , gettid()
542
- , this_query->idx
543
- , "DATA"
544
- , sent
545
- , size
546
- , size > sent ? -((size > 0) ? (((size - sent) / (double) size) * 100.0) : 0.0) : ((size > 0) ? (((sent - size ) / (double) size) * 100.0) : 0.0)
547
- , dt_usec(&w->tv_ready, &w->tv_in) / 1000.0
548
- , dt_usec(&tv, &w->tv_ready) / 1000.0
549
- , dt_usec(&tv, &w->tv_in) / 1000.0
550
- , w->response.code
551
- , strip_control_characters(this_query->query)
552
- );
553
-cleanup:
554
-#ifdef NETDATA_WITH_ZLIB
555
- if(w->response.zinitialized)
556
- deflateEnd(&w->response.zstream);
557
- buffer_free(z_buffer);
558
-#endif
559
- buffer_free(w->response.data);
560
- buffer_free(w->response.header);
561
- buffer_free(w->response.header_output);
562
- freez(w);
563
- buffer_free(local_buffer);
564
- return retval;
565
-}
566
-
567
-#define ACLK_HOST_PTR_COMPULSORY(x) \
568
- if (unlikely(!host)) { \
569
- errno = 0; \
570
- error(x " needs host pointer"); \
571
- break; \
572
- }
573
-
574
-/*
575
- * This function will fetch the next pending command and process it
576
- *
577
- */
578
-static int aclk_process_query(struct aclk_query_thread *t_info)
579
-{
580
- struct aclk_query *this_query;
581
- static long int query_count = 0;
582
- ACLK_METADATA_STATE meta_state;
583
- RRDHOST *host;
584
-
585
- if (!aclk_connected)
586
- return 0;
587
-
588
- this_query = aclk_queue_pop();
589
- if (likely(!this_query)) {
590
- return 0;
591
- }
592
-
593
- if (unlikely(this_query->deleted)) {
594
- debug(D_ACLK, "Garbage collect query %s:%s", this_query->topic, this_query->query);
595
- aclk_query_free(this_query);
596
- return 1;
597
- }
598
- query_count++;
599
-
600
- host = (RRDHOST*)this_query->data;
601
- this_query->idx = t_info->idx;
602
-
603
- debug(
604
- D_ACLK, "Query #%ld (%s) size=%zu in queue %llu ms", query_count, this_query->topic,
605
- this_query->query ? strlen(this_query->query) : 0, (now_realtime_usec() - this_query->created)/USEC_PER_MS);
606
-
607
- switch (this_query->cmd) {
608
- case ACLK_CMD_ONCONNECT:
609
- ACLK_HOST_PTR_COMPULSORY("ACLK_CMD_ONCONNECT");
610
-#if ACLK_VERSION_MIN < ACLK_V_CHILDRENSTATE
611
- if (host != localhost && legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE) {
612
- error("We are not allowed to send connect message in ACLK version before %d", ACLK_V_CHILDRENSTATE);
613
- break;
614
- }
615
-#else
616
-#warning "This check became unnecessary. Remove"
617
-#endif
618
-
619
- debug(D_ACLK, "EXECUTING on connect metadata command for host \"%s\" GUID \"%s\"",
620
- host->hostname,
621
- host->machine_guid);
622
-
623
- rrdhost_aclk_state_lock(host);
624
- meta_state = host->aclk_state.metadata;
625
- host->aclk_state.metadata = ACLK_METADATA_SENT;
626
- rrdhost_aclk_state_unlock(host);
627
- aclk_send_metadata(meta_state, host);
628
- break;
629
-
630
- case ACLK_CMD_CHART:
631
- ACLK_HOST_PTR_COMPULSORY("ACLK_CMD_CHART");
632
-
633
- debug(D_ACLK, "EXECUTING a chart update command");
634
- aclk_send_single_chart(host, this_query->query);
635
- break;
636
-
637
- case ACLK_CMD_CHARTDEL:
638
- ACLK_HOST_PTR_COMPULSORY("ACLK_CMD_CHARTDEL");
639
-
640
- debug(D_ACLK, "EXECUTING a chart delete command");
641
- //TODO: This send the info metadata for now
642
- legacy_aclk_send_info_metadata(ACLK_METADATA_SENT, host);
643
- break;
644
-
645
- case ACLK_CMD_ALARM:
646
- debug(D_ACLK, "EXECUTING an alarm update command");
647
- aclk_send_message(this_query->topic, this_query->query, this_query->msg_id);
648
- break;
649
-
650
- case ACLK_CMD_CLOUD:
651
- debug(D_ACLK, "EXECUTING a cloud command");
652
- aclk_execute_query(this_query);
653
- break;
654
- case ACLK_CMD_CLOUD_QUERY_2:
655
- debug(D_ACLK, "EXECUTING Cloud Query v2");
656
- aclk_execute_query_v2(this_query);
657
- break;
658
-
659
- case ACLK_CMD_CHILD_CONNECT:
660
- case ACLK_CMD_CHILD_DISCONNECT:
661
- ACLK_HOST_PTR_COMPULSORY("ACLK_CMD_CHILD_CONNECT/ACLK_CMD_CHILD_DISCONNECT");
662
-
663
- debug(
664
- D_ACLK, "Execution Child %s command",
665
- this_query->cmd == ACLK_CMD_CHILD_CONNECT ? "connect" : "disconnect");
666
- aclk_send_info_child_connection(host, this_query->cmd);
667
- break;
668
-
669
- default:
670
- errno = 0;
671
- error("Unknown ACLK Query Command");
672
- break;
673
- }
674
- debug(D_ACLK, "Query #%ld (%s) done", query_count, this_query->topic);
675
-
676
- if (aclk_stats_enabled) {
677
- LEGACY_ACLK_STATS_LOCK;
678
- legacy_aclk_metrics_per_sample.queries_dispatched++;
679
- legacy_aclk_queries_per_thread[t_info->idx]++;
680
- LEGACY_ACLK_STATS_UNLOCK;
681
-
682
- if (likely(getrusage_called_this_tick[t_info->idx] < MAX_GETRUSAGE_CALLS_PER_TICK)) {
683
- getrusage(RUSAGE_THREAD, &rusage_per_thread[t_info->idx]);
684
- getrusage_called_this_tick[t_info->idx]++;
685
- }
686
-
687
- }
688
-
689
- aclk_query_free(this_query);
690
-
691
- return 1;
692
-}
693
-
694
-void legacy_aclk_query_threads_cleanup(struct aclk_query_threads *query_threads)
695
-{
696
- if (query_threads && query_threads->thread_list) {
697
- for (int i = 0; i < query_threads->count; i++) {
698
- netdata_thread_join(query_threads->thread_list[i].thread, NULL);
699
- }
700
- freez(query_threads->thread_list);
701
- }
702
-
703
- struct aclk_query *this_query;
704
-
705
- do {
706
- this_query = aclk_queue_pop();
707
- aclk_query_free(this_query);
708
- } while (this_query);
709
-}
710
-
711
-#define TASK_LEN_MAX 22
712
-void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads)
713
-{
714
- info("Starting %d query threads.", query_threads->count);
715
-
716
- char thread_name[TASK_LEN_MAX];
717
- query_threads->thread_list = callocz(query_threads->count, sizeof(struct aclk_query_thread));
718
- for (int i = 0; i < query_threads->count; i++) {
719
- query_threads->thread_list[i].idx = i; //thread needs to know its index for statistics
720
-
721
- if(unlikely(snprintfz(thread_name, TASK_LEN_MAX, "%s_%d", ACLK_QUERY_THREAD_NAME, i) < 0))
722
- error("snprintf encoding error");
723
- netdata_thread_create(
724
- &query_threads->thread_list[i].thread, thread_name, NETDATA_THREAD_OPTION_JOINABLE, legacy_aclk_query_main_thread,
725
- &query_threads->thread_list[i]);
726
- }
727
-}
728
-
729
-/**
730
- * Checks and updates popcorning state of rrdhost
731
- * returns actual/updated popcorning state
732
- */
733
-
734
-ACLK_AGENT_STATE aclk_host_popcorn_check(RRDHOST *host)
735
-{
736
- rrdhost_aclk_state_lock(host);
737
- ACLK_AGENT_STATE ret = host->aclk_state.state;
738
- if (host->aclk_state.state != ACLK_HOST_INITIALIZING){
739
- rrdhost_aclk_state_unlock(host);
740
- return ret;
741
- }
742
-
743
- if (!host->aclk_state.t_last_popcorn_update){
744
- rrdhost_aclk_state_unlock(host);
745
- return ret;
746
- }
747
-
748
- time_t t_diff = now_monotonic_sec() - host->aclk_state.t_last_popcorn_update;
749
-
750
- if (t_diff >= ACLK_STABLE_TIMEOUT) {
751
- host->aclk_state.state = ACLK_HOST_STABLE;
752
- host->aclk_state.t_last_popcorn_update = 0;
753
- rrdhost_aclk_state_unlock(host);
754
- info("Host \"%s\" stable, ACLK popcorning finished. Last interrupt was %ld seconds ago", host->hostname, t_diff);
755
- return ACLK_HOST_STABLE;
756
- }
757
-
758
- rrdhost_aclk_state_unlock(host);
759
- return ret;
760
-}
761
-
762
-/**
763
- * Main query processing thread
764
- *
765
- * On startup wait for the agent collectors to initialize
766
- * Expect at least a time of ACLK_STABLE_TIMEOUT seconds
767
- * of no new collectors coming in in order to mark the agent
768
- * as stable (set agent_state = AGENT_STABLE)
769
- */
770
-void *legacy_aclk_query_main_thread(void *ptr)
771
-{
772
- struct aclk_query_thread *info = ptr;
773
-
774
- while (!netdata_exit) {
775
- if(aclk_host_popcorn_check(localhost) == ACLK_HOST_STABLE) {
776
-#ifdef ACLK_DEBUG
777
- _dump_collector_list();
778
-#endif
779
- break;
780
- }
781
- sleep_usec(USEC_PER_SEC * 1);
782
- }
783
-
784
- while (!netdata_exit) {
785
- if(aclk_disable_runtime) {
786
- sleep(1);
787
- continue;
788
- }
789
- legacy_aclk_shared_state_LOCK;
790
- if (unlikely(!legacy_aclk_shared_state.version_neg)) {
791
- if (!legacy_aclk_shared_state.version_neg_wait_till || legacy_aclk_shared_state.version_neg_wait_till > now_monotonic_usec()) {
792
- legacy_aclk_shared_state_UNLOCK;
793
- info("Waiting for ACLK Version Negotiation message from Cloud");
794
- sleep(1);
795
- continue;
796
- }
797
- info("ACLK version negotiation failed (This is expected). No reply to \"hello\" with \"version\" from cloud in time of %ds."
798
- " Reverting to default ACLK version of %d.", VERSION_NEG_TIMEOUT, ACLK_VERSION_MIN);
799
- legacy_aclk_shared_state.version_neg = ACLK_VERSION_MIN;
800
- aclk_set_rx_handlers(legacy_aclk_shared_state.version_neg);
801
- }
802
- legacy_aclk_shared_state_UNLOCK;
803
-
804
- rrdhost_aclk_state_lock(localhost);
805
- if (unlikely(localhost->aclk_state.metadata == ACLK_METADATA_REQUIRED)) {
806
- if (unlikely(legacy_aclk_queue_query("on_connect", localhost, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT))) {
807
- rrdhost_aclk_state_unlock(localhost);
808
- errno = 0;
809
- error("ACLK failed to queue on_connect command");
810
- sleep(1);
811
- continue;
812
- }
813
- localhost->aclk_state.metadata = ACLK_METADATA_CMD_QUEUED;
814
- }
815
- rrdhost_aclk_state_unlock(localhost);
816
-
817
- legacy_aclk_shared_state_LOCK;
818
- if (legacy_aclk_shared_state.next_popcorn_host && aclk_host_popcorn_check(legacy_aclk_shared_state.next_popcorn_host) == ACLK_HOST_STABLE) {
819
- legacy_aclk_queue_query("on_connect", legacy_aclk_shared_state.next_popcorn_host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT);
820
- legacy_aclk_shared_state.next_popcorn_host = NULL;
821
- aclk_update_next_child_to_popcorn();
822
- }
823
- legacy_aclk_shared_state_UNLOCK;
824
-
825
- while (aclk_process_query(info)) {
826
- // Process all commands
827
- };
828
-
829
- LEGACY_QUERY_THREAD_LOCK;
830
-
831
- // TODO: Need to check if there are queries awaiting already
832
- if (unlikely(pthread_cond_wait(&legacy_query_cond_wait, &legacy_query_lock_wait)))
833
- sleep_usec(USEC_PER_SEC * 1);
834
-
835
- LEGACY_QUERY_THREAD_UNLOCK;
836
- }
837
-
838
- return NULL;
839
-}
840
-
841
-#ifndef __GNUC__
842
-#pragma endregion
843
-#endif
aclk/legacy/aclk_query.h
deleted
-41
@@ -1,41 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef NETDATA_ACLK_QUERY_H
4
-#define NETDATA_ACLK_QUERY_H
5
-
6
-#include "libnetdata/libnetdata.h"
7
-#include "web/server/web_client.h"
8
-
9
-#define ACLK_STABLE_TIMEOUT 3 // Minimum delay to mark AGENT as stable
10
-
11
-#define MAX_GETRUSAGE_CALLS_PER_TICK 5 // Maximum number of times getrusage can be called per tick, per thread.
12
-
13
-extern pthread_cond_t legacy_query_cond_wait;
14
-extern pthread_mutex_t legacy_query_lock_wait;
15
-extern uint8_t *getrusage_called_this_tick;
16
-#define LEGACY_QUERY_THREAD_WAKEUP pthread_cond_signal(&legacy_query_cond_wait)
17
-#define LEGACY_QUERY_THREAD_WAKEUP_ALL pthread_cond_broadcast(&legacy_query_cond_wait)
18
-struct aclk_query_thread {
19
- netdata_thread_t thread;
20
- int idx;
21
-};
22
-
23
-struct aclk_query_threads {
24
- struct aclk_query_thread *thread_list;
25
- int count;
26
-};
27
-
28
-struct aclk_cloud_req_v2 {
29
- char *data;
30
- RRDHOST *host;
31
- char *query_endpoint;
32
-};
33
-
34
-void *legacy_aclk_query_main_thread(void *ptr);
35
-int legacy_aclk_queue_query(char *token, void *data, char *msg_type, char *query, int run_after, int internal, ACLK_CMD cmd);
36
-
37
-void legacy_aclk_query_threads_start(struct aclk_query_threads *query_threads);
38
-void legacy_aclk_query_threads_cleanup(struct aclk_query_threads *query_threads);
39
-unsigned int aclk_query_size();
40
-
41
-#endif //NETDATA_AGENT_CLOUD_LINK_H
aclk/legacy/aclk_rx_msgs.c
deleted
-388
@@ -1,388 +0,0 @@
1
-
2
-#include "aclk_rx_msgs.h"
3
-
4
-#include "aclk_common.h"
5
-#include "aclk_stats.h"
6
-#include "aclk_query.h"
7
-#include "agent_cloud_link.h"
8
-
9
-#ifndef UUID_STR_LEN
10
-#define UUID_STR_LEN 37
11
-#endif
12
-
13
-static inline int aclk_extract_v2_data(char *payload, char **data)
14
-{
15
- char* ptr = strstr(payload, ACLK_V2_PAYLOAD_SEPARATOR);
16
- if(!ptr)
17
- return 1;
18
- ptr += strlen(ACLK_V2_PAYLOAD_SEPARATOR);
19
- *data = strdupz(ptr);
20
- return 0;
21
-}
22
-
23
-#define ACLK_GET_REQ "GET "
24
-#define ACLK_CHILD_REQ "/host/"
25
-#define ACLK_CLOUD_REQ_V2_PREFIX "/api/v1/"
26
-#define STRNCMP_CONSTANT_PREFIX(str, const_pref) strncmp(str, const_pref, strlen(const_pref))
27
-static inline int aclk_v2_payload_get_query(struct aclk_cloud_req_v2 *cloud_req, struct aclk_request *req)
28
-{
29
- const char *start, *end, *ptr, *query_type;
30
- char uuid_str[UUID_STR_LEN];
31
- uuid_t uuid;
32
-
33
- errno = 0;
34
-
35
- if(STRNCMP_CONSTANT_PREFIX(cloud_req->data, ACLK_GET_REQ)) {
36
- error("Only accepting GET HTTP requests from CLOUD");
37
- return 1;
38
- }
39
- start = ptr = cloud_req->data + strlen(ACLK_GET_REQ);
40
-
41
- if(!STRNCMP_CONSTANT_PREFIX(ptr, ACLK_CHILD_REQ)) {
42
- ptr += strlen(ACLK_CHILD_REQ);
43
- if(strlen(ptr) < UUID_STR_LEN) {
44
- error("the child id in URL too short \"%s\"", start);
45
- return 1;
46
- }
47
-
48
- strncpyz(uuid_str, ptr, UUID_STR_LEN - 1);
49
-
50
- for(int i = 0; i < UUID_STR_LEN && uuid_str[i]; i++)
51
- uuid_str[i] = tolower(uuid_str[i]);
52
-
53
- if(ptr[0] && uuid_parse(uuid_str, uuid)) {
54
- error("Got Child query (/host/XXX/...) host id \"%s\" doesn't look like valid GUID", uuid_str);
55
- return 1;
56
- }
57
- ptr += UUID_STR_LEN - 1;
58
-
59
- cloud_req->host = rrdhost_find_by_guid(uuid_str, 0);
60
- if(!cloud_req->host) {
61
- error("Cannot find host with GUID \"%s\"", uuid_str);
62
- return 1;
63
- }
64
- }
65
-
66
- if(STRNCMP_CONSTANT_PREFIX(ptr, ACLK_CLOUD_REQ_V2_PREFIX)) {
67
- error("Only accepting requests that start with \"%s\" from CLOUD.", ACLK_CLOUD_REQ_V2_PREFIX);
68
- return 1;
69
- }
70
- ptr += strlen(ACLK_CLOUD_REQ_V2_PREFIX);
71
- query_type = ptr;
72
-
73
- if(!(end = strstr(ptr, " HTTP/1.1\x0D\x0A"))) {
74
- errno = 0;
75
- error("Doesn't look like HTTP GET request.");
76
- return 1;
77
- }
78
-
79
- if(!(ptr = strchr(ptr, '?')) || ptr > end)
80
- ptr = end;
81
- cloud_req->query_endpoint = mallocz((ptr - query_type) + 1);
82
- strncpyz(cloud_req->query_endpoint, query_type, ptr - query_type);
83
-
84
- req->payload = mallocz((end - start) + 1);
85
- strncpyz(req->payload, start, end - start);
86
-
87
- return 0;
88
-}
89
-
90
-#define HTTP_CHECK_AGENT_INITIALIZED() rrdhost_aclk_state_lock(localhost);\
91
- if (unlikely(localhost->aclk_state.state == ACLK_HOST_INITIALIZING)) {\
92
- debug(D_ACLK, "Ignoring \"http\" cloud request; agent not in stable state");\
93
- rrdhost_aclk_state_unlock(localhost);\
94
- return 1;\
95
- }\
96
- rrdhost_aclk_state_unlock(localhost);
97
-
98
-/*
99
- * Parse the incoming payload and queue a command if valid
100
- */
101
-static int aclk_handle_cloud_request_v1(struct aclk_request *cloud_to_agent, char *raw_payload)
102
-{
103
- UNUSED(raw_payload);
104
- HTTP_CHECK_AGENT_INITIALIZED();
105
-
106
- errno = 0;
107
- if (unlikely(cloud_to_agent->version != 1)) {
108
- error(
109
- "Received \"http\" message from Cloud with version %d, but ACLK version %d is used",
110
- cloud_to_agent->version,
111
- legacy_aclk_shared_state.version_neg);
112
- return 1;
113
- }
114
-
115
- if (unlikely(!cloud_to_agent->payload)) {
116
- error("payload missing");
117
- return 1;
118
- }
119
-
120
- if (unlikely(!cloud_to_agent->callback_topic)) {
121
- error("callback_topic missing");
122
- return 1;
123
- }
124
-
125
- if (unlikely(!cloud_to_agent->msg_id)) {
126
- error("msg_id missing");
127
- return 1;
128
- }
129
-
130
- if (unlikely(legacy_aclk_queue_query(cloud_to_agent->callback_topic, NULL, cloud_to_agent->msg_id, cloud_to_agent->payload, 0, 0, ACLK_CMD_CLOUD)))
131
- debug(D_ACLK, "ACLK failed to queue incoming \"http\" message");
132
-
133
- if (aclk_stats_enabled) {
134
- LEGACY_ACLK_STATS_LOCK;
135
- legacy_aclk_metrics_per_sample.cloud_req_v1++;
136
- legacy_aclk_metrics_per_sample.cloud_req_ok++;
137
- LEGACY_ACLK_STATS_UNLOCK;
138
- }
139
-
140
- return 0;
141
-}
142
-
143
-static int aclk_handle_cloud_request_v2(struct aclk_request *cloud_to_agent, char *raw_payload)
144
-{
145
- HTTP_CHECK_AGENT_INITIALIZED();
146
-
147
- struct aclk_cloud_req_v2 *cloud_req;
148
- char *data;
149
- int stat_idx;
150
-
151
- errno = 0;
152
- if (cloud_to_agent->version < ACLK_V_COMPRESSION) {
153
- error(
154
- "This handler cannot reply to request with version older than %d, received %d.",
155
- ACLK_V_COMPRESSION,
156
- cloud_to_agent->version);
157
- return 1;
158
- }
159
-
160
- if (unlikely(aclk_extract_v2_data(raw_payload, &data))) {
161
- error("Error extracting payload expected after the JSON dictionary.");
162
- return 1;
163
- }
164
-
165
- cloud_req = mallocz(sizeof(struct aclk_cloud_req_v2));
166
- cloud_req->data = data;
167
- cloud_req->host = localhost;
168
-
169
- if (unlikely(aclk_v2_payload_get_query(cloud_req, cloud_to_agent))) {
170
- error("Could not extract payload from query");
171
- goto cleanup;
172
- }
173
-
174
- if (unlikely(!cloud_to_agent->callback_topic)) {
175
- error("Missing callback_topic");
176
- goto cleanup;
177
- }
178
-
179
- if (unlikely(!cloud_to_agent->msg_id)) {
180
- error("Missing msg_id");
181
- goto cleanup;
182
- }
183
-
184
- // we do this here due to cloud_req being taken over by query thread
185
- // which if crazy quick can free it after legacy_aclk_queue_query
186
- stat_idx = aclk_cloud_req_type_to_idx(cloud_req->query_endpoint);
187
-
188
- // legacy_aclk_queue_query takes ownership of data pointer
189
- if (unlikely(legacy_aclk_queue_query(
190
- cloud_to_agent->callback_topic, cloud_req, cloud_to_agent->msg_id, cloud_to_agent->payload, 0, 0,
191
- ACLK_CMD_CLOUD_QUERY_2))) {
192
- error("ACLK failed to queue incoming \"http\" v2 message");
193
- goto cleanup;
194
- }
195
-
196
- if (aclk_stats_enabled) {
197
- LEGACY_ACLK_STATS_LOCK;
198
- legacy_aclk_metrics_per_sample.cloud_req_v2++;
199
- legacy_aclk_metrics_per_sample.cloud_req_ok++;
200
- legacy_aclk_metrics_per_sample.cloud_req_by_type[stat_idx]++;
201
- LEGACY_ACLK_STATS_UNLOCK;
202
- }
203
-
204
- return 0;
205
-cleanup:
206
- freez(cloud_req->query_endpoint);
207
- freez(cloud_req->data);
208
- freez(cloud_req);
209
- return 1;
210
-}
211
-
212
-// This handles `version` message from cloud used to negotiate
213
-// protocol version we will use
214
-static int aclk_handle_version_response(struct aclk_request *cloud_to_agent, char *raw_payload)
215
-{
216
- UNUSED(raw_payload);
217
- int version = -1;
218
- errno = 0;
219
-
220
- if (unlikely(cloud_to_agent->version != ACLK_VERSION_NEG_VERSION)) {
221
- error(
222
- "Unsupported version of \"version\" message from cloud. Expected %d, Got %d",
223
- ACLK_VERSION_NEG_VERSION,
224
- cloud_to_agent->version);
225
- return 1;
226
- }
227
- if (unlikely(!cloud_to_agent->min_version)) {
228
- error("Min version missing or 0");
229
- return 1;
230
- }
231
- if (unlikely(!cloud_to_agent->max_version)) {
232
- error("Max version missing or 0");
233
- return 1;
234
- }
235
- if (unlikely(cloud_to_agent->max_version < cloud_to_agent->min_version)) {
236
- error(
237
- "Max version (%d) must be >= than min version (%d)", cloud_to_agent->max_version,
238
- cloud_to_agent->min_version);
239
- return 1;
240
- }
241
-
242
- if (unlikely(cloud_to_agent->min_version > ACLK_VERSION_MAX)) {
243
- error(
244
- "Agent too old for this cloud. Minimum version required by cloud %d."
245
- " Maximum version supported by this agent %d.",
246
- cloud_to_agent->min_version, ACLK_VERSION_MAX);
247
- aclk_kill_link = 1;
248
- aclk_disable_runtime = 1;
249
- return 1;
250
- }
251
- if (unlikely(cloud_to_agent->max_version < ACLK_VERSION_MIN)) {
252
- error(
253
- "Cloud version is too old for this agent. Maximum version supported by cloud %d."
254
- " Minimum (oldest) version supported by this agent %d.",
255
- cloud_to_agent->max_version, ACLK_VERSION_MIN);
256
- aclk_kill_link = 1;
257
- return 1;
258
- }
259
-
260
- version = MIN(cloud_to_agent->max_version, ACLK_VERSION_MAX);
261
-
262
- legacy_aclk_shared_state_LOCK;
263
- if (unlikely(now_monotonic_usec() > legacy_aclk_shared_state.version_neg_wait_till)) {
264
- errno = 0;
265
- error("The \"version\" message came too late ignoring.");
266
- goto err_cleanup;
267
- }
268
- if (unlikely(legacy_aclk_shared_state.version_neg)) {
269
- errno = 0;
270
- error("Version has already been set to %d", legacy_aclk_shared_state.version_neg);
271
- goto err_cleanup;
272
- }
273
- legacy_aclk_shared_state.version_neg = version;
274
- legacy_aclk_shared_state_UNLOCK;
275
-
276
- info("Choosing version %d of ACLK", version);
277
-
278
- aclk_set_rx_handlers(version);
279
-
280
- return 0;
281
-
282
-err_cleanup:
283
- legacy_aclk_shared_state_UNLOCK;
284
- return 1;
285
-}
286
-
287
-typedef struct aclk_incoming_msg_type{
288
- char *name;
289
- int(*fnc)(struct aclk_request *, char *);
290
-}aclk_incoming_msg_type;
291
-
292
-aclk_incoming_msg_type legacy_aclk_incoming_msg_types_v1[] = {
293
- { .name = "http", .fnc = aclk_handle_cloud_request_v1 },
294
- { .name = "version", .fnc = aclk_handle_version_response },
295
- { .name = NULL, .fnc = NULL }
296
-};
297
-
298
-aclk_incoming_msg_type legacy_aclk_incoming_msg_types_compression[] = {
299
- { .name = "http", .fnc = aclk_handle_cloud_request_v2 },
300
- { .name = "version", .fnc = aclk_handle_version_response },
301
- { .name = NULL, .fnc = NULL }
302
-};
303
-
304
-struct aclk_incoming_msg_type *legacy_aclk_incoming_msg_types = legacy_aclk_incoming_msg_types_v1;
305
-
306
-void aclk_set_rx_handlers(int version)
307
-{
308
- if(version >= ACLK_V_COMPRESSION) {
309
- legacy_aclk_incoming_msg_types = legacy_aclk_incoming_msg_types_compression;
310
- return;
311
- }
312
-
313
- legacy_aclk_incoming_msg_types = legacy_aclk_incoming_msg_types_v1;
314
-}
315
-
316
-int legacy_aclk_handle_cloud_message(char *payload)
317
-{
318
- struct aclk_request cloud_to_agent;
319
- memset(&cloud_to_agent, 0, sizeof(struct aclk_request));
320
-
321
- if (unlikely(!payload)) {
322
- errno = 0;
323
- error("ACLK incoming message is empty");
324
- goto err_cleanup_nojson;
325
- }
326
-
327
- debug(D_ACLK, "ACLK incoming message (%s)", payload);
328
-
329
- int rc = json_parse(payload, &cloud_to_agent, legacy_cloud_to_agent_parse);
330
-
331
- if (unlikely(rc != JSON_OK)) {
332
- errno = 0;
333
- error("Malformed json request (%s)", payload);
334
- goto err_cleanup;
335
- }
336
-
337
- if (!cloud_to_agent.type_id) {
338
- errno = 0;
339
- error("Cloud message is missing compulsory key \"type\"");
340
- goto err_cleanup;
341
- }
342
-
343
- if (!legacy_aclk_shared_state.version_neg && strcmp(cloud_to_agent.type_id, "version")) {
344
- error("Only \"version\" message is allowed before popcorning and version negotiation is finished. Ignoring");
345
- goto err_cleanup;
346
- }
347
-
348
- for (int i = 0; legacy_aclk_incoming_msg_types[i].name; i++) {
349
- if (strcmp(cloud_to_agent.type_id, legacy_aclk_incoming_msg_types[i].name) == 0) {
350
- if (likely(!legacy_aclk_incoming_msg_types[i].fnc(&cloud_to_agent, payload))) {
351
- // in case of success handler is supposed to clean up after itself
352
- // or as in the case of aclk_handle_cloud_request take
353
- // ownership of the pointers (done to avoid copying)
354
- // see what `legacy_aclk_queue_query` parameter `internal` does
355
-
356
- // NEVER CONTINUE THIS LOOP AFTER CALLING FUNCTION!!!
357
- // msg handlers (namely aclk_handle_version_response)
358
- // can freely change what legacy_aclk_incoming_msg_types points to
359
- // so either exit or restart this for loop
360
- freez(cloud_to_agent.type_id);
361
- return 0;
362
- }
363
- goto err_cleanup;
364
- }
365
- }
366
-
367
- errno = 0;
368
- error("Unknown message type from Cloud \"%s\"", cloud_to_agent.type_id);
369
-
370
-err_cleanup:
371
- if (cloud_to_agent.payload)
372
- freez(cloud_to_agent.payload);
373
- if (cloud_to_agent.type_id)
374
- freez(cloud_to_agent.type_id);
375
- if (cloud_to_agent.msg_id)
376
- freez(cloud_to_agent.msg_id);
377
- if (cloud_to_agent.callback_topic)
378
- freez(cloud_to_agent.callback_topic);
379
-
380
-err_cleanup_nojson:
381
- if (aclk_stats_enabled) {
382
- LEGACY_ACLK_STATS_LOCK;
383
- legacy_aclk_metrics_per_sample.cloud_req_err++;
384
- LEGACY_ACLK_STATS_UNLOCK;
385
- }
386
-
387
- return 1;
388
-}
aclk/legacy/aclk_rx_msgs.h
deleted
-13
@@ -1,13 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef NETDATA_ACLK_RX_MSGS_H
4
-#define NETDATA_ACLK_RX_MSGS_H
5
-
6
-#include "daemon/common.h"
7
-#include "libnetdata/libnetdata.h"
8
-
9
-int legacy_aclk_handle_cloud_message(char *payload);
10
-void aclk_set_rx_handlers(int version);
11
-
12
-
13
-#endif /* NETDATA_ACLK_RX_MSGS_H */
aclk/legacy/aclk_stats.c
deleted
-411
@@ -1,411 +0,0 @@
1
-#include "aclk_stats.h"
2
-
3
-netdata_mutex_t legacy_aclk_stats_mutex = NETDATA_MUTEX_INITIALIZER;
4
-
5
-int legacy_query_thread_count;
6
-
7
-// data ACLK stats need per query thread
8
-struct legacy_aclk_qt_data {
9
- RRDDIM *dim;
10
-} *legacy_aclk_qt_data = NULL;
11
-
12
-// ACLK per query thread cpu stats
13
-struct legacy_aclk_cpu_data {
14
- RRDDIM *user;
15
- RRDDIM *system;
16
- RRDSET *st;
17
-} *legacy_aclk_cpu_data = NULL;
18
-
19
-uint32_t *legacy_aclk_queries_per_thread = NULL;
20
-uint32_t *legacy_aclk_queries_per_thread_sample = NULL;
21
-struct rusage *rusage_per_thread;
22
-uint8_t *getrusage_called_this_tick = NULL;
23
-
24
-static struct legacy_aclk_metrics legacy_aclk_metrics = {
25
- .online = 0,
26
-};
27
-
28
-struct legacy_aclk_metrics_per_sample legacy_aclk_metrics_per_sample;
29
-
30
-struct aclk_mat_metrics aclk_mat_metrics = {
31
-#ifdef NETDATA_INTERNAL_CHECKS
32
- .latency = { .name = "aclk_latency_mqtt",
33
- .prio = 200002,
34
- .st = NULL,
35
- .rd_avg = NULL,
36
- .rd_max = NULL,
37
- .rd_total = NULL,
38
- .unit = "ms",
39
- .title = "ACLK Message Publish Latency" },
40
-#endif
41
-
42
- .cloud_q_db_query_time = { .name = "aclk_db_query_time",
43
- .prio = 200006,
44
- .st = NULL,
45
- .rd_avg = NULL,
46
- .rd_max = NULL,
47
- .rd_total = NULL,
48
- .unit = "us",
49
- .title = "Time it took to process cloud requested DB queries" },
50
-
51
- .cloud_q_recvd_to_processed = { .name = "aclk_cloud_q_recvd_to_processed",
52
- .prio = 200007,
53
- .st = NULL,
54
- .rd_avg = NULL,
55
- .rd_max = NULL,
56
- .rd_total = NULL,
57
- .unit = "us",
58
- .title = "Time from receiving the Cloud Query until it was picked up "
59
- "by query thread (just before passing to the database)." }
60
-};
61
-
62
-void legacy_aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurement)
63
-{
64
- if (aclk_stats_enabled) {
65
- LEGACY_ACLK_STATS_LOCK;
66
- if (metric->max < measurement)
67
- metric->max = measurement;
68
-
69
- metric->total += measurement;
70
- metric->count++;
71
- LEGACY_ACLK_STATS_UNLOCK;
72
- }
73
-}
74
-
75
-static void aclk_stats_collect(struct legacy_aclk_metrics_per_sample *per_sample, struct legacy_aclk_metrics *permanent)
76
-{
77
- static RRDSET *st_aclkstats = NULL;
78
- static RRDDIM *rd_online_status = NULL;
79
-
80
- if (unlikely(!st_aclkstats)) {
81
- st_aclkstats = rrdset_create_localhost(
82
- "netdata", "aclk_status", NULL, "aclk", NULL, "ACLK/Cloud connection status",
83
- "connected", "netdata", "stats", 200000, localhost->rrd_update_every, RRDSET_TYPE_LINE);
84
-
85
- rd_online_status = rrddim_add(st_aclkstats, "online", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
86
- } else
87
- rrdset_next(st_aclkstats);
88
-
89
- rrddim_set_by_pointer(st_aclkstats, rd_online_status, per_sample->offline_during_sample ? 0 : permanent->online);
90
-
91
- rrdset_done(st_aclkstats);
92
-}
93
-
94
-static void aclk_stats_query_queue(struct legacy_aclk_metrics_per_sample *per_sample)
95
-{
96
- static RRDSET *st_query_thread = NULL;
97
- static RRDDIM *rd_queued = NULL;
98
- static RRDDIM *rd_dispatched = NULL;
99
-
100
- if (unlikely(!st_query_thread)) {
101
- st_query_thread = rrdset_create_localhost(
102
- "netdata", "aclk_query_per_second", NULL, "aclk", NULL, "ACLK Queries per second", "queries/s",
103
- "netdata", "stats", 200001, localhost->rrd_update_every, RRDSET_TYPE_AREA);
104
-
105
- rd_queued = rrddim_add(st_query_thread, "added", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
106
- rd_dispatched = rrddim_add(st_query_thread, "dispatched", NULL, -1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
107
- } else
108
- rrdset_next(st_query_thread);
109
-
110
- rrddim_set_by_pointer(st_query_thread, rd_queued, per_sample->queries_queued);
111
- rrddim_set_by_pointer(st_query_thread, rd_dispatched, per_sample->queries_dispatched);
112
-
113
- rrdset_done(st_query_thread);
114
-}
115
-
116
-static void aclk_stats_write_q(struct legacy_aclk_metrics_per_sample *per_sample)
117
-{
118
- static RRDSET *st = NULL;
119
- static RRDDIM *rd_wq_add = NULL;
120
- static RRDDIM *rd_wq_consumed = NULL;
121
-
122
- if (unlikely(!st)) {
123
- st = rrdset_create_localhost(
124
- "netdata", "aclk_write_q", NULL, "aclk", NULL, "Write Queue Mosq->Libwebsockets", "KiB/s",
125
- "netdata", "stats", 200003, localhost->rrd_update_every, RRDSET_TYPE_AREA);
126
-
127
- rd_wq_add = rrddim_add(st, "added", NULL, 1, 1024 * localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
128
- rd_wq_consumed = rrddim_add(st, "consumed", NULL, 1, -1024 * localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
129
- } else
130
- rrdset_next(st);
131
-
132
- rrddim_set_by_pointer(st, rd_wq_add, per_sample->write_q_added);
133
- rrddim_set_by_pointer(st, rd_wq_consumed, per_sample->write_q_consumed);
134
-
135
- rrdset_done(st);
136
-}
137
-
138
-static void aclk_stats_read_q(struct legacy_aclk_metrics_per_sample *per_sample)
139
-{
140
- static RRDSET *st = NULL;
141
- static RRDDIM *rd_rq_add = NULL;
142
- static RRDDIM *rd_rq_consumed = NULL;
143
-
144
- if (unlikely(!st)) {
145
- st = rrdset_create_localhost(
146
- "netdata", "aclk_read_q", NULL, "aclk", NULL, "Read Queue Libwebsockets->Mosq", "KiB/s",
147
- "netdata", "stats", 200004, localhost->rrd_update_every, RRDSET_TYPE_AREA);
148
-
149
- rd_rq_add = rrddim_add(st, "added", NULL, 1, 1024 * localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
150
- rd_rq_consumed = rrddim_add(st, "consumed", NULL, 1, -1024 * localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
151
- } else
152
- rrdset_next(st);
153
-
154
- rrddim_set_by_pointer(st, rd_rq_add, per_sample->read_q_added);
155
- rrddim_set_by_pointer(st, rd_rq_consumed, per_sample->read_q_consumed);
156
-
157
- rrdset_done(st);
158
-}
159
-
160
-static void aclk_stats_cloud_req(struct legacy_aclk_metrics_per_sample *per_sample)
161
-{
162
- static RRDSET *st = NULL;
163
- static RRDDIM *rd_rq_ok = NULL;
164
- static RRDDIM *rd_rq_err = NULL;
165
-
166
- if (unlikely(!st)) {
167
- st = rrdset_create_localhost(
168
- "netdata", "aclk_cloud_req", NULL, "aclk", NULL, "Requests received from cloud", "req/s",
169
- "netdata", "stats", 200005, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
170
-
171
- rd_rq_ok = rrddim_add(st, "accepted", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
172
- rd_rq_err = rrddim_add(st, "rejected", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
173
- } else
174
- rrdset_next(st);
175
-
176
- rrddim_set_by_pointer(st, rd_rq_ok, per_sample->cloud_req_ok);
177
- rrddim_set_by_pointer(st, rd_rq_err, per_sample->cloud_req_err);
178
-
179
- rrdset_done(st);
180
-}
181
-
182
-static void aclk_stats_cloud_req_version(struct legacy_aclk_metrics_per_sample *per_sample)
183
-{
184
- static RRDSET *st = NULL;
185
- static RRDDIM *rd_rq_v1 = NULL;
186
- static RRDDIM *rd_rq_v2 = NULL;
187
-
188
- if (unlikely(!st)) {
189
- st = rrdset_create_localhost(
190
- "netdata", "aclk_cloud_req_version", NULL, "aclk", NULL, "Requests received from cloud by their version", "req/s",
191
- "netdata", "stats", 200006, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
192
-
193
- rd_rq_v1 = rrddim_add(st, "v1", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
194
- rd_rq_v2 = rrddim_add(st, "v2+", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
195
- } else
196
- rrdset_next(st);
197
-
198
- rrddim_set_by_pointer(st, rd_rq_v1, per_sample->cloud_req_v1);
199
- rrddim_set_by_pointer(st, rd_rq_v2, per_sample->cloud_req_v2);
200
-
201
- rrdset_done(st);
202
-}
203
-
204
-static char *cloud_req_type_names[ACLK_STATS_CLOUD_REQ_TYPE_CNT] = {
205
- "other",
206
- "info",
207
- "data",
208
- "alarms",
209
- "alarm_log",
210
- "chart",
211
- "charts"
212
- // if you change update:
213
- // #define ACLK_STATS_CLOUD_REQ_TYPE_CNT 7
214
-};
215
-
216
-int aclk_cloud_req_type_to_idx(const char *name)
217
-{
218
- for (int i = 1; i < ACLK_STATS_CLOUD_REQ_TYPE_CNT; i++)
219
- if (!strcmp(cloud_req_type_names[i], name))
220
- return i;
221
- return 0;
222
-}
223
-
224
-static void aclk_stats_cloud_req_cmd(struct legacy_aclk_metrics_per_sample *per_sample)
225
-{
226
- static RRDSET *st;
227
- static int initialized = 0;
228
- static RRDDIM *rd_rq_types[ACLK_STATS_CLOUD_REQ_TYPE_CNT];
229
-
230
- if (unlikely(!initialized)) {
231
- initialized = 1;
232
- st = rrdset_create_localhost(
233
- "netdata", "aclk_cloud_req_cmd", NULL, "aclk", NULL, "Requests received from cloud by their type (api endpoint queried)", "req/s",
234
- "netdata", "stats", 200007, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
235
-
236
- for (int i = 0; i < ACLK_STATS_CLOUD_REQ_TYPE_CNT; i++)
237
- rd_rq_types[i] = rrddim_add(st, cloud_req_type_names[i], NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
238
- } else
239
- rrdset_next(st);
240
-
241
- for (int i = 0; i < ACLK_STATS_CLOUD_REQ_TYPE_CNT; i++)
242
- rrddim_set_by_pointer(st, rd_rq_types[i], per_sample->cloud_req_by_type[i]);
243
-
244
- rrdset_done(st);
245
-}
246
-
247
-#define MAX_DIM_NAME 22
248
-static void aclk_stats_query_threads(uint32_t *queries_per_thread)
249
-{
250
- static RRDSET *st = NULL;
251
-
252
- char dim_name[MAX_DIM_NAME];
253
-
254
- if (unlikely(!st)) {
255
- st = rrdset_create_localhost(
256
- "netdata", "aclk_query_threads", NULL, "aclk", NULL, "Queries Processed Per Thread", "req/s",
257
- "netdata", "stats", 200008, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
258
-
259
- for (int i = 0; i < legacy_query_thread_count; i++) {
260
- if (snprintfz(dim_name, MAX_DIM_NAME, "Query %d", i) < 0)
261
- error("snprintf encoding error");
262
- legacy_aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
263
- }
264
- } else
265
- rrdset_next(st);
266
-
267
- for (int i = 0; i < legacy_query_thread_count; i++) {
268
- rrddim_set_by_pointer(st, legacy_aclk_qt_data[i].dim, queries_per_thread[i]);
269
- }
270
-
271
- rrdset_done(st);
272
-}
273
-
274
-static void aclk_stats_mat_metric_process(struct aclk_metric_mat *metric, struct aclk_metric_mat_data *data)
275
-{
276
- if(unlikely(!metric->st)) {
277
- metric->st = rrdset_create_localhost(
278
- "netdata", metric->name, NULL, "aclk", NULL, metric->title, metric->unit, "netdata", "stats", metric->prio,
279
- localhost->rrd_update_every, RRDSET_TYPE_LINE);
280
-
281
- metric->rd_avg = rrddim_add(metric->st, "avg", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
282
- metric->rd_max = rrddim_add(metric->st, "max", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
283
- metric->rd_total = rrddim_add(metric->st, "total", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
284
- } else
285
- rrdset_next(metric->st);
286
-
287
- if(data->count)
288
- rrddim_set_by_pointer(metric->st, metric->rd_avg, roundf((float)data->total / data->count));
289
- else
290
- rrddim_set_by_pointer(metric->st, metric->rd_avg, 0);
291
- rrddim_set_by_pointer(metric->st, metric->rd_max, data->max);
292
- rrddim_set_by_pointer(metric->st, metric->rd_total, data->total);
293
-
294
- rrdset_done(metric->st);
295
-}
296
-
297
-static void aclk_stats_cpu_threads(void)
298
-{
299
- char id[100 + 1];
300
- char title[100 + 1];
301
-
302
- for (int i = 0; i < legacy_query_thread_count; i++) {
303
- if (unlikely(!legacy_aclk_cpu_data[i].st)) {
304
-
305
- snprintfz(id, 100, "aclk_thread%d_cpu", i);
306
- snprintfz(title, 100, "Cpu Usage For Thread No %d", i);
307
-
308
- legacy_aclk_cpu_data[i].st = rrdset_create_localhost(
309
- "netdata", id, NULL, "aclk", NULL, title, "milliseconds/s",
310
- "netdata", "stats", 200020 + i, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
311
-
312
- legacy_aclk_cpu_data[i].user = rrddim_add(legacy_aclk_cpu_data[i].st, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
313
- legacy_aclk_cpu_data[i].system = rrddim_add(legacy_aclk_cpu_data[i].st, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
314
-
315
- } else
316
- rrdset_next(legacy_aclk_cpu_data[i].st);
317
- }
318
-
319
- for (int i = 0; i < legacy_query_thread_count; i++) {
320
- rrddim_set_by_pointer(legacy_aclk_cpu_data[i].st, legacy_aclk_cpu_data[i].user, rusage_per_thread[i].ru_utime.tv_sec * 1000000ULL + rusage_per_thread[i].ru_utime.tv_usec);
321
- rrddim_set_by_pointer(legacy_aclk_cpu_data[i].st, legacy_aclk_cpu_data[i].system, rusage_per_thread[i].ru_stime.tv_sec * 1000000ULL + rusage_per_thread[i].ru_stime.tv_usec);
322
- rrdset_done(legacy_aclk_cpu_data[i].st);
323
- }
324
-}
325
-
326
-void legacy_aclk_stats_thread_cleanup()
327
-{
328
- freez(legacy_aclk_qt_data);
329
- freez(legacy_aclk_queries_per_thread);
330
- freez(legacy_aclk_queries_per_thread_sample);
331
- freez(legacy_aclk_cpu_data);
332
- freez(rusage_per_thread);
333
-}
334
-
335
-void *legacy_aclk_stats_main_thread(void *ptr)
336
-{
337
- struct aclk_stats_thread *args = ptr;
338
-
339
- legacy_query_thread_count = args->query_thread_count;
340
- legacy_aclk_qt_data = callocz(legacy_query_thread_count, sizeof(struct legacy_aclk_qt_data));
341
- legacy_aclk_cpu_data = callocz(legacy_query_thread_count, sizeof(struct legacy_aclk_cpu_data));
342
- legacy_aclk_queries_per_thread = callocz(legacy_query_thread_count, sizeof(uint32_t));
343
- legacy_aclk_queries_per_thread_sample = callocz(legacy_query_thread_count, sizeof(uint32_t));
344
- rusage_per_thread = callocz(legacy_query_thread_count, sizeof(struct rusage));
345
- getrusage_called_this_tick = callocz(legacy_query_thread_count, sizeof(uint8_t));
346
-
347
- heartbeat_t hb;
348
- heartbeat_init(&hb);
349
- usec_t step_ut = localhost->rrd_update_every * USEC_PER_SEC;
350
-
351
- memset(&legacy_aclk_metrics_per_sample, 0, sizeof(struct legacy_aclk_metrics_per_sample));
352
-
353
- struct legacy_aclk_metrics_per_sample per_sample;
354
- struct legacy_aclk_metrics permanent;
355
-
356
- while (!netdata_exit) {
357
- netdata_thread_testcancel();
358
- // ------------------------------------------------------------------------
359
- // Wait for the next iteration point.
360
-
361
- heartbeat_next(&hb, step_ut);
362
- if (netdata_exit) break;
363
-
364
- LEGACY_ACLK_STATS_LOCK;
365
- // to not hold lock longer than necessary, especially not to hold it
366
- // during database rrd* operations
367
- memcpy(&per_sample, &legacy_aclk_metrics_per_sample, sizeof(struct legacy_aclk_metrics_per_sample));
368
- memcpy(&permanent, &legacy_aclk_metrics, sizeof(struct legacy_aclk_metrics));
369
- memset(&legacy_aclk_metrics_per_sample, 0, sizeof(struct legacy_aclk_metrics_per_sample));
370
-
371
- memcpy(legacy_aclk_queries_per_thread_sample, legacy_aclk_queries_per_thread, sizeof(uint32_t) * legacy_query_thread_count);
372
- memset(legacy_aclk_queries_per_thread, 0, sizeof(uint32_t) * legacy_query_thread_count);
373
- memset(getrusage_called_this_tick, 0, sizeof(uint8_t) * legacy_query_thread_count);
374
- LEGACY_ACLK_STATS_UNLOCK;
375
-
376
- aclk_stats_collect(&per_sample, &permanent);
377
- aclk_stats_query_queue(&per_sample);
378
-
379
- aclk_stats_write_q(&per_sample);
380
- aclk_stats_read_q(&per_sample);
381
-
382
- aclk_stats_cloud_req(&per_sample);
383
- aclk_stats_cloud_req_version(&per_sample);
384
-
385
- aclk_stats_cloud_req_cmd(&per_sample);
386
-
387
- aclk_stats_query_threads(legacy_aclk_queries_per_thread_sample);
388
-
389
- aclk_stats_cpu_threads();
390
-
391
-#ifdef NETDATA_INTERNAL_CHECKS
392
- aclk_stats_mat_metric_process(&aclk_mat_metrics.latency, &per_sample.latency);
393
-#endif
394
- aclk_stats_mat_metric_process(&aclk_mat_metrics.cloud_q_db_query_time, &per_sample.cloud_q_db_query_time);
395
- aclk_stats_mat_metric_process(&aclk_mat_metrics.cloud_q_recvd_to_processed, &per_sample.cloud_q_recvd_to_processed);
396
- }
397
-
398
- return 0;
399
-}
400
-
401
-void legacy_aclk_stats_upd_online(int online) {
402
- if(!aclk_stats_enabled)
403
- return;
404
-
405
- LEGACY_ACLK_STATS_LOCK;
406
- legacy_aclk_metrics.online = online;
407
-
408
- if(!online)
409
- legacy_aclk_metrics_per_sample.offline_during_sample = 1;
410
- LEGACY_ACLK_STATS_UNLOCK;
411
-}
aclk/legacy/aclk_stats.h
deleted
-100
@@ -1,100 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef NETDATA_ACLK_STATS_H
4
-#define NETDATA_ACLK_STATS_H
5
-
6
-#include "daemon/common.h"
7
-#include "libnetdata/libnetdata.h"
8
-#include "aclk_common.h"
9
-
10
-#define ACLK_STATS_THREAD_NAME "ACLK_Stats"
11
-
12
-extern netdata_mutex_t legacy_aclk_stats_mutex;
13
-
14
-#define LEGACY_ACLK_STATS_LOCK netdata_mutex_lock(&legacy_aclk_stats_mutex)
15
-#define LEGACY_ACLK_STATS_UNLOCK netdata_mutex_unlock(&legacy_aclk_stats_mutex)
16
-
17
-struct aclk_stats_thread {
18
- netdata_thread_t *thread;
19
- int query_thread_count;
20
-};
21
-
22
-// preserve between samples
23
-struct legacy_aclk_metrics {
24
- volatile uint8_t online;
25
-};
26
-
27
-//mat = max average total
28
-struct aclk_metric_mat_data {
29
- volatile uint32_t total;
30
- volatile uint32_t count;
31
- volatile uint32_t max;
32
-};
33
-
34
-//mat = max average total
35
-struct aclk_metric_mat {
36
- char *name;
37
- char *title;
38
- RRDSET *st;
39
- RRDDIM *rd_avg;
40
- RRDDIM *rd_max;
41
- RRDDIM *rd_total;
42
- long prio;
43
- char *unit;
44
-};
45
-
46
-extern struct aclk_mat_metrics {
47
-#ifdef NETDATA_INTERNAL_CHECKS
48
- struct aclk_metric_mat latency;
49
-#endif
50
- struct aclk_metric_mat cloud_q_db_query_time;
51
- struct aclk_metric_mat cloud_q_recvd_to_processed;
52
-} aclk_mat_metrics;
53
-
54
-void legacy_aclk_metric_mat_update(struct aclk_metric_mat_data *metric, usec_t measurement);
55
-
56
-#define ACLK_STATS_CLOUD_REQ_TYPE_CNT 7
57
-// if you change update cloud_req_type_names
58
-
59
-int aclk_cloud_req_type_to_idx(const char *name);
60
-
61
-// reset to 0 on every sample
62
-extern struct legacy_aclk_metrics_per_sample {
63
- /* in the unlikely event of ACLK disconnecting
64
- and reconnecting under 1 sampling rate
65
- we want to make sure we record the disconnection
66
- despite it being then seemingly longer in graph */
67
- volatile uint8_t offline_during_sample;
68
-
69
- volatile uint32_t queries_queued;
70
- volatile uint32_t queries_dispatched;
71
-
72
- volatile uint32_t write_q_added;
73
- volatile uint32_t write_q_consumed;
74
-
75
- volatile uint32_t read_q_added;
76
- volatile uint32_t read_q_consumed;
77
-
78
- volatile uint32_t cloud_req_ok;
79
- volatile uint32_t cloud_req_err;
80
-
81
- volatile uint16_t cloud_req_v1;
82
- volatile uint16_t cloud_req_v2;
83
-
84
- volatile uint16_t cloud_req_by_type[ACLK_STATS_CLOUD_REQ_TYPE_CNT];
85
-
86
-#ifdef NETDATA_INTERNAL_CHECKS
87
- struct aclk_metric_mat_data latency;
88
-#endif
89
- struct aclk_metric_mat_data cloud_q_db_query_time;
90
- struct aclk_metric_mat_data cloud_q_recvd_to_processed;
91
-} legacy_aclk_metrics_per_sample;
92
-
93
-extern uint32_t *legacy_aclk_queries_per_thread;
94
-extern struct rusage *rusage_per_thread;
95
-
96
-void *legacy_aclk_stats_main_thread(void *ptr);
97
-void legacy_aclk_stats_thread_cleanup();
98
-void legacy_aclk_stats_upd_online(int online);
99
-
100
-#endif /* NETDATA_ACLK_STATS_H */
aclk/legacy/agent_cloud_link.c
deleted
-1502
@@ -1,1502 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#include "libnetdata/libnetdata.h"
4
-#include "agent_cloud_link.h"
5
-#include "aclk_lws_https_client.h"
6
-#include "aclk_query.h"
7
-#include "aclk_common.h"
8
-#include "aclk_stats.h"
9
-#include "../aclk_collector_list.h"
10
-
11
-#ifdef ENABLE_ACLK
12
-#include <libwebsockets.h>
13
-#endif
14
-
15
-int aclk_shutting_down = 0;
16
-
17
-// Other global state
18
-static int aclk_subscribed = 0;
19
-static char *aclk_username = NULL;
20
-static char *aclk_password = NULL;
21
-
22
-static char *global_base_topic = NULL;
23
-static int aclk_connecting = 0;
24
-int aclk_force_reconnect = 0; // Indication from lower layers
25
-
26
-static netdata_mutex_t aclk_mutex = NETDATA_MUTEX_INITIALIZER;
27
-
28
-#define ACLK_LOCK netdata_mutex_lock(&aclk_mutex)
29
-#define ACLK_UNLOCK netdata_mutex_unlock(&aclk_mutex)
30
-
31
-void lws_wss_check_queues(size_t *write_len, size_t *write_len_bytes, size_t *read_len);
32
-void aclk_lws_wss_destroy_context();
33
-
34
-char *create_uuid()
35
-{
36
- uuid_t uuid;
37
- char *uuid_str = mallocz(36 + 1);
38
-
39
- uuid_generate(uuid);
40
- uuid_unparse(uuid, uuid_str);
41
-
42
- return uuid_str;
43
-}
44
-
45
-int legacy_cloud_to_agent_parse(JSON_ENTRY *e)
46
-{
47
- struct aclk_request *data = e->callback_data;
48
-
49
- switch (e->type) {
50
- case JSON_OBJECT:
51
- case JSON_ARRAY:
52
- break;
53
- case JSON_STRING:
54
- if (!strcmp(e->name, "msg-id")) {
55
- data->msg_id = strdupz(e->data.string);
56
- break;
57
- }
58
- if (!strcmp(e->name, "type")) {
59
- data->type_id = strdupz(e->data.string);
60
- break;
61
- }
62
- if (!strcmp(e->name, "callback-topic")) {
63
- data->callback_topic = strdupz(e->data.string);
64
- break;
65
- }
66
- if (!strcmp(e->name, "payload")) {
67
- if (likely(e->data.string)) {
68
- size_t len = strlen(e->data.string);
69
- data->payload = mallocz(len+1);
70
- if (!url_decode_r(data->payload, e->data.string, len + 1))
71
- strcpy(data->payload, e->data.string);
72
- }
73
- break;
74
- }
75
- break;
76
- case JSON_NUMBER:
77
- if (!strcmp(e->name, "version")) {
78
- data->version = e->data.number;
79
- break;
80
- }
81
- if (!strcmp(e->name, "min-version")) {
82
- data->min_version = e->data.number;
83
- break;
84
- }
85
- if (!strcmp(e->name, "max-version")) {
86
- data->max_version = e->data.number;
87
- break;
88
- }
89
-
90
- break;
91
-
92
- case JSON_BOOLEAN:
93
- break;
94
-
95
- case JSON_NULL:
96
- break;
97
- }
98
- return 0;
99
-}
100
-
101
-
102
-static RSA *aclk_private_key = NULL;
103
-static int create_private_key()
104
-{
105
- if (aclk_private_key != NULL)
106
- RSA_free(aclk_private_key);
107
- aclk_private_key = NULL;
108
- char filename[FILENAME_MAX + 1];
109
- snprintfz(filename, FILENAME_MAX, "%s/cloud.d/private.pem", netdata_configured_varlib_dir);
110
-
111
- long bytes_read;
112
- char *private_key = read_by_filename(filename, &bytes_read);
113
- if (!private_key) {
114
- error("Claimed agent cannot establish ACLK - unable to load private key '%s' failed.", filename);
115
- return 1;
116
- }
117
- debug(D_ACLK, "Claimed agent loaded private key len=%ld bytes", bytes_read);
118
-
119
- BIO *key_bio = BIO_new_mem_buf(private_key, -1);
120
- if (key_bio==NULL) {
121
- error("Claimed agent cannot establish ACLK - failed to create BIO for key");
122
- goto biofailed;
123
- }
124
-
125
- aclk_private_key = PEM_read_bio_RSAPrivateKey(key_bio, NULL, NULL, NULL);
126
- BIO_free(key_bio);
127
- if (aclk_private_key!=NULL)
128
- {
129
- freez(private_key);
130
- return 0;
131
- }
132
- char err[512];
133
- ERR_error_string_n(ERR_get_error(), err, sizeof(err));
134
- error("Claimed agent cannot establish ACLK - cannot create private key: %s", err);
135
-
136
-biofailed:
137
- freez(private_key);
138
- return 1;
139
-}
140
-
141
-/*
142
- * After a connection failure -- delay in milliseconds
143
- * When a connection is established, the delay function
144
- * should be called with
145
- *
146
- * mode 0 to reset the delay
147
- * mode 1 to calculate sleep time [0 .. ACLK_MAX_BACKOFF_DELAY * 1000] ms
148
- *
149
- */
150
-unsigned long int aclk_reconnect_delay(int mode)
151
-{
152
- static int fail = -1;
153
- unsigned long int delay;
154
-
155
- if (!mode || fail == -1) {
156
- srandom(time(NULL));
157
- fail = mode - 1;
158
- return 0;
159
- }
160
-
161
- delay = (1 << fail);
162
-
163
- if (delay >= ACLK_MAX_BACKOFF_DELAY) {
164
- delay = ACLK_MAX_BACKOFF_DELAY * 1000;
165
- } else {
166
- fail++;
167
- delay *= 1000;
168
- delay += (random() % (MAX(1000, delay/2)));
169
- }
170
-
171
- return delay;
172
-}
173
-
174
-// This will give the base topic that the agent will publish messages.
175
-// subtopics will be sent under the base topic e.g. base_topic/subtopic
176
-// This is called during the connection, we delete any previous topic
177
-// in-case the user has changed the agent id and reclaimed.
178
-
179
-char *create_publish_base_topic()
180
-{
181
- char *agent_id = is_agent_claimed();
182
- if (unlikely(!agent_id))
183
- return NULL;
184
-
185
- ACLK_LOCK;
186
-
187
- if (global_base_topic)
188
- freez(global_base_topic);
189
- char tmp_topic[ACLK_MAX_TOPIC + 1], *tmp;
190
-
191
- snprintf(tmp_topic, ACLK_MAX_TOPIC, ACLK_TOPIC_STRUCTURE, agent_id);
192
- tmp = strchr(tmp_topic, '\n');
193
- if (unlikely(tmp))
194
- *tmp = '\0';
195
- global_base_topic = strdupz(tmp_topic);
196
-
197
- ACLK_UNLOCK;
198
- freez(agent_id);
199
- return global_base_topic;
200
-}
201
-
202
-/*
203
- * Build a topic based on sub_topic and final_topic
204
- * if the sub topic starts with / assume that is an absolute topic
205
- *
206
- */
207
-
208
-char *get_topic(char *sub_topic, char *final_topic, int max_size)
209
-{
210
- int rc;
211
-
212
- if (likely(sub_topic && sub_topic[0] == '/'))
213
- return sub_topic;
214
-
215
- if (unlikely(!global_base_topic))
216
- return sub_topic;
217
-
218
- rc = snprintf(final_topic, max_size, "%s/%s", global_base_topic, sub_topic);
219
- if (unlikely(rc >= max_size))
220
- debug(D_ACLK, "Topic has been truncated to [%s] instead of [%s/%s]", final_topic, global_base_topic, sub_topic);
221
-
222
- return final_topic;
223
-}
224
-
225
-/* Avoids the need to scan through all RRDHOSTS
226
- * every time any Query Thread Wakes Up
227
- * (every time we need to check child popcorn expiry)
228
- * call with legacy_aclk_shared_state_LOCK held
229
- */
230
-void aclk_update_next_child_to_popcorn(void)
231
-{
232
- RRDHOST *host;
233
- int any = 0;
234
-
235
- rrd_rdlock();
236
- rrdhost_foreach_read(host) {
237
- if (unlikely(host == localhost || rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED)))
238
- continue;
239
-
240
- rrdhost_aclk_state_lock(host);
241
- if (!ACLK_IS_HOST_POPCORNING(host)) {
242
- rrdhost_aclk_state_unlock(host);
243
- continue;
244
- }
245
-
246
- any = 1;
247
-
248
- if (unlikely(!legacy_aclk_shared_state.next_popcorn_host)) {
249
- legacy_aclk_shared_state.next_popcorn_host = host;
250
- rrdhost_aclk_state_unlock(host);
251
- continue;
252
- }
253
-
254
- if (legacy_aclk_shared_state.next_popcorn_host->aclk_state.t_last_popcorn_update > host->aclk_state.t_last_popcorn_update)
255
- legacy_aclk_shared_state.next_popcorn_host = host;
256
-
257
- rrdhost_aclk_state_unlock(host);
258
- }
259
- if(!any)
260
- legacy_aclk_shared_state.next_popcorn_host = NULL;
261
-
262
- rrd_unlock();
263
-}
264
-
265
-/* If popcorning bump timer.
266
- * If popcorning or initializing (host not stable) return 1
267
- * Otherwise return 0
268
- */
269
-static int aclk_popcorn_check_bump(RRDHOST *host)
270
-{
271
- time_t now = now_monotonic_sec();
272
- int updated = 0, ret;
273
- legacy_aclk_shared_state_LOCK;
274
- rrdhost_aclk_state_lock(host);
275
-
276
- ret = ACLK_IS_HOST_INITIALIZING(host);
277
- if (unlikely(ACLK_IS_HOST_POPCORNING(host))) {
278
- if(now != host->aclk_state.t_last_popcorn_update) {
279
- updated = 1;
280
- info("Restarting ACLK popcorn timer for host \"%s\" with GUID \"%s\"", host->hostname, host->machine_guid);
281
- }
282
- host->aclk_state.t_last_popcorn_update = now;
283
- rrdhost_aclk_state_unlock(host);
284
-
285
- if (host != localhost && updated)
286
- aclk_update_next_child_to_popcorn();
287
-
288
- legacy_aclk_shared_state_UNLOCK;
289
- return ret;
290
- }
291
-
292
- rrdhost_aclk_state_unlock(host);
293
- legacy_aclk_shared_state_UNLOCK;
294
- return ret;
295
-}
296
-
297
-inline static int aclk_host_initializing(RRDHOST *host)
298
-{
299
- rrdhost_aclk_state_lock(host);
300
- int ret = ACLK_IS_HOST_INITIALIZING(host);
301
- rrdhost_aclk_state_unlock(host);
302
- return ret;
303
-}
304
-
305
-static void aclk_start_host_popcorning(RRDHOST *host)
306
-{
307
- usec_t now = now_monotonic_sec();
308
- info("Starting ACLK popcorn timer for host \"%s\" with GUID \"%s\"", host->hostname, host->machine_guid);
309
- legacy_aclk_shared_state_LOCK;
310
- rrdhost_aclk_state_lock(host);
311
- if (host == localhost && !ACLK_IS_HOST_INITIALIZING(host)) {
312
- errno = 0;
313
- error("Localhost is allowed to do popcorning only once after startup!");
314
- rrdhost_aclk_state_unlock(host);
315
- legacy_aclk_shared_state_UNLOCK;
316
- return;
317
- }
318
-
319
- host->aclk_state.state = ACLK_HOST_INITIALIZING;
320
- host->aclk_state.metadata = ACLK_METADATA_REQUIRED;
321
- host->aclk_state.t_last_popcorn_update = now;
322
- rrdhost_aclk_state_unlock(host);
323
- if (host != localhost)
324
- aclk_update_next_child_to_popcorn();
325
- legacy_aclk_shared_state_UNLOCK;
326
-}
327
-
328
-static void aclk_stop_host_popcorning(RRDHOST *host)
329
-{
330
- legacy_aclk_shared_state_LOCK;
331
- rrdhost_aclk_state_lock(host);
332
- if (!ACLK_IS_HOST_POPCORNING(host)) {
333
- rrdhost_aclk_state_unlock(host);
334
- legacy_aclk_shared_state_UNLOCK;
335
- return;
336
- }
337
-
338
- info("Host Disconnected before ACLK popcorning finished. Canceling. Host \"%s\" GUID:\"%s\"", host->hostname, host->machine_guid);
339
- host->aclk_state.t_last_popcorn_update = 0;
340
- host->aclk_state.metadata = ACLK_METADATA_REQUIRED;
341
- rrdhost_aclk_state_unlock(host);
342
-
343
- if(host == legacy_aclk_shared_state.next_popcorn_host) {
344
- legacy_aclk_shared_state.next_popcorn_host = NULL;
345
- aclk_update_next_child_to_popcorn();
346
- }
347
- legacy_aclk_shared_state_UNLOCK;
348
-}
349
-
350
-/*
351
- * Add a new collector to the list
352
- * If it exists, update the chart count
353
- */
354
-void legacy_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
355
-{
356
- struct _collector *tmp_collector;
357
- if (unlikely(!netdata_ready)) {
358
- return;
359
- }
360
-
361
- COLLECTOR_LOCK;
362
-
363
- tmp_collector = _add_collector(host->machine_guid, plugin_name, module_name);
364
-
365
- if (unlikely(tmp_collector->count != 1)) {
366
- COLLECTOR_UNLOCK;
367
- return;
368
- }
369
-
370
- COLLECTOR_UNLOCK;
371
-
372
- if(aclk_popcorn_check_bump(host))
373
- return;
374
-
375
- if (unlikely(legacy_aclk_queue_query("collector", host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT)))
376
- debug(D_ACLK, "ACLK failed to queue on_connect command on collector addition");
377
-}
378
-
379
-/*
380
- * Delete a collector from the list
381
- * If the chart count reaches zero the collector will be removed
382
- * from the list by calling del_collector.
383
- *
384
- * This function will release the memory used and schedule
385
- * a cloud update
386
- */
387
-void legacy_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name)
388
-{
389
- struct _collector *tmp_collector;
390
- if (unlikely(!netdata_ready)) {
391
- return;
392
- }
393
-
394
- COLLECTOR_LOCK;
395
-
396
- tmp_collector = _del_collector(host->machine_guid, plugin_name, module_name);
397
-
398
- if (unlikely(!tmp_collector || tmp_collector->count)) {
399
- COLLECTOR_UNLOCK;
400
- return;
401
- }
402
-
403
- debug(
404
- D_ACLK, "DEL COLLECTOR [%s:%s] -- charts %u", plugin_name ? plugin_name : "*", module_name ? module_name : "*",
405
- tmp_collector->count);
406
-
407
- COLLECTOR_UNLOCK;
408
-
409
- _free_collector(tmp_collector);
410
-
411
- if (aclk_popcorn_check_bump(host))
412
- return;
413
-
414
- if (unlikely(legacy_aclk_queue_query("collector", host, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT)))
415
- debug(D_ACLK, "ACLK failed to queue on_connect command on collector deletion");
416
-}
417
-
418
-static void aclk_graceful_disconnect()
419
-{
420
- size_t write_q, write_q_bytes, read_q;
421
- time_t event_loop_timeout;
422
-
423
- // Send a graceful disconnect message
424
- BUFFER *b = buffer_create(512);
425
- aclk_create_header(b, "disconnect", NULL, 0, 0, legacy_aclk_shared_state.version_neg);
426
- buffer_strcat(b, ",\n\t\"payload\": \"graceful\"}");
427
- aclk_send_message(ACLK_METADATA_TOPIC, (char*)buffer_tostring(b), NULL);
428
- buffer_free(b);
429
-
430
- event_loop_timeout = now_realtime_sec() + 5;
431
- write_q = 1;
432
- while (write_q && event_loop_timeout > now_realtime_sec()) {
433
- _link_event_loop();
434
- lws_wss_check_queues(&write_q, &write_q_bytes, &read_q);
435
- }
436
-
437
- aclk_shutting_down = 1;
438
- _link_shutdown();
439
- aclk_lws_wss_mqtt_layer_disconnect_notif();
440
-
441
- write_q = 1;
442
- event_loop_timeout = now_realtime_sec() + 5;
443
- while (write_q && event_loop_timeout > now_realtime_sec()) {
444
- _link_event_loop();
445
- lws_wss_check_queues(&write_q, &write_q_bytes, &read_q);
446
- }
447
- aclk_shutting_down = 0;
448
-}
449
-
450
-#ifndef __GNUC__
451
-#pragma region Incoming Msg Parsing
452
-#endif
453
-
454
-struct dictionary_singleton {
455
- char *key;
456
- char *result;
457
-};
458
-
459
-int json_extract_singleton(JSON_ENTRY *e)
460
-{
461
- struct dictionary_singleton *data = e->callback_data;
462
-
463
- switch (e->type) {
464
- case JSON_OBJECT:
465
- case JSON_ARRAY:
466
- break;
467
- case JSON_STRING:
468
- if (!strcmp(e->name, data->key)) {
469
- data->result = strdupz(e->data.string);
470
- break;
471
- }
472
- break;
473
- case JSON_NUMBER:
474
- case JSON_BOOLEAN:
475
- case JSON_NULL:
476
- break;
477
- }
478
- return 0;
479
-}
480
-
481
-#ifndef __GNUC__
482
-#pragma endregion
483
-#endif
484
-
485
-
486
-#ifndef __GNUC__
487
-#pragma region Challenge Response
488
-#endif
489
-
490
-// Base-64 decoder.
491
-// Note: This is non-validating, invalid input will be decoded without an error.
492
-// Challenges are packed into json strings so we don't skip newlines.
493
-// Size errors (i.e. invalid input size or insufficient output space) are caught.
494
-size_t base64_decode(unsigned char *input, size_t input_size, unsigned char *output, size_t output_size)
495
-{
496
- static char lookup[256];
497
- static int first_time=1;
498
- if (first_time)
499
- {
500
- first_time = 0;
501
- for(int i=0; i<256; i++)
502
- lookup[i] = -1;
503
- for(int i='A'; i<='Z'; i++)
504
- lookup[i] = i-'A';
505
- for(int i='a'; i<='z'; i++)
506
- lookup[i] = i-'a' + 26;
507
- for(int i='0'; i<='9'; i++)
508
- lookup[i] = i-'0' + 52;
509
- lookup['+'] = 62;
510
- lookup['/'] = 63;
511
- }
512
- if ((input_size & 3) != 0)
513
- {
514
- error("Can't decode base-64 input length %zu", input_size);
515
- return 0;
516
- }
517
- size_t unpadded_size = (input_size/4) * 3;
518
- if ( unpadded_size > output_size )
519
- {
520
- error("Output buffer size %zu is too small to decode %zu into", output_size, input_size);
521
- return 0;
522
- }
523
- // Don't check padding within full quantums
524
- for (size_t i = 0 ; i < input_size-4 ; i+=4 )
525
- {
526
- uint32_t value = (lookup[input[0]] << 18) + (lookup[input[1]] << 12) + (lookup[input[2]] << 6) + lookup[input[3]];
527
- output[0] = value >> 16;
528
- output[1] = value >> 8;
529
- output[2] = value;
530
- //error("Decoded %c %c %c %c -> %02x %02x %02x", input[0], input[1], input[2], input[3], output[0], output[1], output[2]);
531
- output += 3;
532
- input += 4;
533
- }
534
- // Handle padding only in last quantum
535
- if (input[2] == '=') {
536
- uint32_t value = (lookup[input[0]] << 6) + lookup[input[1]];
537
- output[0] = value >> 4;
538
- //error("Decoded %c %c %c %c -> %02x", input[0], input[1], input[2], input[3], output[0]);
539
- return unpadded_size-2;
540
- }
541
- else if (input[3] == '=') {
542
- uint32_t value = (lookup[input[0]] << 12) + (lookup[input[1]] << 6) + lookup[input[2]];
543
- output[0] = value >> 10;
544
- output[1] = value >> 2;
545
- //error("Decoded %c %c %c %c -> %02x %02x", input[0], input[1], input[2], input[3], output[0], output[1]);
546
- return unpadded_size-1;
547
- }
548
- else
549
- {
550
- uint32_t value = (input[0] << 18) + (input[1] << 12) + (input[2]<<6) + input[3];
551
- output[0] = value >> 16;
552
- output[1] = value >> 8;
553
- output[2] = value;
554
- //error("Decoded %c %c %c %c -> %02x %02x %02x", input[0], input[1], input[2], input[3], output[0], output[1], output[2]);
555
- return unpadded_size;
556
- }
557
-}
558
-
559
-size_t base64_encode(unsigned char *input, size_t input_size, char *output, size_t output_size)
560
-{
561
- uint32_t value;
562
- static char lookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
563
- "abcdefghijklmnopqrstuvwxyz"
564
- "0123456789+/";
565
- if ((input_size/3+1)*4 >= output_size)
566
- {
567
- error("Output buffer for encoding size=%zu is not large enough for %zu-bytes input", output_size, input_size);
568
- return 0;
569
- }
570
- size_t count = 0;
571
- while (input_size>3)
572
- {
573
- value = ((input[0] << 16) + (input[1] << 8) + input[2]) & 0xffffff;
574
- output[0] = lookup[value >> 18];
575
- output[1] = lookup[(value >> 12) & 0x3f];
576
- output[2] = lookup[(value >> 6) & 0x3f];
577
- output[3] = lookup[value & 0x3f];
578
- //error("Base-64 encode (%04x) -> %c %c %c %c\n", value, output[0], output[1], output[2], output[3]);
579
- output += 4;
580
- input += 3;
581
- input_size -= 3;
582
- count += 4;
583
- }
584
- switch (input_size)
585
- {
586
- case 2:
587
- value = (input[0] << 10) + (input[1] << 2);
588
- output[0] = lookup[(value >> 12) & 0x3f];
589
- output[1] = lookup[(value >> 6) & 0x3f];
590
- output[2] = lookup[value & 0x3f];
591
- output[3] = '=';
592
- //error("Base-64 encode (%06x) -> %c %c %c %c\n", (value>>2)&0xffff, output[0], output[1], output[2], output[3]);
593
- count += 4;
594
- break;
595
- case 1:
596
- value = input[0] << 4;
597
- output[0] = lookup[(value >> 6) & 0x3f];
598
- output[1] = lookup[value & 0x3f];
599
- output[2] = '=';
600
- output[3] = '=';
601
- //error("Base-64 encode (%06x) -> %c %c %c %c\n", value, output[0], output[1], output[2], output[3]);
602
- count += 4;
603
- break;
604
- case 0:
605
- break;
606
- }
607
- return count;
608
-}
609
-
610
-
611
-
612
-int private_decrypt(unsigned char * enc_data, int data_len, unsigned char *decrypted)
613
-{
614
- int result = RSA_private_decrypt( data_len, enc_data, decrypted, aclk_private_key, RSA_PKCS1_OAEP_PADDING);
615
- if (result == -1) {
616
- char err[512];
617
- ERR_error_string_n(ERR_get_error(), err, sizeof(err));
618
- error("Decryption of the challenge failed: %s", err);
619
- }
620
- return result;
621
-}
622
-
623
-void aclk_get_challenge(char *aclk_hostname, int port)
624
-{
625
- char *data_buffer = mallocz(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
626
- debug(D_ACLK, "Performing challenge-response sequence");
627
- if (aclk_password != NULL)
628
- {
629
- freez(aclk_password);
630
- aclk_password = NULL;
631
- }
632
- // curl http://cloud-iam-agent-service:8080/api/v1/auth/node/00000000-0000-0000-0000-000000000000/challenge
633
- // TODO - target host?
634
- char *agent_id = is_agent_claimed();
635
- if (agent_id == NULL)
636
- {
637
- error("Agent was not claimed - cannot perform challenge/response");
638
- goto CLEANUP;
639
- }
640
- char url[1024];
641
- sprintf(url, "/api/v1/auth/node/%s/challenge", agent_id);
642
- info("Retrieving challenge from cloud: %s %d %s", aclk_hostname, port, url);
643
- if(aclk_send_https_request("GET", aclk_hostname, port, url, data_buffer, NETDATA_WEB_RESPONSE_INITIAL_SIZE, NULL))
644
- {
645
- error("Challenge failed: %s", data_buffer);
646
- goto CLEANUP;
647
- }
648
- struct dictionary_singleton challenge = { .key = "challenge", .result = NULL };
649
-
650
- debug(D_ACLK, "Challenge response from cloud: %s", data_buffer);
651
- if ( json_parse(data_buffer, &challenge, json_extract_singleton) != JSON_OK)
652
- {
653
- freez(challenge.result);
654
- error("Could not parse the json response with the challenge: %s", data_buffer);
655
- goto CLEANUP;
656
- }
657
- if (challenge.result == NULL ) {
658
- error("Could not retrieve challenge from auth response: %s", data_buffer);
659
- goto CLEANUP;
660
- }
661
-
662
-
663
- size_t challenge_len = strlen(challenge.result);
664
- unsigned char decoded[512];
665
- size_t decoded_len = base64_decode((unsigned char*)challenge.result, challenge_len, decoded, sizeof(decoded));
666
-
667
- unsigned char plaintext[4096]={};
668
- int decrypted_length = private_decrypt(decoded, decoded_len, plaintext);
669
- freez(challenge.result);
670
- char encoded[512];
671
- size_t encoded_len = base64_encode(plaintext, decrypted_length, encoded, sizeof(encoded));
672
- encoded[encoded_len] = 0;
673
- debug(D_ACLK, "Encoded len=%zu Decryption len=%d: '%s'", encoded_len, decrypted_length, encoded);
674
-
675
- char response_json[4096]={};
676
- sprintf(response_json, "{\"response\":\"%s\"}", encoded);
677
- debug(D_ACLK, "Password phase: %s",response_json);
678
- // TODO - host
679
- sprintf(url, "/api/v1/auth/node/%s/password", agent_id);
680
- if(aclk_send_https_request("POST", aclk_hostname, port, url, data_buffer, NETDATA_WEB_RESPONSE_INITIAL_SIZE, response_json))
681
- {
682
- error("Challenge-response failed: %s", data_buffer);
683
- goto CLEANUP;
684
- }
685
-
686
- debug(D_ACLK, "Password response from cloud: %s", data_buffer);
687
-
688
- struct dictionary_singleton password = { .key = "password", .result = NULL };
689
- if ( json_parse(data_buffer, &password, json_extract_singleton) != JSON_OK)
690
- {
691
- freez(password.result);
692
- error("Could not parse the json response with the password: %s", data_buffer);
693
- goto CLEANUP;
694
- }
695
-
696
- if (password.result == NULL ) {
697
- error("Could not retrieve password from auth response");
698
- goto CLEANUP;
699
- }
700
- if (aclk_password != NULL )
701
- freez(aclk_password);
702
- aclk_password = password.result;
703
- if (aclk_username != NULL)
704
- freez(aclk_username);
705
- aclk_username = agent_id;
706
- agent_id = NULL;
707
-
708
-CLEANUP:
709
- if (agent_id != NULL)
710
- freez(agent_id);
711
- freez(data_buffer);
712
- return;
713
-}
714
-
715
-#ifndef __GNUC__
716
-#pragma endregion
717
-#endif
718
-
719
-static void aclk_try_to_connect(char *hostname, int port)
720
-{
721
- int rc;
722
-
723
-// this is useful for developers working on ACLK
724
-// allows connecting agent to any MQTT broker
725
-// for debugging, development and testing purposes
726
-#ifndef ACLK_DISABLE_CHALLENGE
727
- if (!aclk_private_key) {
728
- error("Cannot try to establish the agent cloud link - no private key available!");
729
- return;
730
- }
731
-#endif
732
-
733
- info("Attempting to establish the agent cloud link");
734
-#ifdef ACLK_DISABLE_CHALLENGE
735
- error("Agent built with ACLK_DISABLE_CHALLENGE. This is for testing "
736
- "and development purposes only. Warranty void. Won't be able "
737
- "to connect to Netdata Cloud.");
738
- if (aclk_password == NULL)
739
- aclk_password = strdupz("anon");
740
-#else
741
- aclk_get_challenge(hostname, port);
742
- if (aclk_password == NULL)
743
- return;
744
-#endif
745
-
746
- aclk_connecting = 1;
747
- create_publish_base_topic();
748
-
749
- legacy_aclk_shared_state_LOCK;
750
- legacy_aclk_shared_state.version_neg = 0;
751
- legacy_aclk_shared_state.version_neg_wait_till = 0;
752
- legacy_aclk_shared_state_UNLOCK;
753
-
754
- rc = mqtt_attempt_connection(hostname, port, aclk_username, aclk_password);
755
- if (unlikely(rc)) {
756
- error("Failed to initialize the agent cloud link library");
757
- }
758
-}
759
-
760
-// Sends "hello" message to negotiate ACLK version with cloud
761
-static inline void aclk_hello_msg()
762
-{
763
- BUFFER *buf = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE);
764
-
765
- char *msg_id = create_uuid();
766
-
767
- legacy_aclk_shared_state_LOCK;
768
- legacy_aclk_shared_state.version_neg = 0;
769
- legacy_aclk_shared_state.version_neg_wait_till = now_monotonic_usec() + USEC_PER_SEC * VERSION_NEG_TIMEOUT;
770
- legacy_aclk_shared_state_UNLOCK;
771
-
772
- //Hello message is versioned separately from the rest of the protocol
773
- aclk_create_header(buf, "hello", msg_id, 0, 0, ACLK_VERSION_NEG_VERSION);
774
- buffer_sprintf(buf, ",\"min-version\":%d,\"max-version\":%d}", ACLK_VERSION_MIN, ACLK_VERSION_MAX);
775
- aclk_send_message(ACLK_METADATA_TOPIC, buf->buffer, msg_id);
776
- freez(msg_id);
777
- buffer_free(buf);
778
-}
779
-
780
-/**
781
- * Main agent cloud link thread
782
- *
783
- * This thread will simply call the main event loop that handles
784
- * pending requests - both inbound and outbound
785
- *
786
- * @param ptr is a pointer to the netdata_static_thread structure.
787
- *
788
- * @return It always returns NULL
789
- */
790
-void *legacy_aclk_main(void *ptr)
791
-{
792
- struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
793
- struct aclk_query_threads query_threads;
794
- struct aclk_stats_thread *stats_thread = NULL;
795
- time_t last_periodic_query_wakeup = 0;
796
-
797
- query_threads.thread_list = NULL;
798
-
799
- // This thread is unusual in that it cannot be cancelled by cancel_main_threads()
800
- // as it must notify the far end that it shutdown gracefully and avoid the LWT.
801
- netdata_thread_disable_cancelability();
802
-
803
-#if defined( DISABLE_CLOUD ) || !defined( ENABLE_ACLK)
804
- info("Killing ACLK thread -> cloud functionality has been disabled");
805
- static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
806
- return NULL;
807
-#endif
808
-
809
-#ifndef LWS_WITH_SOCKS5
810
- ACLK_PROXY_TYPE proxy_type;
811
- aclk_get_proxy(&proxy_type);
812
- if(proxy_type == PROXY_TYPE_SOCKS5) {
813
- error("Disabling ACLK due to requested SOCKS5 proxy.");
814
- static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
815
- return NULL;
816
- }
817
-#endif
818
-
819
- info("Waiting for netdata to be ready");
820
- while (!netdata_ready) {
821
- sleep_usec(USEC_PER_MS * 300);
822
- }
823
-
824
- info("Waiting for Cloud to be enabled");
825
- while (!netdata_cloud_setting) {
826
- sleep_usec(USEC_PER_SEC * 1);
827
- if (netdata_exit) {
828
- static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
829
- return NULL;
830
- }
831
- }
832
-
833
- query_threads.count = MIN(processors/2, 6);
834
- query_threads.count = MAX(query_threads.count, 2);
835
- query_threads.count = config_get_number(CONFIG_SECTION_CLOUD, "query thread count", query_threads.count);
836
- if(query_threads.count < 1) {
837
- error("You need at least one query thread. Overriding configured setting of \"%d\"", query_threads.count);
838
- query_threads.count = 1;
839
- config_set_number(CONFIG_SECTION_CLOUD, "query thread count", query_threads.count);
840
- }
841
-
842
- //start localhost popcorning
843
- aclk_start_host_popcorning(localhost);
844
-
845
- aclk_stats_enabled = config_get_boolean(CONFIG_SECTION_CLOUD, "statistics", CONFIG_BOOLEAN_YES);
846
- if (aclk_stats_enabled) {
847
- stats_thread = callocz(1, sizeof(struct aclk_stats_thread));
848
- stats_thread->thread = mallocz(sizeof(netdata_thread_t));
849
- stats_thread->query_thread_count = query_threads.count;
850
- netdata_thread_create(
851
- stats_thread->thread, ACLK_STATS_THREAD_NAME, NETDATA_THREAD_OPTION_JOINABLE, legacy_aclk_stats_main_thread,
852
- stats_thread);
853
- }
854
-
855
- char *aclk_hostname = NULL; // Initializers are over-written but prevent gcc complaining about clobbering.
856
- int port_num = 0;
857
- info("Waiting for netdata to be claimed");
858
- while(1) {
859
- char *agent_id = is_agent_claimed();
860
- while (likely(!agent_id)) {
861
- sleep_usec(USEC_PER_SEC * 1);
862
- if (netdata_exit)
863
- goto exited;
864
- agent_id = is_agent_claimed();
865
- }
866
- freez(agent_id);
867
- // The NULL return means the value was never initialised, but this value has been initialized in post_conf_load.
868
- // We trap the impossible NULL here to keep the linter happy without using a fatal() in the code.
869
- char *cloud_base_url = appconfig_get(&cloud_config, CONFIG_SECTION_GLOBAL, "cloud base url", NULL);
870
- if (cloud_base_url == NULL) {
871
- error("Do not move the cloud base url out of post_conf_load!!");
872
- goto exited;
873
- }
874
- if (aclk_decode_base_url(cloud_base_url, &aclk_hostname, &port_num))
875
- error("Agent is claimed but the configuration is invalid, please fix");
876
- else if (!create_private_key() && !_mqtt_lib_init())
877
- break;
878
-
879
- for (int i=0; i<60; i++) {
880
- if (netdata_exit)
881
- goto exited;
882
-
883
- sleep_usec(USEC_PER_SEC * 1);
884
- }
885
- }
886
-
887
- usec_t reconnect_expiry = 0; // In usecs
888
-
889
- while (!netdata_exit) {
890
- static int first_init = 0;
891
- /* size_t write_q, write_q_bytes, read_q;
892
- lws_wss_check_queues(&write_q, &write_q_bytes, &read_q);*/
893
-
894
- if (aclk_disable_runtime && !aclk_connected) {
895
- sleep(1);
896
- continue;
897
- }
898
-
899
- if (aclk_kill_link) { // User has reloaded the claiming state
900
- aclk_kill_link = 0;
901
- aclk_graceful_disconnect();
902
- create_private_key();
903
- continue;
904
- }
905
-
906
- if (aclk_force_reconnect) {
907
- aclk_lws_wss_destroy_context();
908
- aclk_force_reconnect = 0;
909
- }
910
- if (unlikely(!netdata_exit && !aclk_connected && !aclk_force_reconnect)) {
911
- if (unlikely(!first_init)) {
912
- aclk_try_to_connect(aclk_hostname, port_num);
913
- first_init = 1;
914
- } else {
915
- if (aclk_connecting == 0) {
916
- if (reconnect_expiry == 0) {
917
- unsigned long int delay = aclk_reconnect_delay(1);
918
- reconnect_expiry = now_realtime_usec() + delay * 1000;
919
- info("Retrying to establish the ACLK connection in %.3f seconds", delay / 1000.0);
920
- }
921
- if (now_realtime_usec() >= reconnect_expiry) {
922
- reconnect_expiry = 0;
923
- aclk_try_to_connect(aclk_hostname, port_num);
924
- }
925
- sleep_usec(USEC_PER_MS * 100);
926
- }
927
- }
928
- if (aclk_connecting) {
929
- _link_event_loop();
930
- sleep_usec(USEC_PER_MS * 100);
931
- }
932
- continue;
933
- }
934
-
935
- _link_event_loop();
936
- if (unlikely(!aclk_connected || aclk_force_reconnect))
937
- continue;
938
- /*static int stress_counter = 0;
939
- if (write_q_bytes==0 && stress_counter ++ >5)
940
- {
941
- aclk_send_stress_test(8000000);
942
- stress_counter = 0;
943
- }*/
944
-
945
- if (unlikely(!aclk_subscribed)) {
946
- aclk_subscribed = !aclk_subscribe(ACLK_COMMAND_TOPIC, 1);
947
- aclk_hello_msg();
948
- }
949
-
950
- if (unlikely(!query_threads.thread_list)) {
951
- legacy_aclk_query_threads_start(&query_threads);
952
- }
953
-
954
- time_t now = now_monotonic_sec();
955
- if(aclk_connected && last_periodic_query_wakeup < now) {
956
- // to make `legacy_aclk_queue_query()` param `run_after` work
957
- // also makes per child popcorning work
958
- last_periodic_query_wakeup = now;
959
- LEGACY_QUERY_THREAD_WAKEUP;
960
- }
961
- } // forever
962
-exited:
963
- // Wakeup query thread to cleanup
964
- LEGACY_QUERY_THREAD_WAKEUP_ALL;
965
-
966
- freez(aclk_username);
967
- freez(aclk_password);
968
- freez(aclk_hostname);
969
- if (aclk_private_key != NULL)
970
- RSA_free(aclk_private_key);
971
-
972
- static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
973
-
974
- char *agent_id = is_agent_claimed();
975
- if (agent_id && aclk_connected) {
976
- freez(agent_id);
977
- // Wakeup thread to cleanup
978
- LEGACY_QUERY_THREAD_WAKEUP;
979
- aclk_graceful_disconnect();
980
- }
981
-
982
- legacy_aclk_query_threads_cleanup(&query_threads);
983
-
984
- _reset_collector_list();
985
- freez(collector_list);
986
-
987
- if(aclk_stats_enabled) {
988
- netdata_thread_join(*stats_thread->thread, NULL);
989
- legacy_aclk_stats_thread_cleanup();
990
- freez(stats_thread->thread);
991
- freez(stats_thread);
992
- }
993
-
994
- /*
995
- * this must be last -> if all static threads signal
996
- * THREAD_EXITED rrdengine will dealloc the RRDSETs
997
- * and RRDDIMs that are used by still running stat thread.
998
- * see netdata_cleanup_and_exit() for reference
999
- */
1000
- static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
1001
- return NULL;
1002
-}
1003
-
1004
-/*
1005
- * Send a message to the cloud, using a base topic and sib_topic
1006
- * The final topic will be in the form <base_topic>/<sub_topic>
1007
- * If base_topic is missing then the global_base_topic will be used (if available)
1008
- *
1009
- */
1010
-int aclk_send_message_bin(char *sub_topic, const void *message, size_t len, char *msg_id)
1011
-{
1012
- int rc;
1013
- int mid;
1014
- char topic[ACLK_MAX_TOPIC + 1];
1015
- char *final_topic;
1016
-
1017
- UNUSED(msg_id);
1018
-
1019
- if (!aclk_connected)
1020
- return 0;
1021
-
1022
- if (unlikely(!message))
1023
- return 0;
1024
-
1025
- final_topic = get_topic(sub_topic, topic, ACLK_MAX_TOPIC);
1026
-
1027
- if (unlikely(!final_topic)) {
1028
- errno = 0;
1029
- error("Unable to build outgoing topic; truncated?");
1030
- return 1;
1031
- }
1032
-
1033
- ACLK_LOCK;
1034
- rc = _link_send_message(final_topic, message, len, &mid);
1035
- // TODO: link the msg_id with the mid so we can trace it
1036
- ACLK_UNLOCK;
1037
-
1038
- if (unlikely(rc)) {
1039
- errno = 0;
1040
- error("Failed to send message, error code %d (%s)", rc, _link_strerror(rc));
1041
- }
1042
-
1043
- return rc;
1044
-}
1045
-
1046
-int aclk_send_message(char *sub_topic, char *message, char *msg_id)
1047
-{
1048
- return aclk_send_message_bin(sub_topic, message, strlen(message), msg_id);
1049
-}
1050
-
1051
-/*
1052
- * Subscribe to a topic in the cloud
1053
- * The final subscription will be in the form
1054
- * /agent/claim_id/<sub_topic>
1055
- */
1056
-int aclk_subscribe(char *sub_topic, int qos)
1057
-{
1058
- int rc;
1059
- char topic[ACLK_MAX_TOPIC + 1];
1060
- char *final_topic;
1061
-
1062
- final_topic = get_topic(sub_topic, topic, ACLK_MAX_TOPIC);
1063
- if (unlikely(!final_topic)) {
1064
- errno = 0;
1065
- error("Unable to build outgoing topic; truncated?");
1066
- return 1;
1067
- }
1068
-
1069
- if (!aclk_connected) {
1070
- error("Cannot subscribe to %s - not connected!", topic);
1071
- return 1;
1072
- }
1073
-
1074
- ACLK_LOCK;
1075
- rc = _link_subscribe(final_topic, qos);
1076
- ACLK_UNLOCK;
1077
-
1078
- // TODO: Add better handling -- error will flood the logfile here
1079
- if (unlikely(rc)) {
1080
- errno = 0;
1081
- error("Failed subscribe to command topic %d (%s)", rc, _link_strerror(rc));
1082
- }
1083
-
1084
- return rc;
1085
-}
1086
-
1087
-// This is called from a callback when the link goes up
1088
-void aclk_connect()
1089
-{
1090
- info("Connection detected (%u queued queries)", aclk_query_size());
1091
-
1092
- legacy_aclk_stats_upd_online(1);
1093
-
1094
- aclk_connected = 1;
1095
- aclk_reconnect_delay(0);
1096
-
1097
- LEGACY_QUERY_THREAD_WAKEUP;
1098
- return;
1099
-}
1100
-
1101
-// This is called from a callback when the link goes down
1102
-void aclk_disconnect()
1103
-{
1104
- if (likely(aclk_connected))
1105
- info("Disconnect detected (%u queued queries)", aclk_query_size());
1106
-
1107
- legacy_aclk_stats_upd_online(0);
1108
-
1109
- aclk_subscribed = 0;
1110
- rrdhost_aclk_state_lock(localhost);
1111
- localhost->aclk_state.metadata = ACLK_METADATA_REQUIRED;
1112
- rrdhost_aclk_state_unlock(localhost);
1113
- aclk_connected = 0;
1114
- aclk_connecting = 0;
1115
- aclk_force_reconnect = 1;
1116
-}
1117
-
1118
-inline void aclk_create_header(BUFFER *dest, char *type, char *msg_id, time_t ts_secs, usec_t ts_us, int version)
1119
-{
1120
- uuid_t uuid;
1121
- char uuid_str[36 + 1];
1122
-
1123
- if (unlikely(!msg_id)) {
1124
- uuid_generate(uuid);
1125
- uuid_unparse(uuid, uuid_str);
1126
- msg_id = uuid_str;
1127
- }
1128
-
1129
- if (ts_secs == 0) {
1130
- ts_us = now_realtime_usec();
1131
- ts_secs = ts_us / USEC_PER_SEC;
1132
- ts_us = ts_us % USEC_PER_SEC;
1133
- }
1134
-
1135
- buffer_sprintf(
1136
- dest,
1137
- "{\t\"type\": \"%s\",\n"
1138
- "\t\"msg-id\": \"%s\",\n"
1139
- "\t\"timestamp\": %ld,\n"
1140
- "\t\"timestamp-offset-usec\": %llu,\n"
1141
- "\t\"connect\": %ld,\n"
1142
- "\t\"connect-offset-usec\": %llu,\n"
1143
- "\t\"version\": %d",
1144
- type, msg_id, ts_secs, ts_us, aclk_session_sec, aclk_session_us, version);
1145
-
1146
- debug(D_ACLK, "Sending v%d msgid [%s] type [%s] time [%ld]", version, msg_id, type, ts_secs);
1147
-}
1148
-
1149
-
1150
-/*
1151
- * This will send alarm information which includes
1152
- * configured alarms
1153
- * alarm_log
1154
- * active alarms
1155
- */
1156
-void health_active_log_alarms_2json(RRDHOST *host, BUFFER *wb);
1157
-
1158
-void legacy_aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted)
1159
-{
1160
- BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1161
-
1162
- char *msg_id = create_uuid();
1163
- buffer_flush(local_buffer);
1164
- local_buffer->contenttype = CT_APPLICATION_JSON;
1165
-
1166
- debug(D_ACLK, "Metadata alarms start");
1167
-
1168
- // on_connect messages are sent on a health reload, if the on_connect message is real then we
1169
- // use the session time as the fake timestamp to indicate that it starts the session. If it is
1170
- // a fake on_connect message then use the real timestamp to indicate it is within the existing
1171
- // session.
1172
-
1173
- if (metadata_submitted == ACLK_METADATA_SENT)
1174
- aclk_create_header(local_buffer, "connect_alarms", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1175
- else
1176
- aclk_create_header(local_buffer, "connect_alarms", msg_id, aclk_session_sec, aclk_session_us, legacy_aclk_shared_state.version_neg);
1177
- buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1178
-
1179
-
1180
- buffer_sprintf(local_buffer, "{\n\t \"configured-alarms\" : ");
1181
- health_alarms2json(localhost, local_buffer, 1);
1182
- debug(D_ACLK, "Metadata %s with configured alarms has %zu bytes", msg_id, local_buffer->len);
1183
- // buffer_sprintf(local_buffer, ",\n\t \"alarm-log\" : ");
1184
- // health_alarm_log2json(localhost, local_buffer, 0);
1185
- // debug(D_ACLK, "Metadata %s with alarm_log has %zu bytes", msg_id, local_buffer->len);
1186
- buffer_sprintf(local_buffer, ",\n\t \"alarms-active\" : ");
1187
- health_active_log_alarms_2json(localhost, local_buffer);
1188
- //debug(D_ACLK, "Metadata message %s", local_buffer->buffer);
1189
-
1190
-
1191
-
1192
- buffer_sprintf(local_buffer, "\n}\n}");
1193
- aclk_send_message(ACLK_ALARMS_TOPIC, local_buffer->buffer, msg_id);
1194
-
1195
- freez(msg_id);
1196
- buffer_free(local_buffer);
1197
-}
1198
-
1199
-/*
1200
- * This will send the agent metadata
1201
- * /api/v1/info
1202
- * charts
1203
- */
1204
-int legacy_aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *host)
1205
-{
1206
- BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1207
-
1208
- debug(D_ACLK, "Metadata /info start");
1209
-
1210
- char *msg_id = create_uuid();
1211
- buffer_flush(local_buffer);
1212
- local_buffer->contenttype = CT_APPLICATION_JSON;
1213
-
1214
- // on_connect messages are sent on a health reload, if the on_connect message is real then we
1215
- // use the session time as the fake timestamp to indicate that it starts the session. If it is
1216
- // a fake on_connect message then use the real timestamp to indicate it is within the existing
1217
- // session.
1218
- if (metadata_submitted == ACLK_METADATA_SENT)
1219
- aclk_create_header(local_buffer, "update", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1220
- else
1221
- aclk_create_header(local_buffer, "connect", msg_id, aclk_session_sec, aclk_session_us, legacy_aclk_shared_state.version_neg);
1222
- buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1223
-
1224
- buffer_sprintf(local_buffer, "{\n\t \"info\" : ");
1225
- web_client_api_request_v1_info_fill_buffer(host, local_buffer);
1226
- debug(D_ACLK, "Metadata %s with info has %zu bytes", msg_id, local_buffer->len);
1227
-
1228
- buffer_sprintf(local_buffer, ", \n\t \"charts\" : ");
1229
- charts2json(host, local_buffer, 1, 0);
1230
- buffer_sprintf(local_buffer, "\n}\n}");
1231
- debug(D_ACLK, "Metadata %s with chart has %zu bytes", msg_id, local_buffer->len);
1232
-
1233
- aclk_send_message(ACLK_METADATA_TOPIC, local_buffer->buffer, msg_id);
1234
-
1235
- freez(msg_id);
1236
- buffer_free(local_buffer);
1237
- return 0;
1238
-}
1239
-
1240
-int aclk_send_info_child_connection(RRDHOST *host, ACLK_CMD cmd)
1241
-{
1242
- BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1243
- local_buffer->contenttype = CT_APPLICATION_JSON;
1244
-
1245
- if(legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE)
1246
- fatal("This function should not be called if ACLK version is less than %d (current %d)", ACLK_V_CHILDRENSTATE, legacy_aclk_shared_state.version_neg);
1247
-
1248
- debug(D_ACLK, "Sending Child Disconnect");
1249
-
1250
- char *msg_id = create_uuid();
1251
-
1252
- aclk_create_header(local_buffer, cmd == ACLK_CMD_CHILD_CONNECT ? "child_connect" : "child_disconnect", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1253
-
1254
- buffer_strcat(local_buffer, ",\"payload\":");
1255
-
1256
- buffer_sprintf(local_buffer, "{\"guid\":\"%s\",\"claim_id\":", host->machine_guid);
1257
- rrdhost_aclk_state_lock(host);
1258
- if(host->aclk_state.claimed_id)
1259
- buffer_sprintf(local_buffer, "\"%s\"}}", host->aclk_state.claimed_id);
1260
- else
1261
- buffer_strcat(local_buffer, "null}}");
1262
-
1263
- rrdhost_aclk_state_unlock(host);
1264
-
1265
- aclk_send_message(ACLK_METADATA_TOPIC, local_buffer->buffer, msg_id);
1266
-
1267
- freez(msg_id);
1268
- buffer_free(local_buffer);
1269
- return 0;
1270
-}
1271
-
1272
-void legacy_aclk_host_state_update(RRDHOST *host, int connect)
1273
-{
1274
-#if ACLK_VERSION_MIN < ACLK_V_CHILDRENSTATE
1275
- if (legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE)
1276
- return;
1277
-#else
1278
-#warning "This check became unnecessary. Remove"
1279
-#endif
1280
-
1281
- if (unlikely(aclk_host_initializing(localhost)))
1282
- return;
1283
-
1284
- if (connect) {
1285
- debug(D_ACLK, "Child Connected %s %s.", host->hostname, host->machine_guid);
1286
- aclk_start_host_popcorning(host);
1287
- legacy_aclk_queue_query("add_child", host, NULL, NULL, 0, 1, ACLK_CMD_CHILD_CONNECT);
1288
- } else {
1289
- debug(D_ACLK, "Child Disconnected %s %s.", host->hostname, host->machine_guid);
1290
- aclk_stop_host_popcorning(host);
1291
- legacy_aclk_queue_query("del_child", host, NULL, NULL, 0, 1, ACLK_CMD_CHILD_DISCONNECT);
1292
- }
1293
-}
1294
-
1295
-void aclk_send_stress_test(size_t size)
1296
-{
1297
- char *buffer = mallocz(size);
1298
- if (buffer != NULL)
1299
- {
1300
- for(size_t i=0; i<size; i++)
1301
- buffer[i] = 'x';
1302
- buffer[size-1] = 0;
1303
- time_t time_created = now_realtime_sec();
1304
- sprintf(buffer,"{\"type\":\"stress\", \"timestamp\":%ld,\"payload\":", time_created);
1305
- buffer[strlen(buffer)] = '"';
1306
- buffer[size-2] = '}';
1307
- buffer[size-3] = '"';
1308
- aclk_send_message(ACLK_METADATA_TOPIC, buffer, NULL);
1309
- error("Sending stress of size %zu at time %ld", size, time_created);
1310
- }
1311
- free(buffer);
1312
-}
1313
-
1314
-// Send info metadata message to the cloud if the link is established
1315
-// or on request
1316
-int aclk_send_metadata(ACLK_METADATA_STATE state, RRDHOST *host)
1317
-{
1318
- legacy_aclk_send_info_metadata(state, host);
1319
-
1320
- if(host == localhost)
1321
- legacy_aclk_send_alarm_metadata(state);
1322
-
1323
- return 0;
1324
-}
1325
-
1326
-// Triggered by a health reload, sends the alarm metadata
1327
-void legacy_aclk_alarm_reload()
1328
-{
1329
- if (unlikely(aclk_host_initializing(localhost)))
1330
- return;
1331
-
1332
- if (unlikely(legacy_aclk_queue_query("on_connect", localhost, NULL, NULL, 0, 1, ACLK_CMD_ONCONNECT))) {
1333
- if (likely(aclk_connected)) {
1334
- errno = 0;
1335
- error("ACLK failed to queue on_connect command on alarm reload");
1336
- }
1337
- }
1338
-}
1339
-//rrd_stats_api_v1_chart(RRDSET *st, BUFFER *buf)
1340
-
1341
-int aclk_send_single_chart(RRDHOST *host, char *chart)
1342
-{
1343
- RRDSET *st = rrdset_find(host, chart);
1344
- if (!st)
1345
- st = rrdset_find_byname(host, chart);
1346
- if (!st) {
1347
- info("FAILED to find chart %s", chart);
1348
- return 1;
1349
- }
1350
-
1351
- BUFFER *local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1352
- char *msg_id = create_uuid();
1353
- buffer_flush(local_buffer);
1354
- local_buffer->contenttype = CT_APPLICATION_JSON;
1355
-
1356
- aclk_create_header(local_buffer, "chart", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1357
- buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1358
-
1359
- rrdset2json(st, local_buffer, NULL, NULL, 1);
1360
- buffer_sprintf(local_buffer, "\t\n}");
1361
-
1362
- aclk_send_message(ACLK_CHART_TOPIC, local_buffer->buffer, msg_id);
1363
-
1364
- freez(msg_id);
1365
- buffer_free(local_buffer);
1366
- return 0;
1367
-}
1368
-
1369
-int legacy_aclk_update_chart(RRDHOST *host, char *chart_name, int create)
1370
-{
1371
-#ifndef ENABLE_ACLK
1372
- UNUSED(host);
1373
- UNUSED(chart_name);
1374
- return 0;
1375
-#else
1376
- if (unlikely(!netdata_ready))
1377
- return 0;
1378
-
1379
- if (!netdata_cloud_setting)
1380
- return 0;
1381
-
1382
- if (legacy_aclk_shared_state.version_neg < ACLK_V_CHILDRENSTATE && host != localhost)
1383
- return 0;
1384
-
1385
- if (aclk_host_initializing(localhost))
1386
- return 0;
1387
-
1388
- if (unlikely(aclk_disable_single_updates))
1389
- return 0;
1390
-
1391
- if (aclk_popcorn_check_bump(host))
1392
- return 0;
1393
-
1394
- if (unlikely(legacy_aclk_queue_query("_chart", host, NULL, chart_name, 0, 1, create ? ACLK_CMD_CHART : ACLK_CMD_CHARTDEL))) {
1395
- if (likely(aclk_connected)) {
1396
- errno = 0;
1397
- error("ACLK failed to queue chart_update command");
1398
- }
1399
- }
1400
-
1401
- return 0;
1402
-#endif
1403
-}
1404
-
1405
-int legacy_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae)
1406
-{
1407
- BUFFER *local_buffer = NULL;
1408
-
1409
- if (unlikely(!netdata_ready))
1410
- return 0;
1411
-
1412
- if (host != localhost)
1413
- return 0;
1414
-
1415
- if(unlikely(aclk_host_initializing(localhost)))
1416
- return 0;
1417
-
1418
- /*
1419
- * Check if individual updates have been disabled
1420
- * This will be the case when we do health reload
1421
- * and all the alarms will be dropped and recreated.
1422
- * At the end of the health reload the complete alarm metadata
1423
- * info will be sent
1424
- */
1425
- if (unlikely(aclk_disable_single_updates))
1426
- return 0;
1427
-
1428
- local_buffer = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE);
1429
- char *msg_id = create_uuid();
1430
-
1431
- buffer_flush(local_buffer);
1432
- aclk_create_header(local_buffer, "status-change", msg_id, 0, 0, legacy_aclk_shared_state.version_neg);
1433
- buffer_strcat(local_buffer, ",\n\t\"payload\": ");
1434
-
1435
- netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
1436
- health_alarm_entry2json_nolock(local_buffer, ae, host);
1437
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
1438
-
1439
- buffer_sprintf(local_buffer, "\n}");
1440
-
1441
- if (unlikely(legacy_aclk_queue_query(ACLK_ALARMS_TOPIC, NULL, msg_id, local_buffer->buffer, 0, 1, ACLK_CMD_ALARM))) {
1442
- if (likely(aclk_connected)) {
1443
- errno = 0;
1444
- error("ACLK failed to queue alarm_command on alarm_update");
1445
- }
1446
- }
1447
-
1448
- freez(msg_id);
1449
- buffer_free(local_buffer);
1450
-
1451
- return 0;
1452
-}
1453
-
1454
-char *legacy_aclk_state(void)
1455
-{
1456
- BUFFER *wb = buffer_create(1024);
1457
- char *ret;
1458
-
1459
- buffer_strcat(wb,
1460
- "ACLK Available: Yes\n"
1461
- "ACLK Implementation: Legacy\n"
1462
- "Claimed: "
1463
- );
1464
-
1465
- char *agent_id = is_agent_claimed();
1466
- if (agent_id == NULL)
1467
- buffer_strcat(wb, "No\n");
1468
- else {
1469
- buffer_sprintf(wb, "Yes\nClaimed Id: %s\n", agent_id);
1470
- freez(agent_id);
1471
- }
1472
-
1473
- buffer_sprintf(wb, "Online: %s", aclk_connected ? "Yes" : "No");
1474
-
1475
- ret = strdupz(buffer_tostring(wb));
1476
- buffer_free(wb);
1477
- return ret;
1478
-}
1479
-
1480
-char *legacy_aclk_state_json(void)
1481
-{
1482
- BUFFER *wb = buffer_create(1024);
1483
- char *agent_id = is_agent_claimed();
1484
-
1485
- buffer_sprintf(wb,
1486
- "{\"aclk-available\":true,"
1487
- "\"aclk-implementation\":\"Legacy\","
1488
- "\"agent-claimed\":%s,"
1489
- "\"claimed-id\":",
1490
- agent_id ? "true" : "false"
1491
- );
1492
-
1493
- if (agent_id) {
1494
- buffer_sprintf(wb, "\"%s\"", agent_id);
1495
- freez(agent_id);
1496
- } else
1497
- buffer_strcat(wb, "null");
1498
-
1499
- buffer_sprintf(wb, ",\"online\":%s}", aclk_connected ? "true" : "false");
1500
-
1501
- return strdupz(buffer_tostring(wb));
1502
-}
aclk/legacy/agent_cloud_link.h
deleted
-85
@@ -1,85 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef NETDATA_AGENT_CLOUD_LINK_H
4
-#define NETDATA_AGENT_CLOUD_LINK_H
5
-
6
-#include "daemon/common.h"
7
-#include "mqtt.h"
8
-#include "aclk_common.h"
9
-
10
-#define ACLK_CHART_TOPIC "outbound/meta"
11
-#define ACLK_ALARMS_TOPIC "outbound/alarms"
12
-#define ACLK_METADATA_TOPIC "outbound/meta"
13
-#define ACLK_COMMAND_TOPIC "inbound/cmd"
14
-#define ACLK_TOPIC_STRUCTURE "/agent/%s"
15
-
16
-#define ACLK_MAX_BACKOFF_DELAY 1024 // maximum backoff delay in seconds
17
-
18
-#define ACLK_INITIALIZATION_WAIT 60 // Wait for link to initialize in seconds (per msg)
19
-#define ACLK_INITIALIZATION_SLEEP_WAIT 1 // Wait time @ spin lock for MQTT initialization in seconds
20
-#define ACLK_PING_INTERVAL 60
21
-#define ACLK_LOOP_TIMEOUT 5 // seconds to wait for operations in the library loop
22
-
23
-#define ACLK_MAX_TOPIC 255
24
-
25
-#define ACLK_RECONNECT_DELAY 1 // reconnect delay -- with backoff strategy for now
26
-#define ACLK_DEFAULT_PORT 9002
27
-#define ACLK_DEFAULT_HOST "localhost"
28
-
29
-#define ACLK_V2_PAYLOAD_SEPARATOR "\x0D\x0A\x0D\x0A"
30
-
31
-struct aclk_request {
32
- char *type_id;
33
- char *msg_id;
34
- char *callback_topic;
35
- char *payload;
36
- int version;
37
- int min_version;
38
- int max_version;
39
-};
40
-
41
-typedef enum aclk_init_action { ACLK_INIT, ACLK_REINIT } ACLK_INIT_ACTION;
42
-
43
-void *legacy_aclk_main(void *ptr);
44
-
45
-extern int aclk_send_message(char *sub_topic, char *message, char *msg_id);
46
-extern int aclk_send_message_bin(char *sub_topic, const void *message, size_t len, char *msg_id);
47
-
48
-extern char *is_agent_claimed(void);
49
-extern void aclk_lws_wss_mqtt_layer_disconnect_notif();
50
-char *create_uuid();
51
-
52
-// callbacks for agent cloud link
53
-int aclk_subscribe(char *topic, int qos);
54
-int legacy_cloud_to_agent_parse(JSON_ENTRY *e);
55
-void aclk_disconnect();
56
-void aclk_connect();
57
-
58
-#ifdef ENABLE_ACLK
59
-int aclk_send_metadata(ACLK_METADATA_STATE state, RRDHOST *host);
60
-int legacy_aclk_send_info_metadata(ACLK_METADATA_STATE metadata_submitted, RRDHOST *host);
61
-void legacy_aclk_send_alarm_metadata(ACLK_METADATA_STATE metadata_submitted);
62
-
63
-int aclk_wait_for_initialization();
64
-char *create_publish_base_topic();
65
-
66
-int aclk_send_single_chart(RRDHOST *host, char *chart);
67
-int legacy_aclk_update_chart(RRDHOST *host, char *chart_name, int create);
68
-int legacy_aclk_update_alarm(RRDHOST *host, ALARM_ENTRY *ae);
69
-void aclk_create_header(BUFFER *dest, char *type, char *msg_id, time_t ts_secs, usec_t ts_us, int version);
70
-int legacy_aclk_handle_cloud_message(char *payload);
71
-void legacy_aclk_add_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
72
-void legacy_aclk_del_collector(RRDHOST *host, const char *plugin_name, const char *module_name);
73
-void legacy_aclk_alarm_reload(void);
74
-unsigned long int aclk_reconnect_delay(int mode);
75
-extern void health_alarm_entry2json_nolock(BUFFER *wb, ALARM_ENTRY *ae, RRDHOST *host);
76
-
77
-void legacy_aclk_host_state_update(RRDHOST *host, int connect);
78
-int aclk_send_info_child_connection(RRDHOST *host, ACLK_CMD cmd);
79
-void aclk_update_next_child_to_popcorn(void);
80
-
81
-char *legacy_aclk_state(void);
82
-char *legacy_aclk_state_json(void);
83
-#endif
84
-
85
-#endif //NETDATA_AGENT_CLOUD_LINK_H
aclk/legacy/mqtt.c
deleted
-370
@@ -1,370 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#include <libnetdata/json/json.h>
4
-#include "daemon/common.h"
5
-#include "mqtt.h"
6
-#include "aclk_lws_wss_client.h"
7
-#include "aclk_stats.h"
8
-#include "aclk_rx_msgs.h"
9
-
10
-#include "agent_cloud_link.h"
11
-
12
-#define ACLK_QOS 1
13
-
14
-extern usec_t aclk_session_us;
15
-extern time_t aclk_session_sec;
16
-
17
-inline const char *_link_strerror(int rc)
18
-{
19
- return mosquitto_strerror(rc);
20
-}
21
-
22
-#ifdef NETDATA_INTERNAL_CHECKS
23
-static struct timeval sendTimes[1024];
24
-#endif
25
-
26
-static struct mosquitto *mosq = NULL;
27
-
28
-
29
-void mqtt_message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *msg)
30
-{
31
- UNUSED(mosq);
32
- UNUSED(obj);
33
-
34
- legacy_aclk_handle_cloud_message(msg->payload);
35
-}
36
-
37
-void publish_callback(struct mosquitto *mosq, void *obj, int rc)
38
-{
39
- UNUSED(mosq);
40
- UNUSED(obj);
41
- UNUSED(rc);
42
-#ifdef NETDATA_INTERNAL_CHECKS
43
- struct timeval now, *orig;
44
- now_realtime_timeval(&now);
45
- orig = &sendTimes[ rc & 0x3ff ];
46
- int64_t diff = (now.tv_sec - orig->tv_sec) * USEC_PER_SEC + (now.tv_usec - orig->tv_usec);
47
- diff /= 1000;
48
-
49
- info("Publish_callback: mid=%d latency=%" PRId64 "ms", rc, diff);
50
-
51
- legacy_aclk_metric_mat_update(&legacy_aclk_metrics_per_sample.latency, diff);
52
-#endif
53
- return;
54
-}
55
-
56
-void connect_callback(struct mosquitto *mosq, void *obj, int rc)
57
-{
58
- UNUSED(mosq);
59
- UNUSED(obj);
60
- UNUSED(rc);
61
-
62
- info("Connection to cloud established");
63
- aclk_connect();
64
-
65
- return;
66
-}
67
-
68
-void disconnect_callback(struct mosquitto *mosq, void *obj, int rc)
69
-{
70
- UNUSED(mosq);
71
- UNUSED(obj);
72
- UNUSED(rc);
73
-
74
- if (netdata_exit)
75
- info("Connection to cloud terminated due to agent shutdown");
76
- else {
77
- errno = 0;
78
- error("Connection to cloud failed");
79
- }
80
- aclk_disconnect();
81
-
82
- aclk_lws_wss_mqtt_layer_disconnect_notif();
83
-
84
- return;
85
-}
86
-
87
-void _show_mqtt_info()
88
-{
89
- int libmosq_major, libmosq_minor, libmosq_revision, libmosq_version;
90
- libmosq_version = mosquitto_lib_version(&libmosq_major, &libmosq_minor, &libmosq_revision);
91
-
92
- info(
93
- "Detected libmosquitto library version %d, %d.%d.%d", libmosq_version, libmosq_major, libmosq_minor,
94
- libmosq_revision);
95
-}
96
-
97
-size_t _mqtt_external_write_hook(void *buf, size_t count)
98
-{
99
- return aclk_lws_wss_client_write(buf, count);
100
-}
101
-
102
-size_t _mqtt_external_read_hook(void *buf, size_t count)
103
-{
104
- return aclk_lws_wss_client_read(buf, count);
105
-}
106
-
107
-int _mqtt_lib_init()
108
-{
109
- int rc;
110
- //int libmosq_major, libmosq_minor, libmosq_revision, libmosq_version;
111
- /* Commenting out now as it is unused - do not delete, this is needed for the on-prem version.
112
- char *ca_crt;
113
- char *server_crt;
114
- char *server_key;
115
-
116
- // show library info so can have it in the logfile
117
- //libmosq_version = mosquitto_lib_version(&libmosq_major, &libmosq_minor, &libmosq_revision);
118
- ca_crt = config_get(CONFIG_SECTION_CLOUD, "link cert", "*");
119
- server_crt = config_get(CONFIG_SECTION_CLOUD, "link server cert", "*");
120
- server_key = config_get(CONFIG_SECTION_CLOUD, "link server key", "*");
121
-
122
- if (ca_crt[0] == '*') {
123
- freez(ca_crt);
124
- ca_crt = NULL;
125
- }
126
-
127
- if (server_crt[0] == '*') {
128
- freez(server_crt);
129
- server_crt = NULL;
130
- }
131
-
132
- if (server_key[0] == '*') {
133
- freez(server_key);
134
- server_key = NULL;
135
- }
136
- */
137
-
138
- // info(
139
- // "Detected libmosquitto library version %d, %d.%d.%d", libmosq_version, libmosq_major, libmosq_minor,
140
- // libmosq_revision);
141
-
142
- rc = mosquitto_lib_init();
143
- if (unlikely(rc != MOSQ_ERR_SUCCESS)) {
144
- error("Failed to initialize MQTT (libmosquitto library)");
145
- return 1;
146
- }
147
- return 0;
148
-}
149
-
150
-static int _mqtt_create_connection(char *username, char *password)
151
-{
152
- if (mosq != NULL)
153
- mosquitto_destroy(mosq);
154
- mosq = mosquitto_new(username, true, NULL);
155
- if (unlikely(!mosq)) {
156
- mosquitto_lib_cleanup();
157
- error("MQTT new structure -- %s", mosquitto_strerror(errno));
158
- return MOSQ_ERR_UNKNOWN;
159
- }
160
-
161
- // Record the session start time to allow a nominal LWT timestamp
162
- usec_t now = now_realtime_usec();
163
- aclk_session_sec = now / USEC_PER_SEC;
164
- aclk_session_us = now % USEC_PER_SEC;
165
-
166
- _link_set_lwt("outbound/meta", 2);
167
-
168
- mosquitto_connect_callback_set(mosq, connect_callback);
169
- mosquitto_disconnect_callback_set(mosq, disconnect_callback);
170
- mosquitto_publish_callback_set(mosq, publish_callback);
171
-
172
- info("Using challenge-response: %s / %s", username, password);
173
- mosquitto_username_pw_set(mosq, username, password);
174
-
175
- int rc = mosquitto_threaded_set(mosq, 1);
176
- if (unlikely(rc != MOSQ_ERR_SUCCESS))
177
- error("Failed to tune the thread model for libmosquitto (%s)", mosquitto_strerror(rc));
178
-
179
-#if defined(LIBMOSQUITTO_VERSION_NUMBER) >= 1006000
180
- rc = mosquitto_int_option(mosq, MQTT_PROTOCOL_V311, 0);
181
- if (unlikely(rc != MOSQ_ERR_SUCCESS))
182
- error("MQTT protocol specification rc = %d (%s)", rc, mosquitto_strerror(rc));
183
-
184
- rc = mosquitto_int_option(mosq, MOSQ_OPT_SEND_MAXIMUM, 1);
185
- info("MQTT in flight messages set to 1 -- %s", mosquitto_strerror(rc));
186
-#endif
187
-
188
- return rc;
189
-}
190
-
191
-static int _link_mqtt_connect(char *aclk_hostname, int aclk_port)
192
-{
193
- int rc;
194
-
195
- rc = mosquitto_connect_async(mosq, aclk_hostname, aclk_port, ACLK_PING_INTERVAL);
196
-
197
- if (unlikely(rc != MOSQ_ERR_SUCCESS))
198
- error(
199
- "Failed to establish link to [%s:%d] MQTT status = %d (%s)", aclk_hostname, aclk_port, rc,
200
- mosquitto_strerror(rc));
201
- else
202
- info("Establishing MQTT link to [%s:%d]", aclk_hostname, aclk_port);
203
-
204
- return rc;
205
-}
206
-
207
-static inline void _link_mosquitto_write()
208
-{
209
- int rc;
210
-
211
- if (unlikely(!mosq)) {
212
- return;
213
- }
214
-
215
- rc = mosquitto_loop_misc(mosq);
216
- if (unlikely(rc != MOSQ_ERR_SUCCESS))
217
- debug(D_ACLK, "ACLK: failure during mosquitto_loop_misc %s", mosquitto_strerror(rc));
218
-
219
- if (likely(mosquitto_want_write(mosq))) {
220
- rc = mosquitto_loop_write(mosq, 1);
221
- if (rc != MOSQ_ERR_SUCCESS)
222
- debug(D_ACLK, "ACLK: failure during mosquitto_loop_write %s", mosquitto_strerror(rc));
223
- }
224
-}
225
-
226
-void aclk_lws_connection_established(char *hostname, int port)
227
-{
228
- _link_mqtt_connect(hostname, port); // Parameters only used for logging, lower layer connected.
229
- _link_mosquitto_write();
230
-}
231
-
232
-void aclk_lws_connection_data_received()
233
-{
234
- int rc = mosquitto_loop_read(mosq, 1);
235
- if (rc != MOSQ_ERR_SUCCESS)
236
- debug(D_ACLK, "ACLK: failure during mosquitto_loop_read %s", mosquitto_strerror(rc));
237
-}
238
-
239
-void aclk_lws_connection_closed()
240
-{
241
- aclk_disconnect();
242
-
243
-}
244
-
245
-
246
-int mqtt_attempt_connection(char *aclk_hostname, int aclk_port, char *username, char *password)
247
-{
248
- if(aclk_lws_wss_connect(aclk_hostname, aclk_port))
249
- return MOSQ_ERR_UNKNOWN;
250
- aclk_lws_wss_service_loop();
251
-
252
- int rc = _mqtt_create_connection(username, password);
253
- if (rc!= MOSQ_ERR_SUCCESS)
254
- return rc;
255
-
256
- mosquitto_external_callbacks_set(mosq, _mqtt_external_write_hook, _mqtt_external_read_hook);
257
- return rc;
258
-}
259
-
260
-inline int _link_event_loop()
261
-{
262
-
263
- // TODO: Check if we need to flush undelivered messages from libmosquitto on new connection attempts (QoS=1).
264
- _link_mosquitto_write();
265
- aclk_lws_wss_service_loop();
266
-
267
- // this is because if use LWS we don't want
268
- // mqtt to reconnect by itself
269
- return MOSQ_ERR_SUCCESS;
270
-}
271
-
272
-void _link_shutdown()
273
-{
274
- int rc;
275
-
276
- if (likely(!mosq))
277
- return;
278
-
279
- rc = mosquitto_disconnect(mosq);
280
- switch (rc) {
281
- case MOSQ_ERR_SUCCESS:
282
- info("MQTT disconnected from broker");
283
- break;
284
- default:
285
- info("MQTT invalid structure");
286
- break;
287
- };
288
-}
289
-
290
-
291
-int _link_set_lwt(char *sub_topic, int qos)
292
-{
293
- int rc;
294
- char topic[ACLK_MAX_TOPIC + 1];
295
- char *final_topic;
296
-
297
- final_topic = get_topic(sub_topic, topic, ACLK_MAX_TOPIC);
298
- if (unlikely(!final_topic)) {
299
- errno = 0;
300
- error("Unable to build outgoing topic; truncated?");
301
- return 1;
302
- }
303
-
304
- usec_t lwt_time = aclk_session_sec * USEC_PER_SEC + aclk_session_us + 1;
305
- BUFFER *b = buffer_create(512);
306
- aclk_create_header(b, "disconnect", NULL, lwt_time / USEC_PER_SEC, lwt_time % USEC_PER_SEC, ACLK_VERSION_NEG_VERSION);
307
- buffer_strcat(b, ", \"payload\": \"unexpected\" }");
308
- rc = mosquitto_will_set(mosq, topic, buffer_strlen(b), buffer_tostring(b), qos, 0);
309
- buffer_free(b);
310
-
311
- return rc;
312
-}
313
-
314
-int _link_subscribe(char *topic, int qos)
315
-{
316
- int rc;
317
-
318
- if (unlikely(!mosq))
319
- return 1;
320
-
321
- mosquitto_message_callback_set(mosq, mqtt_message_callback);
322
-
323
- rc = mosquitto_subscribe(mosq, NULL, topic, qos);
324
- if (unlikely(rc)) {
325
- errno = 0;
326
- error("Failed to register subscription %d (%s)", rc, mosquitto_strerror(rc));
327
- return 1;
328
- }
329
-
330
- _link_mosquitto_write();
331
- return 0;
332
-}
333
-
334
-/*
335
- * Send a message to the cloud to specific topic
336
- *
337
- */
338
-
339
-int _link_send_message(char *topic, const void *message, size_t len, int *mid)
340
-{
341
- int rc;
342
- size_t write_q, write_q_bytes, read_q;
343
-
344
- rc = mosquitto_pub_topic_check(topic);
345
-
346
- if (unlikely(rc != MOSQ_ERR_SUCCESS))
347
- return rc;
348
-
349
- lws_wss_check_queues(&write_q, &write_q_bytes, &read_q);
350
- rc = mosquitto_publish(mosq, mid, topic, len, message, ACLK_QOS, 0);
351
-
352
-#ifdef NETDATA_INTERNAL_CHECKS
353
- char msg_head[64];
354
- memset(msg_head, 0, sizeof(msg_head));
355
- strncpy(msg_head, (char*)message, 60);
356
- for (size_t i = 0; i < sizeof(msg_head); i++)
357
- if(msg_head[i] == '\n') msg_head[i] = ' ';
358
- info("Sending MQTT len=%d mid=%d wq=%zu (%zu-bytes) readq=%zu: %s", (int)len,
359
- *mid, write_q, write_q_bytes, read_q, msg_head);
360
- now_realtime_timeval(&sendTimes[ *mid & 0x3ff ]);
361
-#endif
362
-
363
- // TODO: Add better handling -- error will flood the logfile here
364
- if (unlikely(rc != MOSQ_ERR_SUCCESS)) {
365
- errno = 0;
366
- error("MQTT message failed : %s", mosquitto_strerror(rc));
367
- }
368
- _link_mosquitto_write();
369
- return rc;
370
-}
aclk/legacy/mqtt.h
deleted
-25
@@ -1,25 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-#ifndef NETDATA_MQTT_H
4
-#define NETDATA_MQTT_H
5
-
6
-#ifdef ENABLE_ACLK
7
-#include "externaldeps/mosquitto/mosquitto.h"
8
-#endif
9
-
10
-void _show_mqtt_info();
11
-int _link_event_loop();
12
-void _link_shutdown();
13
-int mqtt_attempt_connection(char *aclk_hostname, int aclk_port, char *username, char *password);
14
-//int _link_lib_init();
15
-int _mqtt_lib_init();
16
-int _link_subscribe(char *topic, int qos);
17
-int _link_send_message(char *topic, const void *message, size_t len, int *mid);
18
-const char *_link_strerror(int rc);
19
-int _link_set_lwt(char *topic, int qos);
20
-
21
-
22
-int legacy_aclk_handle_cloud_message(char *);
23
-extern char *get_topic(char *sub_topic, char *final_topic, int max_size);
24
-
25
-#endif //NETDATA_MQTT_H
aclk/legacy/tests/fake-charts.d.plugin
deleted
-24
@@ -1,24 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-sleep 45 # Wait until popcorning finishes
4
-
5
-echo "CHART aclk_test.newcol '' 'Generate new collector/chart event' 'units' aclk_test aclk_test lines 900001 1"
6
-sleep 5
7
-echo "DIMENSION aclk1 '' percentage-of-absolute 1 1"
8
-sleep 5
9
-echo "BEGIN aclk_test.newcol 1000000"
10
-echo "SET aclk1 = 3"
11
-echo "END"
12
-sleep 5
13
-echo "DIMENSION aclk2 '' percentage-of-absolute 1 1"
14
-sleep 5
15
-echo "BEGIN aclk_test.newcol 1000000"
16
-echo "SET aclk1 = 3"
17
-echo "SET aclk2 = 3"
18
-echo "END"
19
-sleep 5
20
-echo "CHART aclk_test2.newcol '' 'Generate new collector/chart event' 'units' aclk_test aclk_test lines 900001 1"
21
-echo "DIMENSION aclk1 '' percentage-of-absolute 1 1"
22
-
23
-sleep 5
24
-exit 0 # Signal that we are done
aclk/legacy/tests/install-fake-charts.d.sh.in
deleted
-6
@@ -1,6 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-TARGET="@pluginsdir_POST@"
4
-BASE="$(cd "$(dirname "$0")" && pwd)"
5
-
6
-cp "$BASE/fake-charts.d.plugin" "$TARGET/charts.d.plugin"
aclk/legacy/tests/launch-paho.sh
deleted
-4
@@ -1,4 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-docker build -f paho.Dockerfile . --build-arg "HOST_HOSTNAME=$(ping -c1 "$(hostname).local" | head -n1 | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')" -t paho-client
4
-docker run -it paho-client
aclk/legacy/tests/paho-inspection.py
deleted
-59
@@ -1,59 +0,0 @@
1
-import ssl
2
-import paho.mqtt.client as mqtt
3
-import json
4
-import time
5
-import sys
6
-
7
-def on_connect(mqttc, obj, flags, rc):
8
- if rc==0:
9
- print("Successful connection", flush=True)
10
- else :
11
- print(f"Connection error rc={rc}", flush=True)
12
- mqttc.subscribe("/agent/#",0)
13
-
14
-def on_disconnect(mqttc, obj, flags, rc):
15
- print("disconnected rc: "+str(rc), flush=True)
16
-
17
-def on_message(mqttc, obj, msg):
18
- print(f"{msg.topic} {len(msg.payload)}-bytes qos={msg.qos}", flush=True)
19
- try:
20
- print(f"Trying decode of {msg.payload[:60]}",flush=True)
21
- api_msg = json.loads(msg.payload)
22
- except Exception as e:
23
- print(e,flush=True)
24
- return
25
- ts = api_msg["timestamp"]
26
- mtype = api_msg["type"]
27
- print(f"Message {mtype} time={ts} size {len(api_msg)}", flush=True)
28
- now = time.time()
29
- print(f"Current {now} -> Delay {now-ts}", flush=True)
30
- if mtype=="disconnect":
31
- print(f"Message dump: {api_msg}", flush=True)
32
-
33
-def on_publish(mqttc, obj, mid):
34
- print("mid: "+str(mid), flush=True)
35
-
36
-def on_subscribe(mqttc, obj, mid, granted_qos):
37
- print("Subscribed: "+str(mid)+" "+str(granted_qos), flush=True)
38
-
39
-def on_log(mqttc, obj, level, string):
40
- print(string)
41
-
42
-print(f"Starting paho-inspection on {sys.argv[1]}", flush=True)
43
-mqttc = mqtt.Client(transport='websockets',client_id="paho")
44
-#mqttc.tls_set(certfile="server.crt", keyfile="server.key", cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLS, ciphers=None)
45
-#mqttc.tls_set(ca_certs="server.crt", cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLS, ciphers=None)
46
-mqttc.tls_set(cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLS, ciphers=None)
47
-mqttc.tls_insecure_set(True)
48
-mqttc.on_message = on_message
49
-mqttc.on_connect = on_connect
50
-mqttc.on_disconnect = on_disconnect
51
-mqttc.on_publish = on_publish
52
-mqttc.on_subscribe = on_subscribe
53
-mqttc.username_pw_set("paho","paho")
54
-mqttc.connect(sys.argv[1], 8443, 60)
55
-
56
-#mqttc.publish("/agent/mine","Test1")
57
-#mqttc.subscribe("$SYS/#", 0)
58
-print("Connected successfully, monitoring /agent/#", flush=True)
59
-mqttc.loop_forever()
aclk/legacy/tests/paho.Dockerfile
deleted
-14
@@ -1,14 +0,0 @@
1
-FROM archlinux/base:latest
2
-
3
-RUN pacman -Syyu --noconfirm
4
-RUN pacman --noconfirm --needed -S python-pip
5
-
6
-RUN pip install paho-mqtt
7
-
8
-RUN mkdir -p /opt/paho
9
-COPY paho-inspection.py /opt/paho/
10
-
11
-WORKDIR /opt/paho
12
-ARG HOST_HOSTNAME
13
-RUN echo $HOST_HOSTNAME >host
14
-CMD ["/bin/bash", "-c", "/usr/sbin/python paho-inspection.py $(cat host)"]
configure.ac
+9
-126
@@ -212,22 +212,6 @@ AC_ARG_ENABLE(
212
[ enable_cloud="detect" ]
213
)
214
215
-AC_ARG_WITH(
216
- [aclk-legacy],
217
- [AS_HELP_STRING([--with-aclk-legacy],
218
- [Requires Legacy ACLK to be used even in case ACLK-NG can run on this system])],
219
- [aclk_legacy="$withval"],
220
- [aclk_legacy="detect"]
221
-)
222
-
223
-AC_ARG_WITH(
224
- [aclk-ng],
225
- [AS_HELP_STRING([--with-aclk-ng],
226
- [Requires ACLK-NG to be used even in case ACLK Legacy can run on this system])],
227
- [aclk_ng="$withval"],
228
- [aclk_ng="detect"]
229
-)
230
-
215
AC_ARG_WITH(
216
[new-cloud-protocol],
217
[AS_HELP_STRING([--with-new-cloud-protocol],
@@ -721,22 +705,8 @@ fi
705
706
AC_MSG_CHECKING([if Cloud functionality should be enabled])
707
AC_MSG_RESULT([${enable_cloud}])
724
-if test "$aclk_ng" = "no"; then
725
- AC_DEFINE([ACLK_NG_DISABLED], [1], [ACLK NG was disabled by user request])
726
-fi
727
-if test "$aclk_legacy" = "no"; then
728
- AC_DEFINE([ACLK_LEGACY_DISABLED], [1], [ACLK Legacy was disabled by user request])
729
-fi
730
-
731
-if test "$enable_cloud" = "no" -a "$aclk_legacy" = "yes"; then
732
- AC_MSG_ERROR([--disable-cloud && --with-aclk-legacy not allowed together (such configuration is self contradicting)])
733
-fi
734
-
735
-if test "$enable_cloud" = "no" -a "$aclk_ng" = "yes"; then
736
- AC_MSG_ERROR([--disable-cloud && --with-aclk-ng not allowed together (such configuration is self contradicting)])
737
-fi
708
739
-if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
709
+if test "$enable_cloud" != "no"; then
710
AC_MSG_NOTICE([Checking if ACLK Next Generation can be built])
711
can_enable_ng="yes"
712
AC_MSG_CHECKING([if git submodules present for ACLK Next Generation])
@@ -764,18 +734,16 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
734
735
AC_MSG_CHECKING([ACLK Next Generation can be built])
736
AC_MSG_RESULT([${can_enable_ng}])
767
- if test "$can_enable_ng" = "no" -a "$aclk_ng" = "yes"; then
768
- AC_MSG_ERROR([You have requested --with-aclk-ng but it can't be built. See reasons in lines above])
737
+ if test "$can_enable_ng" = "no" -a "$enable_cloud" = "yes"; then
738
+ AC_MSG_ERROR([You have requested --with-cloud but ACLK can't be built. See reasons in lines above])
739
fi
740
if test "$can_enable_ng" = "yes"; then
771
- aclk_ng="yes"
741
enable_aclk="yes"
773
- AC_DEFINE([ACLK_NG], [1], [ACLK Next Generation Should be used])
742
AC_DEFINE([ENABLE_ACLK], [1], [netdata ACLK])
775
- OPTIONAL_ACLK_NG_CFLAGS="-I \$(abs_top_srcdir)/mqtt_websockets/src/include -I \$(abs_top_srcdir)/mqtt_websockets/c-rbuf/include -I \$(abs_top_srcdir)/mqtt_websockets/MQTT-C/include"
743
+ OPTIONAL_ACLK_CFLAGS="-I \$(abs_top_srcdir)/mqtt_websockets/src/include -I \$(abs_top_srcdir)/mqtt_websockets/c-rbuf/include -I \$(abs_top_srcdir)/mqtt_websockets/MQTT-C/include"
744
fi
745
778
- if test "$aclk_ng" = "yes" -a "$new_cloud_protocol" != "no"; then
746
+ if "$new_cloud_protocol" != "no"; then
747
can_build_new_cloud_protocol="yes"
748
AC_MSG_CHECKING([if protobuf available for New Cloud Protocol])
749
if test "${have_libprotobuf}" != "yes"; then
@@ -807,7 +775,7 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
775
if test "$can_build_new_cloud_protocol" = "yes"; then
776
new_cloud_protocol="yes"
777
AC_DEFINE([ENABLE_NEW_CLOUD_PROTOCOL], [1], [New protobuf based Netdata Cloud Protocol Support])
810
- OPTIONAL_ACLK_NG_CFLAGS="${OPTIONAL_ACLK_NG_CFLAGS} -I \$(abs_top_srcdir)/aclk/aclk-schemas"
778
+ OPTIONAL_ACLK_CFLAGS="${OPTIONAL_ACLK_CFLAGS} -I \$(abs_top_srcdir)/aclk/aclk-schemas"
779
OPTIONAL_PROTOBUF_CFLAGS="${PROTOBUF_CFLAGS}"
780
CXX11FLAG="-std=c++11"
781
OPTIONAL_PROTOBUF_LIBS="${PROTOBUF_LIBS}"
@@ -815,96 +783,12 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
783
fi
784
fi
785
818
-if test "$enable_cloud" != "no" -a "$aclk_legacy" != "no"; then
819
- AC_MSG_NOTICE([Checking if ACLK Legacy can be built])
820
- if test -n "${SSL_LIBS}"; then
821
- OPTIONAL_SSL_CFLAGS="${SSL_CFLAGS}"
822
- OPTIONAL_SSL_LIBS="${SSL_LIBS}"
823
- else
824
- AC_MSG_WARN([OpenSSL required for agent-cloud-link but not found. Try installing 'libssl-dev' or 'openssl-devel'.])
825
- fi
826
-
827
- AC_MSG_CHECKING([if libmosquitto static lib is present (and builds)])
828
- if test -f "externaldeps/mosquitto/libmosquitto.a"; then
829
- LIBS_BKP="${LIBS}"
830
- LIBS="externaldeps/mosquitto/libmosquitto.a ${OPTIONAL_SSL_LIBS} ${LIBS_BKP}"
831
- AC_LINK_IFELSE([AC_LANG_SOURCE([[#include "externaldeps/mosquitto/mosquitto.h"
832
- int main (int argc, char **argv) {
833
- int m,mm,r;
834
- mosquitto_lib_version(&m, &mm, &r);
835
- }]])],
836
- [HAVE_libmosquitto_a="yes"],
837
- [HAVE_libmosquitto_a="no"])
838
- LIBS="${LIBS_BKP}"
839
- else
840
- HAVE_libmosquitto_a="no"
841
- AC_DEFINE([ACLK_NO_LIBMOSQ], [1], [Libmosquitto.a was not found during build.])
842
- fi
843
- AC_MSG_RESULT([${HAVE_libmosquitto_a}])
844
-
845
- if test "${with_bundled_lws}" = "yes"; then
846
- AC_MSG_CHECKING([if libwebsockets static lib is present for ACLK Legacy])
847
- if test -f "externaldeps/libwebsockets/libwebsockets.a"; then
848
- LWS_CFLAGS="-I \$(abs_top_srcdir)/externaldeps/libwebsockets/include"
849
- OPTIONAL_LWS_LIBS="\$(abs_top_srcdir)/externaldeps/libwebsockets/libwebsockets.a"
850
- AC_MSG_RESULT([yes])
851
- AC_DEFINE([BUNDLED_LWS], [1], [using statically linked libwebsockets])
852
- else
853
- AC_DEFINE([ACLK_NO_LWS], [1], [libwebsockets.a was not found during build.])
854
- # this should be error if installer ever changes default to system
855
- # as currently this is default we prefer building netdata without ACLK
856
- # instead of error fail
857
- AC_MSG_RESULT([no])
858
- AC_MSG_WARN([You required static libwebsockets to be used but we can't use it. Disabling ACLK Legacy])
859
- fi
860
- else
861
- AC_CHECK_LIB([websockets],
862
- [lws_get_vhost_by_name],
863
- [OPTIONAL_LWS_LIBS="-lwebsockets"],
864
- [AC_DEFINE([ACLK_NO_LWS], [1], [usable system libwebsockets was not found during build.])])
865
- fi
866
-
867
- if test "${build_target}" = "linux"; then
868
- if test "${have_libcap}" = "yes" -a "${with_libcap}" = "no"; then
869
- AC_MSG_ERROR([agent-cloud-link can't be built without libcap. Disable it by --disable-cloud or enable libcap])
870
- fi
871
- if test "${with_libcap}" = "yes"; then
872
- LWS_CFLAGS+=" ${LIBCAP_CFLAGS}"
873
- fi
874
- fi
875
-
876
- # next 2 lines are just to have info for ACLK dependencies in common place
877
- AC_MSG_CHECKING([if json-c available for ACLK Legacy])
878
- AC_MSG_RESULT([${enable_jsonc}])
879
-
880
- AC_MSG_CHECKING([if netdata ACLK Legacy can be built])
881
- if test "${HAVE_libmosquitto_a}" = "yes" -a -n "${OPTIONAL_LWS_LIBS}" -a -n "${SSL_LIBS}" -a "${enable_jsonc}" = "yes"; then
882
- can_build_legacy="yes"
883
- else
884
- can_build_legacy="no"
885
- fi
886
- AC_MSG_RESULT([${can_build_legacy}])
887
-
888
- if test "$can_build_legacy" = "no" -a "$aclk_legacy" = "yes"; then
889
- AC_MSG_ERROR([You have requested --with-aclk-legacy but it can't be built. See reasons in lines above])
890
- fi
891
-
892
- if test "$can_build_legacy" = "yes"; then
893
- AC_DEFINE([ACLK_LEGACY], [1], [ACLK Legacy Should be used])
894
- AC_DEFINE([ENABLE_ACLK], [1], [netdata ACLK])
895
- aclk_legacy="yes"
896
- enable_aclk="yes"
897
- fi
898
-fi
899
-
786
if test "$enable_cloud" = "yes" -a "$enable_aclk" != "yes"; then
901
- AC_MSG_ERROR([Neither ACLK-NG nor ACLK-Legacy can be built but --enable-cloud was requested])
787
+ AC_MSG_ERROR([ACLK can't be built but --enable-cloud was requested])
788
fi
789
790
AC_SUBST([enable_cloud])
791
AC_SUBST([enable_aclk])
906
-AM_CONDITIONAL([ACLK_NG], [test "${aclk_ng}" = "yes"])
907
-AM_CONDITIONAL([ACLK_LEGACY], [test "${aclk_legacy}" = "yes"])
792
AM_CONDITIONAL([ENABLE_ACLK], [test "${enable_aclk}" = "yes"])
793
AM_CONDITIONAL([ENABLE_NEW_CLOUD_PROTOCOL], [test "${can_build_new_cloud_protocol}" = "yes"])
794
@@ -1703,7 +1587,7 @@ CFLAGS="${CFLAGS} ${OPTIONAL_PROTOBUF_CFLAGS} ${OPTIONAL_MATH_CFLAGS} ${OPTIONAL
1587
${OPTIONAL_LIBCAP_CFLAGS} ${OPTIONAL_IPMIMONITORING_CFLAGS} ${OPTIONAL_CUPS_CFLAGS} ${OPTIONAL_XENSTAT_FLAGS} \
1588
${OPTIONAL_KINESIS_CFLAGS} ${OPTIONAL_PUBSUB_CFLAGS} ${OPTIONAL_PROMETHEUS_REMOTE_WRITE_CFLAGS} \
1589
${OPTIONAL_MONGOC_CFLAGS} ${LWS_CFLAGS} ${OPTIONAL_JSONC_STATIC_CFLAGS} ${OPTIONAL_BPF_CFLAGS} ${OPTIONAL_JUDY_CFLAGS} \
1706
- ${OPTIONAL_ACLK_NG_CFLAGS} ${OPTIONAL_ML_CFLAGS} ${OPTIONAL_ML_TESTS_CFLAGS}"
1590
+ ${OPTIONAL_ACLK_CFLAGS} ${OPTIONAL_ML_CFLAGS} ${OPTIONAL_ML_TESTS_CFLAGS}"
1591
1592
CXXFLAGS="${CFLAGS} ${CXX11FLAG}"
1593
@@ -1753,7 +1637,7 @@ AC_SUBST([OPTIONAL_PROMETHEUS_REMOTE_WRITE_LIBS])
1637
AC_SUBST([OPTIONAL_MONGOC_CFLAGS])
1638
AC_SUBST([OPTIONAL_MONGOC_LIBS])
1639
AC_SUBST([OPTIONAL_LWS_LIBS])
1756
-AC_SUBST([OPTIONAL_ACLK_NG_CFLAGS])
1640
+AC_SUBST([OPTIONAL_ACLK_CFLAGS])
1641
AC_SUBST([OPTIONAL_PROTOBUF_CFLAGS])
1642
AC_SUBST([OPTIONAL_PROTOBUF_LIBS])
1643
AC_SUBST([OPTIONAL_GTEST_CFLAGS])
@@ -1907,7 +1791,6 @@ AC_CONFIG_FILES([
1791
web/server/Makefile
1792
web/server/static/Makefile
1793
claim/Makefile
1910
- aclk/legacy/Makefile
1794
spawn/Makefile
1795
parser/Makefile
1796
])
contrib/debian/rules
+1
-3
@@ -41,15 +41,13 @@ override_dh_installinit:
41
dh_installinit
42
43
override_dh_auto_configure:
44
- packaging/bundle-mosquitto.sh .
45
- packaging/bundle-lws.sh .
44
if [ $(HAVE_EBPF) -eq 1 ]; then \
45
packaging/bundle-libbpf.sh . ${TOP}/usr/libexec/netdata/plugins.d; \
46
fi
47
autoreconf -ivf
48
dh_auto_configure -- --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib \
49
--libexecdir=/usr/libexec --with-user=netdata --with-math --with-zlib --with-webdir=/var/lib/netdata/www \
52
- --with-bundled-lws $(EBPF_CONFIG)
50
+ $(EBPF_CONFIG)
51
52
override_dh_install:
53
cp -v $(BASE_CONFIG) debian/netdata.conf
daemon/analytics.c
+1
-4
@@ -494,10 +494,7 @@ void analytics_misc(void)
494
{
495
#ifdef ENABLE_ACLK
496
analytics_set_data(&analytics_data.netdata_host_cloud_available, "true");
497
- if (aclk_ng)
498
- analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "Next Generation");
499
- else
500
- analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "legacy");
497
+ analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "Next Generation");
498
#else
499
analytics_set_data(&analytics_data.netdata_host_cloud_available, "false");
500
analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "");
daemon/buildinfo.c
+6
-73
@@ -19,24 +19,12 @@
19
#endif
20
#endif
21
22
-#ifdef ACLK_NG
23
-#define FEAT_ACLK_NG 1
24
-#else
25
-#define FEAT_ACLK_NG 0
26
-#endif
27
-
28
-#if defined(ACLK_NG) && defined(ENABLE_NEW_CLOUD_PROTOCOL)
22
+#ifdef ENABLE_NEW_CLOUD_PROTOCOL
23
#define NEW_CLOUD_PROTO 1
24
#else
25
#define NEW_CLOUD_PROTO 0
26
#endif
27
34
-#ifdef ACLK_LEGACY
35
-#define FEAT_ACLK_LEGACY 1
36
-#else
37
-#define FEAT_ACLK_LEGACY 0
38
-#endif
39
-
28
#ifdef ENABLE_DBENGINE
29
#define FEAT_DBENGINE 1
30
#else
@@ -104,30 +92,6 @@
92
#define FEAT_LIBCAP 0
93
#endif
94
107
-#ifndef ACLK_LEGACY_DISABLED
108
- #ifdef ACLK_NO_LIBMOSQ
109
- #define FEAT_MOSQUITTO 0
110
- #else
111
- #define FEAT_MOSQUITTO 1
112
- #endif
113
-
114
- #ifdef ACLK_NO_LWS
115
- #define FEAT_LWS 0
116
- #define FEAT_LWS_MSG ""
117
- #else
118
- #ifdef ACLK_LEGACY
119
- #include <libwebsockets.h>
120
- #endif
121
- #ifdef BUNDLED_LWS
122
- #define FEAT_LWS 1
123
- #define FEAT_LWS_MSG "static"
124
- #else
125
- #define FEAT_LWS 1
126
- #define FEAT_LWS_MSG "shared-lib"
127
- #endif
128
- #endif
129
-#endif /* ACLK_LEGACY_DISABLED */
130
-
95
#ifdef NETDATA_WITH_ZLIB
96
#define FEAT_ZLIB 1
97
#else
@@ -243,9 +207,9 @@ void print_build_info(void) {
207
printf(" dbengine: %s\n", FEAT_YES_NO(FEAT_DBENGINE));
208
printf(" Native HTTPS: %s\n", FEAT_YES_NO(FEAT_NATIVE_HTTPS));
209
printf(" Netdata Cloud: %s %s\n", FEAT_YES_NO(FEAT_CLOUD), FEAT_CLOUD_MSG);
246
- printf(" ACLK Next Generation: %s\n", FEAT_YES_NO(FEAT_ACLK_NG));
210
+ printf(" ACLK Next Generation: %s\n", FEAT_YES_NO(FEAT_CLOUD));
211
printf(" ACLK-NG New Cloud Protocol: %s\n", FEAT_YES_NO(NEW_CLOUD_PROTO));
248
- printf(" ACLK Legacy: %s\n", FEAT_YES_NO(FEAT_ACLK_LEGACY));
212
+ printf(" ACLK Legacy: %s\n", FEAT_YES_NO(0));
213
printf(" TLS Host Verification: %s\n", FEAT_YES_NO(FEAT_TLS_HOST_VERIFY));
214
printf(" Machine Learning: %s\n", FEAT_YES_NO(FEAT_ML));
215
@@ -256,14 +220,6 @@ void print_build_info(void) {
220
printf(" libcap: %s\n", FEAT_YES_NO(FEAT_LIBCAP));
221
printf(" libcrypto: %s\n", FEAT_YES_NO(FEAT_CRYPTO));
222
printf(" libm: %s\n", FEAT_YES_NO(FEAT_LIBM));
259
-#ifndef ACLK_LEGACY_DISABLED
260
-#if defined(ACLK_LEGACY)
261
- printf(" LWS: %s %s v%d.%d.%d\n", FEAT_YES_NO(FEAT_LWS), FEAT_LWS_MSG, LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH);
262
-#else
263
- printf(" LWS: %s %s\n", FEAT_YES_NO(FEAT_LWS), FEAT_LWS_MSG);
264
-#endif
265
- printf(" mosquitto: %s\n", FEAT_YES_NO(FEAT_MOSQUITTO));
266
-#endif
223
printf(" tcalloc: %s\n", FEAT_YES_NO(FEAT_TCMALLOC));
224
printf(" zlib: %s\n", FEAT_YES_NO(FEAT_ZLIB));
225
@@ -303,9 +259,9 @@ void print_build_info_json(void) {
259
#else
260
printf(" \"cloud-disabled\": false,\n");
261
#endif
306
- printf(" \"aclk-ng\": %s,\n", FEAT_JSON_BOOL(FEAT_ACLK_NG));
262
+ printf(" \"aclk-ng\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD));
263
printf(" \"aclk-ng-new-cloud-proto\": %s,\n", FEAT_JSON_BOOL(NEW_CLOUD_PROTO));
308
- printf(" \"aclk-legacy\": %s,\n", FEAT_JSON_BOOL(FEAT_ACLK_LEGACY));
264
+ printf(" \"aclk-legacy\": %s,\n", FEAT_JSON_BOOL(0));
265
266
printf(" \"tls-host-verify\": %s,\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY));
267
printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML));
@@ -319,16 +275,6 @@ void print_build_info_json(void) {
275
printf(" \"libcap\": %s,\n", FEAT_JSON_BOOL(FEAT_LIBCAP));
276
printf(" \"libcrypto\": %s,\n", FEAT_JSON_BOOL(FEAT_CRYPTO));
277
printf(" \"libm\": %s,\n", FEAT_JSON_BOOL(FEAT_LIBM));
322
-#ifndef ACLK_NG
323
-#if defined(ENABLE_ACLK)
324
- printf(" \"lws\": %s,\n", FEAT_JSON_BOOL(FEAT_LWS));
325
- printf(" \"lws-version\": \"%d.%d.%d\",\n", LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH);
326
- printf(" \"lws-type\": \"%s\",\n", FEAT_LWS_MSG);
327
-#else
328
- printf(" \"lws\": %s,\n", FEAT_JSON_BOOL(FEAT_LWS));
329
-#endif
330
- printf(" \"mosquitto\": %s,\n", FEAT_JSON_BOOL(FEAT_MOSQUITTO));
331
-#endif
278
printf(" \"tcmalloc\": %s,\n", FEAT_JSON_BOOL(FEAT_TCMALLOC));
279
printf(" \"zlib\": %s\n", FEAT_JSON_BOOL(FEAT_ZLIB));
280
printf(" },\n");
@@ -361,9 +307,8 @@ void analytics_build_info(BUFFER *b) {
307
if(FEAT_DBENGINE) buffer_strcat (b, "dbengine");
308
if(FEAT_NATIVE_HTTPS) buffer_strcat (b, "|Native HTTPS");
309
if(FEAT_CLOUD) buffer_strcat (b, "|Netdata Cloud");
364
- if(FEAT_ACLK_NG) buffer_strcat (b, "|ACLK Next Generation");
310
+ if(FEAT_CLOUD) buffer_strcat (b, "|ACLK Next Generation");
311
if(NEW_CLOUD_PROTO) buffer_strcat (b, "|New Cloud Protocol Support");
366
- if(FEAT_ACLK_LEGACY) buffer_strcat (b, "|ACLK Legacy");
312
if(FEAT_TLS_HOST_VERIFY) buffer_strcat (b, "|TLS Host Verification");
313
if(FEAT_ML) buffer_strcat (b, "|Machine Learning");
314
@@ -374,18 +319,6 @@ void analytics_build_info(BUFFER *b) {
319
if(FEAT_CRYPTO) buffer_strcat (b, "|libcrypto");
320
if(FEAT_LIBM) buffer_strcat (b, "|libm");
321
377
-#ifndef ACLK_LEGACY_DISABLED
378
-#if defined(ENABLE_ACLK) && defined(ACLK_LEGACY)
379
- {
380
- char buf[20];
381
- snprintfz(buf, 19, "|LWS v%d.%d.%d", LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH);
382
- if(FEAT_LWS) buffer_strcat(b, buf);
383
- }
384
-#else
385
- if(FEAT_LWS) buffer_strcat(b, "|LWS");
386
-#endif
387
- if(FEAT_MOSQUITTO) buffer_strcat(b, "|mosquitto");
388
-#endif
322
if(FEAT_TCMALLOC) buffer_strcat(b, "|tcalloc");
323
if(FEAT_ZLIB) buffer_strcat(b, "|zlib");
324
netdata-installer.sh
-186
@@ -216,7 +216,6 @@ USAGE: ${PROGRAM} [options]
216
--disable-ebpf Disable eBPF Kernel plugin (Default: enabled)
217
--disable-cloud Disable all Netdata Cloud functionality.
218
--require-cloud Fail the install if it can't build Netdata Cloud support.
219
- --aclk-legacy Forces build of ACLK Legacy which is fallback by default.
219
--enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
220
--disable-plugin-freeipmi
221
--disable-https Explicitly disable TLS support
@@ -344,10 +343,6 @@ while [ -n "${1}" ]; do
343
"--enable-ebpf") NETDATA_DISABLE_EBPF=0 ;;
344
"--disable-ebpf") NETDATA_DISABLE_EBPF=1 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-ebpf/} --disable-ebpf" ;;
345
"--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
347
- "--aclk-ng") ;;
348
- "--aclk-legacy")
349
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--with-aclk-legacy/} --with-aclk-legacy"
350
- ;;
346
"--disable-cloud")
347
if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
348
echo "Cloud explicitly enabled, ignoring --disable-cloud."
@@ -610,187 +605,6 @@ trap build_error EXIT
605
606
# -----------------------------------------------------------------------------
607
613
-build_libmosquitto() {
614
- local env_cmd=''
615
-
616
- if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
617
- env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
618
- fi
619
-
620
- if [ "$(uname -s)" = Linux ]; then
621
- run ${env_cmd} ${make} ${MAKEOPTS} -C "${1}/lib"
622
- else
623
- pushd ${1} > /dev/null || return 1
624
- if [ "$(uname)" = "Darwin" ] && [ -d /usr/local/opt/openssl ]; then
625
- run ${env_cmd} cmake \
626
- -D OPENSSL_ROOT_DIR=/usr/local/opt/openssl \
627
- -D OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \
628
- -D WITH_STATIC_LIBRARIES:boolean=YES \
629
- .
630
- else
631
- run ${env_cmd} cmake -D WITH_STATIC_LIBRARIES:boolean=YES .
632
- fi
633
- run ${env_cmd} ${make} ${MAKEOPTS} -C lib
634
- run mv lib/libmosquitto_static.a lib/libmosquitto.a
635
- popd || return 1
636
- fi
637
-}
638
-
639
-copy_libmosquitto() {
640
- target_dir="${PWD}/externaldeps/mosquitto"
641
-
642
- run mkdir -p "${target_dir}"
643
-
644
- run cp "${1}/lib/libmosquitto.a" "${target_dir}"
645
- run cp "${1}/lib/mosquitto.h" "${target_dir}"
646
-}
647
-
648
-bundle_libmosquitto() {
649
- if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
650
- echo "Skipping libmosquitto"
651
- return 0
652
- fi
653
-
654
- [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libmosquitto."
655
-
656
- progress "Prepare custom libmosquitto version"
657
-
658
- MOSQUITTO_PACKAGE_VERSION="$(cat packaging/mosquitto.version)"
659
-
660
- tmp="$(mktemp -d -t netdata-mosquitto-XXXXXX)"
661
- MOSQUITTO_PACKAGE_BASENAME="${MOSQUITTO_PACKAGE_VERSION}.tar.gz"
662
-
663
- if fetch_and_verify "mosquitto" \
664
- "https://github.com/netdata/mosquitto/archive/${MOSQUITTO_PACKAGE_BASENAME}" \
665
- "${MOSQUITTO_PACKAGE_BASENAME}" \
666
- "${tmp}" \
667
- "${NETDATA_LOCAL_TARBALL_OVERRIDE_MOSQUITTO}"; then
668
- if run tar -xf "${tmp}/${MOSQUITTO_PACKAGE_BASENAME}" -C "${tmp}" &&
669
- build_libmosquitto "${tmp}/mosquitto-${MOSQUITTO_PACKAGE_VERSION}" &&
670
- copy_libmosquitto "${tmp}/mosquitto-${MOSQUITTO_PACKAGE_VERSION}" &&
671
- rm -rf "${tmp}"; then
672
- run_ok "libmosquitto built and prepared."
673
- else
674
- run_failed "Failed to build libmosquitto."
675
- defer_error_highlighted "Unable to fetch sources for libmosquitto. You will not be able to connect this node to Netdata Cloud."
676
- fi
677
- else
678
- run_failed "Unable to fetch sources for libmosquitto."
679
- defer_error_highlighted "Unable to fetch sources for libmosquitto. You will not be able to connect this node to Netdata Cloud."
680
- fi
681
-
682
- [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
683
-}
684
-
685
-bundle_libmosquitto
686
-
687
-# -----------------------------------------------------------------------------
688
-
689
-build_libwebsockets() {
690
- local env_cmd=''
691
-
692
- if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
693
- env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
694
- fi
695
-
696
- pushd "${1}" > /dev/null || exit 1
697
-
698
- if [ "$(uname)" = "Darwin" ]; then
699
- run patch -p1 << "EOF"
700
---- a/lib/plat/unix/private.h
701
-+++ b/lib/plat/unix/private.h
702
-@@ -164,6 +164,8 @@ delete_from_fd(const struct lws_context *context, int fd);
703
- * but happily have something equivalent in the SO_NOSIGPIPE flag.
704
- */
705
- #ifdef __APPLE__
706
-+/* iOS SDK 12+ seems to define it, undef it for compatibility both ways */
707
-+#undef MSG_NOSIGNAL
708
- #define MSG_NOSIGNAL SO_NOSIGPIPE
709
- #endif
710
-EOF
711
-
712
- # shellcheck disable=SC2181
713
- if [ $? -ne 0 ]; then
714
- return 1
715
- fi
716
- fi
717
-
718
- if [ "$(uname)" = "Darwin" ] && [ -d /usr/local/opt/openssl ]; then
719
- run ${env_cmd} cmake \
720
- -D OPENSSL_ROOT_DIR=/usr/local/opt/openssl \
721
- -D OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \
722
- -D LWS_WITH_SOCKS5:bool=ON \
723
- -D LWS_IPV6:bool=ON \
724
- $CMAKE_FLAGS \
725
- .
726
- else
727
- run ${env_cmd} cmake \
728
- -D LWS_WITH_SOCKS5:bool=ON \
729
- -D LWS_IPV6:bool=ON \
730
- $CMAKE_FLAGS \
731
- .
732
- fi
733
- run ${env_cmd} ${make} ${MAKEOPTS}
734
- popd > /dev/null || exit 1
735
-}
736
-
737
-copy_libwebsockets() {
738
- target_dir="${PWD}/externaldeps/libwebsockets"
739
-
740
- run mkdir -p "${target_dir}" || return 1
741
-
742
- run cp "${1}/lib/libwebsockets.a" "${target_dir}/libwebsockets.a" || return 1
743
- run cp -r "${1}/include" "${target_dir}" || return 1
744
-}
745
-
746
-bundle_libwebsockets() {
747
- if [ -n "${NETDATA_DISABLE_CLOUD}" ] || [ -n "${USE_SYSTEM_LWS}" ]; then
748
- echo "Skipping libwebsockets"
749
- return 0
750
- fi
751
-
752
- if [ -z "$(command -v cmake)" ]; then
753
- run_failed "Could not find cmake, which is required to build libwebsockets. The install process will continue, but you may not be able to connect this node to Netdata Cloud."
754
- defer_error_highlighted "Could not find cmake, which is required to build libwebsockets. The install process will continue, but you may not be able to connect this node to Netdata Cloud."
755
- return 0
756
- fi
757
-
758
- [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libwebsockets."
759
-
760
- progress "Prepare libwebsockets"
761
-
762
- LIBWEBSOCKETS_PACKAGE_VERSION="$(cat packaging/libwebsockets.version)"
763
-
764
- tmp="$(mktemp -d -t netdata-libwebsockets-XXXXXX)"
765
- LIBWEBSOCKETS_PACKAGE_BASENAME="v${LIBWEBSOCKETS_PACKAGE_VERSION}.tar.gz"
766
-
767
- if fetch_and_verify "libwebsockets" \
768
- "https://github.com/warmcat/libwebsockets/archive/${LIBWEBSOCKETS_PACKAGE_BASENAME}" \
769
- "${LIBWEBSOCKETS_PACKAGE_BASENAME}" \
770
- "${tmp}" \
771
- "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBWEBSOCKETS}"; then
772
- if run tar -xf "${tmp}/${LIBWEBSOCKETS_PACKAGE_BASENAME}" -C "${tmp}" &&
773
- build_libwebsockets "${tmp}/libwebsockets-${LIBWEBSOCKETS_PACKAGE_VERSION}" &&
774
- copy_libwebsockets "${tmp}/libwebsockets-${LIBWEBSOCKETS_PACKAGE_VERSION}" &&
775
- rm -rf "${tmp}"; then
776
- run_ok "libwebsockets built and prepared."
777
- NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-lws"
778
- else
779
- run_failed "Failed to build libwebsockets."
780
- defer_error_highlighted "Failed to build libwebsockets. You may not be able to connect this node to Netdata Cloud."
781
- fi
782
- else
783
- run_failed "Unable to fetch sources for libwebsockets."
784
- defer_error_highlighted "Unable to fetch sources for libwebsockets. You may not be able to connect this node to Netdata Cloud."
785
- fi
786
-
787
- [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
788
-}
789
-
790
-bundle_libwebsockets
791
-
792
-# -----------------------------------------------------------------------------
793
-
608
build_protobuf() {
609
local env_cmd=''
610
netdata.spec.in
+2
-10
@@ -138,9 +138,6 @@ BuildRequires: zlib-devel
138
BuildRequires: libuuid-devel
139
BuildRequires: libuv-devel >= 1
140
BuildRequires: openssl-devel
141
-%if 0%{?fedora}
142
-BuildRequires: libwebsockets-devel >= 3.2
143
-%endif
141
%if 0%{?suse_version}
142
BuildRequires: judy-devel
143
BuildRequires: liblz4-devel
@@ -226,10 +223,6 @@ happened, on your systems and applications.
223
224
%prep
225
%setup -q -n %{name}-%{version}
229
-export CFLAGS="${CFLAGS} -fPIC" && ${RPM_BUILD_DIR}/%{name}-%{version}/packaging/bundle-mosquitto.sh ${RPM_BUILD_DIR}/%{name}-%{version}
230
-%if 0%{!?fedora:1}
231
-export CFLAGS="${CFLAGS} -fPIC" && ${RPM_BUILD_DIR}/%{name}-%{version}/packaging/bundle-lws.sh ${RPM_BUILD_DIR}/%{name}-%{version}
232
-%endif
226
# Only bundle libJudy if this isn't Fedora or SUSE
227
%if 0%{!?fedora:1} && 0%{!?suse_version:1}
228
export CFLAGS="${CFLAGS} -fPIC" && ${RPM_BUILD_DIR}/%{name}-%{version}/packaging/bundle-judy.sh ${RPM_BUILD_DIR}/%{name}-%{version}
@@ -256,9 +249,6 @@ autoreconf -ivf
249
%if 0%{!?fedora:1} && 0%{!?suse_version:1}
250
--with-bundled-libJudy \
251
%endif
259
- %if 0%{?centos_ver} < 8 || 0%{!?fedora:1}
260
- --with-bundled-lws \
261
- %endif
252
--prefix="%{_prefix}" \
253
--sysconfdir="%{_sysconfdir}" \
254
--localstatedir="%{_localstatedir}" \
@@ -554,6 +544,8 @@ are sensor monitoring, system event monitoring, power control, and serial-over-L
544
%attr(4750,root,netdata) %{_libexecdir}/%{name}/plugins.d/freeipmi.plugin
545
546
%changelog
547
+* Mon Oct 11 2021 Austin Hemmelgarn <austin@netdata.cloud> 0.0.0-15
548
+- Remove support code for legacy ACLK implementation.
549
* Wed Sep 16 2020 Austin Hemmelgarn <austin@netdata.cloud> 0.0.0-14
550
- Convert to using 'AutoReq: yes' for library dependencies.
551
* Thu Feb 13 2020 Austin Hemmelgarn <austin@netdata.cloud> 0.0.0-13
packaging/bundle-lws.sh
deleted
-17
@@ -1,17 +0,0 @@
1
-#!/bin/sh
2
-
3
-startdir="${PWD}"
4
-
5
-LWS_TARBALL="v$(cat "${1}/packaging/libwebsockets.version").tar.gz"
6
-LWS_BUILD_PATH="${1}/externaldeps/libwebsockets/libwebsockets-$(cat "${1}/packaging/libwebsockets.version")"
7
-
8
-mkdir -p "${1}/externaldeps/libwebsockets" || exit 1
9
-curl -sSL --connect-timeout 10 --retry 3 "https://github.com/warmcat/libwebsockets/archive/${LWS_TARBALL}" > "${LWS_TARBALL}" || exit 1
10
-sha256sum -c "${1}/packaging/libwebsockets.checksums" || exit 1
11
-tar -xzf "${LWS_TARBALL}" -C "${1}/externaldeps/libwebsockets" || exit 1
12
-cd "${LWS_BUILD_PATH}" || exit 1
13
-cmake -Wno-dev -Wno-deprecated -D LWS_WITH_SOCKS5:boolean=YES -D WITHOUT_LWS_TESTAPPS:boolean=YES . || exit 1
14
-make || exit 1
15
-cd "${startdir}" || exit 1
16
-cp -a "${LWS_BUILD_PATH}/lib/libwebsockets.a" "${1}/externaldeps/libwebsockets" || exit 1
17
-cp -a "${LWS_BUILD_PATH}/include" "${1}/externaldeps/libwebsockets" || exit 1
packaging/bundle-mosquitto.sh
deleted
-12
@@ -1,12 +0,0 @@
1
-#!/bin/sh
2
-
3
-MOSQUITTO_TARBALL="$(cat "${1}/packaging/mosquitto.version").tar.gz"
4
-MOSQUITTO_BUILD_PATH="${1}/externaldeps/mosquitto/mosquitto-$(cat "${1}/packaging/mosquitto.version")/lib"
5
-
6
-mkdir -p "${1}/externaldeps/mosquitto" || exit 1
7
-curl -sSL --connect-timeout 10 --retry 3 "https://github.com/netdata/mosquitto/archive/${MOSQUITTO_TARBALL}" > "${MOSQUITTO_TARBALL}" || exit 1
8
-sha256sum -c "${1}/packaging/mosquitto.checksums" || exit 1
9
-tar -xzf "${MOSQUITTO_TARBALL}" -C "${1}/externaldeps/mosquitto" || exit 1
10
-make -C "${MOSQUITTO_BUILD_PATH}" || exit 1
11
-cp -a "${MOSQUITTO_BUILD_PATH}/libmosquitto.a" "${1}/externaldeps/mosquitto" || exit 1
12
-cp -a "${MOSQUITTO_BUILD_PATH}/mosquitto.h" "${1}/externaldeps/mosquitto" || exit 1
packaging/libwebsockets.checksums
deleted
-1
@@ -1 +0,0 @@
1
-166d6e17cab64bfc10c2a71799c298284540a1fa63f6ea3de5caccb34502243c v3.2.2.tar.gz
packaging/libwebsockets.version
deleted
-1
@@ -1 +0,0 @@
1
-3.2.2
packaging/mosquitto.checksums
deleted
-1
@@ -1 +0,0 @@
1
-532665f163348019909bd47f3e51a8ca8c9c26a01c08c09c51b903688f78cc11 v.1.6.8_Netdata-5.tar.gz
packaging/mosquitto.version
deleted
-1
@@ -1 +0,0 @@
1
-v.1.6.8_Netdata-5
web/api/web_api_v1.c
+1
-7
@@ -995,13 +995,7 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
995
#else
996
buffer_strcat(wb, "\t\"aclk-legacy-available\": false,\n");
997
#endif
998
- buffer_strcat(wb, "\t\"aclk-implementation\": \"");
999
- if (aclk_ng) {
1000
- buffer_strcat(wb, "Next Generation");
1001
- } else {
1002
- buffer_strcat(wb, "legacy");
1003
- }
1004
- buffer_strcat(wb, "\",\n");
998
+ buffer_strcat(wb, "\t\"aclk-implementation\": \"Next Generation\",\n");
999
#else
1000
buffer_strcat(wb, "\t\"cloud-available\": false,\n");
1001
#endif