@cryptotaxi247 / netdata-1 / commits / 8a54890f8

Load chart labels on demand (#18699)

Load labels on demand

Stelios Fragkakis committed Oct 15, 2024 at 10:06 UTC 8a54890f82a38172341cc84ad848fce2ed222f65
3 files changed +37 -26
src/database/contexts/instance.c
+12 -6
@@ -37,6 +37,11 @@ inline STRING *rrdinstance_acquired_units_dup(RRDINSTANCE_ACQUIRED *ria) {
37
38 inline RRDLABELS *rrdinstance_acquired_labels(RRDINSTANCE_ACQUIRED *ria) {
39 RRDINSTANCE *ri = rrdinstance_acquired_value(ria);
40 + if (rrd_flag_check(ri, RRD_FLAG_OWN_LABELS | RRD_FLAG_DEMAND_LABELS)) {
41 + rrd_flag_clear(ri, RRD_FLAG_DEMAND_LABELS);
42 + load_instance_labels_on_demand(&ri->uuid, ri);
43 + rrdinstance_trigger_updates(ri, __FUNCTION__ );
44 + }
45 return ri->rrdlabels;
46 }
47
@@ -101,11 +106,11 @@ static void rrdinstance_insert_callback(const DICTIONARY_ITEM *item __maybe_unus
106
107 if(ri->rrdset) {
108 ri->rrdlabels = ri->rrdset->rrdlabels;
104 - ri->flags &= ~RRD_FLAG_OWN_LABELS; // no need of atomics at the constructor
109 + ri->flags &= ~(RRD_FLAG_OWN_LABELS| RRD_FLAG_DEMAND_LABELS); // no need of atomics at the constructor
110 }
111 else {
112 ri->rrdlabels = rrdlabels_create();
108 - ri->flags |= RRD_FLAG_OWN_LABELS; // no need of atomics at the constructor
113 + ri->flags |= (RRD_FLAG_OWN_LABELS | RRD_FLAG_DEMAND_LABELS); // no need of atomics at the constructor
114 }
115
116 if(ri->rrdset) {
@@ -213,12 +218,12 @@ static bool rrdinstance_conflict_callback(const DICTIONARY_ITEM *item __maybe_un
218 if(ri->rrdset && rrd_flag_check(ri, RRD_FLAG_OWN_LABELS)) {
219 RRDLABELS *old = ri->rrdlabels;
220 ri->rrdlabels = ri->rrdset->rrdlabels;
216 - rrd_flag_clear(ri, RRD_FLAG_OWN_LABELS);
221 + rrd_flag_clear(ri, RRD_FLAG_OWN_LABELS| RRD_FLAG_DEMAND_LABELS);
222 rrdlabels_destroy(old);
223 }
224 else if(!ri->rrdset && !rrd_flag_check(ri, RRD_FLAG_OWN_LABELS)) {
225 ri->rrdlabels = rrdlabels_create();
221 - rrd_flag_set(ri, RRD_FLAG_OWN_LABELS);
226 + rrd_flag_set(ri, RRD_FLAG_OWN_LABELS | RRD_FLAG_DEMAND_LABELS);
227 }
228 }
229
@@ -431,8 +436,9 @@ inline void rrdinstance_rrdset_is_freed(RRDSET *st) {
436
437 if(!rrd_flag_check(ri, RRD_FLAG_OWN_LABELS)) {
438 ri->rrdlabels = rrdlabels_create();
434 - rrdlabels_copy(ri->rrdlabels, st->rrdlabels);
435 - rrd_flag_set(ri, RRD_FLAG_OWN_LABELS);
439 + // Do not load copy labels, just load on demand
440 + //rrdlabels_copy(ri->rrdlabels, st->rrdlabels);
441 + rrd_flag_set(ri, RRD_FLAG_OWN_LABELS | RRD_FLAG_DEMAND_LABELS);
442 }
443
444 ri->rrdset = NULL;
src/database/contexts/internal.h
+21 -19
@@ -39,25 +39,26 @@ typedef enum __attribute__ ((__packed__)) {
39 RRD_FLAG_UPDATED = (1 << 2), // this object has updates to propagate
40 RRD_FLAG_ARCHIVED = (1 << 3), // this object is not currently being collected
41 RRD_FLAG_OWN_LABELS = (1 << 4), // this instance has its own labels - not linked to an RRDSET
42 - RRD_FLAG_LIVE_RETENTION = (1 << 5), // we have got live retention from the database
43 - RRD_FLAG_QUEUED_FOR_HUB = (1 << 6), // this context is currently queued to be dispatched to hub
44 - RRD_FLAG_QUEUED_FOR_PP = (1 << 7), // this context is currently queued to be post-processed
45 - RRD_FLAG_HIDDEN = (1 << 8), // don't expose this to the hub or the API
46 -
47 - RRD_FLAG_UPDATE_REASON_TRIGGERED = (1 << 9), // the update was triggered by the child object
48 - RRD_FLAG_UPDATE_REASON_LOAD_SQL = (1 << 10), // this object has just been loaded from SQL
49 - RRD_FLAG_UPDATE_REASON_NEW_OBJECT = (1 << 11), // this object has just been created
50 - RRD_FLAG_UPDATE_REASON_UPDATED_OBJECT = (1 << 12), // we received an update on this object
51 - RRD_FLAG_UPDATE_REASON_CHANGED_LINKING = (1 << 13), // an instance or a metric switched RRDSET or RRDDIM
52 - RRD_FLAG_UPDATE_REASON_CHANGED_METADATA = (1 << 14), // this context or instance changed uuid, name, units, title, family, chart type, priority, update every, rrd changed flags
53 - RRD_FLAG_UPDATE_REASON_ZERO_RETENTION = (1 << 15), // this object has no retention
54 - RRD_FLAG_UPDATE_REASON_CHANGED_FIRST_TIME_T = (1 << 16), // this object changed its oldest time in the db
55 - RRD_FLAG_UPDATE_REASON_CHANGED_LAST_TIME_T = (1 << 17), // this object change its latest time in the db
56 - RRD_FLAG_UPDATE_REASON_STOPPED_BEING_COLLECTED = (1 << 18), // this object has stopped being collected
57 - RRD_FLAG_UPDATE_REASON_STARTED_BEING_COLLECTED = (1 << 19), // this object has started being collected
58 - RRD_FLAG_UPDATE_REASON_DISCONNECTED_CHILD = (1 << 20), // this context belongs to a host that just disconnected
59 - RRD_FLAG_UPDATE_REASON_UNUSED = (1 << 21), // this context is not used anymore
60 - RRD_FLAG_UPDATE_REASON_DB_ROTATION = (1 << 22), // this context changed because of a db rotation
42 + RRD_FLAG_DEMAND_LABELS = (1 << 5), // this instance should load labels on demand
43 + RRD_FLAG_LIVE_RETENTION = (1 << 6), // we have got live retention from the database
44 + RRD_FLAG_QUEUED_FOR_HUB = (1 << 7), // this context is currently queued to be dispatched to hub
45 + RRD_FLAG_QUEUED_FOR_PP = (1 << 8), // this context is currently queued to be post-processed
46 + RRD_FLAG_HIDDEN = (1 << 9), // don't expose this to the hub or the API
47 +
48 + RRD_FLAG_UPDATE_REASON_TRIGGERED = (1 << 10), // the update was triggered by the child object
49 + RRD_FLAG_UPDATE_REASON_LOAD_SQL = (1 << 11), // this object has just been loaded from SQL
50 + RRD_FLAG_UPDATE_REASON_NEW_OBJECT = (1 << 12), // this object has just been created
51 + RRD_FLAG_UPDATE_REASON_UPDATED_OBJECT = (1 << 13), // we received an update on this object
52 + RRD_FLAG_UPDATE_REASON_CHANGED_LINKING = (1 << 14), // an instance or a metric switched RRDSET or RRDDIM
53 + RRD_FLAG_UPDATE_REASON_CHANGED_METADATA = (1 << 15), // this context or instance changed uuid, name, units, title, family, chart type, priority, update every, rrd changed flags
54 + RRD_FLAG_UPDATE_REASON_ZERO_RETENTION = (1 << 16), // this object has no retention
55 + RRD_FLAG_UPDATE_REASON_CHANGED_FIRST_TIME_T = (1 << 17), // this object changed its oldest time in the db
56 + RRD_FLAG_UPDATE_REASON_CHANGED_LAST_TIME_T = (1 << 18), // this object change its latest time in the db
57 + RRD_FLAG_UPDATE_REASON_STOPPED_BEING_COLLECTED = (1 << 19), // this object has stopped being collected
58 + RRD_FLAG_UPDATE_REASON_STARTED_BEING_COLLECTED = (1 << 20), // this object has started being collected
59 + RRD_FLAG_UPDATE_REASON_DISCONNECTED_CHILD = (1 << 21), // this context belongs to a host that just disconnected
60 + RRD_FLAG_UPDATE_REASON_UNUSED = (1 << 22), // this context is not used anymore
61 + RRD_FLAG_UPDATE_REASON_DB_ROTATION = (1 << 23), // this context changed because of a db rotation
62
63 RRD_FLAG_MERGED_COLLECTED_RI_TO_RC = (1 << 29),
64
@@ -354,6 +355,7 @@ static inline void rrdcontext_release(RRDCONTEXT_ACQUIRED *rca) {
355
356 // ----------------------------------------------------------------------------
357 // Forward definitions
358 +void load_instance_labels_on_demand(nd_uuid_t *uuid, void *data);
359
360 void rrdcontext_recalculate_context_retention(RRDCONTEXT *rc, RRD_FLAGS reason, bool worker_jobs);
361 void rrdcontext_recalculate_host_retention(RRDHOST *host, RRD_FLAGS reason, bool worker_jobs);
src/database/contexts/worker.c
+4 -1
@@ -24,6 +24,10 @@ static void rrdinstance_load_clabel(SQL_CLABEL_DATA *sld, void *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(SQL_DIMENSION_DATA *sd, void *data) {
32 RRDINSTANCE *ri = data;
33
@@ -73,7 +77,6 @@ static void rrdinstance_load_chart_callback(SQL_CHART_DATA *sc, void *data) {
77 RRDINSTANCE *ri = rrdinstance_acquired_value(ria);
78
79 ctx_get_dimension_list(&ri->uuid, rrdinstance_load_dimension, ri);
76 - ctx_get_label_list(&ri->uuid, rrdinstance_load_clabel, ri);
80 rrdinstance_trigger_updates(ri, __FUNCTION__ );
81 rrdinstance_release(ria);
82 rrdcontext_release(rca);