Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2021-12-02 01:06:33 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2021-12-02 01:06:33 +0300
commit6317d366b0372b91f44758cf0124d3feed8da721 (patch)
treec8d8d417d721b0116426b1b8bc2fb069a3669ee7
parent8eafa5283b438773c4f1a7d3461d91434ccca019 (diff)
........S. [ZBXNEXT-7049] updated prometheus pattern preprocessing/tests to support new parameter format
-rw-r--r--include/zbxprometheus.h8
-rw-r--r--src/libs/zbxprometheus/zbxprometheus.c265
-rw-r--r--src/zabbix_server/preprocessor/item_preproc.c14
-rw-r--r--tests/libs/zbxprometheus/prometheus_filter_init.c19
-rw-r--r--tests/libs/zbxprometheus/prometheus_filter_init.yaml40
-rw-r--r--tests/libs/zbxprometheus/prometheus_test.c3
-rw-r--r--tests/libs/zbxprometheus/prometheus_test.h2
-rw-r--r--tests/libs/zbxprometheus/zbx_prometheus_pattern.c9
-rw-r--r--tests/libs/zbxprometheus/zbx_prometheus_pattern.yaml520
-rw-r--r--tests/zabbix_server/preprocessor/zbx_item_preproc.yaml17
10 files changed, 546 insertions, 351 deletions
diff --git a/include/zbxprometheus.h b/include/zbxprometheus.h
index e999c3e7f8b..8b79eb82ab5 100644
--- a/include/zbxprometheus.h
+++ b/include/zbxprometheus.h
@@ -22,8 +22,8 @@
#include "zbxalgo.h"
-int zbx_prometheus_pattern(const char *data, const char *filter_data, const char *output, char **value,
- char **error);
+int zbx_prometheus_pattern(const char *data, const char *filter_data, const char *request, const char *output,
+ char **value, char **error);
int zbx_prometheus_to_json(const char *data, const char *filter_data, char **value, char **error);
int zbx_prometheus_validate_filter(const char *pattern, char **error);
@@ -38,7 +38,7 @@ zbx_prometheus_t;
int zbx_prometheus_init(zbx_prometheus_t *prom, const char *data, char **error);
void zbx_prometheus_clear(zbx_prometheus_t *prom);
-int zbx_prometheus_pattern_ex(zbx_prometheus_t *prom, const char *filter_data, const char *output, char **value,
- char **error);
+int zbx_prometheus_pattern_ex(zbx_prometheus_t *prom, const char *filter_data, const char *request,
+ const char *output, char **value, char **error);
#endif
diff --git a/src/libs/zbxprometheus/zbxprometheus.c b/src/libs/zbxprometheus/zbxprometheus.c
index 13f216df2d7..4b22372ab3a 100644
--- a/src/libs/zbxprometheus/zbxprometheus.c
+++ b/src/libs/zbxprometheus/zbxprometheus.c
@@ -66,8 +66,6 @@ typedef struct
zbx_prometheus_condition_t *value;
/* label filters */
zbx_vector_ptr_t labels;
- /* aggregation function */
- char *function;
}
zbx_prometheus_filter_t;
@@ -661,8 +659,6 @@ static void prometheus_filter_clear(zbx_prometheus_filter_t *filter)
zbx_vector_ptr_clear_ext(&filter->labels, (zbx_clean_func_t)prometheus_condition_free);
zbx_vector_ptr_destroy(&filter->labels);
-
- zbx_free(filter->function);
}
/******************************************************************************
@@ -787,40 +783,23 @@ static int prometheus_filter_parse_labels(zbx_prometheus_filter_t *filter, const
******************************************************************************/
static int prometheus_filter_init(zbx_prometheus_filter_t *filter, const char *data, char **error)
{
- int ret = FAIL, metric_ret;
+ int ret = FAIL;
size_t pos = 0;
zbx_strloc_t loc;
- char terminator;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
memset(filter, 0, sizeof(zbx_prometheus_filter_t));
zbx_vector_ptr_create(&filter->labels);
- if (NULL == data)
- {
- ret = SUCCEED;
- goto out;
- }
-
pos = skip_spaces(data, pos);
- if (SUCCEED == (metric_ret = parse_metric(data, pos, &loc)))
+ if (SUCCEED == parse_metric(data, pos, &loc))
{
- if ('(' == data[loc.r + 1])
- {
- filter->function = str_loc_dup(data, &loc);
- pos = skip_spaces(data, loc.r + 2);
- metric_ret = parse_metric(data, pos, &loc);
- }
+ filter->metric = prometheus_condition_create(NULL, str_loc_dup(data, &loc),
+ ZBX_PROMETHEUS_CONDITION_OP_EQUAL);
- if (SUCCEED == metric_ret)
- {
- filter->metric = prometheus_condition_create(NULL, str_loc_dup(data, &loc),
- ZBX_PROMETHEUS_CONDITION_OP_EQUAL);
-
- pos = skip_spaces(data, loc.r + 1);
- }
+ pos = skip_spaces(data, loc.r + 1);
}
if ('{' == data[pos])
@@ -833,10 +812,8 @@ static int prometheus_filter_init(zbx_prometheus_filter_t *filter, const char *d
pos = skip_spaces(data, pos);
- terminator = (NULL == filter->function ? '\0' : ')');
-
/* parse metric value condition */
- if (data[pos] != terminator)
+ if ('\0' != data[pos])
{
zbx_strloc_t loc_op, loc_value;
@@ -855,7 +832,7 @@ static int prometheus_filter_init(zbx_prometheus_filter_t *filter, const char *d
}
pos = skip_spaces(data, loc_value.r + 1);
- if (data[pos] != terminator)
+ if ('\0' != data[pos])
{
*error = zbx_dsprintf(*error, "unexpected data after metric comparison value at \"%s\"",
data + pos);
@@ -867,16 +844,6 @@ static int prometheus_filter_init(zbx_prometheus_filter_t *filter, const char *d
zbx_strlower(filter->value->pattern);
}
- if (')' == terminator)
- {
- pos = skip_spaces(data, pos + 1);
- if ('\0' != data[pos])
- {
- *error = zbx_dsprintf(*error, "unexpected data after function end \"%s\"", data + pos);
- goto out;
- }
- }
-
ret = SUCCEED;
out:
if (FAIL == ret)
@@ -1528,80 +1495,21 @@ out:
* *
* Function: prometheus_extract_value *
* *
- * Purpose: extracts value from filtered rows according to output template *
+ * Purpose: extracts value from row *
* *
- * Parameters: filter - [IN] the prometheus filter *
- * function - [IN] the aggregation function (optional) *
- * output - [IN] the output template *
- * value - [OUT] the extracted value *
- * error - [OUT] the error message *
+ * Parameters: rows - [IN] the source rows *
+ * output - [IN] the output template *
+ * value - [OUT] the extracted value *
+ * error - [OUT] the error message *
* *
* Return value: SUCCEED - the value was extracted successfully *
* FAIL - otherwise *
* *
******************************************************************************/
-static int prometheus_extract_value(const zbx_vector_ptr_t *rows, const char *function, const char *output,
- char **value, char **error)
+static int prometheus_extract_value(const zbx_vector_ptr_t *rows, const char *output, char **value, char **error)
{
const zbx_prometheus_row_t *row;
- if (NULL != function)
- {
- zbx_vector_dbl_t values;
- int i, ret;
- double value_dbl;
-
- zbx_vector_dbl_create(&values);
-
- for (i = 0; i < rows->values_num; i++)
- {
- row = (const zbx_prometheus_row_t *)rows->values[i];
-
- value_dbl = atof(row->value);
- zbx_vector_dbl_append(&values, value_dbl);
- }
-
- if (0 == strcmp(function, "avg"))
- {
- ret = zbx_eval_calc_avg(&values, &value_dbl, error);
- }
- else if (0 == strcmp(function, "min"))
- {
- ret = zbx_eval_calc_min(&values, &value_dbl, error);
- }
- else if (0 == strcmp(function, "max"))
- {
- ret = zbx_eval_calc_max(&values, &value_dbl, error);
- }
- else if (0 == strcmp(function, "sum"))
- {
- zbx_eval_calc_sum(&values, &value_dbl);
- ret = SUCCEED;
- }
- else if (0 == strcmp(function, "count"))
- {
- value_dbl = (double)values.values_num;
- ret = SUCCEED;
- }
- else
- {
- *error = zbx_dsprintf(NULL, "unsupported aggregation function \"%s\"", function);
- ret = FAIL;
- }
-
- zbx_vector_dbl_destroy(&values);
-
- if (SUCCEED == ret)
- {
- char buffer[32];
-
- zbx_print_double(buffer, sizeof(buffer), value_dbl);
- *value = zbx_strdup(NULL, buffer);
- }
-
- return ret;
- }
-
if (0 == rows->values_num)
{
*error = zbx_strdup(*error, "no matching metrics found");
@@ -1666,6 +1574,104 @@ static int prometheus_extract_value(const zbx_vector_ptr_t *rows, const char *fu
/******************************************************************************
* *
+ * Function: prometheus_aggregate_values *
+ * *
+ * Purpose: aggregates row values *
+ * *
+ * Parameters: rows - [IN] the source rows *
+ * function - [IN] the aggregation function *
+ * value - [OUT] the aggregated value *
+ * error - [OUT] the error message *
+ * *
+ * Return value: SUCCEED - the values were aggregated successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int prometheus_aggregate_values(const zbx_vector_ptr_t *rows, const char *function, char **value, char **error)
+{
+ zbx_vector_dbl_t values;
+ int i, ret;
+ double value_dbl;
+ const zbx_prometheus_row_t *row;
+
+ zbx_vector_dbl_create(&values);
+
+ for (i = 0; i < rows->values_num; i++)
+ {
+ row = (const zbx_prometheus_row_t *)rows->values[i];
+
+ value_dbl = atof(row->value);
+ zbx_vector_dbl_append(&values, value_dbl);
+ }
+
+ if (0 == strcmp(function, "avg"))
+ {
+ ret = zbx_eval_calc_avg(&values, &value_dbl, error);
+ }
+ else if (0 == strcmp(function, "min"))
+ {
+ ret = zbx_eval_calc_min(&values, &value_dbl, error);
+ }
+ else if (0 == strcmp(function, "max"))
+ {
+ ret = zbx_eval_calc_max(&values, &value_dbl, error);
+ }
+ else if (0 == strcmp(function, "sum"))
+ {
+ zbx_eval_calc_sum(&values, &value_dbl);
+ ret = SUCCEED;
+ }
+ else if (0 == strcmp(function, "count"))
+ {
+ value_dbl = (double)values.values_num;
+ ret = SUCCEED;
+ }
+ else
+ {
+ *error = zbx_dsprintf(NULL, "unsupported aggregation function \"%s\"", function);
+ ret = FAIL;
+ }
+
+ zbx_vector_dbl_destroy(&values);
+
+ if (SUCCEED == ret)
+ {
+ char buffer[32];
+
+ zbx_print_double(buffer, sizeof(buffer), value_dbl);
+ *value = zbx_strdup(NULL, buffer);
+ }
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: prometheus_query_rows *
+ * *
+ * Purpose: performs the specified request on rows *
+ * *
+ * Parameters: rows - [IN] the source rows *
+ * request - [IN] the request (value, label, <function>) *
+ * output - [IN] the output template *
+ * value - [OUT] the result value *
+ * error - [OUT] the error message *
+ * *
+ * Return value: SUCCEED - the request was performed successfully *
+ * FAIL - otherwise *
+ * *
+ ******************************************************************************/
+static int prometheus_query_rows(const zbx_vector_ptr_t *rows, const char *request, const char *output,
+ char **value, char **error)
+{
+ if (0 == strcmp(request, "value") || 0 == strcmp(request, "label"))
+ return prometheus_extract_value(rows, output, value, error);
+ else
+ return prometheus_aggregate_values(rows, request, value, error);
+}
+
+/******************************************************************************
+ * *
* Function: prometheus_filter_rows *
* *
* Purpose: get rows matching the filter criteria *
@@ -1952,6 +1958,8 @@ static int prometheus_get_indexed_rows_by_label(zbx_prometheus_t *prom, zbx_prom
* *
* Parameters: data - [IN] the prometheus cache *
* fitler_data - [IN] the filter in text format *
+ * request - [IN] the data request - value, label, *
+ * <aggregation function> *
* output - [IN] the output template *
* value - [OUT] the extracted value *
* error - [OUT] the error message *
@@ -1960,8 +1968,8 @@ static int prometheus_get_indexed_rows_by_label(zbx_prometheus_t *prom, zbx_prom
* FAIL - otherwise *
* *
******************************************************************************/
-int zbx_prometheus_pattern_ex(zbx_prometheus_t *prom, const char *filter_data, const char *output, char **value,
- char **error)
+int zbx_prometheus_pattern_ex(zbx_prometheus_t *prom, const char *filter_data, const char *request,
+ const char *output, char **value, char **error)
{
zbx_prometheus_filter_t filter;
int ret = FAIL;
@@ -1979,9 +1987,18 @@ int zbx_prometheus_pattern_ex(zbx_prometheus_t *prom, const char *filter_data, c
zbx_vector_ptr_create(&rows);
- if (NULL != filter.function && '\0' != *output)
+ if (0 == strcmp(request, "label"))
+ {
+ if ('\0' == *output)
+ {
+ *error = zbx_strdup(NULL, "no output label specified");
+ zbx_free(errmsg);
+ goto cleanup;
+ }
+ }
+ else if ('\0' != *output)
{
- *error = zbx_strdup(NULL, "aggregation function cannot be used with output parameter");
+ *error = zbx_strdup(NULL, "output can be specified only with label request");
zbx_free(errmsg);
goto cleanup;
}
@@ -1991,7 +2008,7 @@ int zbx_prometheus_pattern_ex(zbx_prometheus_t *prom, const char *filter_data, c
prometheus_filter_rows(prows, &filter, &rows);
- if (FAIL == (ret = prometheus_extract_value(&rows, filter.function, output, value, &errmsg)))
+ if (FAIL == (ret = prometheus_query_rows(&rows, request, output, value, &errmsg)))
{
*error = zbx_dsprintf(*error, "data extraction error: %s", errmsg);
zbx_free(errmsg);
@@ -2014,6 +2031,8 @@ out:
* *
* Parameters: data - [IN] the prometheus data *
* fitler_data - [IN] the filter in text format *
+ * request - [IN] the data request - value, label, *
+ * <aggregation function> *
* output - [IN] the output template *
* value - [OUT] the extracted value *
* error - [OUT] the error message *
@@ -2022,8 +2041,8 @@ out:
* FAIL - otherwise *
* *
******************************************************************************/
-int zbx_prometheus_pattern(const char *data, const char *filter_data, const char *output, char **value,
- char **error)
+int zbx_prometheus_pattern(const char *data, const char *filter_data, const char *request, const char *output,
+ char **value, char **error)
{
zbx_prometheus_filter_t filter;
char *errmsg = NULL;
@@ -2041,9 +2060,18 @@ int zbx_prometheus_pattern(const char *data, const char *filter_data, const char
zbx_vector_ptr_create(&rows);
- if (NULL != filter.function && '\0' != *output)
+ if (0 == strcmp(request, "label"))
{
- *error = zbx_strdup(NULL, "aggregation function cannot be used with output parameter");
+ if ('\0' == *output)
+ {
+ *error = zbx_strdup(NULL, "no output label specified");
+ zbx_free(errmsg);
+ goto cleanup;
+ }
+ }
+ else if ('\0' != *output)
+ {
+ *error = zbx_strdup(NULL, "output can be specified only with label request");
zbx_free(errmsg);
goto cleanup;
}
@@ -2051,7 +2079,7 @@ int zbx_prometheus_pattern(const char *data, const char *filter_data, const char
if (FAIL == prometheus_parse_rows(&filter, data, &rows, NULL, error))
goto cleanup;
- if (FAIL == prometheus_extract_value(&rows, filter.function, output, value, &errmsg))
+ if (FAIL == prometheus_query_rows(&rows, request, output, value, &errmsg))
{
*error = zbx_dsprintf(*error, "data extraction error: %s", errmsg);
zbx_free(errmsg);
@@ -2104,13 +2132,6 @@ int zbx_prometheus_to_json(const char *data, const char *filter_data, char **val
goto out;
}
- if (NULL != filter.function)
- {
- *error = zbx_strdup(NULL, "aggregation function cannot be used when converting Prometheus data to JSON");
- zbx_free(errmsg);
- goto out;
- }
-
zbx_vector_ptr_create(&rows);
zbx_hashset_create(&hints, 100, prometheus_hint_hash, prometheus_hint_compare);
diff --git a/src/zabbix_server/preprocessor/item_preproc.c b/src/zabbix_server/preprocessor/item_preproc.c
index 6b741a8f0a0..00470dbd836 100644
--- a/src/zabbix_server/preprocessor/item_preproc.c
+++ b/src/zabbix_server/preprocessor/item_preproc.c
@@ -1536,7 +1536,7 @@ fail:
static int item_preproc_prometheus_pattern(zbx_preproc_cache_t *cache, zbx_variant_t *value, const char *params,
char **errmsg)
{
- char pattern[ITEM_PREPROC_PARAMS_LEN * ZBX_MAX_BYTES_IN_UTF8_CHAR + 1], *output, *value_out = NULL,
+ char pattern[ITEM_PREPROC_PARAMS_LEN * ZBX_MAX_BYTES_IN_UTF8_CHAR + 1], *request, *output, *value_out = NULL,
*err = NULL;
int ret = FAIL;
@@ -1545,17 +1545,23 @@ static int item_preproc_prometheus_pattern(zbx_preproc_cache_t *cache, zbx_varia
zbx_strlcpy(pattern, params, sizeof(pattern));
- if (NULL == (output = strchr(pattern, '\n')))
+ if (NULL == (request = strchr(pattern, '\n')))
{
*errmsg = zbx_strdup(*errmsg, "cannot find second parameter");
return FAIL;
}
+ *request++ = '\0';
+ if (NULL == (output = strchr(request, '\n')))
+ {
+ *errmsg = zbx_strdup(*errmsg, "cannot find third parameter");
+ return FAIL;
+ }
*output++ = '\0';
if (NULL == cache)
{
- ret = zbx_prometheus_pattern(value->data.str, pattern, output, &value_out, &err);
+ ret = zbx_prometheus_pattern(value->data.str, pattern, request, output, &value_out, &err);
}
else
{
@@ -1572,7 +1578,7 @@ static int item_preproc_prometheus_pattern(zbx_preproc_cache_t *cache, zbx_varia
zbx_preproc_cache_put(cache, ZBX_PREPROC_PROMETHEUS_PATTERN, prom_cache);
}
- ret = zbx_prometheus_pattern_ex(prom_cache, pattern, output, &value_out, &err);
+ ret = zbx_prometheus_pattern_ex(prom_cache, pattern, request, output, &value_out, &err);
}
out:
if (FAIL == ret)
diff --git a/tests/libs/zbxprometheus/prometheus_filter_init.c b/tests/libs/zbxprometheus/prometheus_filter_init.c
index 37b8d96f069..c0526d7a93f 100644
--- a/tests/libs/zbxprometheus/prometheus_filter_init.c
+++ b/tests/libs/zbxprometheus/prometheus_filter_init.c
@@ -77,7 +77,7 @@ void zbx_mock_test_entry(void **state)
zbx_prometheus_condition_test_t *metric = NULL, *value = NULL;
zbx_vector_ptr_t labels;
int ret, expected_ret, index;
- char *error = NULL, *function = NULL;
+ char *error = NULL;
zbx_mock_handle_t hmetric, hvalue, hlabels, hlabel, hfunction;
zbx_mock_error_t mock_ret;
@@ -87,7 +87,7 @@ void zbx_mock_test_entry(void **state)
filter = zbx_mock_get_parameter_string("in.filter");
- if (SUCCEED != (ret = zbx_prometheus_filter_parse(filter, &function, &metric, &labels, &value, &error)))
+ if (SUCCEED != (ret = zbx_prometheus_filter_parse(filter, &metric, &labels, &value, &error)))
printf("filter parsing error: %s\n", error);
expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return"));
@@ -103,20 +103,6 @@ void zbx_mock_test_entry(void **state)
hvalue = -1;
test_match("value", hvalue, value);
- if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("out.function", &hfunction))
- {
- const char *function_exp;
-
- if (NULL == function)
- fail_msg("expected function while got none");
-
- zbx_mock_string(hfunction, &function_exp);
-
- zbx_mock_assert_str_eq("function name", function_exp, function);
- }
- else
- zbx_mock_assert_ptr_eq("function name", NULL, function);
-
if (ZBX_MOCK_SUCCESS != zbx_mock_parameter("out.labels", &hlabels))
hlabels = -1;
@@ -152,7 +138,6 @@ void zbx_mock_test_entry(void **state)
zbx_vector_ptr_clear_ext(&labels, (zbx_clean_func_t)zbx_prometheus_condition_test_free);
zbx_vector_ptr_destroy(&labels);
- zbx_free(function);
zbx_free(error);
}
diff --git a/tests/libs/zbxprometheus/prometheus_filter_init.yaml b/tests/libs/zbxprometheus/prometheus_filter_init.yaml
index 7739e9c0974..28f3aef01a6 100644
--- a/tests/libs/zbxprometheus/prometheus_filter_init.yaml
+++ b/tests/libs/zbxprometheus/prometheus_filter_init.yaml
@@ -402,44 +402,4 @@ out:
value:
pattern: inf
op: ==
----
-test case: count(cpu{type="intel"} == 1)
-in:
- filter: count(cpu{type="intel"} == 1)
-out:
- return: SUCCEED
- metric:
- pattern: cpu
- op: =
- value:
- pattern: 1
- op: ==
- labels:
- - key: type
- pattern: intel
- op: =
- function: count
----
-test case: count( cpu{type="intel"} == 1 )
-in:
- filter: count( cpu{type="intel"} == 1 )
-out:
- return: SUCCEED
- metric:
- pattern: cpu
- op: =
- value:
- pattern: 1
- op: ==
- labels:
- - key: type
- pattern: intel
- op: =
- function: count
----
-test case: count(cpu{type="intel"} == 1
-in:
- filter: count(cpu{type="intel"} == 1
-out:
- return: FAIL
...
diff --git a/tests/libs/zbxprometheus/prometheus_test.c b/tests/libs/zbxprometheus/prometheus_test.c
index 7f928e2700d..776b3a473c3 100644
--- a/tests/libs/zbxprometheus/prometheus_test.c
+++ b/tests/libs/zbxprometheus/prometheus_test.c
@@ -55,7 +55,7 @@ static zbx_prometheus_condition_test_t *prometheus_condition_dup(zbx_prometheus_
return test_condition;
}
-int zbx_prometheus_filter_parse(const char *data, char **function, zbx_prometheus_condition_test_t **metric,
+int zbx_prometheus_filter_parse(const char *data, zbx_prometheus_condition_test_t **metric,
zbx_vector_ptr_t *labels, zbx_prometheus_condition_test_t **value, char **error)
{
zbx_prometheus_filter_t filter;
@@ -67,7 +67,6 @@ int zbx_prometheus_filter_parse(const char *data, char **function, zbx_prometheu
return FAIL;
}
- *function = (NULL != filter.function ? zbx_strdup(NULL, filter.function) : NULL);
*metric = prometheus_condition_dup(filter.metric);
*value = prometheus_condition_dup(filter.value);
diff --git a/tests/libs/zbxprometheus/prometheus_test.h b/tests/libs/zbxprometheus/prometheus_test.h
index 80d9c6de212..2c6e794524b 100644
--- a/tests/libs/zbxprometheus/prometheus_test.h
+++ b/tests/libs/zbxprometheus/prometheus_test.h
@@ -29,7 +29,7 @@ typedef struct
}
zbx_prometheus_condition_test_t;
-int zbx_prometheus_filter_parse(const char *data, char **function, zbx_prometheus_condition_test_t **metric,
+int zbx_prometheus_filter_parse(const char *data, zbx_prometheus_condition_test_t **metric,
zbx_vector_ptr_t *labels, zbx_prometheus_condition_test_t **value, char **error);
int zbx_prometheus_row_parse(const char *data, char **metric, zbx_vector_ptr_pair_t *labels, char **value,
diff --git a/tests/libs/zbxprometheus/zbx_prometheus_pattern.c b/tests/libs/zbxprometheus/zbx_prometheus_pattern.c
index 1bec96b4b87..3546474cb12 100644
--- a/tests/libs/zbxprometheus/zbx_prometheus_pattern.c
+++ b/tests/libs/zbxprometheus/zbx_prometheus_pattern.c
@@ -27,7 +27,7 @@
void zbx_mock_test_entry(void **state)
{
- const char *data, *params, *value_type;
+ const char *data, *params, *output, *request;
char *ret_err = NULL, *ret_output = NULL;
int ret, expected_ret;
@@ -35,9 +35,10 @@ void zbx_mock_test_entry(void **state)
data = zbx_mock_get_parameter_string("in.data");
params = zbx_mock_get_parameter_string("in.params");
- value_type = zbx_mock_get_parameter_string("in.value_type");
+ output = zbx_mock_get_parameter_string("in.output");
+ request = zbx_mock_get_parameter_string("in.request");
- if (SUCCEED != (ret = zbx_prometheus_pattern(data, params, value_type, &ret_output, &ret_err)))
+ if (SUCCEED != (ret = zbx_prometheus_pattern(data, params, request, output, &ret_output, &ret_err)))
zabbix_log(LOG_LEVEL_DEBUG, "Error: %s", ret_err);
expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.result"));
@@ -45,8 +46,6 @@ void zbx_mock_test_entry(void **state)
if (SUCCEED == ret)
{
- const char *output;
-
output = zbx_mock_get_parameter_string("out.output");
zbx_mock_assert_str_eq("Invalid zbx_prometheus_pattern() returned output", output, ret_output);
zbx_free(ret_output);
diff --git a/tests/libs/zbxprometheus/zbx_prometheus_pattern.yaml b/tests/libs/zbxprometheus/zbx_prometheus_pattern.yaml
index 17b6c647b93..3e714e71f75 100644
--- a/tests/libs/zbxprometheus/zbx_prometheus_pattern.yaml
+++ b/tests/libs/zbxprometheus/zbx_prometheus_pattern.yaml
@@ -3,7 +3,8 @@ test case: 'Get metric value using params: "wmi_os_physical_memory_free_bytes"'
in:
data: wmi_os_physical_memory_free_bytes 8.492331008e+09
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 8.492331008e+09
@@ -17,7 +18,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -31,7 +33,8 @@ in:
wmi_logical_disk_free_bytes{volume="D:"} 2.627731456e+09
wmi_logical_disk_free_bytes{volume="HarddiskVolume4"} 4.59276288e+08
params: 'wmi_logical_disk_free_bytes{volume="{#VOLUME}"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 3.5180249088e+11
@@ -45,7 +48,8 @@ in:
wmi_logical_disk_free_bytes{volume="{#VOLUME}"} 2.627731456e+09
wmi_logical_disk_free_bytes{volume="HarddiskVolume4"} 4.59276288e+08
params: 'wmi_logical_disk_free_bytes{volume="{#VOLUME}"}'
- value_type: volume
+ request: label
+ output: volume
out:
result: SUCCEED
output: '{#VOLUME}'
@@ -59,7 +63,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total",host=~".*"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -73,7 +78,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total",host=~".*"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -87,7 +93,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -101,7 +108,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu=~"cpu-tot.+"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -115,7 +123,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -129,7 +138,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu=~".*"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -142,7 +152,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu=~"cpu-tot.+"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -172,7 +183,8 @@ in:
wmi_service_state{name="diagnosticshub.standardcollector.service",state="stopped"} 1
wmi_service_state{name="diagnosticshub.standardcollector.service",state="unknown"} 0
params: wmi_service_state{name="dhcp"} == 1
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: 'running'
@@ -184,7 +196,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone="MSK"} 1
params: wmi_os_timezone{timezone=~".*"} == 1
- value_type: timezone
+ request: label
+ output: timezone
out:
result: SUCCEED
output: 'MSK'
@@ -197,7 +210,8 @@ in:
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"} 3 1395066363000
params: http_requests_total{code="400"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 3
@@ -206,7 +220,8 @@ test case: 'Escaping in label values'
in:
data: msdos_file_access_time_seconds{path="C:\\DIR\\FILE.TXT",error="Cannot find file:\n\"FILE.TXT\""} 1.458255915e9
params: msdos_file_access_time_seconds{error="Cannot find file:\n\"FILE.TXT\""} == 1.458255915e9
- value_type: path
+ request: label
+ output: path
out:
result: SUCCEED
output: 'C:\DIR\FILE.TXT'
@@ -215,7 +230,8 @@ test case: 'Minimalistic line'
in:
data: metric_without_timestamp_and_labels 12.47
params: metric_without_timestamp_and_labels
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 12.47
@@ -224,7 +240,8 @@ test case: 'A weird metric from before the epoch'
in:
data: something_weird{problem="division by zero"} +Inf -3982045
params: something_weird
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: +Inf
@@ -243,7 +260,8 @@ in:
http_request_duration_seconds_sum 53423
http_request_duration_seconds_count 144320
params: http_request_duration_seconds_bucket{le="+Inf"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 144320
@@ -261,7 +279,8 @@ in:
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
params: rpc_duration_seconds_sum
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.7560473e+07
@@ -270,7 +289,8 @@ test case: 'Invalid metric (expected "fail"): empty metric'
in:
data: ""
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -278,7 +298,8 @@ test case: 'Empty params'
in:
data: wmi_os_timezone{timezone="MSK"} 1
params: ""
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1
@@ -287,7 +308,8 @@ test case: 'Empty params but value_type is set'
in:
data: wmi_os_timezone{timezone="MSK"} 1
params: ""
- value_type: timezone
+ request: label
+ output: timezone
out:
result: SUCCEED
output: 'MSK'
@@ -300,7 +322,8 @@ in:
wmi_service_state{name="dhcp",state="stop pending"} 0
wmi_service_state{name="postdhcp",state="stopped"} 1
params: ""
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -308,7 +331,8 @@ test case: 'Invalid metric (expected "fail"): empty metric and empty params'
in:
data: ""
params: ""
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -316,7 +340,8 @@ test case: 'Invalid metric (expected "fail"): metric consists of spaces only #1'
in:
data: ' '
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -324,7 +349,8 @@ test case: 'Params hold multiple spaces only'
in:
data: wmi_os_timezone{timezone="MSK"} 1
params: ' '
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1
@@ -340,7 +366,8 @@ in:
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
params: ' '
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -348,7 +375,8 @@ test case: 'Invalid metric (expected "fail"): metric consists of spaces only #2'
in:
data: ' '
params: ' '
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -356,7 +384,8 @@ test case: 'Empty multiline metric'
in:
data: "\n\n\n\n"
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -364,7 +393,8 @@ test case: 'Empty value_type'
in:
data: wmi_os_physical_memory_free_bytes 8.492331008e+09
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 8.492331008e+09
@@ -373,7 +403,8 @@ test case: 'Invalid metric (expected "fail"): metric without value'
in:
data: wmi_os_physical_memory_free_bytes
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -384,7 +415,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone=} 1
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -395,7 +427,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone} 1
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -406,7 +439,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone} 1
params: wmi_os_timezone == 1
- value_type: timezone
+ request: label
+ output: timezone
out:
result: FAIL
---
@@ -417,7 +451,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone} 1
params: wmi_os_timezone{timezone=~".*"} == 1
- value_type: timezone
+ request: label
+ output: timezone
out:
result: FAIL
---
@@ -425,7 +460,8 @@ test case: 'Invalid metric (expected "fail"): wrong metric data'
in:
data: asdlkdlkasdasd09814mnvclmx
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -433,7 +469,8 @@ test case: 'Invalid metric (expected "fail"): wrong metric data (a space within)
in:
data: asdlkdlkasda sd09814mnvclmx
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -441,7 +478,8 @@ test case: 'Invalid metric (expected "fail"): metric name with unsupported chara
in:
data: wmi_os_physical_^&;memory_free_bytes 8.492331008e+09
params: wmi_os_physical_^&;memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -452,7 +490,8 @@ in:
# TYPE wmi_os_timezone gauge
asdlkdlkasdasd09814mnvclmx
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -460,7 +499,8 @@ test case: 'Invalid metric (expected "fail"): metric consists of hash symbol onl
in:
data: '#'
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -468,7 +508,8 @@ test case: 'Invalid metric (expected "fail"): metric consists of empty space onl
in:
data: ' '
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -476,7 +517,8 @@ test case: 'Invalid metric (expected "fail"): metric consists of 3 byte UTF-8 ch
in:
data: "ࠀ"
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -488,7 +530,8 @@ in:
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="-⃠"} 3 1395066363000
params: http_requests_total == 3
- value_type: code
+ request: label
+ output: code
out:
result: SUCCEED
output: '-⃠'
@@ -497,7 +540,8 @@ test case: 'Invalid metric (expected "fail"): metric with missing "{"'
in:
data: cpu_usage_systemcpu="cpu-total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -505,7 +549,8 @@ test case: 'Invalid metric (expected "fail"): metric with missing "}"'
in:
data: cpu_usage_system{cpu="cpu-total" 1.1940298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -513,7 +558,8 @@ test case: 'Invalid metric (expected "fail"): metric with missing "'
in:
data: cpu_usage_system{cpu=cpu-total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -521,7 +567,8 @@ test case: 'Invalid metric (expected "fail"): metric with missing ","'
in:
data: cpu_usage_system{cpu="cpu-total"host="host1"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -529,7 +576,8 @@ test case: 'Invalid metric (expected "fail"): metric with missing "," and params
in:
data: cpu_usage_system{cpu="cpu-total"host="host1"} 1.1940298507220641
params: ""
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -542,7 +590,8 @@ in:
cpu_usage_system{cpu=="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -555,7 +604,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -563,7 +613,8 @@ test case: 'Invalid metric (expected "fail"): double equal sign (==) instead of
in:
data: cpu_usage_system{cpu=="cpu-total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -571,7 +622,8 @@ test case: 'Label value and params holds new line character'
in:
data: "cpu_usage_system{cpu=\"cpu\ntotal\"} 1.1940298507220641"
params: "cpu_usage_system{cpu=\"cpu\ntotal\"}"
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -580,7 +632,8 @@ test case: 'Invalid metric (expected "fail"): metric name holds new line charact
in:
data: "cpu_usa\nge_system{cpu=\"cputotal\"} 1.1940298507220641"
params: 'cpu_usage_system{cpu="cputotal"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -588,7 +641,8 @@ test case: 'Invalid params (expected "fail"): params hold new line character'
in:
data: 'cpu_usage_system{cpu=\"cputotal\"} 1.1940298507220641'
params: "cpu_usa\nge_system{cpu=\"cputotal\"}"
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -596,7 +650,8 @@ test case: 'Invalid metric (expected "fail"): metric name and params hold new li
in:
data: "cpu_usa\nge_system{cpu=\"cputotal\"} 1.1940298507220641"
params: "cpu_usa\nge_system{cpu=\"cputotal\"}"
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -609,7 +664,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu=="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -622,7 +678,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"} = 1.1940298507220641
- value_type: cpu
+ request: label
+ output: cpu
out:
result: FAIL
---
@@ -635,7 +692,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"} = 1.1940298507220641
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -664,7 +722,8 @@ in:
wmi_service_state{name="diagnosticshub.standardcollector.service",state="stopped"} 1
wmi_service_state{name="diagnosticshub.standardcollector.service",state="unknown"} 0
params: wmi_service_state{name="dhcp"} == 1
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -680,7 +739,8 @@ in:
wmi_service_state{name="dhcp",state="stopped"} 1
wmi_service_state{name="dhcp",state="unknown"} 1
params: wmi_service_state{name="dhcp"} == 1
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -704,7 +764,8 @@ in:
wmi_service_state{name="dhcp",state="stopped"} 1
wmi_service_state{name="dhcp",state="unknown"} 1
params: wmi_service_state{name="dhcp"} == 1
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -730,7 +791,8 @@ in:
wmi_service_state{name="dhcp",state="unknown"} 1
wmi_service_state{name="dhcp",state="unknown"} 0
params: wmi_service_state == 1
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -738,7 +800,8 @@ test case: 'Metric with "Nan" value'
in:
data: wmi_os_physical_memory_free_bytes Nan
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: Nan
@@ -747,7 +810,8 @@ test case: 'Metric with "+Inf" value'
in:
data: wmi_os_physical_memory_free_bytes +Inf
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: +Inf
@@ -756,7 +820,8 @@ test case: 'Metric with "-Inf" value'
in:
data: wmi_os_physical_memory_free_bytes -Inf
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: -Inf
@@ -765,7 +830,8 @@ test case: 'Invalid metric (expected "fail"): metric with "NAN" value'
in:
data: wmi_os_physical_memory_free_bytes NAN
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
output: NAN
result: SUCCEED
@@ -774,7 +840,8 @@ test case: 'Metric with timestamp'
in:
data: wmi_os_physical_memory_free_bytes 8.492331008e+09 25
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 8.492331008e+09
@@ -788,7 +855,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -797,7 +865,8 @@ test case: 'Metric with negative timestamp'
in:
data: http_requests_total{method="post",code="200"} 1027 -123
params: http_requests_total
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1027
@@ -806,7 +875,8 @@ test case: 'Metric with negative value'
in:
data: http_requests_total{method="post",code="200"} -1027
params: http_requests_total
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: -1027
@@ -820,7 +890,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: -654
@@ -834,7 +905,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{cpu="cpu-total",__name__="cpu_usage_system"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -848,7 +920,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{cpu=~"cpu-tot.+",__name__=~"cpu_usage_syst.+"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -862,7 +935,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: something
+ request: label
+ output: something
out:
result: FAIL
---
@@ -875,7 +949,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.19402985
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: 'cpu_usage_system{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -888,7 +963,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.19402985
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: 'cpu_usage_system{__name__=~"cpu_age_syst.+",cpu=~"cpu-tot.+"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -899,7 +975,8 @@ in:
# TYPE wmi_logical_disk_free_bytes gauge
wmi_logical_disk_free_bytes{volume="C:"} 3.5180249088e+11
params: wmi_logical_disk_free_bytes
- value_type: \\&{},.13%},.
+ request: label
+ output: \\&{},.13%},.
out:
result: FAIL
---
@@ -913,7 +990,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -928,7 +1006,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -942,7 +1021,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -956,7 +1036,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -970,7 +1051,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -979,7 +1061,8 @@ test case: 'Multiple spaces before metric value'
in:
data: wmi_os_physical_memory_free_bytes 8.492331008e+09
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 8.492331008e+09
@@ -992,7 +1075,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1001,7 +1085,8 @@ test case: 'Invalid metric (expected "fail"): unsupported characters in label na
in:
data: cpu_usage_system{cp%^&u="cpu-total"} 1.1940298507220641
params: cpu_usage_system{cp%^&u="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1012,7 +1097,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone="MSK"} 1
params: wmi_os_timezone
- value_type: timezone
+ request: label
+ output: timezone
out:
result: SUCCEED
output: 'MSK'
@@ -1021,7 +1107,8 @@ test case: 'Metric name consists of all supported characters'
in:
data: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789 1
params: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1
@@ -1030,7 +1117,8 @@ test case: 'Label name consists of all supported characters'
in:
data: cpu_usage_system{AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789="test"} 1
params: cpu_usage_system == 1
- value_type: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789
+ request: label
+ output: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789
out:
result: SUCCEED
output: 'test'
@@ -1044,7 +1132,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total",host=".*"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1057,7 +1146,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total",host=~"[0-9"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1070,7 +1160,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{__name__="cpu_usage_system",__cpu__="cpu-total"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1083,7 +1174,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{__name__=~"cpu_usage_syst.+",__cpu__=~"cpu-tot.+"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1091,7 +1183,8 @@ test case: 'Invalid metric (expected "fail"): incorrect float'
in:
data: wmi_logical_disk_free_bytes{volume="D:"} 8.49233.1008e+09
params: wmi_logical_disk_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1104,7 +1197,8 @@ in:
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: '{}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1117,7 +1211,8 @@ in:
a{cpu="cpu0"} 1.1940298507220641
a{cpu="cpu1"} 1.1340298507220641
params: a{}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1125,7 +1220,8 @@ test case: 'Invalid metric (expected "fail"): "{}"'
in:
data: '{}'
params: metric
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1136,7 +1232,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone="MSK"} -1
params: wmi_os_timezone{timezone="MSK"} == -1
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: -1
@@ -1147,7 +1244,8 @@ in:
random_date{year="2019",month="february",day="02/12/2019"} 1
random_date{year="2019",month="march",day="03/07/2019"} 2
params: random_date{year="2019",day=~"^([0-2][0-9]|(3)[0-1])(\\/)(((0)[0-9])|((1)[0-2]))(\\/)\\d{4}$"} == 1
- value_type: month
+ request: label
+ output: month
out:
result: SUCCEED
output: 'february'
@@ -1158,7 +1256,8 @@ in:
random_date{year="2019",month="february",day="02/12/2019"} 1
random_date{year="2019",month="march",day="03/07/2019"} 2
params: random_date{year="2019",day=~"^([0-2][0-9]|(3)[0-1])(\\/)(((0)[0-9])|((1)[0-2]))(\\/)\\d{4}$"} == 2
- value_type: month
+ request: label
+ output: month
out:
result: SUCCEED
output: 'march'
@@ -1169,7 +1268,8 @@ in:
random_date{year="2019",month="february",day="02/12/2019"} 1
random_date{year="2019",month="march",day="03/07/2019"} 2
params: random_date{year="2019",day=~"^([0-2][0-9]|(3)[0-1])(\\/)(((0)[0-9])|((1)[0-2]))(\\/)\\d{4}$"} == 2
- value_type: day
+ request: label
+ output: day
out:
result: SUCCEED
output: '03/07/2019'
@@ -1180,7 +1280,8 @@ in:
random_date{year="2019",month="february",day="02/12/2019"} 1
random_date{year="2019",month="march",day="03-07-2019"} 2
params: random_date{year="2019",day=~"^([0-2][0-9]|(3)[0-1])(\\/)(((0)[0-9])|((1)[0-2]))(\\/)\\d{4}$"} == 2
- value_type: day
+ request: label
+ output: day
out:
result: FAIL
---
@@ -1190,7 +1291,8 @@ in:
random_date{year="2019",month="february",day="02/12/2019"} 1
random_date{year="2019",month="march",day="03/07/2019"} 2
params: random_date{year="2019",day=~"^([0-2][0-9]|(3)[0-1])(\\/)(((0)[0-9])|((1)[0-2]))(\\/)\\d{4}$"}
- value_type: day
+ request: label
+ output: day
out:
result: FAIL
---
@@ -1201,7 +1303,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone="MSK"} 1
params: wmi_os_timezone 1
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1212,7 +1315,8 @@ in:
some_user{country="lv",addr="user2@domain.org"} 2
some_user{country="lv",addr="no_valid_addr"} 2
params: some_user{country="lv",addr=~"[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}"} == 1
- value_type: addr
+ request: label
+ output: addr
out:
result: SUCCEED
output: 'user1@domain.com'
@@ -1224,7 +1328,8 @@ in:
some_user{country="lv",addr="user2@domain.org"} 2
some_user{country="lv",addr="no_valid_addr"} 2
params: some_user{country="lv",addr=~"^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"} == 2
- value_type: addr
+ request: label
+ output: addr
out:
result: SUCCEED
output: 'user2@domain.org'
@@ -1236,7 +1341,8 @@ in:
some_user{country="lv",addr="user2@domain.org"} 2
some_user{country="lv",addr="no_valid_addr"} 3
params: some_user{country="lv",addr=~"^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"} == 3
- value_type: addr
+ request: label
+ output: addr
out:
result: FAIL
---
@@ -1247,7 +1353,8 @@ in:
some_user{country="lv",addr="user2@domain.org"} 2
some_user{country="lv",addr="no_valid_addr"} 3
params: some_user{country="lv",addr=~"^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"}
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1255,7 +1362,8 @@ test case: 'Label value holds "{"'
in:
data: cpu_usage_system{cpu="cpu{total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu{total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1264,7 +1372,8 @@ test case: 'Label value holds "{}"'
in:
data: cpu_usage_system{cpu="cpu{}total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu{}total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1273,7 +1382,8 @@ test case: 'Label value holds "}"'
in:
data: cpu_usage_system{cpu="cpu}total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu}total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1282,7 +1392,8 @@ test case: 'Label value holds ","'
in:
data: important_metric{important_number="42,0"} 42
params: important_metric{important_number="42,0"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 42
@@ -1291,7 +1402,8 @@ test case: 'Get label value (cpu) using params: "cpu_usage_system{cpu="cpu{total
in:
data: cpu_usage_system{cpu="cpu{total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu{total"} == 1.1940298507220641
- value_type: cpu
+ request: label
+ output: cpu
out:
result: SUCCEED
output: 'cpu{total'
@@ -1300,7 +1412,8 @@ test case: 'Get label value (cpu) using params: "cpu_usage_system{cpu="cpu}total
in:
data: cpu_usage_system{cpu="cpu}total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu}total"} == 1.1940298507220641
- value_type: cpu
+ request: label
+ output: cpu
out:
result: SUCCEED
output: 'cpu}total'
@@ -1309,7 +1422,8 @@ test case: 'Metric with five values'
in:
data: cpu_usage_system{cpu="cputotal"} 1.1940298507220641 2.23443 333 four five
params: cpu_usage_system{cpu="cputotal"} == 1.1940298507220641
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1324,7 +1438,8 @@ in:
wmi_os_timezone{timezone="MSK"} 1
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu1",host=~".*"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1340298507220641
@@ -1339,7 +1454,8 @@ in:
wmi_os_timezone{timezone="MSK"} 1
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: wmi_os_timezone
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1
@@ -1357,7 +1473,8 @@ in:
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"} 3 1395066363000
params: http_requests_total == 3
- value_type: code
+ request: label
+ output: code
out:
result: SUCCEED
output: 400
@@ -1375,7 +1492,8 @@ in:
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"} 3 1395066363000
params: '{cpu="cpu0"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1393,7 +1511,8 @@ in:
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400",host="host1"} 3 1395066363000
params: '{host="host1"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1406,7 +1525,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1",perf="100"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1",perf="100"} 1.1340298507220641
params: cpu_usage_system { cpu = "cpu-total" , host = "host1",perf="100" }
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1419,7 +1539,8 @@ in:
http_requests_total{method="post2",code="200"} 1027 1395066363000
http_requests_total{method="post1",code="400"} 3 1395066363000
params: http_requests_total{code="400"}==3
- value_type: "method"
+ request: label
+ output: "method"
out:
result: SUCCEED
output: post1
@@ -1432,7 +1553,8 @@ in:
http_requests_total{method="post1",code="200"} 1027 1395066363000
http_requests_total{method="post2",code="400"} 3 1395066363000
params: http_requests_total{code="400"} == 3
- value_type: "method"
+ request: label
+ output: "method"
out:
result: SUCCEED
output: post2
@@ -1441,7 +1563,8 @@ test case: 'Invalid metric (expected "fail"): metric with string value'
in:
data: wmi_os_physical_memory_free_bytes some_value
params: wmi_os_physical_memory_free_bytes
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1452,7 +1575,8 @@ in:
# TYPE wmi_os_timezone gauge
wmi_os_timezone{timezone="MSK"} 1
params: wmi_os_timezone{timezone="MSK"} == some_value
- value_type: "timezone"
+ request: label
+ output: "timezone"
out:
result: FAIL
---
@@ -1465,7 +1589,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
params: '{__name__=~".*",cpu="cpu-total",__name__="cpu_usage_system"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1478,7 +1603,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1",perf="100"} 1.1640298507220641
cpu_usage_system{cpu="cpu1",host="host1",perf="100"} 1.1340298507220641
params: '{cpu=~".*",cpu=~"cpu-tot.+",perf="100"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 1.1940298507220641
@@ -1492,7 +1618,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1",perf="100"} 1.1640298507220641
cpu_usage_system{cpu="cpu1",host="host1",perf="100"} 1.1340298507220641
params: '{cpu=~"z.+",cpu=~"cpu-tot.+",perf="100"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1505,7 +1632,8 @@ in:
cpu_usage_system{cpu="cpu0",host="host1",perf="100"} 1.1640298507220641
cpu_usage_system{cpu="cpu1",host="host1",perf="100"} 1.1340298507220641
params: '{cpu=~"z.+",cpu=~"y.+",perf="100"}'
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1516,7 +1644,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} inf
params: apache == INF
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1527,7 +1656,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} +inf
params: apache == INF
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1538,7 +1668,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} nan
params: apache == NAN
- value_type: ""
+ request: value
+ output: ""
out:
result: FAIL
---
@@ -1549,7 +1680,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 0
params: apache == INF
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: red
@@ -1561,7 +1693,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 0
params: apache == +INF
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: red
@@ -1573,7 +1706,8 @@ in:
apache{state="yellow"} -Inf
apache{state="green"} 0
params: apache == -INF
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: yellow
@@ -1585,7 +1719,8 @@ in:
apache{state="yellow"} NaN
apache{state="green"} 0
params: apache == -INF
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -1596,7 +1731,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} NaN
params: apache == NAN
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1608,7 +1744,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 1.0
params: apache == 1
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1620,7 +1757,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 1e1
params: apache == 10
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1632,7 +1770,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 1.25e2
params: apache == 125
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1644,7 +1783,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 1e-2
params: apache == 00.0100
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1656,7 +1796,8 @@ in:
apache{state="yellow"} 1.25e2
apache{state="green"} 12500e-2
params: apache == 125
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -1667,7 +1808,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} +1
params: apache == 1
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1679,7 +1821,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} +1
params: apache == +1
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1691,7 +1834,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} 1
params: apache == +1
- value_type: state
+ request: label
+ output: state
out:
result: SUCCEED
output: green
@@ -1703,7 +1847,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} -1
params: apache == +1
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -1714,7 +1859,8 @@ in:
apache{state="yellow"} 0
apache{state="green"} +1
params: apache == -1
- value_type: state
+ request: label
+ output: state
out:
result: FAIL
---
@@ -1725,7 +1871,8 @@ in:
cpu_usage_system{cpu="cpu0",state="10",host="host2"} nan
cpu_usage_system{cpu="cpu1",state="88",host="host3"} 3.5180249088e+11
params: cpu_usage_system==3.5180249088e+11
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 3.5180249088e+11
@@ -1738,7 +1885,8 @@ in:
cpu_usage_system{cpu="cpu-total",host="host1"} 1.23456
cpu_usage_system{cpu="cpu0",host="host1"} 7.891011
params: cpu_usage_system{cpu!="cpu-total"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 7.891011
@@ -1751,9 +1899,83 @@ in:
cpu_usage_system{cpu="cpu-total",host="host1"} 1.23456
cpu_usage_system{cpu="cpu0",host="host1"} 7.891011
params: cpu_usage_system{cpu!~"total$"}
- value_type: ""
+ request: value
+ output: ""
out:
result: SUCCEED
output: 7.891011
+---
+test case: 'Count the metrics'
+in:
+ data: |
+ apache{state="red"} 0
+ apache{state="yellow"} 0
+ apache{state="green"} 1
+ params: apache
+ request: count
+ output: ""
+out:
+ result: SUCCEED
+ output: 3
+---
+test case: 'Sum metric values using params: "cpu_usage_system{cpu=~"cpu-total"}"'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 100.0
+ cpu_usage_system{cpu="cpu0"} 60.0
+ cpu_usage_system{cpu="cpu1"} 40.0
+ params: cpu_usage_system{cpu=~"cpu[0-9]+"}
+ request: sum
+ output: ""
+out:
+ result: SUCCEED
+ output: 100
+---
+test case: 'Avg metric values using params: "cpu_usage_system{cpu=~"cpu-total"}"'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 100.0
+ cpu_usage_system{cpu="cpu0"} 60.0
+ cpu_usage_system{cpu="cpu1"} 40.0
+ params: cpu_usage_system{cpu=~"cpu[0-9]+"}
+ request: avg
+ output: ""
+out:
+ result: SUCCEED
+ output: 50
+---
+test case: 'Min metric values using params: "cpu_usage_system{cpu=~"cpu-total"}"'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 100.0
+ cpu_usage_system{cpu="cpu0"} 60.0
+ cpu_usage_system{cpu="cpu1"} 40.0
+ params: cpu_usage_system{cpu=~"cpu[0-9]+"}
+ request: min
+ output: ""
+out:
+ result: SUCCEED
+ output: 40
+---
+test case: 'Max metric values using params: "cpu_usage_system{cpu=~"cpu-total"}"'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 100.0
+ cpu_usage_system{cpu="cpu0"} 60.0
+ cpu_usage_system{cpu="cpu1"} 40.0
+ params: cpu_usage_system{cpu=~"cpu[0-9]+"}
+ request: max
+ output: ""
+out:
+ result: SUCCEED
+ output: 60
...
diff --git a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml
index 362ee0c5b0f..ef12178fa0a 100644
--- a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml
+++ b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml
@@ -1657,7 +1657,7 @@ in:
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "cpu_usage_system{cpu=\"cpu-total\",host=~\".*\"}\n"
+ params: "cpu_usage_system{cpu=\"cpu-total\",host=~\".*\"}\nvalue\n"
out:
return: SUCCEED
value: 1.1940298507220641
@@ -1670,7 +1670,7 @@ in:
data: metric_without_timestamp_and_labels 12.47
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "metric_without_timestamp_and_labels\n"
+ params: "metric_without_timestamp_and_labels\nvalue\n"
out:
return: SUCCEED
value: 12.47
@@ -1688,7 +1688,7 @@ in:
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "{cpu=\"cpu0\",__name__=\"cpu_usage_system\"}\n"
+ params: "{cpu=\"cpu0\",__name__=\"cpu_usage_system\"}\nvalue\n"
out:
return: SUCCEED
value: 1.1940298507220641
@@ -1705,7 +1705,7 @@ in:
http_requests_total{method="post",code="400"} 3 1395066363000
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "http_requests_total{code=\"200\"}\n"
+ params: "http_requests_total{code=\"200\"}\nvalue\n"
out:
return: SUCCEED
value: 1027
@@ -1721,7 +1721,7 @@ in:
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "\n"
+ params: "\nvalue\n"
out:
return: SUCCEED
value: 1.1340298507220641
@@ -1737,7 +1737,7 @@ in:
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "cpu_usage_system\n"
+ params: "cpu_usage_system\nvalue\n"
out:
return: SUCCEED
value: 1.1340298507220641
@@ -1755,7 +1755,7 @@ in:
cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641
step:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
- params: "cpu_usage_system{cpu=\"cpu0\"} == 1.1940298507220641\nhost"
+ params: "cpu_usage_system{cpu=\"cpu0\"} == 1.1940298507220641\nlabel\nhost"
out:
return: SUCCEED
value: host2
@@ -1772,6 +1772,7 @@ in:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
params: |-
AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789 == 123123123
+ label
AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789
out:
return: SUCCEED
@@ -1792,6 +1793,7 @@ in:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
params: |-
cpu_usage_system{cpu="cpu0"} == 1.1940298507220641
+ label
host
out:
return: SUCCEED
@@ -1812,6 +1814,7 @@ in:
type: ZBX_PREPROC_PROMETHEUS_PATTERN
params: |-
cpu_usage_system{cpu="cpu1"}
+ label
host
out:
return: SUCCEED