Adds all query types to aclk_processed_query_type (#12036)
* all query types in stats
Timotej S committed
Feb 24, 2022 at 17:20 UTC
4da3e67a378ce938c07eb97a44bb2786e48a2ec2
6 files changed
+45
-87
aclk/aclk_query.c
+28
-18
@@ -2,7 +2,6 @@
2
3
#include "aclk_query.h"
4
#include "aclk_stats.h"
5
-#include "aclk_query_queue.h"
5
#include "aclk_tx_msgs.h"
6
7
#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)
286
#endif
287
288
aclk_query_handler aclk_query_handlers[] = {
290
- { .type = HTTP_API_V2, .name = "http api request v2", .fnc = http_api_v2 },
291
- { .type = ALARM_STATE_UPDATE, .name = "alarm state update", .fnc = alarm_state_update_query },
292
- { .type = METADATA_INFO, .name = "info metadata", .fnc = info_metadata },
293
- { .type = METADATA_ALARMS, .name = "alarms metadata", .fnc = alarms_metadata },
294
- { .type = CHART_NEW, .name = "chart new", .fnc = chart_query },
295
- { .type = CHART_DEL, .name = "chart delete", .fnc = info_metadata },
289
+ { .type = HTTP_API_V2, .name = "http_api_request_v2", .fnc = http_api_v2 },
290
+ { .type = ALARM_STATE_UPDATE, .name = "alarm_state_update", .fnc = alarm_state_update_query },
291
+ { .type = METADATA_INFO, .name = "info_metadata", .fnc = info_metadata },
292
+ { .type = METADATA_ALARMS, .name = "alarms_metadata", .fnc = alarms_metadata },
293
+ { .type = CHART_NEW, .name = "chart_new", .fnc = chart_query },
294
+ { .type = CHART_DEL, .name = "chart_delete", .fnc = info_metadata },
295
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
297
- { .type = REGISTER_NODE, .name = "register node", .fnc = register_node },
298
- { .type = NODE_STATE_UPDATE, .name = "node state update", .fnc = node_state_update },
299
- { .type = CHART_DIMS_UPDATE, .name = "chart and dim update bin", .fnc = send_bin_msg },
300
- { .type = CHART_CONFIG_UPDATED, .name = "chart config updated", .fnc = send_bin_msg },
301
- { .type = CHART_RESET, .name = "reset chart messages", .fnc = send_bin_msg },
302
- { .type = RETENTION_UPDATED, .name = "update retention info", .fnc = send_bin_msg },
303
- { .type = UPDATE_NODE_INFO, .name = "update node info", .fnc = send_bin_msg },
304
- { .type = ALARM_LOG_HEALTH, .name = "alarm log health", .fnc = send_bin_msg },
305
- { .type = ALARM_PROVIDE_CFG, .name = "provide alarm config", .fnc = send_bin_msg },
306
- { .type = ALARM_SNAPSHOT, .name = "alarm snapshot", .fnc = send_bin_msg },
296
+ { .type = REGISTER_NODE, .name = "register_node", .fnc = register_node },
297
+ { .type = NODE_STATE_UPDATE, .name = "node_state_update", .fnc = node_state_update },
298
+ { .type = CHART_DIMS_UPDATE, .name = "chart_and_dim_update", .fnc = send_bin_msg },
299
+ { .type = CHART_CONFIG_UPDATED, .name = "chart_config_updated", .fnc = send_bin_msg },
300
+ { .type = CHART_RESET, .name = "reset_chart_messages", .fnc = send_bin_msg },
301
+ { .type = RETENTION_UPDATED, .name = "update_retention_info", .fnc = send_bin_msg },
302
+ { .type = UPDATE_NODE_INFO, .name = "update_node_info", .fnc = send_bin_msg },
303
+ { .type = ALARM_LOG_HEALTH, .name = "alarm_log_health", .fnc = send_bin_msg },
304
+ { .type = ALARM_PROVIDE_CFG, .name = "provide_alarm_config", .fnc = send_bin_msg },
305
+ { .type = ALARM_SNAPSHOT, .name = "alarm_snapshot", .fnc = send_bin_msg },
306
#endif
307
{ .type = UNKNOWN, .name = NULL, .fnc = NULL }
308
};
309
310
+const char *aclk_query_get_name(aclk_query_type_t qt)
311
+{
312
+ aclk_query_handler *ptr = aclk_query_handlers;
313
+ while (ptr->type != UNKNOWN) {
314
+ if (ptr->type == qt)
315
+ return ptr->name;
316
+ ptr++;
317
+ }
318
+ return "unknown";
319
+}
320
321
static void aclk_query_process_msg(struct aclk_query_thread *query_thr, aclk_query_t query)
322
{
@@ -315,13 +324,14 @@ static void aclk_query_process_msg(struct aclk_query_thread *query_thr, aclk_que
324
if (aclk_query_handlers[i].type == query->type) {
325
debug(D_ACLK, "Processing Queued Message of type: \"%s\"", aclk_query_handlers[i].name);
326
aclk_query_handlers[i].fnc(query_thr, query);
318
- aclk_query_free(query);
327
if (aclk_stats_enabled) {
328
ACLK_STATS_LOCK;
329
aclk_metrics_per_sample.queries_dispatched++;
330
aclk_queries_per_thread[query_thr->idx]++;
331
+ aclk_metrics_per_sample.queries_per_type[query->type]++;
332
ACLK_STATS_UNLOCK;
333
}
334
+ aclk_query_free(query);
335
return;
336
}
337
}
aclk/aclk_query.h
+4
@@ -7,6 +7,8 @@
7
8
#include "mqtt_wss_client.h"
9
10
+#include "aclk_query_queue.h"
11
+
12
extern pthread_cond_t query_cond_wait;
13
extern pthread_mutex_t query_lock_wait;
14
#define QUERY_THREAD_WAKEUP pthread_cond_signal(&query_cond_wait)
@@ -29,4 +31,6 @@ struct aclk_query_threads {
31
void aclk_query_threads_start(struct aclk_query_threads *query_threads, mqtt_wss_client client);
32
void aclk_query_threads_cleanup(struct aclk_query_threads *query_threads);
33
34
+const char *aclk_query_get_name(aclk_query_type_t qt);
35
+
36
#endif //NETDATA_AGENT_CLOUD_LINK_H
aclk/aclk_query_queue.c
-35
@@ -45,49 +45,14 @@ static inline int _aclk_queue_query(aclk_query_t query)
45
46
}
47
48
-// Gets a pointer to the metric associated with a particular query type.
49
-// NULL if the query type has no associated metric.
50
-static inline volatile uint32_t *aclk_stats_qmetric_for_qtype(aclk_query_type_t qtype) {
51
- switch (qtype) {
52
- case HTTP_API_V2:
53
- return &aclk_metrics_per_sample.query_type_http;
54
- case ALARM_STATE_UPDATE:
55
- return &aclk_metrics_per_sample.query_type_alarm_upd;
56
- case METADATA_INFO:
57
- return &aclk_metrics_per_sample.query_type_metadata_info;
58
- case METADATA_ALARMS:
59
- return &aclk_metrics_per_sample.query_type_metadata_alarms;
60
- case CHART_NEW:
61
- return &aclk_metrics_per_sample.query_type_chart_new;
62
- case CHART_DEL:
63
- return &aclk_metrics_per_sample.query_type_chart_del;
64
- case REGISTER_NODE:
65
- return &aclk_metrics_per_sample.query_type_register_node;
66
- case NODE_STATE_UPDATE:
67
- return &aclk_metrics_per_sample.query_type_node_upd;
68
- default:
69
- return NULL;
70
- }
71
-}
72
-
48
int aclk_queue_query(aclk_query_t query)
49
{
50
int ret = _aclk_queue_query(query);
51
if (!ret) {
77
- // local cache of query type before we wake up query thread, which may
78
- // free the query in a race.
79
- aclk_query_type_t qtype = query->type;
52
QUERY_THREAD_WAKEUP;
81
-
53
if (aclk_stats_enabled) {
83
- // get target query type metric before lock so we keep lock for
84
- // minimal time.
85
- volatile uint32_t *metric = aclk_stats_qmetric_for_qtype(qtype);
86
-
54
ACLK_STATS_LOCK;
55
aclk_metrics_per_sample.queries_queued++;
89
- if (metric)
90
- *metric += 1;
56
ACLK_STATS_UNLOCK;
57
}
58
}
aclk/aclk_query_queue.h
+3
-2
@@ -10,7 +10,7 @@
10
#include "aclk_util.h"
11
12
typedef enum {
13
- UNKNOWN,
13
+ UNKNOWN = 0,
14
METADATA_INFO,
15
METADATA_ALARMS,
16
HTTP_API_V2,
@@ -26,7 +26,8 @@ typedef enum {
26
UPDATE_NODE_INFO,
27
ALARM_LOG_HEALTH,
28
ALARM_PROVIDE_CFG,
29
- ALARM_SNAPSHOT
29
+ ALARM_SNAPSHOT,
30
+ ACLK_QUERY_TYPE_COUNT // always keep this as last
31
} aclk_query_type_t;
32
33
struct aclk_query_metadata {
aclk/aclk_stats.c
+8
-24
@@ -2,6 +2,8 @@
2
3
#include "aclk_stats.h"
4
5
+#include "aclk_query.h"
6
+
7
netdata_mutex_t aclk_stats_mutex = NETDATA_MUTEX_INITIALIZER;
8
9
int query_thread_count;
@@ -113,39 +115,21 @@ static void aclk_stats_cloud_req(struct aclk_metrics_per_sample *per_sample)
115
static void aclk_stats_cloud_req_type(struct aclk_metrics_per_sample *per_sample)
116
{
117
static RRDSET *st = NULL;
116
- static RRDDIM *rd_type_http = NULL;
117
- static RRDDIM *rd_type_alarm_upd = NULL;
118
- static RRDDIM *rd_type_metadata_info = NULL;
119
- static RRDDIM *rd_type_metadata_alarms = NULL;
120
- static RRDDIM *rd_type_chart_new = NULL;
121
- static RRDDIM *rd_type_chart_del = NULL;
122
- static RRDDIM *rd_type_register_node = NULL;
123
- static RRDDIM *rd_type_node_upd = NULL;
118
+ static RRDDIM *dims[ACLK_QUERY_TYPE_COUNT];
119
120
if (unlikely(!st)) {
121
st = rrdset_create_localhost(
122
"netdata", "aclk_processed_query_type", NULL, "aclk", NULL, "Query thread commands processed by their type", "cmd/s",
123
"netdata", "stats", 200006, localhost->rrd_update_every, RRDSET_TYPE_STACKED);
124
130
- rd_type_http = rrddim_add(st, "http", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
131
- rd_type_alarm_upd = rrddim_add(st, "alarm update", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
132
- rd_type_metadata_info = rrddim_add(st, "info metadata", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
133
- rd_type_metadata_alarms = rrddim_add(st, "alarms metadata", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
134
- rd_type_chart_new = rrddim_add(st, "chart new", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
135
- rd_type_chart_del = rrddim_add(st, "chart delete", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
136
- rd_type_register_node = rrddim_add(st, "register node", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
137
- rd_type_node_upd = rrddim_add(st, "node update", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
125
+ for (int i = 0; i < ACLK_QUERY_TYPE_COUNT; i++)
126
+ dims[i] = rrddim_add(st, aclk_query_get_name(i), NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE);
127
+
128
} else
129
rrdset_next(st);
130
141
- rrddim_set_by_pointer(st, rd_type_http, per_sample->query_type_http);
142
- rrddim_set_by_pointer(st, rd_type_alarm_upd, per_sample->query_type_alarm_upd);
143
- rrddim_set_by_pointer(st, rd_type_metadata_info, per_sample->query_type_metadata_info);
144
- rrddim_set_by_pointer(st, rd_type_metadata_alarms, per_sample->query_type_metadata_alarms);
145
- rrddim_set_by_pointer(st, rd_type_chart_new, per_sample->query_type_chart_new);
146
- rrddim_set_by_pointer(st, rd_type_chart_del, per_sample->query_type_chart_del);
147
- rrddim_set_by_pointer(st, rd_type_register_node, per_sample->query_type_register_node);
148
- rrddim_set_by_pointer(st, rd_type_node_upd, per_sample->query_type_node_upd);
131
+ for (int i = 0; i < ACLK_QUERY_TYPE_COUNT; i++)
132
+ rrddim_set_by_pointer(st, dims[i], per_sample->queries_per_type[i]);
133
134
rrdset_done(st);
135
}
aclk/aclk_stats.h
+2
-8
@@ -5,6 +5,7 @@
5
6
#include "daemon/common.h"
7
#include "libnetdata/libnetdata.h"
8
+#include "aclk_query_queue.h"
9
10
#define ACLK_STATS_THREAD_NAME "ACLK_Stats"
11
@@ -49,14 +50,7 @@ extern struct aclk_metrics_per_sample {
50
volatile uint32_t cloud_req_err;
51
52
// query types.
52
- volatile uint32_t query_type_http;
53
- volatile uint32_t query_type_alarm_upd;
54
- volatile uint32_t query_type_metadata_info;
55
- volatile uint32_t query_type_metadata_alarms;
56
- volatile uint32_t query_type_chart_new;
57
- volatile uint32_t query_type_chart_del;
58
- volatile uint32_t query_type_register_node;
59
- volatile uint32_t query_type_node_upd;
53
+ volatile uint32_t queries_per_type[ACLK_QUERY_TYPE_COUNT];
54
55
// HTTP-specific request types.
56
volatile uint32_t cloud_req_http_by_type[ACLK_STATS_CLOUD_HTTP_REQ_TYPE_CNT];