log a summary of metadata ignored contexts (#19348)
Costa Tsaousis committed
Jan 8, 2025 at 14:57 UTC
079c6ff9d1c6a595d1f9514f5201ba7b5853c9fc
4 files changed
+148
-127
CMakeLists.txt
+1
@@ -1454,6 +1454,7 @@ set(RRD_PLUGIN_FILES
1454
src/database/rrd-database-mode.c
1455
src/database/rrdhost-system-info.c
1456
src/database/rrdhost-system-info.h
1457
+ src/database/contexts/contexts-loading.c
1458
)
1459
1460
if(ENABLE_DBENGINE)
src/database/contexts/contexts-loading.c
new
+144
@@ -0,0 +1,144 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#include "internal.h"
4
+
5
+static __thread size_t ignored_contexts_on_metrics = 0, ignored_contexts_on_instances = 0,
6
+ ignored_instances_on_metrics = 0;
7
+
8
+static void rrdinstance_load_clabel(SQL_CLABEL_DATA *sld, void *data) {
9
+ RRDINSTANCE *ri = data;
10
+ rrdlabels_add(ri->rrdlabels, sld->label_key, sld->label_value, sld->label_source);
11
+}
12
+
13
+void load_instance_labels_on_demand(nd_uuid_t *uuid, void *data) {
14
+ ctx_get_label_list(uuid, rrdinstance_load_clabel, data);
15
+}
16
+
17
+static void rrdinstance_load_dimension_callback(SQL_DIMENSION_DATA *sd, void *data) {
18
+ RRDHOST *host = data;
19
+ RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdctx.contexts, sd->context);
20
+ if(!rca) {
21
+ ignored_contexts_on_metrics++;
22
+// nd_log(NDLS_DAEMON, NDLP_ERR,
23
+// "RRDCONTEXT: context '%s' is not found in host '%s' - not loading dimensions",
24
+// sd->context, rrdhost_hostname(host));
25
+ return;
26
+ }
27
+ RRDCONTEXT *rc = rrdcontext_acquired_value(rca);
28
+
29
+ RRDINSTANCE_ACQUIRED *ria = (RRDINSTANCE_ACQUIRED *)dictionary_get_and_acquire_item(rc->rrdinstances, sd->chart_id);
30
+ if(!ria) {
31
+ rrdcontext_release(rca);
32
+ ignored_instances_on_metrics++;
33
+// nd_log(NDLS_DAEMON, NDLP_ERR,
34
+// "RRDCONTEXT: instance '%s' of context '%s' is not found in host '%s' - not loading dimensions",
35
+// sd->chart_id, sd->context, rrdhost_hostname(host));
36
+ return;
37
+ }
38
+ RRDINSTANCE *ri = rrdinstance_acquired_value(ria);
39
+
40
+ RRDMETRIC trm = {
41
+ .id = string_strdupz(sd->id),
42
+ .name = string_strdupz(sd->name),
43
+ .flags = RRD_FLAG_ARCHIVED | RRD_FLAG_UPDATE_REASON_LOAD_SQL, // no need for atomic
44
+ };
45
+ if(sd->hidden) trm.flags |= RRD_FLAG_HIDDEN;
46
+
47
+ uuid_copy(trm.uuid, sd->dim_id);
48
+
49
+ dictionary_set(ri->rrdmetrics, string2str(trm.id), &trm, sizeof(trm));
50
+
51
+ rrdinstance_release(ria);
52
+ rrdcontext_release(rca);
53
+}
54
+
55
+static void rrdinstance_load_instance_callback(SQL_CHART_DATA *sc, void *data) {
56
+ RRDHOST *host = data;
57
+
58
+ RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdctx.contexts, sc->context);
59
+ if(!rca) {
60
+ ignored_contexts_on_instances++;
61
+// nd_log(NDLS_DAEMON, NDLP_ERR,
62
+// "RRDCONTEXT: context '%s' is not found in host '%s' - not loadings instances",
63
+// sc->context, rrdhost_hostname(host));
64
+ return;
65
+ }
66
+ RRDCONTEXT *rc = rrdcontext_acquired_value(rca);
67
+
68
+ RRDINSTANCE tri = {
69
+ .id = string_strdupz(sc->id),
70
+ .name = string_strdupz(sc->name),
71
+ .title = string_strdupz(sc->title),
72
+ .units = string_strdupz(sc->units),
73
+ .family = string_strdupz(sc->family),
74
+ .chart_type = sc->chart_type,
75
+ .priority = sc->priority,
76
+ .update_every_s = sc->update_every,
77
+ .flags = RRD_FLAG_ARCHIVED | RRD_FLAG_UPDATE_REASON_LOAD_SQL, // no need for atomics
78
+ };
79
+ uuid_copy(tri.uuid, sc->chart_id);
80
+
81
+ RRDINSTANCE_ACQUIRED *ria = (RRDINSTANCE_ACQUIRED *)dictionary_set_and_acquire_item(rc->rrdinstances, sc->id, &tri, sizeof(tri));
82
+
83
+ rrdinstance_release(ria);
84
+ rrdcontext_release(rca);
85
+}
86
+
87
+static void rrdcontext_load_context_callback(VERSIONED_CONTEXT_DATA *ctx_data, void *data) {
88
+ RRDHOST *host = data;
89
+ (void)host;
90
+
91
+ RRDCONTEXT trc = {
92
+ .id = string_strdupz(ctx_data->id),
93
+ .flags = RRD_FLAG_ARCHIVED | RRD_FLAG_UPDATE_REASON_LOAD_SQL, // no need for atomics
94
+
95
+ // no need to set more data here
96
+ // we only need the hub data
97
+
98
+ .hub = *ctx_data,
99
+ };
100
+ dictionary_set(host->rrdctx.contexts, string2str(trc.id), &trc, sizeof(trc));
101
+}
102
+
103
+void rrdhost_load_rrdcontext_data(RRDHOST *host) {
104
+ if(host->rrdctx.contexts) return;
105
+
106
+ rrdhost_create_rrdcontexts(host);
107
+ if (host->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)
108
+ return;
109
+
110
+ ignored_contexts_on_metrics = 0;
111
+ ignored_contexts_on_instances = 0;
112
+ ignored_instances_on_metrics = 0;
113
+
114
+ ctx_get_context_list(&host->host_id.uuid, rrdcontext_load_context_callback, host);
115
+ ctx_get_chart_list(&host->host_id.uuid, rrdinstance_load_instance_callback, host);
116
+ ctx_get_dimension_list(&host->host_id.uuid, rrdinstance_load_dimension_callback, host);
117
+
118
+ if(ignored_contexts_on_instances + ignored_contexts_on_metrics + ignored_instances_on_metrics)
119
+ nd_log(NDLS_DAEMON, NDLP_WARNING,
120
+ "RRDCONTEXT: metadata report for node '%s':"
121
+ " did not load %zu contexts and %zu instances while loading metrics, "
122
+ " and %zu contexts while loadings instances",
123
+ rrdhost_hostname(host),
124
+ ignored_contexts_on_metrics, ignored_instances_on_metrics,
125
+ ignored_contexts_on_instances);
126
+
127
+ RRDCONTEXT *rc;
128
+ dfe_start_read(host->rrdctx.contexts, rc) {
129
+ RRDINSTANCE *ri;
130
+ dfe_start_read(rc->rrdinstances, ri) {
131
+ RRDMETRIC *rm;
132
+ dfe_start_read(ri->rrdmetrics, rm) {
133
+ rrdmetric_trigger_updates(rm, __FUNCTION__ );
134
+ }
135
+ dfe_done(rm);
136
+ rrdinstance_trigger_updates(ri, __FUNCTION__ );
137
+ }
138
+ dfe_done(ri);
139
+ rrdcontext_trigger_updates(rc, __FUNCTION__ );
140
+ }
141
+ dfe_done(rc);
142
+
143
+ rrdcontext_garbage_collect_single_host(host, false);
144
+}
src/database/contexts/internal.h
+2
@@ -468,4 +468,6 @@ void rrdcontext_message_send_unsafe(RRDCONTEXT *rc, bool snapshot __maybe_unused
468
469
void rrdcontext_update_from_collected_rrdinstance(RRDINSTANCE *ri);
470
471
+void rrdcontext_garbage_collect_single_host(RRDHOST *host, bool worker_jobs);
472
+
473
#endif //NETDATA_RRDCONTEXT_INTERNAL_H
src/database/contexts/worker.c
+1
-127
@@ -11,136 +11,10 @@ static void rrdcontext_delete_from_sql_unsafe(RRDCONTEXT *rc);
11
static void rrdcontext_dequeue_from_post_processing(RRDCONTEXT *rc);
12
static void rrdcontext_post_process_updates(RRDCONTEXT *rc, bool force, RRD_FLAGS reason, bool worker_jobs);
13
14
-static void rrdcontext_garbage_collect_single_host(RRDHOST *host, bool worker_jobs);
14
static void rrdcontext_garbage_collect_for_all_hosts(void);
15
16
extern usec_t rrdcontext_next_db_rotation_ut;
17
19
-// ----------------------------------------------------------------------------
20
-// load from SQL
21
-
22
-static void rrdinstance_load_clabel(SQL_CLABEL_DATA *sld, void *data) {
23
- RRDINSTANCE *ri = data;
24
- rrdlabels_add(ri->rrdlabels, sld->label_key, sld->label_value, sld->label_source);
25
-}
26
-
27
-void load_instance_labels_on_demand(nd_uuid_t *uuid, void *data) {
28
- ctx_get_label_list(uuid, rrdinstance_load_clabel, data);
29
-}
30
-
31
-static void rrdinstance_load_dimension_callback(SQL_DIMENSION_DATA *sd, void *data) {
32
- RRDHOST *host = data;
33
- RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdctx.contexts, sd->context);
34
- if(!rca) {
35
- nd_log(NDLS_DAEMON, NDLP_ERR,
36
- "RRDCONTEXT: context '%s' is not found in host '%s' - not loading dimensions",
37
- sd->context, rrdhost_hostname(host));
38
- return;
39
- }
40
- RRDCONTEXT *rc = rrdcontext_acquired_value(rca);
41
-
42
- RRDINSTANCE_ACQUIRED *ria = (RRDINSTANCE_ACQUIRED *)dictionary_get_and_acquire_item(rc->rrdinstances, sd->chart_id);
43
- if(!ria) {
44
- rrdcontext_release(rca);
45
- nd_log(NDLS_DAEMON, NDLP_ERR,
46
- "RRDCONTEXT: instance '%s' of context '%s' is not found in host '%s' - not loading dimensions",
47
- sd->chart_id, sd->context, rrdhost_hostname(host));
48
- return;
49
- }
50
- RRDINSTANCE *ri = rrdinstance_acquired_value(ria);
51
-
52
- RRDMETRIC trm = {
53
- .id = string_strdupz(sd->id),
54
- .name = string_strdupz(sd->name),
55
- .flags = RRD_FLAG_ARCHIVED | RRD_FLAG_UPDATE_REASON_LOAD_SQL, // no need for atomic
56
- };
57
- if(sd->hidden) trm.flags |= RRD_FLAG_HIDDEN;
58
-
59
- uuid_copy(trm.uuid, sd->dim_id);
60
-
61
- dictionary_set(ri->rrdmetrics, string2str(trm.id), &trm, sizeof(trm));
62
-
63
- rrdinstance_release(ria);
64
- rrdcontext_release(rca);
65
-}
66
-
67
-static void rrdinstance_load_instance_callback(SQL_CHART_DATA *sc, void *data) {
68
- RRDHOST *host = data;
69
-
70
- RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdctx.contexts, sc->context);
71
- if(!rca) {
72
- nd_log(NDLS_DAEMON, NDLP_ERR,
73
- "RRDCONTEXT: context '%s' is not found in host '%s' - not loadings instances",
74
- sc->context, rrdhost_hostname(host));
75
- return;
76
- }
77
- RRDCONTEXT *rc = rrdcontext_acquired_value(rca);
78
-
79
- RRDINSTANCE tri = {
80
- .id = string_strdupz(sc->id),
81
- .name = string_strdupz(sc->name),
82
- .title = string_strdupz(sc->title),
83
- .units = string_strdupz(sc->units),
84
- .family = string_strdupz(sc->family),
85
- .chart_type = sc->chart_type,
86
- .priority = sc->priority,
87
- .update_every_s = sc->update_every,
88
- .flags = RRD_FLAG_ARCHIVED | RRD_FLAG_UPDATE_REASON_LOAD_SQL, // no need for atomics
89
- };
90
- uuid_copy(tri.uuid, sc->chart_id);
91
-
92
- RRDINSTANCE_ACQUIRED *ria = (RRDINSTANCE_ACQUIRED *)dictionary_set_and_acquire_item(rc->rrdinstances, sc->id, &tri, sizeof(tri));
93
-
94
- rrdinstance_release(ria);
95
- rrdcontext_release(rca);
96
-}
97
-
98
-static void rrdcontext_load_context_callback(VERSIONED_CONTEXT_DATA *ctx_data, void *data) {
99
- RRDHOST *host = data;
100
- (void)host;
101
-
102
- RRDCONTEXT trc = {
103
- .id = string_strdupz(ctx_data->id),
104
- .flags = RRD_FLAG_ARCHIVED | RRD_FLAG_UPDATE_REASON_LOAD_SQL, // no need for atomics
105
-
106
- // no need to set more data here
107
- // we only need the hub data
108
-
109
- .hub = *ctx_data,
110
- };
111
- dictionary_set(host->rrdctx.contexts, string2str(trc.id), &trc, sizeof(trc));
112
-}
113
-
114
-void rrdhost_load_rrdcontext_data(RRDHOST *host) {
115
- if(host->rrdctx.contexts) return;
116
-
117
- rrdhost_create_rrdcontexts(host);
118
- if (host->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)
119
- return;
120
-
121
- ctx_get_context_list(&host->host_id.uuid, rrdcontext_load_context_callback, host);
122
- ctx_get_chart_list(&host->host_id.uuid, rrdinstance_load_instance_callback, host);
123
- ctx_get_dimension_list(&host->host_id.uuid, rrdinstance_load_dimension_callback, host);
124
-
125
- RRDCONTEXT *rc;
126
- dfe_start_read(host->rrdctx.contexts, rc) {
127
- RRDINSTANCE *ri;
128
- dfe_start_read(rc->rrdinstances, ri) {
129
- RRDMETRIC *rm;
130
- dfe_start_read(ri->rrdmetrics, rm) {
131
- rrdmetric_trigger_updates(rm, __FUNCTION__ );
132
- }
133
- dfe_done(rm);
134
- rrdinstance_trigger_updates(ri, __FUNCTION__ );
135
- }
136
- dfe_done(ri);
137
- rrdcontext_trigger_updates(rc, __FUNCTION__ );
138
- }
139
- dfe_done(rc);
140
-
141
- rrdcontext_garbage_collect_single_host(host, false);
142
-}
143
-
18
// ----------------------------------------------------------------------------
19
// version hash calculation
20
@@ -394,7 +268,7 @@ void rrdcontext_delete_from_sql_unsafe(RRDCONTEXT *rc) {
268
rc->hub.id, rc->hub.version);
269
}
270
397
-static void rrdcontext_garbage_collect_single_host(RRDHOST *host, bool worker_jobs) {
271
+void rrdcontext_garbage_collect_single_host(RRDHOST *host, bool worker_jobs) {
272
273
internal_error(true, "RRDCONTEXT: garbage collecting context structures of host '%s'", rrdhost_hostname(host));
274