From 70f277088184231872a6ade236ae3fb5eb9f3e7f Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sat, 28 Jan 2017 03:25:11 +0200 Subject: [PATCH] proper fix: nonzero option should return all selected dimensions if they are all zero; fixes #1658; fixes #1514 --- src/rrd2json.c | 12 ++++++------ src/rrd2json.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/rrd2json.c b/src/rrd2json.c index 65346f31..aa07b6fc 100644 --- a/src/rrd2json.c +++ b/src/rrd2json.c @@ -449,6 +449,7 @@ void rrd_stats_all_json(BUFFER *wb) #define RRDR_RESET 0x02 // the dimension contains / the value is reset #define RRDR_HIDDEN 0x04 // the dimension contains / the value is hidden #define RRDR_NONZERO 0x08 // the dimension contains / the value is non-zero +#define RRDR_SELECTED 0x10 // the dimension is selected // RRDR result options #define RRDR_RESULT_OPTION_ABSOLUTE 0x00000001 @@ -564,13 +565,12 @@ 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))) { - dims_selected++; - r->od[c] |= RRDR_OPTION_SELECTED; - - // remove the hidden flag, if it is set - if(likely(r->od[c] & RRDR_HIDDEN)) + if(likely(r->od[c] & RRDR_HIDDEN)) { + r->od[c] |= RRDR_SELECTED; r->od[c] &= ~RRDR_HIDDEN; + dims_selected++; + } // since the user needs this dimension // make it appear as NONZERO, to return it @@ -593,7 +593,7 @@ void rrdr_disable_not_selected_dimensions(RRDR *r, uint32_t options, const char // 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)) + if(unlikely(r->od[c] & RRDR_SELECTED)) r->od[c] |= RRDR_NONZERO; } } diff --git a/src/rrd2json.h b/src/rrd2json.h index de82de43..7b140197 100644 --- a/src/rrd2json.h +++ b/src/rrd2json.h @@ -57,7 +57,6 @@ #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); -- 2.39.2