Browse Source

minor - add capability signifying this agent can speak apiv2 (#14817)

* capa apiv2

* build new cancellation proto

* commited on wrong branch :D Revert "build new cancellation proto"

This reverts commit 8290422de4074b9c383e29ad10e041668056679a.

* use common source of truth for capas in apiv2

* fix for possible races
Timotej S 1 year ago
parent
commit
c09dbb224a
4 changed files with 38 additions and 36 deletions
  1. 2 2
      CMakeLists.txt
  2. 2 2
      Makefile.am
  3. 20 16
      aclk/aclk_capas.c
  4. 14 16
      database/contexts/api_v2.c

+ 2 - 2
CMakeLists.txt

@@ -886,6 +886,8 @@ set(ACLK_ALWAYS_BUILD
         aclk/aclk_proxy.h
         aclk/aclk.c
         aclk/aclk.h
+        aclk/aclk_capas.c
+        aclk/aclk_capas.h
         )
 
 set(ACLK_FILES
@@ -909,8 +911,6 @@ set(ACLK_FILES
         aclk/aclk_alarm_api.h
         aclk/aclk_contexts_api.c
         aclk/aclk_contexts_api.h
-        aclk/aclk_capas.c
-        aclk/aclk_capas.h
         aclk/schema-wrappers/connection.cc
         aclk/schema-wrappers/connection.h
         aclk/schema-wrappers/node_connection.cc

+ 2 - 2
Makefile.am

@@ -696,8 +696,6 @@ ACLK_FILES = \
     aclk/aclk_alarm_api.h \
     aclk/aclk_contexts_api.c \
     aclk/aclk_contexts_api.h \
-    aclk/aclk_capas.c \
-    aclk/aclk_capas.h \
     aclk/helpers/mqtt_wss_pal.h \
     aclk/helpers/ringbuffer_pal.h \
     aclk/schema-wrappers/connection.cc \
@@ -843,6 +841,8 @@ ACLK_ALWAYS_BUILD_FILES = \
     aclk/aclk_proxy.h \
     aclk/aclk.c \
     aclk/aclk.h \
+    aclk/aclk_capas.c \
+    aclk/aclk_capas.h \
     $(NULL)
 
 SPAWN_PLUGIN_FILES = \

+ 20 - 16
aclk/aclk_capas.c

@@ -7,13 +7,14 @@
 const struct capability *aclk_get_agent_capas()
 {
     static struct capability agent_capabilities[] = {
-        { .name = "json",  .version = 2, .enabled = 0 },
-        { .name = "proto", .version = 1, .enabled = 1 },
-        { .name = "ml",    .version = 0, .enabled = 0 },
-        { .name = "mc",    .version = 0, .enabled = 0 },
-        { .name = "ctx",   .version = 1, .enabled = 1 },
-        { .name = "funcs", .version = 1, .enabled = 1 },
-        { .name = NULL,    .version = 0, .enabled = 0 }
+        { .name = "json",        .version = 2, .enabled = 0 },
+        { .name = "proto",       .version = 1, .enabled = 1 },
+        { .name = "ml",          .version = 0, .enabled = 0 },
+        { .name = "mc",          .version = 0, .enabled = 0 },
+        { .name = "ctx",         .version = 1, .enabled = 1 },
+        { .name = "funcs",       .version = 1, .enabled = 1 },
+        { .name = "http_api_v2", .version = 1, .enabled = 1 },
+        { .name = NULL,          .version = 0, .enabled = 0 }
     };
     agent_capabilities[2].version = ml_capable() ? 1 : 0;
     agent_capabilities[2].enabled = ml_enabled(localhost);
@@ -27,21 +28,24 @@ const struct capability *aclk_get_agent_capas()
 struct capability *aclk_get_node_instance_capas(RRDHOST *host)
 {
     struct capability ni_caps[] = {
-        { .name = "proto", .version = 1,                     .enabled = 1 },
-        { .name = "ml",    .version = ml_capable(),          .enabled = ml_enabled(host) },
+        { .name = "proto",       .version = 1,                     .enabled = 1 },
+        { .name = "ml",          .version = ml_capable(),          .enabled = ml_enabled(host) },
         { .name = "mc",
           .version = enable_metric_correlations ? metric_correlations_version : 0,
           .enabled = enable_metric_correlations },
-        { .name = "ctx",   .version = 1,                     .enabled = 1 },
-        { .name = "funcs", .version = 0,                     .enabled = 0 },
-        { .name = NULL,    .version = 0,                     .enabled = 0 }
+        { .name = "ctx",         .version = 1,                     .enabled = 1 },
+        { .name = "funcs",       .version = 0,                     .enabled = 0 },
+        { .name = "http_api_v2", .version = 1,                     .enabled = 1 },
+        { .name = NULL,          .version = 0,                     .enabled = 0 }
     };
-    if (host == localhost || (host->receiver && stream_has_capability(host->receiver, STREAM_CAP_FUNCTIONS))) {
-        ni_caps[4].version = 1;
-        ni_caps[4].enabled = 1;
-    }
 
     struct capability *ret = mallocz(sizeof(ni_caps));
     memcpy(ret, ni_caps, sizeof(ni_caps));
+
+    if (host == localhost || (host->receiver && stream_has_capability(host->receiver, STREAM_CAP_FUNCTIONS))) {
+        ret[4].version = 1;
+        ret[4].enabled = 1;
+    }
+
     return ret;
 }

+ 14 - 16
database/contexts/api_v2.c

@@ -2,6 +2,7 @@
 
 #include "internal.h"
 
+#include "aclk/aclk_capas.h"
 
 // ----------------------------------------------------------------------------
 // /api/v2/contexts API
@@ -306,23 +307,20 @@ static ssize_t rrdcontext_to_json_v2_add_host(void *data, RRDHOST *host, bool qu
             buffer_json_member_add_array(wb, "services");
             buffer_json_array_close(wb);
 
-            buffer_json_member_add_array(wb, "capabilities");
-            buffer_json_add_array_item_object(wb);
-            buffer_json_member_add_string(wb, "name", "funcs");
-            buffer_json_member_add_uint64(wb, "version", 1);
-            buffer_json_member_add_boolean(wb, "enabled", true);
-            buffer_json_object_close(wb);
-            buffer_json_add_array_item_object(wb);
-            buffer_json_member_add_string(wb, "name", "mc");
-            buffer_json_member_add_uint64(wb, "version", 1);
-            buffer_json_member_add_boolean(wb, "enabled", true);
-            buffer_json_object_close(wb);
-            buffer_json_add_array_item_object(wb);
-            buffer_json_member_add_string(wb, "name", "ml");
-            buffer_json_member_add_uint64(wb, "version", 1);
-            buffer_json_member_add_boolean(wb, "enabled", true);
-            buffer_json_object_close(wb);
+            buffer_json_member_add_array(wb, "nodeInstanceCapabilities");
+
+            struct capability *capas = aclk_get_node_instance_capas(host);
+            struct capability *capa = capas;
+            while(capa->name != NULL) {
+                buffer_json_add_array_item_object(wb);
+                buffer_json_member_add_string(wb, "name", capa->name);
+                buffer_json_member_add_uint64(wb, "version", capa->version);
+                buffer_json_member_add_boolean(wb, "enabled", capa->enabled);
+                buffer_json_object_close(wb);
+                capa++;
+            }
             buffer_json_array_close(wb);
+            freez(capas);
 
             web_client_api_request_v1_info_summary_alarm_statuses(host, wb, "alarmCounters");