summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2023-08-08 21:43:10 +0300
committerGitHub <noreply@github.com>2023-08-08 21:43:10 +0300
commitcfe9dc42862f08670657688d2b6cddd6e2492c68 (patch)
treecb7cecf13534e0ed64758fdacf27814b4a419c54 /libnetdata
parent56289bdc901c84f62139ec012309cf0ce9a3f9ca (diff)
extend the trimming window to avoid empty points at the end of queries (#15773)
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/buffer/buffer.h21
-rw-r--r--libnetdata/facets/facets.c1
2 files changed, 16 insertions, 6 deletions
diff --git a/libnetdata/buffer/buffer.h b/libnetdata/buffer/buffer.h
index 02134c8b26..0f15402871 100644
--- a/libnetdata/buffer/buffer.h
+++ b/libnetdata/buffer/buffer.h
@@ -71,7 +71,7 @@ typedef enum __attribute__ ((__packed__)) {
typedef enum __attribute__ ((__packed__)) {
BUFFER_JSON_OPTIONS_DEFAULT = 0,
BUFFER_JSON_OPTIONS_MINIFY = (1 << 0),
- BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAYS = (1 << 1),
+ BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAY_ITEMS = (1 << 1),
} BUFFER_JSON_OPTIONS;
typedef struct web_buffer {
@@ -670,12 +670,16 @@ static inline void buffer_print_spaces(BUFFER *wb, size_t spaces) {
buffer_overflow_check(wb);
}
-static inline void buffer_print_json_comma_newline_spacing(BUFFER *wb) {
+static inline void buffer_print_json_comma(BUFFER *wb) {
if(wb->json.stack[wb->json.depth].count)
buffer_fast_strcat(wb, ",", 1);
+}
+
+static inline void buffer_print_json_comma_newline_spacing(BUFFER *wb) {
+ buffer_print_json_comma(wb);
if((wb->json.options & BUFFER_JSON_OPTIONS_MINIFY) ||
- (wb->json.stack[wb->json.depth].type == BUFFER_JSON_ARRAY && !(wb->json.options & BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAYS)))
+ (wb->json.stack[wb->json.depth].type == BUFFER_JSON_ARRAY && !(wb->json.options & BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAY_ITEMS)))
return;
buffer_fast_strcat(wb, "\n", 1);
@@ -799,7 +803,14 @@ static inline void buffer_json_member_add_array(BUFFER *wb, const char *key) {
}
static inline void buffer_json_add_array_item_array(BUFFER *wb) {
- buffer_print_json_comma_newline_spacing(wb);
+ if(!(wb->json.options & BUFFER_JSON_OPTIONS_MINIFY) && wb->json.stack[wb->json.depth].type == BUFFER_JSON_ARRAY) {
+ // an array inside another array
+ buffer_print_json_comma(wb);
+ buffer_fast_strcat(wb, "\n", 1);
+ buffer_print_spaces(wb, wb->json.depth + 1);
+ }
+ else
+ buffer_print_json_comma_newline_spacing(wb);
buffer_fast_strcat(wb, "[", 1);
wb->json.stack[wb->json.depth].count++;
@@ -918,7 +929,7 @@ static inline void buffer_json_array_close(BUFFER *wb) {
assert(wb->json.depth >= 0 && "BUFFER JSON: nothing is open to close it");
assert(wb->json.stack[wb->json.depth].type == BUFFER_JSON_ARRAY && "BUFFER JSON: an array is not open to close it");
#endif
- if(wb->json.options & BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAYS) {
+ if(wb->json.options & BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAY_ITEMS) {
buffer_fast_strcat(wb, "\n", 1);
buffer_print_spaces(wb, wb->json.depth);
}
diff --git a/libnetdata/facets/facets.c b/libnetdata/facets/facets.c
index c232ebf567..8762b43b9b 100644
--- a/libnetdata/facets/facets.c
+++ b/libnetdata/facets/facets.c
@@ -622,7 +622,6 @@ void facets_row_finished(FACETS *facets, usec_t usec) {
// dfe_start_read(facets->keys, k) {
for(k = facets->keys_ll ; k ; k = k->next) {
if(!k->key_found_in_row) {
- internal_fatal(buffer_strlen(k->current_value.b), "key is not found in row but it has a current value");
// put the FACET_VALUE_UNSET value into it
facets_check_value(facets, k);
}