Browse Source

Adds all query types to aclk_processed_query_type (#12036)

* all query types in stats
Timotej S 3 years ago
parent
commit
4da3e67a37
6 changed files with 45 additions and 87 deletions
  1. 28 18
      aclk/aclk_query.c
  2. 4 0
      aclk/aclk_query.h
  3. 0 35
      aclk/aclk_query_queue.c
  4. 3 2
      aclk/aclk_query_queue.h
  5. 8 24
      aclk/aclk_stats.c
  6. 2 8
      aclk/aclk_stats.h

+ 28 - 18
aclk/aclk_query.c

@@ -2,7 +2,6 @@
 
 #include "aclk_query.h"
 #include "aclk_stats.h"
-#include "aclk_query_queue.h"
 #include "aclk_tx_msgs.h"
 
 #define ACLK_QUERY_THREAD_NAME "ACLK_Query"
@@ -287,27 +286,37 @@ static int send_bin_msg(struct aclk_query_thread *query_thr, aclk_query_t query)
 #endif
 
 aclk_query_handler aclk_query_handlers[] = {
-    { .type = HTTP_API_V2,          .name = "http api request v2",      .fnc = http_api_v2              },
-    { .type = ALARM_STATE_UPDATE,   .name = "alarm state update",       .fnc = alarm_state_update_query },
-    { .type = METADATA_INFO,        .name = "info metadata",            .fnc = info_metadata            },
-    { .type = METADATA_ALARMS,      .name = "alarms metadata",          .fnc = alarms_metadata          },
-    { .type = CHART_NEW,            .name = "chart new",                .fnc = chart_query              },
-    { .type = CHART_DEL,            .name = "chart delete",             .fnc = info_metadata            },
+    { .type = HTTP_API_V2,          .name = "http_api_request_v2",      .fnc = http_api_v2              },
+    { .type = ALARM_STATE_UPDATE,   .name = "alarm_state_update",       .fnc = alarm_state_update_query },
+    { .type = METADATA_INFO,        .name = "info_metadata",            .fnc = info_metadata            },
+    { .type = METADATA_ALARMS,      .name = "alarms_metadata",          .fnc = alarms_metadata          },
+    { .type = CHART_NEW,            .name = "chart_new",                .fnc = chart_query              },
+    { .type = CHART_DEL,            .name = "chart_delete",             .fnc = info_metadata            },
 #ifdef ENABLE_NEW_CLOUD_PROTOCOL
-    { .type = REGISTER_NODE,        .name = "register node",            .fnc = register_node            },
-    { .type = NODE_STATE_UPDATE,    .name = "node state update",        .fnc = node_state_update        },
-    { .type = CHART_DIMS_UPDATE,    .name = "chart and dim update bin", .fnc = send_bin_msg             },
-    { .type = CHART_CONFIG_UPDATED, .name = "chart config updated",     .fnc = send_bin_msg             },
-    { .type = CHART_RESET,          .name = "reset chart messages",     .fnc = send_bin_msg             },
-    { .type = RETENTION_UPDATED,    .name = "update retention info",    .fnc = send_bin_msg             },
-    { .type = UPDATE_NODE_INFO,     .name = "update node info",         .fnc = send_bin_msg             },
-    { .type = ALARM_LOG_HEALTH,     .name = "alarm log health",         .fnc = send_bin_msg             },
-    { .type = ALARM_PROVIDE_CFG,    .name = "provide alarm config",     .fnc = send_bin_msg             },
-    { .type = ALARM_SNAPSHOT,       .name = "alarm snapshot",           .fnc = send_bin_msg             },
+    { .type = REGISTER_NODE,        .name = "register_node",            .fnc = register_node            },
+    { .type = NODE_STATE_UPDATE,    .name = "node_state_update",        .fnc = node_state_update        },
+    { .type = CHART_DIMS_UPDATE,    .name = "chart_and_dim_update",     .fnc = send_bin_msg             },
+    { .type = CHART_CONFIG_UPDATED, .name = "chart_config_updated",     .fnc = send_bin_msg             },
+    { .type = CHART_RESET,          .name = "reset_chart_messages",     .fnc = send_bin_msg             },
+    { .type = RETENTION_UPDATED,    .name = "update_retention_info",    .fnc = send_bin_msg             },
+    { .type = UPDATE_NODE_INFO,     .name = "update_node_info",         .fnc = send_bin_msg             },
+    { .type = ALARM_LOG_HEALTH,     .name = "alarm_log_health",         .fnc = send_bin_msg             },
+    { .type = ALARM_PROVIDE_CFG,    .name = "provide_alarm_config",     .fnc = send_bin_msg             },
+    { .type = ALARM_SNAPSHOT,       .name = "alarm_snapshot",           .fnc = send_bin_msg             },
 #endif
     { .type = UNKNOWN,              .name = NULL,                       .fnc = NULL                     }
 };
 
+const char *aclk_query_get_name(aclk_query_type_t qt)
+{
+    aclk_query_handler *ptr = aclk_query_handlers;
+    while (ptr->type != UNKNOWN) {
+        if (ptr->type == qt)
+            return ptr->name;
+        ptr++;
+    }
+    return "unknown";
+}
 
 static void aclk_query_process_msg(struct aclk_query_thread *query_thr, aclk_query_t query)
 {
@@ -315,13 +324,14 @@ static void aclk_query_process_msg(struct aclk_query_thread *query_thr, aclk_que
         if (aclk_query_handlers[i].type == query->type) {
             debug(D_ACLK, "Processing Queued Message of type: \"%s\"", aclk_query_handlers[i].name);
             aclk_query_handlers[i].fnc(query_thr, query);
-            aclk_query_free(query);
             if (aclk_stats_enabled) {
                 ACLK_STATS_LOCK;
                 aclk_metrics_per_sample.queries_dispatched++;
                 aclk_queries_per_thread[query_thr->idx]++;
+                aclk_metrics_per_sample.queries_per_type[query->type]++;
                 ACLK_STATS_UNLOCK;
             }
+            aclk_query_free(query);
             return;
         }
     }

+ 4 - 0
aclk/aclk_query.h

@@ -7,6 +7,8 @@
 
 #include "mqtt_wss_client.h"
 
+#include "aclk_query_queue.h"
+
 extern pthread_cond_t query_cond_wait;
 extern pthread_mutex_t query_lock_wait;
 #define QUERY_THREAD_WAKEUP pthread_cond_signal(&query_cond_wait)
@@ -29,4 +31,6 @@ struct aclk_query_threads {
 void aclk_query_threads_start(struct aclk_query_threads *query_threads, mqtt_wss_client client);
 void aclk_query_threads_cleanup(struct aclk_query_threads *query_threads);
 
+const char *aclk_query_get_name(aclk_query_type_t qt);
+
 #endif //NETDATA_AGENT_CLOUD_LINK_H

+ 0 - 35
aclk/aclk_query_queue.c

@@ -45,49 +45,14 @@ static inline int _aclk_queue_query(aclk_query_t query)
 
 }
 
-// Gets a pointer to the metric associated with a particular query type.
-// NULL if the query type has no associated metric.
-static inline volatile uint32_t *aclk_stats_qmetric_for_qtype(aclk_query_type_t qtype) {
-    switch (qtype) {
-        case HTTP_API_V2:
-            return &aclk_metrics_per_sample.query_type_http;
-        case ALARM_STATE_UPDATE:
-            return &aclk_metrics_per_sample.query_type_alarm_upd;
-        case METADATA_INFO:
-            return &aclk_metrics_per_sample.query_type_metadata_info;
-        case METADATA_ALARMS:
-            return &aclk_metrics_per_sample.query_type_metadata_alarms;
-        case CHART_NEW:
-            return &aclk_metrics_per_sample.query_type_chart_new;
-        case CHART_DEL:
-            return &aclk_metrics_per_sample.query_type_chart_del;
-        case REGISTER_NODE:
-            return &aclk_metrics_per_sample.query_type_register_node;
-        case NODE_STATE_UPDATE:
-            return &aclk_metrics_per_sample.query_type_node_upd;
-        default:
-            return NULL;
-    }
-}
-
 int aclk_queue_query(aclk_query_t query)
 {
     int ret = _aclk_queue_query(query);
     if (!ret) {
-        // local cache of query type before we wake up query thread, which may
-        // free the query in a race.
-        aclk_query_type_t qtype = query->type;
         QUERY_THREAD_WAKEUP;
-
         if (aclk_stats_enabled) {
-            // get target query type metric before lock so we keep lock for
-            // minimal time.
-            volatile uint32_t *metric = aclk_stats_qmetric_for_qtype(qtype);
-
             ACLK_STATS_LOCK;
             aclk_metrics_per_sample.queries_queued++;
-            if (metric)
-                *metric += 1;
             ACLK_STATS_UNLOCK;
         }
     }

+ 3 - 2
aclk/aclk_query_queue.h

@@ -10,7 +10,7 @@
 #include "aclk_util.h"
 
 typedef enum {
-    UNKNOWN,
+    UNKNOWN = 0,
     METADATA_INFO,
     METADATA_ALARMS,
     HTTP_API_V2,
@@ -26,7 +26,8 @@ typedef enum {
     UPDATE_NODE_INFO,
     ALARM_LOG_HEALTH,
     ALARM_PROVIDE_CFG,
-    ALARM_SNAPSHOT
+    ALARM_SNAPSHOT,
+    ACLK_QUERY_TYPE_COUNT // always keep this as last
 } aclk_query_type_t;
 
 struct aclk_query_metadata {

+ 8 - 24
aclk/aclk_stats.c

@@ -2,6 +2,8 @@
 
 #include "aclk_stats.h"
 
+#include "aclk_query.h"
+
 netdata_mutex_t aclk_stats_mutex = NETDATA_MUTEX_INITIALIZER;
 
 int query_thread_count;
@@ -113,39 +115,21 @@ static void aclk_stats_cloud_req(struct aclk_metrics_per_sample *per_sample)
 static void aclk_stats_cloud_req_type(struct aclk_metrics_per_sample *per_sample)
 {
     static RRDSET *st = NULL;
-    static RRDDIM *rd_type_http = NULL;
-    static RRDDIM *rd_type_alarm_upd = NULL;
-    static RRDDIM *rd_type_metadata_info = NULL;
-    static RRDDIM *rd_type_metadata_alarms = NULL;
-    static RRDDIM *rd_type_chart_new = NULL;
-    static RRDDIM *rd_type_chart_del = NULL;
-    static RRDDIM *rd_type_register_node = NULL;
-    static RRDDIM *rd_type_node_upd = NULL;
+    static RRDDIM *dims[ACLK_QUERY_TYPE_COUNT];
 
     if (unlikely(!st)) {
         st = rrdset_create_localhost(
             "netdata", "aclk_processed_query_type", NULL, "aclk", NULL, "Query thread commands processed by their type", "cmd/s",
             "netdata", "stats", 200006, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
 
-        rd_type_http = rrddim_add(st, "http", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_alarm_upd = rrddim_add(st, "alarm update", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_metadata_info = rrddim_add(st, "info metadata", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_metadata_alarms = rrddim_add(st, "alarms metadata", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_chart_new = rrddim_add(st, "chart new", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_chart_del = rrddim_add(st, "chart delete", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_register_node = rrddim_add(st, "register node", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
-        rd_type_node_upd = rrddim_add(st, "node update", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
+        for (int i = 0; i < ACLK_QUERY_TYPE_COUNT; i++)
+            dims[i] = rrddim_add(st, aclk_query_get_name(i), NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
+
     } else
         rrdset_next(st);
 
-    rrddim_set_by_pointer(st, rd_type_http, per_sample->query_type_http);
-    rrddim_set_by_pointer(st, rd_type_alarm_upd, per_sample->query_type_alarm_upd);
-    rrddim_set_by_pointer(st, rd_type_metadata_info, per_sample->query_type_metadata_info);
-    rrddim_set_by_pointer(st, rd_type_metadata_alarms, per_sample->query_type_metadata_alarms);
-    rrddim_set_by_pointer(st, rd_type_chart_new, per_sample->query_type_chart_new);
-    rrddim_set_by_pointer(st, rd_type_chart_del, per_sample->query_type_chart_del);
-    rrddim_set_by_pointer(st, rd_type_register_node, per_sample->query_type_register_node);
-    rrddim_set_by_pointer(st, rd_type_node_upd, per_sample->query_type_node_upd);
+    for (int i = 0; i < ACLK_QUERY_TYPE_COUNT; i++)
+        rrddim_set_by_pointer(st, dims[i], per_sample->queries_per_type[i]);
 
     rrdset_done(st);
 }

+ 2 - 8
aclk/aclk_stats.h

@@ -5,6 +5,7 @@
 
 #include "daemon/common.h"
 #include "libnetdata/libnetdata.h"
+#include "aclk_query_queue.h"
 
 #define ACLK_STATS_THREAD_NAME "ACLK_Stats"
 
@@ -49,14 +50,7 @@ extern struct aclk_metrics_per_sample {
     volatile uint32_t cloud_req_err;
 
     // query types.
-    volatile uint32_t query_type_http;
-    volatile uint32_t query_type_alarm_upd;
-    volatile uint32_t query_type_metadata_info;
-    volatile uint32_t query_type_metadata_alarms;
-    volatile uint32_t query_type_chart_new;
-    volatile uint32_t query_type_chart_del;
-    volatile uint32_t query_type_register_node;
-    volatile uint32_t query_type_node_upd;
+    volatile uint32_t queries_per_type[ACLK_QUERY_TYPE_COUNT];
 
     // HTTP-specific request types.
     volatile uint32_t cloud_req_http_by_type[ACLK_STATS_CLOUD_HTTP_REQ_TYPE_CNT];