Add 'funcs' capability (#13992)
* cleanup capas + add func capa * make it const * fixes * freez
Timotej S committed
Nov 16, 2022 at 04:05 UTC
f289ba344990ae1f16f6019c72de1e52dcf260bf
14 files changed
+85
-50
CMakeLists.txt
+2
@@ -898,6 +898,8 @@ set(ACLK_FILES
898
aclk/aclk_alarm_api.h
899
aclk/aclk_contexts_api.c
900
aclk/aclk_contexts_api.h
901
+ aclk/aclk_capas.c
902
+ aclk/aclk_capas.h
903
aclk/schema-wrappers/connection.cc
904
aclk/schema-wrappers/connection.h
905
aclk/schema-wrappers/node_connection.cc
Makefile.am
+2
@@ -690,6 +690,8 @@ ACLK_FILES = \
690
aclk/aclk_alarm_api.h \
691
aclk/aclk_contexts_api.c \
692
aclk/aclk_contexts_api.h \
693
+ aclk/aclk_capas.c \
694
+ aclk/aclk_capas.h \
695
aclk/helpers/mqtt_wss_pal.h \
696
aclk/helpers/ringbuffer_pal.h \
697
aclk/schema-wrappers/connection.cc \
aclk/aclk.c
+5
-16
@@ -13,6 +13,7 @@
13
#include "aclk_rx_msgs.h"
14
#include "https_client.h"
15
#include "schema-wrappers/schema_wrappers.h"
16
+#include "aclk_capas.h"
17
18
#include "aclk_proxy.h"
19
@@ -779,14 +780,7 @@ void aclk_host_state_update(RRDHOST *host, int cmd)
780
node_state_update.node_id = mallocz(UUID_STR_LEN);
781
uuid_unparse_lower(node_id, (char*)node_state_update.node_id);
782
782
- struct capability caps[] = {
783
- { .name = "proto", .version = 1, .enabled = 1 },
784
- { .name = "ml", .version = ml_capable(localhost), .enabled = ml_enabled(host) },
785
- { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
786
- { .name = "ctx", .version = 1, .enabled = 1 },
787
- { .name = NULL, .version = 0, .enabled = 0 }
788
- };
789
- node_state_update.capabilities = caps;
783
+ node_state_update.capabilities = aclk_get_agent_capas();
784
785
rrdhost_aclk_state_lock(localhost);
786
node_state_update.claim_id = localhost->aclk_state.claimed_id;
@@ -825,14 +819,7 @@ void aclk_send_node_instances()
819
uuid_unparse_lower(list->host_id, host_id);
820
821
RRDHOST *host = rrdhost_find_by_guid(host_id);
828
- struct capability caps[] = {
829
- { .name = "proto", .version = 1, .enabled = 1 },
830
- { .name = "ml", .version = ml_capable(localhost), .enabled = host ? ml_enabled(host) : 0 },
831
- { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
832
- { .name = "ctx", .version = 1, .enabled = 1 },
833
- { .name = NULL, .version = 0, .enabled = 0 }
834
- };
835
- node_state_update.capabilities = caps;
822
+ node_state_update.capabilities = aclk_get_node_instance_capas(host);
823
824
rrdhost_aclk_state_lock(localhost);
825
node_state_update.claim_id = localhost->aclk_state.claimed_id;
@@ -841,6 +828,8 @@ void aclk_send_node_instances()
828
info("Queuing status update for node=%s, live=%d, hops=%d",(char*)node_state_update.node_id,
829
list->live,
830
list->hops);
831
+
832
+ freez((void*)node_state_update.capabilities);
833
freez((void*)node_state_update.node_id);
834
query->data.bin_payload.msg_name = "UpdateNodeInstanceConnection";
835
query->data.bin_payload.topic = ACLK_TOPICID_NODE_CONN;
aclk/aclk_capas.c
new
+47
@@ -0,0 +1,47 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#include "aclk_capas.h"
4
+
5
+#include "ml/ml.h"
6
+
7
+const struct capability *aclk_get_agent_capas()
8
+{
9
+ static struct capability agent_capabilities[] = {
10
+ { .name = "json", .version = 2, .enabled = 0 },
11
+ { .name = "proto", .version = 1, .enabled = 1 },
12
+ { .name = "ml", .version = 0, .enabled = 0 },
13
+ { .name = "mc", .version = 0, .enabled = 0 },
14
+ { .name = "ctx", .version = 1, .enabled = 1 },
15
+ { .name = "funcs", .version = 1, .enabled = 1 },
16
+ { .name = NULL, .version = 0, .enabled = 0 }
17
+ };
18
+ agent_capabilities[2].version = ml_capable() ? 1 : 0;
19
+ agent_capabilities[2].enabled = ml_enabled(localhost);
20
+
21
+ agent_capabilities[3].version = enable_metric_correlations ? metric_correlations_version : 0;
22
+ agent_capabilities[3].enabled = enable_metric_correlations;
23
+
24
+ return agent_capabilities;
25
+}
26
+
27
+struct capability *aclk_get_node_instance_capas(RRDHOST *host)
28
+{
29
+ struct capability ni_caps[] = {
30
+ { .name = "proto", .version = 1, .enabled = 1 },
31
+ { .name = "ml", .version = ml_capable(), .enabled = ml_enabled(host) },
32
+ { .name = "mc",
33
+ .version = enable_metric_correlations ? metric_correlations_version : 0,
34
+ .enabled = enable_metric_correlations },
35
+ { .name = "ctx", .version = 1, .enabled = 1 },
36
+ { .name = "funcs", .version = 0, .enabled = 0 },
37
+ { .name = NULL, .version = 0, .enabled = 0 }
38
+ };
39
+ if (host->receiver && stream_has_capability(host->receiver, STREAM_CAP_FUNCTIONS)) {
40
+ ni_caps[4].version = 1;
41
+ ni_caps[4].enabled = 1;
42
+ }
43
+
44
+ struct capability *ret = mallocz(sizeof(ni_caps));
45
+ memcpy(ret, ni_caps, sizeof(ni_caps));
46
+ return ret;
47
+}
aclk/aclk_capas.h
new
+14
@@ -0,0 +1,14 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#ifndef ACLK_CAPAS_H
4
+#define ACLK_CAPAS_H
5
+
6
+#include "daemon/common.h"
7
+#include "libnetdata/libnetdata.h"
8
+
9
+#include "schema-wrappers/capability.h"
10
+
11
+const struct capability *aclk_get_agent_capas();
12
+struct capability *aclk_get_node_instance_capas(RRDHOST *host);
13
+
14
+#endif /* ACLK_CAPAS_H */
aclk/aclk_rx_msgs.c
+4
-8
@@ -5,6 +5,7 @@
5
#include "aclk_stats.h"
6
#include "aclk_query_queue.h"
7
#include "aclk.h"
8
+#include "aclk_capas.h"
9
10
#include "schema-wrappers/proto_2_json.h"
11
@@ -289,20 +290,15 @@ int create_node_instance_result(const char *msg, size_t msg_len)
290
}
291
}
292
292
- struct capability caps[] = {
293
- { .name = "proto", .version = 1, .enabled = 1 },
294
- { .name = "ml", .version = ml_capable(localhost), .enabled = host ? ml_enabled(host) : 0 },
295
- { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
296
- { .name = "ctx", .version = 1, .enabled = 1 },
297
- { .name = NULL, .version = 0, .enabled = 0 }
298
- };
299
- node_state_update.capabilities = caps;
293
+ node_state_update.capabilities = aclk_get_node_instance_capas(host);
294
295
rrdhost_aclk_state_lock(localhost);
296
node_state_update.claim_id = localhost->aclk_state.claimed_id;
297
query->data.bin_payload.payload = generate_node_instance_connection(&query->data.bin_payload.size, &node_state_update);
298
rrdhost_aclk_state_unlock(localhost);
299
300
+ freez((void *)node_state_update.capabilities);
301
+
302
query->data.bin_payload.msg_name = "UpdateNodeInstanceConnection";
303
query->data.bin_payload.topic = ACLK_TOPICID_NODE_CONN;
304
aclk/aclk_tx_msgs.c
+2
-12
@@ -5,6 +5,7 @@
5
#include "aclk_util.h"
6
#include "aclk_stats.h"
7
#include "aclk.h"
8
+#include "aclk_capas.h"
9
10
#include "schema-wrappers/proto_2_json.h"
11
@@ -211,22 +212,11 @@ uint16_t aclk_send_agent_connection_update(mqtt_wss_client client, int reachable
212
size_t len;
213
uint16_t pid;
214
214
- struct capability agent_capabilities[] = {
215
- { .name = "json", .version = 2, .enabled = 0 },
216
- { .name = "proto", .version = 1, .enabled = 1 },
217
-#ifdef ENABLE_ML
218
- { .name = "ml", .version = 1, .enabled = ml_enabled(localhost) },
219
-#endif
220
- { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
221
- { .name = "ctx", .version = 1, .enabled = 1 },
222
- { .name = NULL, .version = 0, .enabled = 0 }
223
- };
224
-
215
update_agent_connection_t conn = {
216
.reachable = (reachable ? 1 : 0),
217
.lwt = 0,
218
.session_id = aclk_session_newarch,
229
- .capabilities = agent_capabilities
219
+ .capabilities = aclk_get_agent_capas()
220
};
221
222
rrdhost_aclk_state_lock(localhost);
aclk/schema-wrappers/capability.cc
+1
-1
@@ -4,7 +4,7 @@
4
5
#include "capability.h"
6
7
-void capability_set(aclk_lib::v1::Capability *proto_capa, struct capability *c_capa) {
7
+void capability_set(aclk_lib::v1::Capability *proto_capa, const struct capability *c_capa) {
8
proto_capa->set_name(c_capa->name);
9
proto_capa->set_enabled(c_capa->enabled);
10
proto_capa->set_version(c_capa->version);
aclk/schema-wrappers/capability.h
+1
-1
@@ -18,7 +18,7 @@ struct capability {
18
19
#include "proto/aclk/v1/lib.pb.h"
20
21
-void capability_set(aclk_lib::v1::Capability *proto_capa, struct capability *c_capa);
21
+void capability_set(aclk_lib::v1::Capability *proto_capa, const struct capability *c_capa);
22
#endif
23
24
#endif /* ACLK_SCHEMA_CAPABILITY_H */
aclk/schema-wrappers/connection.cc
+1
-1
@@ -29,7 +29,7 @@ char *generate_update_agent_connection(size_t *len, const update_agent_connectio
29
timestamp->set_nanos(tv.tv_usec * 1000);
30
31
if (data->capabilities) {
32
- struct capability *capa = data->capabilities;
32
+ const struct capability *capa = data->capabilities;
33
while (capa->name) {
34
aclk_lib::v1::Capability *proto_capa = connupd.add_capabilities();
35
capability_set(proto_capa, capa);
aclk/schema-wrappers/connection.h
+1
-1
@@ -17,7 +17,7 @@ typedef struct {
17
18
unsigned int lwt:1;
19
20
- struct capability *capabilities;
20
+ const struct capability *capabilities;
21
22
// TODO in future optional fields
23
// > 15 optional fields:
aclk/schema-wrappers/node_connection.cc
+1
-1
@@ -29,7 +29,7 @@ char *generate_node_instance_connection(size_t *len, const node_instance_connect
29
timestamp->set_nanos(tv.tv_usec * 1000);
30
31
if (data->capabilities) {
32
- struct capability *capa = data->capabilities;
32
+ const struct capability *capa = data->capabilities;
33
while (capa->name) {
34
aclk_lib::v1::Capability *proto_capa = msg.add_capabilities();
35
capability_set(proto_capa, capa);
aclk/schema-wrappers/node_connection.h
+1
-1
@@ -19,7 +19,7 @@ typedef struct {
19
int64_t session_id;
20
21
int32_t hops;
22
- struct capability *capabilities;
22
+ const struct capability *capabilities;
23
} node_instance_connection_t;
24
25
char *generate_node_instance_connection(size_t *len, const node_instance_connection_t *data);
database/sqlite/sqlite_aclk_node.c
+3
-8
@@ -4,6 +4,7 @@
4
#include "sqlite_aclk_node.h"
5
6
#include "../../aclk/aclk_contexts_api.h"
7
+#include "../../aclk/aclk_capas.h"
8
9
#ifdef ENABLE_ACLK
10
DICTIONARY *collectors_from_charts(RRDHOST *host, DICTIONARY *dict) {
@@ -71,14 +72,7 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat
72
node_info.ml_info.ml_capable = ml_capable(localhost);
73
node_info.ml_info.ml_enabled = ml_enabled(wc->host);
74
74
- struct capability instance_caps[] = {
75
- { .name = "proto", .version = 1, .enabled = 1 },
76
- { .name = "ml", .version = ml_capable(localhost), .enabled = ml_enabled(wc->host) },
77
- { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
78
- { .name = "ctx", .version = 1, .enabled = 1 },
79
- { .name = NULL, .version = 0, .enabled = 0 }
80
- };
81
- node_info.node_instance_capabilities = instance_caps;
75
+ node_info.node_instance_capabilities = aclk_get_node_instance_capas(wc->host);
76
77
now_realtime_timeval(&node_info.updated_at);
78
@@ -126,6 +120,7 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat
120
121
rrd_unlock();
122
freez(node_info.claim_id);
123
+ freez(node_info.node_instance_capabilities);
124
freez(host_version);
125
126
wc->node_collectors_send = now_realtime_sec();