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
Stelios Fragkakis committed
Feb 17, 2022 at 09:13 UTC
305708523eb43a4f2557ee366e4e23f696b0f685
5 files changed
+14
-14
web/api/formatters/rrd2json.c
+7
-7
@@ -197,7 +197,7 @@ int rrdset2value_api_v1(
197
if(db_before) *db_before = r->before;
198
199
long i = (!(options & RRDR_OPTION_REVERSED))?rrdr_rows(r) - 1:0;
200
- *n = rrdr2value(r, i, options, value_is_null);
200
+ *n = rrdr2value(r, i, options, value_is_null, NULL);
201
202
rrdr_free(r);
203
return HTTP_RESP_OK;
@@ -243,12 +243,12 @@ int rrdset2anything_api_v1(
243
if(options & RRDR_OPTION_JSON_WRAP) {
244
wb->contenttype = CT_APPLICATION_JSON;
245
rrdr_json_wrapper_begin(r, wb, format, options, 1, context_param_list, chart_label_key);
246
- rrdr2ssv(r, wb, options, "", " ", "");
246
+ rrdr2ssv(r, wb, options, "", " ", "", temp_rd);
247
rrdr_json_wrapper_end(r, wb, format, options, 1);
248
}
249
else {
250
wb->contenttype = CT_TEXT_PLAIN;
251
- rrdr2ssv(r, wb, options, "", " ", "");
251
+ rrdr2ssv(r, wb, options, "", " ", "", temp_rd);
252
}
253
break;
254
@@ -256,12 +256,12 @@ int rrdset2anything_api_v1(
256
if(options & RRDR_OPTION_JSON_WRAP) {
257
wb->contenttype = CT_APPLICATION_JSON;
258
rrdr_json_wrapper_begin(r, wb, format, options, 1, context_param_list, chart_label_key);
259
- rrdr2ssv(r, wb, options, "", ",", "");
259
+ rrdr2ssv(r, wb, options, "", ",", "", temp_rd);
260
rrdr_json_wrapper_end(r, wb, format, options, 1);
261
}
262
else {
263
wb->contenttype = CT_TEXT_PLAIN;
264
- rrdr2ssv(r, wb, options, "", ",", "");
264
+ rrdr2ssv(r, wb, options, "", ",", "", temp_rd);
265
}
266
break;
267
@@ -269,12 +269,12 @@ int rrdset2anything_api_v1(
269
if(options & RRDR_OPTION_JSON_WRAP) {
270
wb->contenttype = CT_APPLICATION_JSON;
271
rrdr_json_wrapper_begin(r, wb, format, options, 0, context_param_list, chart_label_key);
272
- rrdr2ssv(r, wb, options, "[", ",", "]");
272
+ rrdr2ssv(r, wb, options, "[", ",", "]", temp_rd);
273
rrdr_json_wrapper_end(r, wb, format, options, 0);
274
}
275
else {
276
wb->contenttype = CT_APPLICATION_JSON;
277
- rrdr2ssv(r, wb, options, "[", ",", "]");
277
+ rrdr2ssv(r, wb, options, "[", ",", "]", temp_rd);
278
}
279
break;
280
web/api/formatters/ssv/ssv.c
+2
-2
@@ -2,7 +2,7 @@
2
3
#include "ssv.h"
4
5
-void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix) {
5
+void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix, RRDDIM *temp_rd) {
6
//info("RRD2SSV(): %s: BEGIN", r->st->id);
7
long i;
8
@@ -17,7 +17,7 @@ void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, con
17
// for each line in the array
18
for(i = start; i != end ;i += step) {
19
int all_values_are_null = 0;
20
- calculated_number v = rrdr2value(r, i, options, &all_values_are_null);
20
+ calculated_number v = rrdr2value(r, i, options, &all_values_are_null, temp_rd);
21
22
if(likely(i != start)) {
23
if(r->min > v) r->min = v;
web/api/formatters/ssv/ssv.h
+1
-1
@@ -5,6 +5,6 @@
5
6
#include "../rrd2json.h"
7
8
-extern void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix);
8
+extern void rrdr2ssv(RRDR *r, BUFFER *wb, RRDR_OPTIONS options, const char *prefix, const char *separator, const char *suffix, RRDDIM *temp_rd);
9
10
#endif //NETDATA_API_FORMATTER_SSV_H
web/api/formatters/value/value.c
+3
-3
@@ -3,7 +3,7 @@
3
#include "value.h"
4
5
6
-inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null) {
6
+inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null, RRDDIM *temp_rd) {
7
if (r->st_needs_lock)
8
rrdset_check_rdlock(r->st);
9
@@ -20,7 +20,7 @@ inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *
20
int set_min_max = 0;
21
if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
22
total = 0;
23
- for(c = 0, d = r->st->dimensions; d && c < r->d ;c++, d = d->next) {
23
+ for (c = 0, d = temp_rd ? temp_rd : r->st->dimensions; d && c < r->d; c++, d = d->next) {
24
calculated_number n = cn[c];
25
26
if(likely((options & RRDR_OPTION_ABSOLUTE) && n < 0))
@@ -34,7 +34,7 @@ inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *
34
}
35
36
// for each dimension
37
- for(c = 0, d = r->st->dimensions; d && c < r->d ;c++, d = d->next) {
37
+ for (c = 0, d = temp_rd ? temp_rd : r->st->dimensions; d && c < r->d; c++, d = d->next) {
38
if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
39
if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
40
web/api/formatters/value/value.h
+1
-1
@@ -5,6 +5,6 @@
5
6
#include "../rrd2json.h"
7
8
-extern calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null);
8
+extern calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null, RRDDIM *temp_rd);
9
10
#endif //NETDATA_API_FORMATTER_VALUE_H