summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2022-04-12 08:18:40 +0300
committerGitHub <noreply@github.com>2022-04-12 08:18:40 +0300
commitfedab0d7fa6f3b42cfc6e7c65ed13a32b7b907b5 (patch)
tree97feefebfb4aa91227476427b58d16d46f16c623 /web
parentd5ad2681bb5ce1456ea5caa9b956617b36c2bd6a (diff)
Add a chart label filter parameter in context data queries (#12652)
* Add function to filter chart labels * Add new parameter to filter chart labels on context queries * Change swagger * Better formatting for swagger
Diffstat (limited to 'web')
-rw-r--r--web/api/netdata-swagger.json22
-rw-r--r--web/api/netdata-swagger.yaml18
-rw-r--r--web/api/web_api_v1.c13
-rw-r--r--web/api/web_api_v1.h1
4 files changed, 51 insertions, 3 deletions
diff --git a/web/api/netdata-swagger.json b/web/api/netdata-swagger.json
index 64c3a95bcf..4952e6116a 100644
--- a/web/api/netdata-swagger.json
+++ b/web/api/netdata-swagger.json
@@ -200,6 +200,28 @@
}
},
{
+ "name": "chart_label_key",
+ "in": "query",
+ "description": "Specify the chart label keys that need to match for context queries as comma separated values. At least one matching key is needed to match the corresponding chart.",
+ "required": false,
+ "allowEmptyValue": false,
+ "schema": {
+ "type": "string",
+ "format": "key1,key2,key3"
+ }
+ },
+ {
+ "name": "chart_labels_filter",
+ "in": "query",
+ "description": "Specify the chart label keys and values to match for context queries. All keys/values need to match for the chart to be included in the query. The labels are specified as key1:value1,key2:value2",
+ "required": false,
+ "allowEmptyValue": false,
+ "schema": {
+ "type": "string",
+ "format": "key1:value1,key2:value2,key3:value3"
+ }
+ },
+ {
"name": "group",
"in": "query",
"description": "The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. methods supported \"min\", \"max\", \"average\", \"sum\", \"incremental-sum\". \"max\" is actually calculated on the absolute value collected (so it works for both positive and negative dimensions to return the most extreme value in either direction).",
diff --git a/web/api/netdata-swagger.yaml b/web/api/netdata-swagger.yaml
index a03180ea08..1e20ad0f5b 100644
--- a/web/api/netdata-swagger.yaml
+++ b/web/api/netdata-swagger.yaml
@@ -170,6 +170,24 @@ paths:
type: number
format: integer
default: 20
+ - name: chart_label_key
+ in: query
+ description: Specify the chart label keys that need to match for context queries as comma separated values.
+ At least one matching key is needed to match the corresponding chart.
+ required: false
+ allowEmptyValue: false
+ schema:
+ type: string
+ format: key1,key2,key3
+ - name: chart_labels_filter
+ in: query
+ description: Specify the chart label keys and values to match for context queries. All keys/values need to
+ match for the chart to be included in the query. The labels are specified as key1:value1,key2:value2
+ required: false
+ allowEmptyValue: false
+ schema:
+ type: string
+ format: key1:value1,key2:value2,key3:value3
- name: group
in: query
description: The grouping method. If multiple collected values are to be grouped
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c
index 20318a1318..8cf89d38d5 100644
--- a/web/api/web_api_v1.c
+++ b/web/api/web_api_v1.c
@@ -419,6 +419,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
char *max_anomaly_rates_str = NULL;
char *context = NULL;
char *chart_label_key = NULL;
+ char *chart_labels_filter = NULL;
int group = RRDR_GROUPING_AVERAGE;
uint32_t format = DATASOURCE_JSON;
@@ -439,6 +440,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
if(!strcmp(name, "context")) context = value;
else if(!strcmp(name, "chart_label_key")) chart_label_key = value;
+ else if(!strcmp(name, "chart_labels_filter")) chart_labels_filter = value;
else if(!strcmp(name, "chart")) chart = value;
else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) {
if(!dimensions) dimensions = buffer_create(100);
@@ -522,16 +524,21 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
uint32_t context_hash = simple_hash(context);
rrdhost_rdlock(host);
+ char *words[MAX_CHART_LABELS_FILTER];
+ uint32_t hash_key_list[MAX_CHART_LABELS_FILTER];
+ int word_count = 0;
rrdset_foreach_read(st1, host) {
if (st1->hash_context == context_hash && !strcmp(st1->context, context) &&
- (!chart_label_key || rrdset_contains_label_keylist(st1, chart_label_key)))
- build_context_param_list(&context_param_list, st1);
+ (!chart_label_key || rrdset_contains_label_keylist(st1, chart_label_key)) &&
+ (!chart_labels_filter ||
+ rrdset_matches_label_keys(st1, chart_labels_filter, words, hash_key_list, &word_count, MAX_CHART_LABELS_FILTER)))
+ build_context_param_list(&context_param_list, st1);
}
rrdhost_unlock(host);
if (likely(context_param_list && context_param_list->rd)) // Just set the first one
st = context_param_list->rd->rrdset;
else {
- if (!chart_label_key)
+ if (!chart_label_key && !chart_labels_filter)
sql_build_context_param_list(&context_param_list, host, context, NULL);
}
}
diff --git a/web/api/web_api_v1.h b/web/api/web_api_v1.h
index 445b0e4a5c..a88c511ad8 100644
--- a/web/api/web_api_v1.h
+++ b/web/api/web_api_v1.h
@@ -8,6 +8,7 @@
#include "web/api/formatters/rrd2json.h"
#include "web/api/health/health_cmdapi.h"
+#define MAX_CHART_LABELS_FILTER (32)
extern uint32_t web_client_api_request_v1_data_options(char *o);
extern uint32_t web_client_api_request_v1_data_format(char *name);
extern uint32_t web_client_api_request_v1_data_google_format(char *name);