0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-10 08:07:34 +00:00

Fix the format=array output in context queries ()

* 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
This commit is contained in:
Stelios Fragkakis 2022-02-17 09:13:56 +02:00 committed by GitHub
parent 15dd0e4b5a
commit 305708523e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 14 deletions
web/api/formatters

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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