Implements new capability fields in aclk_schemas (#12602)
use new capability fields
Timotej S committed
May 13, 2022 at 12:22 UTC
6d98eb16fc00acf76d19958f0ac82396f5e56d13
12 files changed
+105
-3
CMakeLists.txt
+2
@@ -825,6 +825,8 @@ set(ACLK_FILES
825
aclk/schema-wrappers/alarm_config.h
826
aclk/schema-wrappers/node_info.cc
827
aclk/schema-wrappers/node_info.h
828
+ aclk/schema-wrappers/capability.cc
829
+ aclk/schema-wrappers/capability.h
830
aclk/schema-wrappers/schema_wrappers.h
831
aclk/schema-wrappers/schema_wrapper_utils.cc
832
aclk/schema-wrappers/schema_wrapper_utils.h
Makefile.am
+2
@@ -657,6 +657,8 @@ ACLK_FILES += \
657
aclk/schema-wrappers/alarm_config.h \
658
aclk/schema-wrappers/node_info.cc \
659
aclk/schema-wrappers/node_info.h \
660
+ aclk/schema-wrappers/capability.cc \
661
+ aclk/schema-wrappers/capability.h \
662
aclk/schema-wrappers/schema_wrappers.h \
663
aclk/schema-wrappers/schema_wrapper_utils.cc \
664
aclk/schema-wrappers/schema_wrapper_utils.h \
aclk/aclk-schemas
+1
-1
@@ -1 +1 @@
1
-Subproject commit b23f6a671ccf6d2766d6a208fc1e48b0fbf2fdad
1
+Subproject commit d8342ee6d932c152a78c9fe886281fe28170a6c4
aclk/aclk_tx_msgs.c
+14
-2
@@ -452,10 +452,21 @@ int aclk_send_app_layer_disconnect(mqtt_wss_client client, const char *message)
452
uint16_t aclk_send_agent_connection_update(mqtt_wss_client client, int reachable) {
453
size_t len;
454
uint16_t pid;
455
+
456
+ struct capability agent_capabilities[] = {
457
+ { .name = "json", .version = 2, .enabled = 0 },
458
+ { .name = "proto", .version = 1, .enabled = 1 },
459
+#ifdef ENABLE_ML
460
+ { .name = "ml", .version = 1, .enabled = ml_enabled(localhost) },
461
+#endif
462
+ { .name = NULL, .version = 0, .enabled = 0 }
463
+ };
464
+
465
update_agent_connection_t conn = {
466
.reachable = (reachable ? 1 : 0),
467
.lwt = 0,
458
- .session_id = aclk_session_newarch
468
+ .session_id = aclk_session_newarch,
469
+ .capabilities = agent_capabilities
470
};
471
472
rrdhost_aclk_state_lock(localhost);
@@ -490,7 +501,8 @@ char *aclk_generate_lwt(size_t *size) {
501
update_agent_connection_t conn = {
502
.reachable = 0,
503
.lwt = 1,
493
- .session_id = aclk_session_newarch
504
+ .session_id = aclk_session_newarch,
505
+ .capabilities = NULL
506
};
507
508
rrdhost_aclk_state_lock(localhost);
aclk/schema-wrappers/capability.cc
new
+11
@@ -0,0 +1,11 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#include "proto/aclk/v1/lib.pb.h"
4
+
5
+#include "capability.h"
6
+
7
+void capability_set(aclk_lib::v1::Capability *proto_capa, 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);
11
+}
aclk/schema-wrappers/capability.h
new
+24
@@ -0,0 +1,24 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#ifndef ACLK_SCHEMA_CAPABILITY_H
4
+#define ACLK_SCHEMA_CAPABILITY_H
5
+
6
+#ifdef __cplusplus
7
+extern "C" {
8
+#endif
9
+
10
+struct capability {
11
+ const char *name;
12
+ uint32_t version;
13
+ int enabled;
14
+};
15
+
16
+#ifdef __cplusplus
17
+}
18
+
19
+#include "proto/aclk/v1/lib.pb.h"
20
+
21
+void capability_set(aclk_lib::v1::Capability *proto_capa, struct capability *c_capa);
22
+#endif
23
+
24
+#endif /* ACLK_SCHEMA_CAPABILITY_H */
aclk/schema-wrappers/connection.cc
+9
@@ -28,6 +28,15 @@ char *generate_update_agent_connection(size_t *len, const update_agent_connectio
28
timestamp->set_seconds(tv.tv_sec);
29
timestamp->set_nanos(tv.tv_usec * 1000);
30
31
+ if (data->capabilities) {
32
+ 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);
36
+ capa++;
37
+ }
38
+ }
39
+
40
*len = PROTO_COMPAT_MSG_SIZE(connupd);
41
char *msg = (char*)malloc(*len);
42
if (msg)
aclk/schema-wrappers/connection.h
+4
@@ -3,6 +3,8 @@
3
#ifndef ACLK_SCHEMA_WRAPPER_CONNECTION_H
4
#define ACLK_SCHEMA_WRAPPER_CONNECTION_H
5
6
+#include "capability.h"
7
+
8
#ifdef __cplusplus
9
extern "C" {
10
#endif
@@ -15,6 +17,8 @@ typedef struct {
17
18
unsigned int lwt:1;
19
20
+ struct capability *capabilities;
21
+
22
// TODO in future optional fields
23
// > 15 optional fields:
24
// How long the system was running until connection (only applicable when reachable=true)
aclk/schema-wrappers/node_info.cc
+18
@@ -94,6 +94,24 @@ char *generate_update_node_info_message(size_t *len, struct update_node_info *in
94
ml_info->set_ml_capable(info->ml_info.ml_capable);
95
ml_info->set_ml_enabled(info->ml_info.ml_enabled);
96
97
+ struct capability *capa;
98
+ if (info->node_capabilities) {
99
+ capa = info->node_capabilities;
100
+ while (capa->name) {
101
+ aclk_lib::v1::Capability *proto_capa = msg.mutable_node_info()->add_capabilities();
102
+ capability_set(proto_capa, capa);
103
+ capa++;
104
+ }
105
+ }
106
+ if (info->node_instance_capabilities) {
107
+ capa = info->node_instance_capabilities;
108
+ while (capa->name) {
109
+ aclk_lib::v1::Capability *proto_capa = msg.mutable_node_instance_info()->add_capabilities();
110
+ capability_set(proto_capa, capa);
111
+ capa++;
112
+ }
113
+ }
114
+
115
*len = PROTO_COMPAT_MSG_SIZE(msg);
116
char *bin = (char*)malloc(*len);
117
if (bin)
aclk/schema-wrappers/node_info.h
+4
@@ -6,6 +6,7 @@
6
#include <stdlib.h>
7
8
#include "database/rrd.h"
9
+#include "capability.h"
10
11
#ifdef __cplusplus
12
extern "C" {
@@ -67,6 +68,9 @@ struct update_node_info {
68
int child;
69
70
struct machine_learning_info ml_info;
71
+
72
+ struct capability *node_capabilities;
73
+ struct capability *node_instance_capabilities;
74
};
75
76
char *generate_update_node_info_message(size_t *len, struct update_node_info *info);
aclk/schema-wrappers/schema_wrappers.h
+1
@@ -13,5 +13,6 @@
13
#include "alarm_config.h"
14
#include "alarm_stream.h"
15
#include "node_info.h"
16
+#include "capability.h"
17
18
#endif /* SCHEMA_WRAPPERS_H */
database/sqlite/sqlite_aclk_node.c
+15
@@ -24,6 +24,14 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat
24
node_info.child = (wc->host != localhost);
25
node_info.ml_info.ml_capable = ml_capable(localhost);
26
node_info.ml_info.ml_enabled = ml_enabled(wc->host);
27
+
28
+ struct capability instance_caps[] = {
29
+ { .name = "proto", .version = 1, .enabled = 1 },
30
+ { .name = "ml", .version = ml_capable(localhost), .enabled = ml_enabled(wc->host) },
31
+ { .name = NULL, .version = 0, .enabled = 0 }
32
+ };
33
+ node_info.node_instance_capabilities = instance_caps;
34
+
35
now_realtime_timeval(&node_info.updated_at);
36
37
RRDHOST *host = wc->host;
@@ -55,6 +63,13 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat
63
node_info.data.services = NULL; // char **
64
node_info.data.service_count = 0;
65
node_info.data.machine_guid = wc->host_guid;
66
+
67
+ struct capability node_caps[] = {
68
+ { .name = "ml", .version = host->system_info->ml_capable, .enabled = host->system_info->ml_enabled },
69
+ { .name = NULL, .version = 0, .enabled = 0 }
70
+ };
71
+ node_info.node_capabilities = node_caps;
72
+
73
node_info.data.ml_info.ml_capable = host->system_info->ml_capable;
74
node_info.data.ml_info.ml_enabled = host->system_info->ml_enabled;
75