diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2021-01-14 18:50:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 18:50:33 +0200 |
commit | cd443de780118c46dd8f02530086667d00948373 (patch) | |
tree | e29f21e28eb9eeb1d11539216a9e623ac225d3de /web | |
parent | de6035c543296de179e359a415664106d66c3878 (diff) |
Support multiple chart label keys in data queries (#10483)
Diffstat (limited to 'web')
-rw-r--r-- | web/api/formatters/json_wrapper.c | 64 | ||||
-rw-r--r-- | web/api/web_api_v1.c | 6 |
2 files changed, 37 insertions, 33 deletions
diff --git a/web/api/formatters/json_wrapper.c b/web/api/formatters/json_wrapper.c index 72967375d7..cf4f1099a2 100644 --- a/web/api/formatters/json_wrapper.c +++ b/web/api/formatters/json_wrapper.c @@ -116,43 +116,51 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, RRDR_OPTIONS } buffer_strcat(wb, "],\n"); if (chart_label_key) { - uint32_t key_hash = simple_hash(chart_label_key); - struct label *current_label; + buffer_sprintf(wb, " %schart_labels%s: { ", kq, kq); - buffer_sprintf( - wb, - " %schart_labels%s: { %s%s%s : [", - kq, kq, kq, chart_label_key, kq); + SIMPLE_PATTERN *pattern = simple_pattern_create(chart_label_key, ",|\t\r\n\f\v", SIMPLE_PATTERN_EXACT); + SIMPLE_PATTERN *original_pattern = pattern; + char *label_key = NULL; + int keys = 0; + while (pattern && (label_key = simple_pattern_iterate(&pattern))) { + uint32_t key_hash = simple_hash(label_key); + struct label *current_label; - for (c = 0, i = 0, rd = temp_rd; rd && c < r->d; c++, rd = rd->next) { - if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) - continue; - if (unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) - continue; - - if (i) + if (keys) buffer_strcat(wb, ", "); - - current_label = rrdset_lookup_label_key(rd->rrdset, chart_label_key, key_hash); - if (current_label) { + buffer_sprintf(wb, "%s%s%s : [", kq, label_key, kq); + keys++; + + for (c = 0, i = 0, rd = temp_rd; rd && c < r->d; c++, rd = rd->next) { + if (unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) + continue; + if (unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) + continue; + if (i) + buffer_strcat(wb, ", "); + + current_label = rrdset_lookup_label_key(rd->rrdset, label_key, key_hash); + if (current_label) { + buffer_strcat(wb, sq); + buffer_strcat(wb, current_label->value); + buffer_strcat(wb, sq); + } else + buffer_strcat(wb, "null"); + i++; + } + if (!i) { + rows = 0; buffer_strcat(wb, sq); - buffer_strcat(wb, current_label->value); + buffer_strcat(wb, "no data"); buffer_strcat(wb, sq); - } else - buffer_strcat(wb, "null"); - i++; + } + buffer_strcat(wb, "]"); } - if (!i) { - rows = 0; - buffer_strcat(wb, sq); - buffer_strcat(wb, "no data"); - buffer_strcat(wb, sq); - } - buffer_strcat(wb, "] },\n"); + buffer_strcat(wb, "},\n"); + simple_pattern_free(original_pattern); } } - buffer_sprintf(wb, " %slatest_values%s: [" , kq, kq); diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index cbfeee9a5c..4287675418 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -501,15 +501,11 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c if (context && !chart) { RRDSET *st1; uint32_t context_hash = simple_hash(context); - uint32_t key_hash; - - if (chart_label_key) - key_hash = simple_hash(chart_label_key); rrdhost_rdlock(host); rrdset_foreach_read(st1, host) { if (st1->hash_context == context_hash && !strcmp(st1->context, context) && - (!chart_label_key || rrdset_contains_label_key(st1, chart_label_key, key_hash))) + (!chart_label_key || rrdset_contains_label_keylist(st1, chart_label_key))) build_context_param_list(&context_param_list, st1); } rrdhost_unlock(host); |