@cryptotaxi247 / netdata-1 / commits / 82150596e

do not report dimensions that failed to be queried (#14447)

* do not report dimensions that failed to be queried * renamed SELECTED to QUERIED to have clarity on what it means * fix wrong placement of continue

Costa Tsaousis committed Feb 7, 2023 at 11:25 UTC 82150596e79199539b22aa86ff76831b9f17fd0b
8 files changed +49 -21
database/rrdcontext.c
+5 -5
@@ -2501,7 +2501,7 @@ static void query_target_add_metric(QUERY_TARGET_LOCALS *qtl, RRDMETRIC_ACQUIRED
2501 if (rrd_flag_check(rm, RRD_FLAG_HIDDEN)
2502 || (rm->rrddim && rrddim_option_check(rm->rrddim, RRDDIM_OPTION_HIDDEN))) {
2503 options |= RRDR_DIMENSION_HIDDEN;
2504 - options &= ~RRDR_DIMENSION_SELECTED;
2504 + options &= ~RRDR_DIMENSION_QUERIED;
2505 }
2506
2507 if (qt->query.pattern) {
@@ -2512,13 +2512,13 @@ static void query_target_add_metric(QUERY_TARGET_LOCALS *qtl, RRDMETRIC_ACQUIRED
2512 || (qtl->match_names && simple_pattern_matches(qt->query.pattern, string2str(rm->name)))
2513 ) {
2514 // it matches the pattern
2515 - options |= (RRDR_DIMENSION_SELECTED | RRDR_DIMENSION_NONZERO);
2515 + options |= (RRDR_DIMENSION_QUERIED | RRDR_DIMENSION_NONZERO);
2516 options &= ~RRDR_DIMENSION_HIDDEN;
2517 }
2518 else {
2519 // it does not match the pattern
2520 options |= RRDR_DIMENSION_HIDDEN;
2521 - options &= ~RRDR_DIMENSION_SELECTED;
2521 + options &= ~RRDR_DIMENSION_QUERIED;
2522 }
2523 }
2524 else {
@@ -2526,10 +2526,10 @@ static void query_target_add_metric(QUERY_TARGET_LOCALS *qtl, RRDMETRIC_ACQUIRED
2526 // so this is a selected dimension
2527 // if it is not hidden
2528 if(!(options & RRDR_DIMENSION_HIDDEN))
2529 - options |= RRDR_DIMENSION_SELECTED;
2529 + options |= RRDR_DIMENSION_QUERIED;
2530 }
2531
2532 - if((options & RRDR_DIMENSION_HIDDEN) && (options & RRDR_DIMENSION_SELECTED))
2532 + if((options & RRDR_DIMENSION_HIDDEN) && (options & RRDR_DIMENSION_QUERIED))
2533 options &= ~RRDR_DIMENSION_HIDDEN;
2534
2535 if(!(options & RRDR_DIMENSION_HIDDEN) || (qt->request.options & RRDR_OPTION_PERCENTAGE)) {
web/api/formatters/csv/csv.c
+5
@@ -12,6 +12,7 @@ void rrdr2csv(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS options, const
12 // print the csv header
13 for(c = 0, i = 0; c < used ; c++) {
14 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
15 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
16 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
17
18 if(!i) {
@@ -32,6 +33,7 @@ void rrdr2csv(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS options, const
33 // print the --- line after header
34 for(c = 0, i = 0; c < used ;c++) {
35 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
36 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
37 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
38
39 if(!i) {
@@ -89,6 +91,8 @@ void rrdr2csv(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS options, const
91 if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
92 total = 0;
93 for(c = 0; c < used ;c++) {
94 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
95 +
96 NETDATA_DOUBLE n = cn[c];
97
98 if(likely((options & RRDR_OPTION_ABSOLUTE) && n < 0))
@@ -104,6 +108,7 @@ void rrdr2csv(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS options, const
108 // for each dimension
109 for(c = 0; c < used ;c++) {
110 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
111 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
112 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
113
114 buffer_strcat(wb, separator);
web/api/formatters/json/json.c
+5 -1
@@ -111,6 +111,7 @@ void rrdr2json(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, int datatable) {
111 // print the header lines
112 for(c = 0, i = 0; c < used ; c++) {
113 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
114 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
115 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
116
117 buffer_fast_strcat(wb, pre_label, pre_label_len);
@@ -180,7 +181,7 @@ void rrdr2json(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, int datatable) {
181 // google supports one annotation per row
182 int annotation_found = 0;
183 for(c = 0; c < used ; c++) {
183 - if(unlikely(!(r->od[c] & RRDR_DIMENSION_SELECTED))) continue;
184 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
185
186 if(unlikely(co[c] & RRDR_VALUE_RESET)) {
187 buffer_fast_strcat(wb, overflow_annotation, overflow_annotation_len);
@@ -215,6 +216,8 @@ void rrdr2json(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, int datatable) {
216 if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
217 total = 0;
218 for(c = 0; c < used ;c++) {
219 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
220 +
221 NETDATA_DOUBLE n;
222 if(unlikely(options & RRDR_OPTION_INTERNAL_AR))
223 n = ar[c];
@@ -234,6 +237,7 @@ void rrdr2json(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, int datatable) {
237 // for each dimension
238 for(c = 0; c < used ;c++) {
239 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
240 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
241 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
242
243 NETDATA_DOUBLE n;
web/api/formatters/json_wrapper.c
+9 -5
@@ -131,6 +131,7 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
131
132 for(c = 0, i = 0; c < query_used ; c++) {
133 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
134 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
135 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
136
137 if(i) buffer_strcat(wb, ", ");
@@ -155,6 +156,7 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
156
157 for(c = 0, i = 0; c < query_used ; c++) {
158 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
159 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
160 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
161
162 if(i) buffer_strcat(wb, ", ");
@@ -260,9 +262,8 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
262 for (c = 0, i = 0; c < query_used; c++) {
263 QUERY_METRIC *qm = &qt->query.array[c];
264
263 - if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN))
264 - continue;
265 -
265 + if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
266 + if (unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
267 if (unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO)))
268 continue;
269
@@ -295,8 +296,8 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
296 for (c = 0, i = 0; c < query_used; c++) {
297 QUERY_METRIC *qm = &qt->query.array[c];
298
298 - if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN))
299 - continue;
299 + if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
300 + if (unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
301 if (unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO)))
302 continue;
303
@@ -351,6 +352,8 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
352 if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
353 total = 0;
354 for(c = 0; c < query_used ;c++) {
355 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
356 +
357 NETDATA_DOUBLE *cn = &r->v[ (rrdr_rows(r) - 1) * r->d ];
358 NETDATA_DOUBLE n = cn[c];
359
@@ -365,6 +368,7 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS
368
369 for(c = 0, i = 0; c < query_used ;c++) {
370 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
371 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
372 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
373
374 if(i) buffer_strcat(wb, ", ");
web/api/formatters/value/value.c
+2
@@ -22,6 +22,7 @@ inline NETDATA_DOUBLE rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all
22 if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
23 total = 0;
24 for (c = 0; c < used; c++) {
25 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
26 NETDATA_DOUBLE n = cn[c];
27
28 if(likely((options & RRDR_OPTION_ABSOLUTE) && n < 0))
@@ -37,6 +38,7 @@ inline NETDATA_DOUBLE rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all
38 // for each dimension
39 for (c = 0; c < used; c++) {
40 if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
41 + if(unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
42 if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
43
44 NETDATA_DOUBLE n = cn[c];
web/api/queries/query.c
+19 -9
@@ -2273,9 +2273,11 @@ RRDR *rrd2rrdr(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
2273 r->internal.grouping_reset(r);
2274
2275 if(ops[c]) {
2276 - r->od[c] |= RRDR_DIMENSION_SELECTED;
2276 + r->od[c] |= RRDR_DIMENSION_QUERIED;
2277 rrd2rrdr_query_execute(r, c, ops[c]);
2278 }
2279 + else
2280 + continue;
2281
2282 global_statistics_rrdr_query_completed(
2283 1,
@@ -2385,15 +2387,23 @@ RRDR *rrd2rrdr(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
2387 // free all resources used by the grouping method
2388 r->internal.grouping_free(r);
2389
2388 - // when all the dimensions are zero, we should return all of them
2389 - if(unlikely((qt->window.options & RRDR_OPTION_NONZERO) && !dimensions_nonzero && !(r->result_options & RRDR_RESULT_OPTION_CANCEL))) {
2390 - // all the dimensions are zero
2391 - // mark them as NONZERO to send them all
2392 - for(size_t c = 0, max = qt->query.used; c < max ; c++) {
2393 - if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
2394 - r->od[c] |= RRDR_DIMENSION_NONZERO;
2390 + if(likely(dimensions_used)) {
2391 + // when all the dimensions are zero, we should return all of them
2392 + if (unlikely((qt->window.options & RRDR_OPTION_NONZERO) && !dimensions_nonzero &&
2393 + !(r->result_options & RRDR_RESULT_OPTION_CANCEL))) {
2394 + // all the dimensions are zero
2395 + // mark them as NONZERO to send them all
2396 + for (size_t c = 0, max = qt->query.used; c < max; c++) {
2397 + if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
2398 + if (unlikely(!(r->od[c] & RRDR_DIMENSION_QUERIED))) continue;
2399 + r->od[c] |= RRDR_DIMENSION_NONZERO;
2400 + }
2401 }
2402 +
2403 + return r;
2404 }
2405
2398 - return r;
2406 + // we couldn't query any dimension
2407 + rrdr_free(owa, r);
2408 + return NULL;
2409 }
web/api/queries/rrdr.h
+1 -1
@@ -58,7 +58,7 @@ typedef enum rrdr_dimension_flag {
58 RRDR_DIMENSION_DEFAULT = 0x00,
59 RRDR_DIMENSION_HIDDEN = 0x04, // the dimension is hidden (not to be presented to callers)
60 RRDR_DIMENSION_NONZERO = 0x08, // the dimension is non zero (contains non-zero values)
61 - RRDR_DIMENSION_SELECTED = 0x10, // the dimension is selected for evaluation in this RRDR
61 + RRDR_DIMENSION_QUERIED = 0x10, // the dimension is selected for evaluation in this RRDR
62 } RRDR_DIMENSION_FLAGS;
63
64 // RRDR result options
web/api/queries/weights.c
+3
@@ -541,6 +541,9 @@ NETDATA_DOUBLE *rrd2rrdr_ks2(
541 if(unlikely(r->od[0] & RRDR_DIMENSION_HIDDEN))
542 goto cleanup;
543
544 + if(unlikely(!(r->od[0] & RRDR_DIMENSION_QUERIED)))
545 + goto cleanup;
546 +
547 if(unlikely(!(r->od[0] & RRDR_DIMENSION_NONZERO)))
548 goto cleanup;
549