diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2022-02-17 09:13:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-17 09:13:56 +0200 |
commit | 305708523eb43a4f2557ee366e4e23f696b0f685 (patch) | |
tree | 9974704729943b20d377002563e75b0bc4dd187e /web | |
parent | 15dd0e4b5ae301e9a9a31870e74f654cec033135 (diff) |
Fix the format=array output in context queries (#12129)
* Add a new parameter (list of dimensions for the context query) to rrdr2ssv & rrdr2value
Add the parameter to the function calls
* Use the temporary dimension list (if available) for the calculations
Diffstat (limited to 'web')
-rw-r--r-- | web/api/formatters/rrd2json.c | 14 | ||||
-rw-r--r-- | web/api/formatters/ssv/ssv.c | 4 | ||||
-rw-r--r-- | web/api/formatters/ssv/ssv.h | 2 | ||||
-rw-r--r-- | web/api/formatters/value/value.c | 6 | ||||
-rw-r--r-- | web/api/formatters/value/value.h | 2 |
5 files changed, 14 insertions, 14 deletions
diff --git a/web/api/formatters/rrd2json.c b/web/api/formatters/rrd2json.c index 29bb4beb5d..f27ee77c29 100644 --- a/web/api/formatters/rrd2json.c +++ b/web/api/formatters/rrd2json.c @@ -197,7 +197,7 @@ int rrdset2value_api_v1( if(db_before) *db_before = r->before; long i = (!(options & RRDR_OPTION_REVERSED))?rrdr_rows(r) - 1:0; - *n = rrdr2value(r, i, options, value_is_null); + *n = rrdr2value(r, i, options, value_is_null, NULL); rrdr_free(r); return HTTP_RESP_OK; @@ -243,12 +243,12 @@ int rrdset2anything_api_v1( if(options & RRDR_OPTION_JSON_WRAP) { wb->contenttype = CT_APPLICATION_JSON; rrdr_json_wrapper_begin(r, wb, format, options, 1, context_param_list, chart_label_key); - rrdr2ssv(r, wb, options, "", " ", ""); + rrdr2ssv(r, wb, options, "", " ", "", temp_rd); rrdr_json_wrapper_end(r, wb, format, options, 1); } else { wb->contenttype = CT_TEXT_PLAIN; - rrdr2ssv(r, wb, options, "", " ", ""); + rrdr2ssv(r, wb, options, "", " ", "", temp_rd); } break; @@ -256,12 +256,12 @@ int rrdset2anything_api_v1( if(options & RRDR_OPTION_JSON_WRAP) { wb->contenttype = CT_APPLICATION_JSON; rrdr_json_wrapper_begin(r, wb, format, options, 1, context_param_list, chart_label_key); - rrdr2ssv(r, wb, options, "", ",", ""); + rrdr2ssv(r, wb, options, "", ",", "", temp_rd); rrdr_json_wrapper_end(r, wb, format, options, 1); } else { wb->contenttype = CT_TEXT_PLAIN; - rrdr2ssv(r, wb, options, "", ",", ""); + rrdr2ssv(r, wb, options, "", ",", "", temp_rd); } break; @@ -269,12 +269,12 @@ int rrdset2anything_api_v1( if(options & RRDR_OPTION_JSON_WRAP) { wb->contenttype = CT_APPLICATION_JSON; rrdr_json_wrapper_begin(r, wb, format, options, 0, context_param_list, chart_label_key); - rrdr2ssv(r, wb, options, "[", ",", "]"); + rrdr2ssv(r, wb, options, "[", ",", "]", temp_rd); rrdr_json_wrapper_end(r, wb, format, options, 0); } else { wb->contenttype = CT_APPLICATION_JSON; - rrdr2ssv(r, wb, options, "[", ",", "]"); + rrdr2ssv(r, wb, options, "[", ",", "]", temp_rd); } break; diff --git a/web/api/formatters/ssv/ssv.c b/web/api/formatters/ssv/ssv.c index eeba0283d0..8d3ddbfdf1 100644 --- a/web/api/formatters/ssv/ssv.c +++ b/web/api/formatters/ssv/ssv.c @@ -2,7 +2,7 @@ #include "ssv.h" -void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix) { +void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix, RRDDIM *temp_rd) { //info("RRD2SSV(): %s: BEGIN", r->st->id); long i; @@ -17,7 +17,7 @@ void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, con // for each line in the array for(i = start; i != end ;i += step) { int all_values_are_null = 0; - calculated_number v = rrdr2value(r, i, options, &all_values_are_null); + calculated_number v = rrdr2value(r, i, options, &all_values_are_null, temp_rd); if(likely(i != start)) { if(r->min > v) r->min = v; diff --git a/web/api/formatters/ssv/ssv.h b/web/api/formatters/ssv/ssv.h index 6963dcf6e5..66716b9c9f 100644 --- a/web/api/formatters/ssv/ssv.h +++ b/web/api/formatters/ssv/ssv.h @@ -5,6 +5,6 @@ #include "../rrd2json.h" -extern void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix); +extern void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix, RRDDIM *temp_rd); #endif //NETDATA_API_FORMATTER_SSV_H diff --git a/web/api/formatters/value/value.c b/web/api/formatters/value/value.c index a69af61658..9ac91f509f 100644 --- a/web/api/formatters/value/value.c +++ b/web/api/formatters/value/value.c @@ -3,7 +3,7 @@ #include "value.h" -inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null) { +inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null, RRDDIM *temp_rd) { if (r->st_needs_lock) rrdset_check_rdlock(r->st); @@ -20,7 +20,7 @@ inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int * int set_min_max = 0; if(unlikely(options & RRDR_OPTION_PERCENTAGE)) { total = 0; - for(c = 0, d = r->st->dimensions; d && c < r->d ;c++, d = d->next) { + for (c = 0, d = temp_rd ? temp_rd : r->st->dimensions; d && c < r->d; c++, d = d->next) { calculated_number n = cn[c]; if(likely((options & RRDR_OPTION_ABSOLUTE) && n < 0)) @@ -34,7 +34,7 @@ inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int * } // for each dimension - for(c = 0, d = r->st->dimensions; d && c < r->d ;c++, d = d->next) { + for (c = 0, d = temp_rd ? temp_rd : r->st->dimensions; d && c < r->d; c++, d = d->next) { if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue; if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue; diff --git a/web/api/formatters/value/value.h b/web/api/formatters/value/value.h index d9e981f88c..2d6bd12429 100644 --- a/web/api/formatters/value/value.h +++ b/web/api/formatters/value/value.h @@ -5,6 +5,6 @@ #include "../rrd2json.h" -extern calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null); +extern calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null, RRDDIM *temp_rd); #endif //NETDATA_API_FORMATTER_VALUE_H |