]> arthur.barton.de Git - netdata.git/commitdiff
nonzero option should return all selected dimensions if they are all zero; fixes...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 27 Jan 2017 19:29:36 +0000 (21:29 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 27 Jan 2017 19:29:36 +0000 (21:29 +0200)
src/rrd.h
src/rrd2json.c
src/rrd2json.h

index dbaf986503675fde06923ddc66d01024e08c5b23..4189d36cd43f497b4f7cd643379a6c9b7f66f677 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -124,6 +124,7 @@ struct rrddim {
 
     // FIXME
     // we need the hash_name too!
+    // needed at rrdr_disable_not_selected_dimensions()
 
     uint32_t flags;
 
index 568d04e8d9275e20291d2532d77c96973d88cdde..65346f31e732010b21fd1499d20a228c8c7e6de5 100644 (file)
@@ -543,11 +543,13 @@ static void rrdr_dump(RRDR *r)
 
 void rrdr_disable_not_selected_dimensions(RRDR *r, uint32_t options, const char *dims)
 {
+    if(unlikely(!dims || !*dims)) return;
+
     char b[strlen(dims) + 1];
     char *o = b, *tok;
     strcpy(o, dims);
 
-    long c;
+    long c, dims_selected = 0, dims_not_hidden_not_zero = 0;
     RRDDIM *d;
 
     // disable all of them
@@ -562,16 +564,38 @@ void rrdr_disable_not_selected_dimensions(RRDR *r, uint32_t options, const char
         // find it and enable it
         for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
             if(unlikely((hash == d->hash && !strcmp(d->id, tok)) || !strcmp(d->name, tok))) {
-                r->od[c] &= ~RRDR_HIDDEN;
+                dims_selected++;
+
+                r->od[c] |= RRDR_OPTION_SELECTED;
+
+                // remove the hidden flag, if it is set
+                if(likely(r->od[c] & RRDR_HIDDEN))
+                    r->od[c] &= ~RRDR_HIDDEN;
 
                 // since the user needs this dimension
                 // make it appear as NONZERO, to return it
                 // even if the dimension has only zeros
                 // unless option non_zero is set
-                if (!(options & RRDR_OPTION_NONZERO)) r->od[c] |= RRDR_NONZERO;
+                if(likely(!(options & RRDR_OPTION_NONZERO)))
+                    r->od[c] |= RRDR_NONZERO;
+
+                // count the visible dimensions
+                if(likely(r->od[c] & RRDR_NONZERO))
+                    dims_not_hidden_not_zero++;
             }
         }
     }
+
+    // check if all dimensions are hidden
+    if(unlikely(!dims_not_hidden_not_zero && dims_selected)) {
+        // there are a few selected dimensions
+        // but they are all zero
+        // enable the selected ones
+        // to avoid returning an empty chart
+        for(c = 0, d = r->st->dimensions; d ;c++, d = d->next)
+            if(unlikely(r->od[c] & RRDR_OPTION_SELECTED))
+                r->od[c] |= RRDR_NONZERO;
+    }
 }
 
 void rrdr_buffer_print_format(BUFFER *wb, uint32_t format)
index 7b14019708e32f54b3a18703e938320ac278c509..de82de43188f0105cdf3e99d7e667447ce5685b3 100644 (file)
@@ -57,6 +57,7 @@
 #define RRDR_OPTION_LABEL_QUOTES    0x00000400 // in CSV output, wrap header labels in double quotes
 #define RRDR_OPTION_PERCENTAGE      0x00000800 // give values as percentage of total
 #define RRDR_OPTION_NOT_ALIGNED     0x00001000 // do not align charts for persistant timeframes
+#define RRDR_OPTION_SELECTED        0x00002000 // the dimension is selected by the caller: rrdr_disable_not_selected_dimensions()
 
 extern void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb);
 extern void rrd_stats_api_v1_charts(BUFFER *wb);