@cryptotaxi247 / netdata-1 / commits / 85f2def81

nonzero option should return all selected dimensions if they are all zero; fixes #1658; fixes #1514

Costa Tsaousis (ktsaou) committed Jan 27, 2017 at 21:29 UTC 85f2def814fbc2d9968394c13e619a31b9efd25a
3 files changed +29 -3
src/rrd.h
+1
@@ -124,6 +124,7 @@ struct rrddim {
124
125 // FIXME
126 // we need the hash_name too!
127 + // needed at rrdr_disable_not_selected_dimensions()
128
129 uint32_t flags;
130
src/rrd2json.c
+27 -3
@@ -543,11 +543,13 @@ static void rrdr_dump(RRDR *r)
543
544 void rrdr_disable_not_selected_dimensions(RRDR *r, uint32_t options, const char *dims)
545 {
546 + if(unlikely(!dims || !*dims)) return;
547 +
548 char b[strlen(dims) + 1];
549 char *o = b, *tok;
550 strcpy(o, dims);
551
550 - long c;
552 + long c, dims_selected = 0, dims_not_hidden_not_zero = 0;
553 RRDDIM *d;
554
555 // disable all of them
@@ -562,16 +564,38 @@ void rrdr_disable_not_selected_dimensions(RRDR *r, uint32_t options, const char
564 // find it and enable it
565 for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
566 if(unlikely((hash == d->hash && !strcmp(d->id, tok)) || !strcmp(d->name, tok))) {
565 - r->od[c] &= ~RRDR_HIDDEN;
567 + dims_selected++;
568 +
569 + r->od[c] |= RRDR_OPTION_SELECTED;
570 +
571 + // remove the hidden flag, if it is set
572 + if(likely(r->od[c] & RRDR_HIDDEN))
573 + r->od[c] &= ~RRDR_HIDDEN;
574
575 // since the user needs this dimension
576 // make it appear as NONZERO, to return it
577 // even if the dimension has only zeros
578 // unless option non_zero is set
571 - if (!(options & RRDR_OPTION_NONZERO)) r->od[c] |= RRDR_NONZERO;
579 + if(likely(!(options & RRDR_OPTION_NONZERO)))
580 + r->od[c] |= RRDR_NONZERO;
581 +
582 + // count the visible dimensions
583 + if(likely(r->od[c] & RRDR_NONZERO))
584 + dims_not_hidden_not_zero++;
585 }
586 }
587 }
588 +
589 + // check if all dimensions are hidden
590 + if(unlikely(!dims_not_hidden_not_zero && dims_selected)) {
591 + // there are a few selected dimensions
592 + // but they are all zero
593 + // enable the selected ones
594 + // to avoid returning an empty chart
595 + for(c = 0, d = r->st->dimensions; d ;c++, d = d->next)
596 + if(unlikely(r->od[c] & RRDR_OPTION_SELECTED))
597 + r->od[c] |= RRDR_NONZERO;
598 + }
599 }
600
601 void rrdr_buffer_print_format(BUFFER *wb, uint32_t format)
src/rrd2json.h
+1
@@ -57,6 +57,7 @@
57 #define RRDR_OPTION_LABEL_QUOTES 0x00000400 // in CSV output, wrap header labels in double quotes
58 #define RRDR_OPTION_PERCENTAGE 0x00000800 // give values as percentage of total
59 #define RRDR_OPTION_NOT_ALIGNED 0x00001000 // do not align charts for persistant timeframes
60 +#define RRDR_OPTION_SELECTED 0x00002000 // the dimension is selected by the caller: rrdr_disable_not_selected_dimensions()
61
62 extern void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb);
63 extern void rrd_stats_api_v1_charts(BUFFER *wb);