diff options
-rw-r--r-- | src/libs/zbxprometheus/zbxprometheus.c | 64 | ||||
-rw-r--r-- | tests/libs/zbxprometheus/prometheus_filter_init.yaml | 14 |
2 files changed, 47 insertions, 31 deletions
diff --git a/src/libs/zbxprometheus/zbxprometheus.c b/src/libs/zbxprometheus/zbxprometheus.c index eb978e14b86..b6ea2bd0ca9 100644 --- a/src/libs/zbxprometheus/zbxprometheus.c +++ b/src/libs/zbxprometheus/zbxprometheus.c @@ -607,48 +607,52 @@ static int prometheus_filter_parse_labels(zbx_prometheus_filter_t *filter, const loc->l = pos; pos = skip_spaces(data, pos + 1); - while ('}' != data[pos]) + if ('}' != data[pos]) { - zbx_prometheus_condition_op_t op; - - if (FAIL == parse_condition(data, pos, &loc_key, &loc_op, &loc_value)) + while (1) { - *error = zbx_dsprintf(*error, "cannot parse label condition at \"%s\"", data + pos); - return FAIL; - } + zbx_prometheus_condition_op_t op; - op = str_loc_op(data, &loc_op); - if (0 == strncmp(data + loc_key.l, "__name__", loc_key.r - loc_key.l + 1)) - { - if (NULL != filter->metric) + if (FAIL == parse_condition(data, pos, &loc_key, &loc_op, &loc_value)) { - *error = zbx_strdup(*error, "duplicate metric condition specified"); + *error = zbx_dsprintf(*error, "cannot parse label condition at \"%s\"", data + pos); return FAIL; } - filter->metric = prometheus_condition_create(NULL, str_loc_unquote_dyn(data, &loc_value), op); - } - else - { - zbx_prometheus_condition_t *condition; + op = str_loc_op(data, &loc_op); + if (0 == strncmp(data + loc_key.l, "__name__", loc_key.r - loc_key.l + 1)) + { + if (NULL != filter->metric) + { + *error = zbx_strdup(*error, "duplicate metric condition specified"); + return FAIL; + } + + filter->metric = prometheus_condition_create(NULL, + str_loc_unquote_dyn(data, &loc_value), op); + } + else + { + zbx_prometheus_condition_t *condition; - condition = prometheus_condition_create(str_loc_dup(data, &loc_key), - str_loc_unquote_dyn(data, &loc_value), op); - zbx_vector_ptr_append(&filter->labels, condition); - } + condition = prometheus_condition_create(str_loc_dup(data, &loc_key), + str_loc_unquote_dyn(data, &loc_value), op); + zbx_vector_ptr_append(&filter->labels, condition); + } - pos = skip_spaces(data, loc_value.r + 1); + pos = skip_spaces(data, loc_value.r + 1); + + if (',' != data[pos]) + { + if ('}' == data[pos]) + break; + + *error = zbx_strdup(*error, "missing label condition list terminating character \"}\""); + return FAIL; + } - if (',' == data[pos]) - { pos = skip_spaces(data, pos + 1); - continue; - } - if ('\0' == data[pos]) - { - *error = zbx_strdup(*error, "missing label condition list terminating character \"}\""); - return FAIL; } } diff --git a/tests/libs/zbxprometheus/prometheus_filter_init.yaml b/tests/libs/zbxprometheus/prometheus_filter_init.yaml index d7234f25f70..eb0e0ee3ba4 100644 --- a/tests/libs/zbxprometheus/prometheus_filter_init.yaml +++ b/tests/libs/zbxprometheus/prometheus_filter_init.yaml @@ -28,7 +28,7 @@ out: pattern: intel op: = --- -test case: '{__name__="cpu", type="intel", cores="4"}' +test case: '{__name__="cpu", type="intel", cores=~"4"}' in: filter: '{__name__="cpu", type="intel", cores=~"4"}' out: @@ -224,5 +224,17 @@ in: filter: sensor == 1e1 1 out: return: FAIL +--- +test case: '{type="intel"cores="4"}' +in: + filter: '{type="intel"cores=~"4"}' +out: + return: FAIL +--- +test case: '{}' +in: + filter: '{}' +out: + return: SUCCEED ... |