@cryptotaxi247 / netdata-1 / commits / b3ef98cbc

added /api/v3/stream_path (#18943)

Costa Tsaousis committed Nov 9, 2024 at 13:02 UTC b3ef98cbc378e2e65e1be09b33b7cf0e8be15de9
10 files changed +67 -21
CMakeLists.txt
+1
@@ -1425,6 +1425,7 @@ set(WEB_PLUGIN_FILES
1425 src/web/server/static/static-threaded.h
1426 src/web/server/web_client_cache.c
1427 src/web/server/web_client_cache.h
1428 + src/web/api/v3/api_v3_stream_path.c
1429 )
1430
1431 set(CLAIM_PLUGIN_FILES
src/database/contexts/api_v2_contexts.c
+11 -3
@@ -382,11 +382,11 @@ static void rrdcontext_to_json_v2_rrdhost(BUFFER *wb, RRDHOST *host, struct rrdc
382 buffer_json_node_add_v2(wb, host, node_id, 0,
383 (ctl->mode & CONTEXTS_V2_AGENTS) && !(ctl->mode & CONTEXTS_V2_NODE_INSTANCES));
384
385 - if(ctl->mode & (CONTEXTS_V2_NODES_INFO | CONTEXTS_V2_NODE_INSTANCES)) {
385 + if(ctl->mode & (CONTEXTS_V2_NODES_INFO | CONTEXTS_V2_NODES_STREAM_PATH | CONTEXTS_V2_NODE_INSTANCES)) {
386 RRDHOST_STATUS s;
387 rrdhost_status(host, ctl->now, &s);
388
389 - if (ctl->mode & (CONTEXTS_V2_NODES_INFO)) {
389 + if (ctl->mode & (CONTEXTS_V2_NODES_INFO | CONTEXTS_V2_NODES_STREAM_PATH)) {
390 buffer_json_member_add_string(wb, "v", rrdhost_program_version(host));
391
392 host_labels2json(host, wb, "labels");
@@ -423,9 +423,14 @@ static void rrdcontext_to_json_v2_rrdhost(BUFFER *wb, RRDHOST *host, struct rrdc
423 // reachable - connected with live data
424 // pruned - not connected for some time and has been removed
425 buffer_json_member_add_string(wb, "state", rrdhost_is_online(host) ? "reachable" : "stale");
426 + }
427
428 + if (ctl->mode & (CONTEXTS_V2_NODES_INFO)) {
429 rrdhost_health_to_json_v2(wb, "health", &s);
430 agent_capabilities_to_json(wb, host, "capabilities");
431 + }
432 +
433 + if (ctl->mode & (CONTEXTS_V2_NODES_STREAM_PATH)) {
434 rrdhost_stream_path_to_json(wb, host, STREAM_PATH_JSON_MEMBER, false);
435 }
436
@@ -608,6 +613,9 @@ static void buffer_json_contexts_v2_mode_to_array(BUFFER *wb, const char *key, C
613 if(mode & CONTEXTS_V2_NODES_INFO)
614 buffer_json_add_array_item_string(wb, "nodes-info");
615
616 + if(mode & CONTEXTS_V2_NODES_STREAM_PATH)
617 + buffer_json_add_array_item_string(wb, "nodes-stream-path");
618 +
619 if(mode & CONTEXTS_V2_NODE_INSTANCES)
620 buffer_json_add_array_item_string(wb, "nodes-instances");
621
@@ -750,7 +758,7 @@ int rrdcontext_to_json_v2(BUFFER *wb, struct api_v2_contexts_request *req, CONTE
758 if(mode & (CONTEXTS_V2_AGENTS_INFO))
759 mode |= CONTEXTS_V2_AGENTS;
760
753 - if(mode & (CONTEXTS_V2_FUNCTIONS | CONTEXTS_V2_CONTEXTS | CONTEXTS_V2_SEARCH | CONTEXTS_V2_NODES_INFO | CONTEXTS_V2_NODE_INSTANCES))
761 + if(mode & (CONTEXTS_V2_FUNCTIONS | CONTEXTS_V2_CONTEXTS | CONTEXTS_V2_SEARCH | CONTEXTS_V2_NODES_INFO | CONTEXTS_V2_NODES_STREAM_PATH | CONTEXTS_V2_NODE_INSTANCES))
762 mode |= CONTEXTS_V2_NODES;
763
764 if(mode & CONTEXTS_V2_ALERTS) {
src/database/contexts/rrdcontext.h
+8 -7
@@ -648,13 +648,14 @@ typedef enum __attribute__ ((__packed__)) {
648 CONTEXTS_V2_NODES = (1 << 2),
649 CONTEXTS_V2_NODES_INFO = (1 << 3),
650 CONTEXTS_V2_NODE_INSTANCES = (1 << 4),
651 - CONTEXTS_V2_CONTEXTS = (1 << 5),
652 - CONTEXTS_V2_AGENTS = (1 << 6),
653 - CONTEXTS_V2_AGENTS_INFO = (1 << 7),
654 - CONTEXTS_V2_VERSIONS = (1 << 8),
655 - CONTEXTS_V2_FUNCTIONS = (1 << 9),
656 - CONTEXTS_V2_ALERTS = (1 << 10),
657 - CONTEXTS_V2_ALERT_TRANSITIONS = (1 << 11),
651 + CONTEXTS_V2_NODES_STREAM_PATH = (1 << 5),
652 + CONTEXTS_V2_CONTEXTS = (1 << 6),
653 + CONTEXTS_V2_AGENTS = (1 << 7),
654 + CONTEXTS_V2_AGENTS_INFO = (1 << 8),
655 + CONTEXTS_V2_VERSIONS = (1 << 9),
656 + CONTEXTS_V2_FUNCTIONS = (1 << 10),
657 + CONTEXTS_V2_ALERTS = (1 << 11),
658 + CONTEXTS_V2_ALERT_TRANSITIONS = (1 << 12),
659 } CONTEXTS_V2_MODE;
660
661 int rrdcontext_to_json_v2(BUFFER *wb, struct api_v2_contexts_request *req, CONTEXTS_V2_MODE mode);
src/database/rrd.h
+2 -2
@@ -1104,8 +1104,8 @@ typedef struct health {
1104 time_t health_delay_up_to; // a timestamp to delay alarms processing up to
1105 STRING *health_default_exec; // the full path of the alarms notifications program
1106 STRING *health_default_recipient; // the default recipient for all alarms
1107 - unsigned int health_enabled; // 1 when this host has health enabled
1108 - bool use_summary_for_notifications; // whether or not to use the summary field as a subject for notifications
1107 + bool health_enabled; // 1 when this host has health enabled
1108 + bool use_summary_for_notifications; // whether to use the summary field as a subject for notifications
1109 } HEALTH;
1110
1111 // ----------------------------------------------------------------------------
src/database/sqlite/sqlite_metadata.c
+1 -1
@@ -958,7 +958,7 @@ static int store_host_metadata(RRDHOST *host)
958 SQLITE_BIND_FAIL(bind_fail, bind_text_null(res, ++param, rrdhost_program_name(host), 1));
959 SQLITE_BIND_FAIL(bind_fail, bind_text_null(res, ++param, rrdhost_program_version(host), 1));
960 SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int64(res, ++param, host->rrd_history_entries));
961 - SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int(res, ++param, (int ) host->health.health_enabled));
961 + SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int(res, ++param, (int)host->health.health_enabled));
962 SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_int64(res, ++param, (sqlite3_int64) host->last_connected));
963
964 int store_rc = sqlite3_step_monitored(res);
src/streaming/stream-path.c
+19 -6
@@ -5,7 +5,11 @@
5 #include "plugins.d/pluginsd_internals.h"
6
7 ENUM_STR_MAP_DEFINE(STREAM_PATH_FLAGS) = {
8 - { .id = STREAM_PATH_FLAG_ACLK, .name = "aclk" },
8 + { .id = STREAM_PATH_FLAG_ACLK, .name = "aclk" },
9 + { .id = STREAM_PATH_FLAG_HEALTH, .name = "health" },
10 + { .id = STREAM_PATH_FLAG_ML, .name = "ml" },
11 + { .id = STREAM_PATH_FLAG_EPHEMERAL, .name = "ephemeral" },
12 + { .id = STREAM_PATH_FLAG_VIRTUAL, .name = "virtual" },
13
14 // terminator
15 { . id = 0, .name = NULL }
@@ -79,19 +83,28 @@ static STREAM_PATH rrdhost_stream_path_self(RRDHOST *host) {
83 if(!UUIDiszero(p.claim_id))
84 p.flags |= STREAM_PATH_FLAG_ACLK;
85
82 - bool has_receiver = false;
86 + if(rrdhost_option_check(host, RRDHOST_OPTION_EPHEMERAL_HOST))
87 + p.flags |= STREAM_PATH_FLAG_EPHEMERAL;
88 +
89 + if(rrdhost_option_check(host, RRDHOST_OPTION_VIRTUAL_HOST))
90 + p.flags |= STREAM_PATH_FLAG_VIRTUAL;
91 +
92 + if(host->health.health_enabled)
93 + p.flags |= STREAM_PATH_FLAG_HEALTH;
94 +
95 + if(ml_enabled(host))
96 + p.flags |= STREAM_PATH_FLAG_ML;
97 +
98 spinlock_lock(&host->receiver_lock);
99 if(host->receiver) {
85 - has_receiver = true;
100 p.hops = (int16_t)host->receiver->hops;
101 p.since = host->receiver->connected_since_s;
102 }
89 - spinlock_unlock(&host->receiver_lock);
90 -
91 - if(!has_receiver) {
103 + else {
104 p.hops = (is_localhost) ? 0 : -1; // -1 for stale nodes
105 p.since = netdata_start_time;
106 }
107 + spinlock_unlock(&host->receiver_lock);
108
109 // the following may get the receiver lock again!
110 p.capabilities = stream_our_capabilities(host, true);
src/streaming/stream-path.h
+6 -2
@@ -8,8 +8,12 @@
8 #define STREAM_PATH_JSON_MEMBER "streaming_path"
9
10 typedef enum __attribute__((packed)) {
11 - STREAM_PATH_FLAG_NONE = 0,
12 - STREAM_PATH_FLAG_ACLK = (1 << 0),
11 + STREAM_PATH_FLAG_NONE = 0,
12 + STREAM_PATH_FLAG_ACLK = (1 << 0),
13 + STREAM_PATH_FLAG_HEALTH = (1 << 1),
14 + STREAM_PATH_FLAG_ML = (1 << 2),
15 + STREAM_PATH_FLAG_EPHEMERAL = (1 << 3),
16 + STREAM_PATH_FLAG_VIRTUAL = (1 << 4),
17 } STREAM_PATH_FLAGS;
18
19 typedef struct stream_path {
src/web/api/v3/api_v3_calls.h
+4
@@ -5,7 +5,11 @@
5
6 #include "../web_api_v3.h"
7
8 +int api_v2_contexts_internal(RRDHOST *host, struct web_client *w, char *url, CONTEXTS_V2_MODE mode);
9 +#define api_v3_contexts_internal(host, w, url, mode) api_v2_contexts_internal(host, w, url, mode)
10 +
11 int api_v3_settings(RRDHOST *host, struct web_client *w, char *url);
12 int api_v3_me(RRDHOST *host, struct web_client *w, char *url);
13 +int api_v3_stream_path(RRDHOST *host __maybe_unused, struct web_client *w, char *url);
14
15 #endif //NETDATA_API_V3_CALLS_H
src/web/api/v3/api_v3_stream_path.c new
+7
@@ -0,0 +1,7 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "api_v3_calls.h"
4 +
5 +int api_v3_stream_path(RRDHOST *host __maybe_unused, struct web_client *w, char *url) {
6 + return api_v3_contexts_internal(host, w, url, CONTEXTS_V2_NODES | CONTEXTS_V2_NODES_STREAM_PATH);
7 +}
src/web/api/web_api_v3.c
+8
@@ -130,6 +130,14 @@ static struct web_api_command api_commands_v3[] = {
130 .callback = api_v2_node_instances,
131 .allow_subpaths = 0
132 },
133 + {
134 + .api = "stream_path",
135 + .hash = 0,
136 + .acl = HTTP_ACL_NODES,
137 + .access = HTTP_ACCESS_ANONYMOUS_DATA,
138 + .callback = api_v3_stream_path,
139 + .allow_subpaths = 0
140 + },
141 {
142 .api = "versions",
143 .hash = 0,