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:
authorAleksejs Šestakovs <aleksejs.sestakovs@zabbix.com>2019-02-18 11:31:52 +0300
committerAleksejs Šestakovs <aleksejs.sestakovs@zabbix.com>2019-02-18 11:31:52 +0300
commitb7ecd64972014436d164d06278bfc92aec208573 (patch)
treec8f3aade8b85244c2f9bdd27394e0c5d21e6e775 /tests/libs/zbxprometheus
parentd06b9de4522fda5656c143eb99c4ab3b8d642c74 (diff)
.......... [DEV-974] added tests for prometheus_to_json and preprocessing
Diffstat (limited to 'tests/libs/zbxprometheus')
-rw-r--r--tests/libs/zbxprometheus/zbx_prometheus_getmetric.c11
-rw-r--r--tests/libs/zbxprometheus/zbx_prometheus_getmetric.yaml326
-rw-r--r--tests/libs/zbxprometheus/zbx_prometheus_tojson.c10
-rw-r--r--tests/libs/zbxprometheus/zbx_prometheus_tojson.yaml2202
4 files changed, 2434 insertions, 115 deletions
diff --git a/tests/libs/zbxprometheus/zbx_prometheus_getmetric.c b/tests/libs/zbxprometheus/zbx_prometheus_getmetric.c
index 333a2234f0f..b6cf224408e 100644
--- a/tests/libs/zbxprometheus/zbx_prometheus_getmetric.c
+++ b/tests/libs/zbxprometheus/zbx_prometheus_getmetric.c
@@ -17,9 +17,6 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-/* Temporary printf debug output - remove it before final commit */
-#define MY_DEBUG_PRINTF
-
#include "zbxmocktest.h"
#include "zbxmockdata.h"
#include "zbxmockassert.h"
@@ -40,14 +37,6 @@ void zbx_mock_test_entry(void **state)
value_type = zbx_mock_get_parameter_string("in.value_type");
result = zbx_mock_get_parameter_string("out.result");
-#ifdef MY_DEBUG_PRINTF
- /* Add printfs for the debug in case of failed test */
- printf("MYDBG_YAML_ data: %s\n", data);
- printf("MYDBG_YAML_ params: %s\n", params);
- printf("MYDBG_YAML_ value_type: %s\n", value_type);
- printf("MYDBG_YAML_ result: %s\n", result);
-#endif
-
if (SUCCEED == (ret = zbx_prometheus_pattern(data, params, value_type, &ret_output, &ret_err)))
{
/* Check result and output */
diff --git a/tests/libs/zbxprometheus/zbx_prometheus_getmetric.yaml b/tests/libs/zbxprometheus/zbx_prometheus_getmetric.yaml
index e061a0fdf31..50b4c88b99a 100644
--- a/tests/libs/zbxprometheus/zbx_prometheus_getmetric.yaml
+++ b/tests/libs/zbxprometheus/zbx_prometheus_getmetric.yaml
@@ -1,5 +1,5 @@
---
-test case: 'Get metric value using params: wmi_os_physical_memory_free_bytes'
+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
@@ -8,7 +8,7 @@ out:
result: succeed
output: 8.492331008e+09
---
-test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu="cpu-total"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -22,7 +22,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: wmi_logical_disk_free_bytes{volume="{#VOLUME}"}'
+test case: 'Get metric value using params: "wmi_logical_disk_free_bytes{volume="{#VOLUME}"}"'
in:
data: |
# HELP wmi_logical_disk_free_bytes Free space in bytes (LogicalDisk.PercentFreeSpace)
@@ -36,7 +36,7 @@ out:
result: succeed
output: 3.5180249088e+11
---
-test case: 'Get label value using params: wmi_logical_disk_free_bytes{volume="{#VOLUME}"}'
+test case: 'Get label value (volume) using params: "wmi_logical_disk_free_bytes{volume="{#VOLUME}"}"'
in:
data: |
# HELP wmi_logical_disk_free_bytes Free space in bytes (LogicalDisk.PercentFreeSpace)
@@ -50,7 +50,7 @@ out:
result: succeed
output: '"{#VOLUME}"'
---
-test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~".*"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu="cpu-total",host=~".*"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -64,7 +64,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~"*",\value=~".*"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu="cpu-total",host=~"*",\value=~".*"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -78,7 +78,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~"*"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu="cpu-total",host=~"*"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -92,7 +92,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu="cpu-total"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -106,7 +106,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: cpu_usage_system{cpu=~"cpu-tot.+"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu=~"cpu-tot.+"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -120,7 +120,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: {__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
+test case: 'Get metric value using params: "{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -134,7 +134,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get metric value using params: cpu_usage_system{cpu=~".*"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu=~".*"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -152,7 +152,7 @@ out:
cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
---
-test case: 'Get metric value using params: cpu_usage_system{cpu=~"cpu-tot.+"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu=~"cpu-tot.+"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -166,7 +166,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get label "state" value using params: wmi_service_state{name="dhcp"} == 1'
+test case: 'Get label value (state) using params: "wmi_service_state{name="dhcp"} == 1"'
in:
data: |
wmi_service_state{name="devicesflowusersvc_7b100",state="running"} 1
@@ -196,7 +196,7 @@ out:
result: succeed
output: '"running"'
---
-test case: 'Get label "timezone" value using params: wmi_os_timezone{timezone=~".*"} == 1'
+test case: 'Get label value (timezone) using params: "wmi_os_timezone{timezone=~".*"} == 1"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -208,7 +208,7 @@ out:
result: succeed
output: '"MSK"'
---
-test case: 'Get metric for http_requests_total{code="400"} 3 1395066363000'
+test case: 'Multiple spaces in metric before the value'
in:
data: |
# HELP http_requests_total The total number of HTTP requests.
@@ -285,7 +285,7 @@ out:
result: succeed
output: 1.7560473e+07
---
-test case: 'Empty metric'
+test case: 'Invalid metric (expected "fail"): empty metric'
in:
data: ""
params: wmi_os_timezone
@@ -330,7 +330,7 @@ out:
wmi_service_state{name="dhcp",state="stop pending"} 0
wmi_service_state{name="postdhcp",state="stopped"} 1
---
-test case: 'Empty metric and empty params'
+test case: 'Invalid metric (expected "fail"): empty metric and empty params'
in:
data: ""
params: ""
@@ -339,7 +339,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Only spaces in metric'
+test case: 'Invalid metric (expected "fail"): metric consists of spaces only #1'
in:
data: ' '
params: wmi_os_timezone
@@ -348,7 +348,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Only spaces in params'
+test case: 'Params hold multiple spaces only'
in:
data: wmi_os_timezone{timezone="MSK"} 1
params: ' '
@@ -357,7 +357,7 @@ out:
result: succeed
output: 1
---
-test case: 'Only spaces in params (multiline metric)'
+test case: 'Params hold multiple spaces only (multiline metric)'
in:
data: |
rpc_duration_seconds{quantile="0.01"} 3102
@@ -381,7 +381,7 @@ out:
rpc_duration_seconds_sum 1.7560473e+07
rpc_duration_seconds_count 2693
---
-test case: 'Only spaces in metric and in params'
+test case: 'Invalid metric (expected "fail"): metric consists of spaces only #2'
in:
data: ' '
params: ' '
@@ -408,7 +408,7 @@ out:
result: succeed
output: 8.492331008e+09
---
-test case: 'Metric without value'
+test case: 'Invalid metric (expected "fail"): metric without value'
in:
data: wmi_os_physical_memory_free_bytes
params: wmi_os_physical_memory_free_bytes
@@ -417,7 +417,7 @@ out:
result: fail
error: value not found
---
-test case: 'Metric with missing label value: wmi_os_timezone{timezone=} 1'
+test case: 'Invalid metric (expected "succeed"): label value is missing but equal sign remains "wmi_os_timezone{timezone=} 1"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -429,7 +429,7 @@ out:
result: succeed
output: 1
---
-test case: 'Metric with missing label value: wmi_os_timezone{timezone} 1'
+test case: 'Invalid metric (expected "succeed"): label value is missing "wmi_os_timezone{timezone} 1"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -441,7 +441,7 @@ out:
result: succeed
output: 1
---
-test case: 'Metric with missing label value: "wmi_os_timezone{timezone} 1" and value_type set to that label'
+test case: 'Invalid metric (expected "fail"): label value is missing and value_type is set to that label "wmi_os_timezone{timezone} 1"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -453,7 +453,7 @@ out:
result: fail
error: label value not found
---
-test case: 'Metric with missing label value, value_type set to that label, params: wmi_os_timezone{timezone=~".*"} == 1'
+test case: 'Invalid metric (expected "succeed"): label value is missing, value_type is set to that label; params: "wmi_os_timezone{timezone=~".*"} == 1"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -465,7 +465,7 @@ out:
result: fail
error: label value not found
---
-test case: 'Incorrect metric data'
+test case: 'Invalid metric (expected "fail"): wrong metric data'
in:
data: asdlkdlkasdasd09814mnvclmx
params: wmi_os_timezone
@@ -474,7 +474,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Incorrect metric data (a space within)'
+test case: 'Invalid metric (expected "fail"): wrong metric data (a space within)'
in:
data: asdlkdlkasda sd09814mnvclmx
params: wmi_os_timezone
@@ -483,7 +483,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric name with invalid characters included'
+test case: 'Invalid metric (expected "fail"): metric name with unsupported characters included'
in:
data: wmi_os_physical_^&;memory_free_bytes 8.492331008e+09
params: wmi_os_physical_^&;memory_free_bytes
@@ -492,7 +492,7 @@ out:
result: succeed
output: 8.492331008e+09
---
-test case: 'Incorrect metric data with valid HELP/TYPE'
+test case: 'Invalid metric (expected "fail"): wrong metric data with valid HELP/TYPE'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -504,7 +504,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with a hash symbol only'
+test case: 'Invalid metric (expected "fail"): metric consists of hash symbol only'
in:
data: '#'
params: wmi_os_timezone
@@ -513,7 +513,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with an empty space only'
+test case: 'Invalid metric (expected "fail"): metric consists of empty space only'
in:
data: ' '
params: wmi_os_timezone
@@ -522,7 +522,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with UTF-8 3 byte character only'
+test case: 'Invalid metric (expected "fail"): metric consists of 3 byte UTF-8 character only'
in:
data: "ࠀ"
params: wmi_os_timezone
@@ -531,7 +531,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with UTF-8 3 byte character in label value'
+test case: 'Metric with 3 byte UTF-8 byte character included in label value'
in:
data: |
# HELP http_requests_total The total number of HTTP requests.
@@ -544,7 +544,7 @@ out:
result: succeed
output: '"-⃠"'
---
-test case: 'Metric with missing "{"'
+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"}
@@ -553,7 +553,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with missing "}"'
+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"}
@@ -562,7 +562,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with missing "'
+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"}
@@ -571,7 +571,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with missing ","'
+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"}
@@ -580,7 +580,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric with missing "," but empty params'
+test case: 'Invalid metric (expected "fail"): metric with missing "," and params set to empty'
in:
data: cpu_usage_system{cpu="cpu-total"host="host1"} 1.1940298507220641
params: ""
@@ -589,7 +589,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Double equal sign (==) instead of single equal sign (=) for label value assignment in multiline metric'
+test case: 'Invalid metric (expected "succeed"): double equal sign (==) instead of single equal sign (=) in label value assignment (multiline metric)'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -603,7 +603,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Double equal sign (==) instead of single equal sign (=) for label value assignment in desired metric'
+test case: 'Invalid metric (expected "fail"): double equal sign (==) instead of single equal sign (=) in label value assignment (desired metric)'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -617,7 +617,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Double equal sign (==) instead of single equal sign (=) for label value assignment in metric'
+test case: 'Invalid metric (expected "succeed"): double equal sign (==) instead of single equal sign (=) in label value assignment'
in:
data: cpu_usage_system{cpu=="cpu-total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu-total"}
@@ -644,7 +644,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Double equal sign (==) instead of single equal sign (=) for label value in params'
+test case: 'Invalid params (expected "fail"): double equal sign (==) instead of single equal sign (=) in label value assignment'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -658,7 +658,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Single equal sign (=) instead of double equal sign (==) for metric value in params #1'
+test case: 'Invalid params (expected "succeed"): single equal sign (=) instead of double equal sign (==) in metric value assignment #1'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -672,7 +672,7 @@ out:
result: succeed
output: '"cpu-total"'
---
-test case: 'Single equal sign (=) instead of double equal sign (==) for metric value in params #2'
+test case: 'Invalid params (expected "succeed"): single equal sign (=) instead of double equal sign (==) in metric value assignment #2'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -781,6 +781,44 @@ out:
wmi_service_state{name="dhcp",state="continue pending"} 1
wmi_service_state{name="dhcp",state="pause pending"} 1
---
+test case: 'Multiple metrics (16 of 18) correspond to the given params'
+in:
+ data: |
+ wmi_service_state{name="dhcp",state="continue pending"} 0
+ wmi_service_state{name="dhcp",state="continue pending"} 1
+ wmi_service_state{name="dhcp",state="pause pending"} 1
+ wmi_service_state{name="dhcp",state="paused"} 1
+ wmi_service_state{name="dhcp",state="running"} 1
+ wmi_service_state{name="dhcp",state="start pending"} 1
+ wmi_service_state{name="dhcp",state="stop pending"} 1
+ wmi_service_state{name="dhcp",state="stopped"} 1
+ wmi_service_state{name="dhcp",state="unknown"} 1
+ wmi_service_state{name="dhcp",state="continue pending"} 1
+ wmi_service_state{name="dhcp",state="pause pending"} 1
+ wmi_service_state{name="dhcp",state="paused"} 1
+ wmi_service_state{name="dhcp",state="running"} 1
+ wmi_service_state{name="dhcp",state="start pending"} 1
+ wmi_service_state{name="dhcp",state="stop pending"} 1
+ wmi_service_state{name="dhcp",state="stopped"} 1
+ wmi_service_state{name="dhcp",state="unknown"} 1
+ wmi_service_state{name="dhcp",state="unknown"} 0
+ params: wmi_service_state == 1
+ value_type: state
+out:
+ result: fail
+ error: |
+ multiple metric result:
+ wmi_service_state{name="dhcp",state="continue pending"} 1
+ wmi_service_state{name="dhcp",state="pause pending"} 1
+ wmi_service_state{name="dhcp",state="paused"} 1
+ wmi_service_state{name="dhcp",state="running"} 1
+ wmi_service_state{name="dhcp",state="start pending"} 1
+ wmi_service_state{name="dhcp",state="stop pending"} 1
+ wmi_service_state{name="dhcp",state="stopped"} 1
+ wmi_service_state{name="dhcp",state="unknown"} 1
+ wmi_service_state{name="dhcp",state="continue pending"} 1
+ wmi_service_state{name="dhcp",state="pause pending"} 1
+---
test case: 'Metric with "Nan" value'
in:
data: wmi_os_physical_memory_free_bytes Nan
@@ -826,7 +864,7 @@ out:
result: succeed
output: 8.492331008e+09
---
-test case: 'Metric with additional value after timestamp'
+test case: 'Invalid metric (expected "succeed"): additional value after timestamp'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -858,7 +896,7 @@ out:
result: succeed
output: -1027
---
-test case: 'Multilne metric with negative value'
+test case: 'Multilne metric with negative value (multiline metric)'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -872,7 +910,7 @@ out:
result: succeed
output: -654
---
-test case: 'The __name__ identifier is specified as last in params'
+test case: 'The __name__ identifier is specified as last in params #1'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -886,7 +924,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'The __name__ identifier is specified as last in params (regex)'
+test case: 'The __name__ identifier is specified as last in params #2'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -900,7 +938,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Label set in value_type is not found'
+test case: 'Label name set in value_type is not present in the metrics'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -914,13 +952,13 @@ out:
result: fail
error: label name not found
---
-test case: 'Params set to cpu_usage_system{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
+test case: 'Get metric value using params: "cpu_usage_system{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
# TYPE cpu_usage_system gauge
cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
- cpu_usage_system{cpu="cpu0",host="host1"} 1.19402985 output: TODO07220641
+ 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: \value
@@ -928,13 +966,13 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Params set to cpu_usage_system{__name__=~"cpu_age_syst.+",cpu=~"cpu-tot.+"}'
+test case: 'Get metric value using params: "cpu_usage_system{__name__=~"cpu_age_syst.+",cpu=~"cpu-tot.+"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
# TYPE cpu_usage_system gauge
cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
- cpu_usage_system{cpu="cpu0",host="host1"} 1.19402985 output: TODO07220641
+ 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: \value
@@ -954,7 +992,7 @@ out:
result: fail
error: label name not found
---
-test case: 'Metric with multiple HELP lines'
+test case: 'Invalid metric (expected "succeed"): multiple HELP lines'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -969,7 +1007,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Metric with multiple TYPE:untyped lines'
+test case: 'Invalid metric (expected "succeed"): multiple TYPE:untyped lines'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -984,7 +1022,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Metric with wrong TYPE'
+test case: 'Invalid metric (expected "succeed"): unsupported TYPE'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -998,7 +1036,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Metric with only one argument for TYPE'
+test case: 'Invalid metric (expected "succeed"): only one argument for TYPE'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1012,7 +1050,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Metric with no arguments for TYPE'
+test case: 'Invalid metric (expected "succeed"): empty TYPE'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1026,7 +1064,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Metric with multiple spaces before value'
+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
@@ -1035,7 +1073,7 @@ out:
result: succeed
output: 8.492331008e+09
---
-test case: 'Metric with no description after HELP'
+test case: 'Invalid metric (expected "succeed"): empty HELP'
in:
data: |
# HELP
@@ -1048,7 +1086,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Metric with invalid characters in label name'
+test case: 'Invalid metric (expected "succeed"): unsupported characters in label name'
in:
data: cpu_usage_system{cp%^&u="cpu-total"} 1.1940298507220641
params: cpu_usage_system{cp%^&u="cpu-total"}
@@ -1057,7 +1095,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get label value using params: wmi_os_timezone'
+test case: 'Get metric value using params: "wmi_os_timezone"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -1069,7 +1107,7 @@ out:
result: succeed
output: '"MSK"'
---
-test case: 'Metric name consists of all valid characters'
+test case: 'Metric name consists of all supported characters'
in:
data: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789 1
params: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789
@@ -1078,7 +1116,7 @@ out:
result: succeed
output: 1
---
-test case: 'Label name consists of all valid characters'
+test case: 'Label name consists of all supported characters'
in:
data: cpu_usage_system{AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789="test"} 1
params: cpu_usage_system == 1
@@ -1087,7 +1125,7 @@ out:
result: succeed
output: '"test"'
---
-test case: 'Params with regex expression but without prefix "~"'
+test case: 'Invalid params (expected "fail"): regular expression but without prefix "~"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1101,7 +1139,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Wrong regex expression in params'
+test case: 'Invalid params (expected "fail"): wrong regular expression'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1115,7 +1153,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Incorrect identifier __cpu__ set in params'
+test case: 'Invalid params (expected "fail"): unsupported identifier __cpu__ #1'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1129,7 +1167,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Incorrect identifier __cpu__ set in params (regex)'
+test case: 'Invalid params (expected "fail"): unsupported identifier __cpu__ #2'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1152,7 +1190,7 @@ out:
result: succeed
output: 2.627731456e+383
---
-test case: 'Incorrect float in metric value #1'
+test case: 'Incorrect float in metric value #2'
in:
data: wmi_logical_disk_free_bytes{volume="D:"} 8.49233.1008e+09
params: wmi_logical_disk_free_bytes
@@ -1161,7 +1199,7 @@ out:
result: succeed
output: 8.49233.1008e+09
---
-test case: 'Params set to "{}"'
+test case: 'Invalid params (expected "fail"): "{}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1175,7 +1213,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Params set to "a{}"'
+test case: 'Invalid params (expected "fail"): "a{}"'
in:
data: |
# HELP a Telegraf collected metric
@@ -1189,7 +1227,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Metric data contains "{}" only'
+test case: 'Invalid metric (expected "fail"): "{}"'
in:
data: '{}'
params: metric
@@ -1198,7 +1236,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Negative value in params for metric value'
+test case: 'Get metric value using params: "wmi_os_timezone{timezone="MSK"} == -1"'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -1210,7 +1248,7 @@ out:
result: succeed
output: -1
---
-test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~".*",\value="1.1940298507220641"}'
+test case: 'Get metric value using params: "cpu_usage_system{cpu="cpu-total",host=~".*",\value="1.1940298507220641"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1224,7 +1262,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Get label value using params: cpu_usage_system{cpu="cpu-total",host=~".*",\value="1.1940298507220641"}'
+test case: 'Get label value using params: "cpu_usage_system{cpu="cpu-total",host=~".*",\value="1.1940298507220641"}"'
in:
data: |
# HELP cpu_usage_system Telegraf collected metric
@@ -1238,7 +1276,7 @@ out:
result: succeed
output: '"host1"'
---
-test case: 'Get label value using regex for date (mm/dd/yyyy) #1'
+test case: 'Get label value using regular expression for date #1'
in:
data: |
random_date{year="2019",month="february",day="02/12/2019"} 1
@@ -1249,7 +1287,7 @@ out:
result: succeed
output: '"february"'
---
-test case: 'Get label value using regex for date (mm/dd/yyyy) #2'
+test case: 'Get label value using regular expression for date #2'
in:
data: |
random_date{year="2019",month="february",day="02/12/2019"} 1
@@ -1260,7 +1298,7 @@ out:
result: succeed
output: '"march"'
---
-test case: 'Get label value using regex for date (mm/dd/yyyy) #3'
+test case: 'Get label value using regular expression for date #3'
in:
data: |
random_date{year="2019",month="february",day="02/12/2019"} 1
@@ -1271,7 +1309,7 @@ out:
result: succeed
output: '"03/07/2019"'
---
-test case: 'Get label value using regex for date (mm/dd/yyyy) #4'
+test case: 'Get label value using regular expression for date #4'
in:
data: |
random_date{year="2019",month="february",day="02/12/2019"} 1
@@ -1282,7 +1320,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Get label value using regex for date (mm/dd/yyyy) #5'
+test case: 'Get label value using regular expression for date #5'
in:
data: |
random_date{year="2019",month="february",day="02/12/2019"} 1
@@ -1296,7 +1334,7 @@ out:
random_date{year="2019",month="february",day="02/12/2019"} 1
random_date{year="2019",month="march",day="03/07/2019"} 2
---
-test case: 'Missing "==" in params'
+test case: 'Invalid params (expected "fail"): double equal sign (==) is missing'
in:
data: |
# HELP wmi_os_timezone OperatingSystem.LocalDateTime
@@ -1308,7 +1346,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Get label value using regex for email address #1'
+test case: 'Get label value using regular expression for email address #1'
in:
data: |
some_user{country="lv",addr="user1@domain.com"} some_name
@@ -1320,7 +1358,7 @@ out:
result: succeed
output: '"user1@domain.com"'
---
-test case: 'Get label value using regex for email address #2'
+test case: 'Get label value using regular expression for email address #2'
in:
data: |
some_user{country="lv",addr="user1@domain.com"} some_name
@@ -1332,7 +1370,7 @@ out:
result: succeed
output: '"user2@domain.org"'
---
-test case: 'Get label value using regex for email address #3'
+test case: 'Get label value using regular expression for email address #3'
in:
data: |
some_user{country="lv",addr="user1@domain.com"} some_name
@@ -1344,7 +1382,7 @@ out:
result: fail
error: metric not found
---
-test case: 'Get metric value using regex for email address'
+test case: 'Get metric value using regular expression for email address'
in:
data: |
some_user{country="lv",addr="user1@domain.com"} some_name
@@ -1359,7 +1397,7 @@ out:
some_user{country="lv",addr="user1@domain.com"} some_name
some_user{country="lv",addr="user2@domain.org"} some_other_name
---
-test case: 'Label value and params holds "{"'
+test case: 'Label value holds "{"'
in:
data: cpu_usage_system{cpu="cpu{total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu{total"}
@@ -1368,7 +1406,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Label value and params holds "{}"'
+test case: 'Label value holds "{}"'
in:
data: cpu_usage_system{cpu="cpu{}total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu{}total"}
@@ -1377,7 +1415,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Label value and params holds "}"'
+test case: 'Label value holds "}"'
in:
data: cpu_usage_system{cpu="cpu}total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu}total"}
@@ -1386,7 +1424,7 @@ out:
result: succeed
output: 1.1940298507220641
---
-test case: 'Label value and params holds ","'
+test case: 'Label value holds ","'
in:
data: important_metric{important_number="42,0"} 42
params: important_metric{important_number="42,0"}
@@ -1395,7 +1433,7 @@ out:
result: succeed
output: 42
---
-test case: 'Get "cpu" label value: cpu_usage_system{cpu="cpu{total"} 1.1940298507220641'
+test case: 'Get label value (cpu) using params: "cpu_usage_system{cpu="cpu{total"} == 1.1940298507220641"'
in:
data: cpu_usage_system{cpu="cpu{total"} 1.1940298507220641
params: cpu_usage_system{cpu="cpu{total"} == 1.1940298507220641
@@ -1403,4 +1441,110 @@ in:
out:
result: succeed
output: '"cpu{total"'
+---
+test case: 'Get label value (cpu) using params: "cpu_usage_system{cpu="cpu}total"} == 1.1940298507220641"'
+in:
+ data: cpu_usage_system{cpu="cpu}total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu}total"} == 1.1940298507220641
+ value_type: cpu
+out:
+ result: succeed
+ output: '"cpu}total"'
+---
+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: \value
+out:
+ result: succeed
+ output: 1.1940298507220641
+---
+test case: 'Different metrics under one HELP/TYPE header #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ wmi_os_timezone{timezone="MSK"} 1
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu1",host=~".*"}
+ value_type: \value
+out:
+ result: succeed
+ output: 1.1340298507220641
+---
+test case: 'Different metrics under one HELP/TYPE header #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ wmi_os_timezone{timezone="MSK"} 1
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ params: wmi_os_timezone
+ value_type: \value
+out:
+ result: succeed
+ output: 1
+---
+test case: 'Metrics of different type #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ 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
+out:
+ result: succeed
+ output: '"400"'
+---
+test case: 'Metrics of different type #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ http_requests_total{method="post",code="200"} 1027 1395066363000
+ http_requests_total{method="post",code="400"} 3 1395066363000
+ params: '{cpu="cpu0"}'
+ value_type: \value
+out:
+ result: succeed
+ output: 1.1940298507220641
+---
+test case: 'Metrics of different type #3'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ 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: \value
+out:
+ result: fail
+ error: |
+ multiple metric result:
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ http_requests_total{method="post",code="400",host="host1"} 3 1395066363000
...
diff --git a/tests/libs/zbxprometheus/zbx_prometheus_tojson.c b/tests/libs/zbxprometheus/zbx_prometheus_tojson.c
index d8afabdcc44..722fc1c853a 100644
--- a/tests/libs/zbxprometheus/zbx_prometheus_tojson.c
+++ b/tests/libs/zbxprometheus/zbx_prometheus_tojson.c
@@ -17,9 +17,6 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-/* Temporary printf debug output - remove it before final commit */
-#define MY_DEBUG_PRINTF
-
#include "zbxmocktest.h"
#include "zbxmockdata.h"
#include "zbxmockassert.h"
@@ -39,13 +36,6 @@ void zbx_mock_test_entry(void **state)
params = zbx_mock_get_parameter_string("in.params");
result = zbx_mock_get_parameter_string("out.result");
-#ifdef MY_DEBUG_PRINTF
- /* Add printfs for the debug in case of failed test */
- printf("MYDBG_YAML_ data: %s\n", data);
- printf("MYDBG_YAML_ params: %s\n", params);
- printf("MYDBG_YAML_ result: %s\n", result);
-#endif
-
if (SUCCEED == (ret = zbx_prometheus_to_json(data, params, &ret_output, &ret_err)))
{
/* Check result and output */
diff --git a/tests/libs/zbxprometheus/zbx_prometheus_tojson.yaml b/tests/libs/zbxprometheus/zbx_prometheus_tojson.yaml
index 6c56ac68723..32bab67e763 100644
--- a/tests/libs/zbxprometheus/zbx_prometheus_tojson.yaml
+++ b/tests/libs/zbxprometheus/zbx_prometheus_tojson.yaml
@@ -1,22 +1,2218 @@
---
-test case: 'Get metric value using params: wmi_os_physical_memory_free_bytes'
+test case: 'Simple metric 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
out:
result: succeed
- output: TODO
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "8.492331008e+09",
+ "line_raw": "wmi_os_physical_memory_free_bytes 8.492331008e+09"
+ }
+ ]
+---
+test case: 'Get metric 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"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric using params: wmi_logical_disk_free_bytes{volume="{#VOLUME}"}'
+in:
+ data: |
+ # HELP wmi_logical_disk_free_bytes Free space in bytes (LogicalDisk.PercentFreeSpace)
+ # TYPE wmi_logical_disk_free_bytes gauge
+ wmi_logical_disk_free_bytes{volume="{#VOLUME}"} 3.5180249088e+11
+ 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}"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_logical_disk_free_bytes",
+ "help": "Free space in bytes (LogicalDisk.PercentFreeSpace)",
+ "type": "gauge",
+ "labels": {
+ "volume": "{#VOLUME}"
+ },
+ "value": "3.5180249088e+11",
+ "wmi_logical_disk_free_bytes{volume="{#VOLUME}"} 3.5180249088e+11"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~".*"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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=~".*"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~"*",\value=~".*"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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=~".*"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~"*"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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=~"*"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
---
test case: 'Get metric value 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",host="host1"} 1.1940298507220641
+ 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"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu=~"cpu-tot.+"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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.+"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using params: {__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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.+"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu=~".*"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ params: cpu_usage_system{cpu=~".*"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu1",
+ "host": "host1"
+ },
+ "value": "1.1340298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu=~"cpu-tot.+"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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.+"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric for http_requests_total{code="400"} 3 1395066363000'
+in:
+ data: |
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ http_requests_total{method="post",code="200"} 1027 1395066363000
+ http_requests_total{method="post",code="400"} 3 1395066363000
+ params: http_requests_total{code="400"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "http_requests_total",
+ "help": "The total number of HTTP requests.",
+ "type": "counter",
+ "labels": {
+ "method": "post",
+ "code": "400"
+ },
+ "value": "3",
+ "line_raw": "http_requests_total{method="post",code="400"} 3 1395066363000"
+ }
+ ]
+---
+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
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "msdos_file_access_time_seconds",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "path": "C:\\DIR\\FILE.TXT",
+ "error": "Cannot find file:\n\"FILE.TXT\""
+ },
+ "value": "1.458255915e9",
+ "line_raw": "msdos_file_access_time_seconds{path="C:\\DIR\\FILE.TXT",error="Cannot find file:\n\"FILE.TXT\""} 1.458255915e9"
+ }
+ ]
+---
+test case: 'Minimalistic line'
+in:
+ data: metric_without_timestamp_and_labels 12.47
+ params: metric_without_timestamp_and_labels
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "metric_without_timestamp_and_labels",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "12.47",
+ "line_raw": "metric_without_timestamp_and_labels 12.47"
+ }
+ ]
+---
+test case: 'A weird metric from before the epoch'
+in:
+ data: something_weird{problem="division by zero"} +Inf -3982045
+ params: something_weird
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "something_weird",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "problem": "division by zero"
+ },
+ "value": "+Inf",
+ "line_raw": "something_weird{problem="division by zero"} +Inf -3982045"
+ }
+ ]
+---
+test case: 'A histogram, which has a pretty complex representation in the text format'
+in:
+ data: |
+ # HELP http_request_duration_seconds A histogram of the request duration.
+ # TYPE http_request_duration_seconds histogram
+ http_request_duration_seconds_bucket{le="0.05"} 24054
+ http_request_duration_seconds_bucket{le="0.1"} 33444
+ http_request_duration_seconds_bucket{le="0.2"} 100392
+ http_request_duration_seconds_bucket{le="0.5"} 129389
+ http_request_duration_seconds_bucket{le="1"} 133988
+ http_request_duration_seconds_bucket{le="+Inf"} 144320
+ http_request_duration_seconds_sum 53423
+ http_request_duration_seconds_count 144320
+ params: http_request_duration_seconds_bucket{le="+Inf"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "http_request_duration_seconds_bucket",
+ "help": "A histogram of the request duration.",
+ "type": "histogram",
+ "labels": {
+ "le": "+Inf"
+ },
+ "value": "144320",
+ "line_raw": "http_request_duration_seconds_bucket{le="+Inf"} 144320"
+ }
+ ]
+---
+test case: 'A summary, which has a complex representation'
+in:
+ data: |
+ # HELP rpc_duration_seconds A summary of the RPC duration in seconds.
+ # TYPE rpc_duration_seconds summary
+ rpc_duration_seconds{quantile="0.01"} 3102
+ rpc_duration_seconds{quantile="0.05"} 3272
+ rpc_duration_seconds{quantile="0.5"} 4773
+ rpc_duration_seconds{quantile="0.9"} 9001
+ rpc_duration_seconds{quantile="0.99"} 76656
+ rpc_duration_seconds_sum 1.7560473e+07
+ rpc_duration_seconds_count 2693
+ params: rpc_duration_seconds_sum
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "rpc_duration_seconds",
+ "help": "A summary of the RPC duration in seconds.",
+ "type": "histogram",
+ "value": "1.7560473e+07",
+ "line_raw": "rpc_duration_seconds_sum 1.7560473e+07"
+ }
+ ]
+---
+test case: 'Empty metric'
+in:
+ data: ""
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Empty params'
+in:
+ data: wmi_os_timezone{timezone="MSK"} 1
+ params: ""
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "timezone": "MSK"
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone="MSK"} 1"
+ }
+ ]
+---
+test case: 'Empty metric and empty params'
+in:
+ data: ""
+ params: ""
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Only spaces in metric'
+in:
+ data: ' '
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Only spaces in params'
+in:
+ data: wmi_os_timezone{timezone="MSK"} 1
+ params: ' '
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "timezone": "MSK"
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone="MSK"} 1"
+ }
+ ]
+---
+test case: 'Only spaces in params (multiline metric)'
+in:
+ data: |
+ rpc_duration_seconds{quantile="0.01"} 3102
+ rpc_duration_seconds{quantile="0.05"} 3272
+ rpc_duration_seconds{quantile="0.5"} 4773
+ rpc_duration_seconds{quantile="0.9"} 9001
+ rpc_duration_seconds{quantile="0.99"} 76656
+ rpc_duration_seconds_sum 1.7560473e+07
+ rpc_duration_seconds_count 2693
+ params: ' '
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "rpc_duration_seconds",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "quantile": "0.01"
+ },
+ "value": "3102",
+ "line_raw": "rpc_duration_seconds{quantile="0.01"} 3102"
+ },
+ {
+ "name": "rpc_duration_seconds",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "quantile": "0.05"
+ },
+ "value": "3272",
+ "line_raw": "rpc_duration_seconds{quantile="0.05"} 3272"
+ },
+ {
+ "name": "rpc_duration_seconds",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "quantile": "0.5"
+ },
+ "value": "4773",
+ "line_raw": "rpc_duration_seconds{quantile="0.5"} 4773"
+ },
+ {
+ "name": "rpc_duration_seconds",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "quantile": "0.9"
+ },
+ "value": "9001",
+ "line_raw": "rpc_duration_seconds{quantile="0.9"} 9001"
+ },
+ {
+ "name": "rpc_duration_seconds",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "quantile": "0.99"
+ },
+ "value": "76656",
+ "line_raw": "rpc_duration_seconds{quantile="0.99"} 76656"
+ },
+ {
+ "name": "rpc_duration_seconds_sum",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "1.7560473e+07",
+ "line_raw": "rpc_duration_seconds_sum 1.7560473e+07"
+ },
+ {
+ "name": "rpc_duration_seconds_count",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "2693",
+ "line_raw": "rpc_duration_seconds_count 2693"
+ }
+ ]
+---
+test case: 'Only spaces in metric and in params'
+in:
+ data: ' '
+ params: ' '
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Empty multiline metric'
+in:
+ data: "\n\n\n\n"
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric without value'
+in:
+ data: wmi_os_physical_memory_free_bytes
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: fail
+ error: value not found
+---
+test case: 'Metric with missing label value: wmi_os_timezone{timezone=} 1'
+in:
+ data: |
+ # HELP wmi_os_timezone OperatingSystem.LocalDateTime
+ # TYPE wmi_os_timezone gauge
+ wmi_os_timezone{timezone=} 1
+ params: wmi_os_timezone
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "OperatingSystem.LocalDateTime",
+ "type": "gauge",
+ "labels": {
+ "timezone": ""
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone=} 1"
+ }
+ ]
+---
+test case: 'Metric with missing label value: wmi_os_timezone{timezone} 1'
+in:
+ data: |
+ # HELP wmi_os_timezone OperatingSystem.LocalDateTime
+ # TYPE wmi_os_timezone gauge
+ wmi_os_timezone{timezone} 1
+ params: wmi_os_timezone
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "OperatingSystem.LocalDateTime",
+ "type": "gauge",
+ "labels": {
+ "timezone": ""
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone} 1"
+ }
+ ]
+---
+test case: 'Incorrect metric data'
+in:
+ data: asdlkdlkasdasd09814mnvclmx
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Incorrect metric data (a space within)'
+in:
+ data: asdlkdlkasda sd09814mnvclmx
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric name with invalid characters included'
+in:
+ data: wmi_os_physical_^&;memory_free_bytes 8.492331008e+09
+ params: wmi_os_physical_^&;memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_^&;memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "8.492331008e+09",
+ "line_raw": "wmi_os_physical_^&;memory_free_bytes 8.492331008e+09"
+ }
+ ]
+---
+test case: 'Incorrect metric data with valid HELP/TYPE'
+in:
+ data: |
+ # HELP wmi_os_timezone OperatingSystem.LocalDateTime
+ # TYPE wmi_os_timezone gauge
+ asdlkdlkasdasd09814mnvclmx
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with a hash symbol only'
+in:
+ data: '#'
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with an empty space only'
+in:
+ data: ' '
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with UTF-8 3 byte character only'
+in:
+ data: "ࠀ"
+ params: wmi_os_timezone
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with UTF-8 3 byte character in label value'
+in:
+ data: |
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ http_requests_total{method="post",code="200"} 1027 1395066363000
+ http_requests_total{method="post",code="-⃠"} 3 1395066363000
+ params: http_requests_total == 3
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "http_requests_total",
+ "help": "The total number of HTTP requests.",
+ "type": "counter",
+ "labels": {
+ "method": "post",
+ "code": "-⃠"
+ },
+ "value": "3",
+ "line_raw": "http_requests_total{method="post",code="-⃠"} 3 1395066363000"
+ }
+ ]
+---
+test case: 'Metric with missing "{"'
+in:
+ data: cpu_usage_systemcpu="cpu-total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with missing "}"'
+in:
+ data: cpu_usage_system{cpu="cpu-total" 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with missing "'
+in:
+ data: cpu_usage_system{cpu=cpu-total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with missing ","'
+in:
+ data: cpu_usage_system{cpu="cpu-total"host="host1"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with missing "," but empty params'
+in:
+ data: cpu_usage_system{cpu="cpu-total"host="host1"} 1.1940298507220641
+ params: ""
+out:
+ result: succeed
+ output: no metrics
+---
+test case: 'Double equal sign (==) instead of single equal sign (=) in label value assignment #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu=="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu1"
+ },
+ "value": "1.1340298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu1"} 1.1340298507220641"
+ }
+ ]
+---
+test case: 'Double equal sign (==) instead of single equal sign (=) in label value assignment #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu=="cpu-total"} 1.1940298507220641
cpu_usage_system{cpu="cpu0"} 1.1940298507220641
cpu_usage_system{cpu="cpu1"} 1.1340298507220641
params: cpu_usage_system{cpu="cpu-total"}
out:
+ result: fail
+ error: no metrics
+---
+test case: 'Double equal sign (==) instead of single equal sign (=) in label value assignment #3'
+in:
+ data: cpu_usage_system{cpu=="cpu-total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: fail
+ error: no metrics
+---
+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\"}"
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cpu\ntotal"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu=\"cpu\ntotal\"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric name and params holds new line character'
+in:
+ data: "cpu_usa\nge_system{cpu=\"cputotal\"} 1.1940298507220641"
+ params: "cpu_usa\nge_system{cpu=\"cputotal\"}"
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Double equal sign (==) instead of single equal sign (=) for label value in params'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu=="cpu-total"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Single equal sign (=) instead of double equal sign (==) for metric value in params'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"} = 1.1940298507220641
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'More than one metric (2) corresponds to the given params'
+in:
+ data: |
+ wmi_service_state{name="devicesflowusersvc_7b100",state="running"} 1
+ wmi_service_state{name="devicesflowusersvc_7b100",state="start pending"} 0
+ wmi_service_state{name="devicesflowusersvc_7b100",state="stop pending"} 0
+ wmi_service_state{name="devicesflowusersvc_7b100",state="stopped"} 0
+ wmi_service_state{name="devicesflowusersvc_7b100",state="unknown"} 0
+ wmi_service_state{name="dhcp",state="continue pending"} 0
+ wmi_service_state{name="dhcp",state="pause pending"} 0
+ wmi_service_state{name="dhcp",state="paused"} 0
+ wmi_service_state{name="dhcp",state="running"} 1
+ wmi_service_state{name="dhcp",state="start pending"} 0
+ wmi_service_state{name="dhcp",state="stop pending"} 0
+ wmi_service_state{name="dhcp",state="stopped"} 1
+ wmi_service_state{name="dhcp",state="unknown"} 0
+ wmi_service_state{name="diagnosticshub.standardcollector.service",state="continue pending"} 0
+ wmi_service_state{name="diagnosticshub.standardcollector.service",state="pause pending"} 0
+ wmi_service_state{name="diagnosticshub.standardcollector.service",state="paused"} 0
+ wmi_service_state{name="diagnosticshub.standardcollector.service",state="running"} 0
+ wmi_service_state{name="diagnosticshub.standardcollector.service",state="start pending"} 0
+ wmi_service_state{name="diagnosticshub.standardcollector.service",state="stop pending"} 0
+ 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
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_service_state",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "name": "dhcp",
+ "state": "running"
+ },
+ "value": "1",
+ "line_raw": "wmi_service_state{name="dhcp",state="running"} 1"
+ },
+ {
+ "name": "wmi_service_state",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "name": "dhcp",
+ "state": "stopped"
+ },
+ "value": "1",
+ "line_raw": "wmi_service_state{name="dhcp",state="stopped"} 1"
+ }
+ ]
+---
+test case: 'Metric with "Nan" value'
+in:
+ data: wmi_os_physical_memory_free_bytes Nan
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "Nan",
+ "line_raw": "wmi_os_physical_memory_free_bytes Nan"
+ }
+ ]
+---
+test case: 'Metric with "+Inf" value'
+in:
+ data: wmi_os_physical_memory_free_bytes +Inf
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "+Inf",
+ "line_raw": "wmi_os_physical_memory_free_bytes +Inf"
+ }
+ ]
+---
+test case: 'Metric with "-Inf" value'
+in:
+ data: wmi_os_physical_memory_free_bytes -Inf
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "-Inf",
+ "line_raw": "wmi_os_physical_memory_free_bytes -Inf"
+ }
+ ]
+---
+test case: 'Metric with "NAN" value'
+in:
+ data: wmi_os_physical_memory_free_bytes NAN
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "NAN",
+ "line_raw": "wmi_os_physical_memory_free_bytes NAN"
+ }
+ ]
+---
+test case: 'Metric with timestamp'
+in:
+ data: wmi_os_physical_memory_free_bytes 8.492331008e+09 25
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "8.492331008e+09",
+ "line_raw": "wmi_os_physical_memory_free_bytes 8.492331008e+09 25"
+ }
+ ]
+---
+test case: 'Metric with additional value after timestamp'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641 25 66
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641 25 66"
+ }
+ ]
+---
+test case: 'Metric with negative timestamp'
+in:
+ data: http_requests_total{method="post",code="200"} 1027 -123
+ params: http_requests_total
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "http_requests_total",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "method": "post",
+ "code": "200"
+ },
+ "value": "1027",
+ "line_raw": "http_requests_total{method="post",code="200"} 1027 -123"
+ }
+ ]
+---
+test case: 'Metric with negative value'
+in:
+ data: http_requests_total{method="post",code="200"} -1027
+ params: http_requests_total
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "http_requests_total",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "method": "post",
+ "code": "200"
+ },
+ "value": "-1027",
+ "line_raw": "http_requests_total{method="post",code="200"} -1027"
+ }
+ ]
+---
+test case: 'Multilne metric with negative value'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} -654
+ 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.+"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "-654",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} -654"
+ }
+ ]
+---
+test case: 'The __name__ identifier is specified as last in params #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'The __name__ identifier is specified as last in params #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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.+"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Params set to cpu_usage_system{__name__=~"cpu_usage_syst.+",cpu=~"cpu-tot.+"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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.+"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Params set to cpu_usage_system{__name__=~"cpu_age_syst.+",cpu=~"cpu-tot.+"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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.+"}'
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric with multiple HELP lines'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # HELP cpu_usage_system collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric with multiple TYPE:untyped lines'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system untyped
+ # TYPE cpu_usage_system untyped
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "untyped",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric with wrong TYPE'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system something
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "something",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric with only one argument for TYPE'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric with no arguments for TYPE'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric with multiple spaces before value'
+in:
+ data: wmi_os_physical_memory_free_bytes 8.492331008e+09
+ params: wmi_os_physical_memory_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_physical_memory_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "8.492331008e+09",
+ "line_raw": "wmi_os_physical_memory_free_bytes 8.492331008e+09"
+ }
+ ]
+---
+test case: 'Metric with no description after HELP'
+in:
+ data: |
+ # HELP
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric with invalid characters in label name'
+in:
+ data: cpu_usage_system{cp%^&u="cpu-total"} 1.1940298507220641
+ params: cpu_usage_system{cp%^&u="cpu-total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cp%^&u": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cp%^&u="cpu-total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Metric name consists of all valid characters'
+in:
+ data: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789 1
+ params: AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789",
+ "help": "(null)",
+ "type": "(null)",
+ "value": "1",
+ "line_raw": "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:_0123456789 1"
+ }
+ ]
+---
+test case: 'Label name consists of all valid characters'
+in:
+ data: cpu_usage_system{AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789="test"} 1
+ params: cpu_usage_system == 1
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789": "test"
+ },
+ "value": "1",
+ "line_raw": "cpu_usage_system{AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_0123456789="test"} 1"
+ }
+ ]
+---
+test case: 'Params with regular expression but without prefix "~"'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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=".*"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Wrong regular expression in params'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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"}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Incorrect identifier __cpu__ set in params #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} -654
+ 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"}'
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Incorrect identifier __cpu__ set in params #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} -654
+ 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.+"}'
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Incorrect float in metric value #1'
+in:
+ data: wmi_logical_disk_free_bytes{volume="D:"} 2.627731456e+383
+ params: wmi_logical_disk_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_logical_disk_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "volume": "D:"
+ },
+ "value": "2.627731456e+383",
+ "line_raw": "wmi_logical_disk_free_bytes{volume="D:"} 2.627731456e+383"
+ }
+ ]
+---
+test case: 'Incorrect float in metric value #2'
+in:
+ data: wmi_logical_disk_free_bytes{volume="D:"} 8.49233.1008e+09
+ params: wmi_logical_disk_free_bytes
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_logical_disk_free_bytes",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "volume": "D:"
+ },
+ "value": "8.49233.1008e+09",
+ "line_raw": "wmi_logical_disk_free_bytes{volume="D:"} 8.49233.1008e+09"
+ }
+ ]
+---
+test case: 'Params set to "{}"'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cputotal"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: '{}'
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Params set to "a{}"'
+in:
+ data: |
+ # HELP a Telegraf collected metric
+ # TYPE a gauge
+ a{cpu="cputotal"} 1.1940298507220641
+ a{cpu="cpu0"} 1.1940298507220641
+ a{cpu="cpu1"} 1.1340298507220641
+ params: a{}
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Metric data contains "{}" only'
+in:
+ data: '{}'
+ params: metric
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Negative value in params for metric value'
+in:
+ data: |
+ # HELP wmi_os_timezone OperatingSystem.LocalDateTime
+ # TYPE wmi_os_timezone gauge
+ wmi_os_timezone{timezone="MSK"} -1
+ params: wmi_os_timezone{timezone="MSK"} == -1
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "OperatingSystem.LocalDateTime",
+ "type": "gauge",
+ "labels": {
+ "timezone": "MSK"
+ },
+ "value": "-1",
+ "line_raw": "wmi_os_timezone{timezone="MSK"} -1"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system{cpu="cpu-total",host=~".*",\value="1.1940298507220641"}'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ 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="1.1940298507220641"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Get metric value using regular expression for date (mm/dd/yyyy) #1'
+in:
+ data: |
+ 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}$"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "random_date",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "year": "2019",
+ "month": "february",
+ "day": "02/12/2019"
+ },
+ "value": "1",
+ "line_raw": "random_date{year="2019",month="february",day="02/12/2019"} 1"
+ },
+ {
+ "name": "random_date",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "year": "2019",
+ "month": "march",
+ "day": "03/07/2019"
+ },
+ "value": "2",
+ "line_raw": "random_date{year="2019",month="march",day="03/07/2019"} 2"
+ }
+ ]
+---
+test case: 'Get metric value using regular expression for date (mm/dd/yyyy) #2'
+in:
+ data: |
+ 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
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "random_date",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "year": "2019",
+ "month": "march",
+ "day": "03/07/2019"
+ },
+ "value": "2",
+ "line_raw": "random_date{year="2019",month="march",day="03/07/2019"} 2"
+ }
+ ]
+---
+test case: 'Get metric value using regular expression for date (mm/dd/yyyy) #3'
+in:
+ data: |
+ 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
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Missing "==" in params'
+in:
+ data: |
+ # HELP wmi_os_timezone OperatingSystem.LocalDateTime
+ # TYPE wmi_os_timezone gauge
+ wmi_os_timezone{timezone="MSK"} 1
+ params: wmi_os_timezone 1
+out:
+ result: fail
+ error: no metrics
+---
+test case: 'Get metric value using regular expression for email address'
+in:
+ data: |
+ some_user{country="lv",addr="user1@domain.com"} some_name
+ some_user{country="lv",addr="user2@domain.org"} some_other_name
+ some_user{country="lv",addr="no_valid_addr"} some_other_name
+ params: some_user{country="lv",addr=~"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "some_user",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "country": "lv",
+ "addr": "user1@domain.com"
+ },
+ "value": "some_name",
+ "line_raw": "some_user{country="lv",addr="user1@domain.com"} some_name"
+ },
+ {
+ "name": "some_user",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "country": "lv",
+ "addr": "user2@domain.com"
+ },
+ "value": "some_other_name",
+ "line_raw": "some_user{country="lv",addr="user2@domain.org"} some_other_name"
+ }
+ ]
+---
+test case: 'Label value and params hold "{"'
+in:
+ data: cpu_usage_system{cpu="cpu{total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu{total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cpu{total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu{total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Label value and params hold "{}"'
+in:
+ data: cpu_usage_system{cpu="cpu{}total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu{}total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cpu{}total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu{}total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Label value and params hold "}"'
+in:
+ data: cpu_usage_system{cpu="cpu}total"} 1.1940298507220641
+ params: cpu_usage_system{cpu="cpu}total"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cpu}total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu}total"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Label value and params hold ","'
+in:
+ data: important_metric{important_number="42,0"} 42
+ params: important_metric{important_number="42,0"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "important_metric",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "important_number": "42,0"
+ },
+ "value": "42",
+ "line_raw": "important_metric{important_number="42,0"} 42"
+ }
+ ]
+---
+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
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "cpu": "cputotal"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cputotal"} 1.1940298507220641 2.23443 333 four five"
+ }
+ ]
+---
+test case: 'Different metrics under one header #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641
+ wmi_os_timezone{timezone="MSK"} 1
+ cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641
+ params: cpu_usage_system{cpu="cpu1",host=~".*"}
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu1",
+ "host": "host3"
+ },
+ "value": "1.1340298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641"
+ }
+ ]
+---
+test case: 'Different metrics under one header #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641
+ wmi_os_timezone{timezone="MSK",host="host2"} 1
+ cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641
+ params: '{host="host2"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0",
+ "host": "host2"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641"
+ }
+ ],
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "timezone": "MSK",
+ "host": "host2"
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone="MSK",host="host2"} 1"
+ }
+ ]
+---
+test case: 'Different metrics under one header #3'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641
+
+ wmi_os_timezone{timezone="MSK",host="host2"} 1
+ params: '{host="host2"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0",
+ "host": "host2"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641"
+ }
+ ],
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "timezone": "MSK",
+ "host": "host2"
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone="MSK",host="host2"} 1"
+ }
+ ]
+---
+test case: 'Metrics of different type #1'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1.1340298507220641
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ http_requests_total{method="post",code="200"} 1027 1395066363000
+ http_requests_total{method="post",code="400"} 3 1395066363000
+ params: http_requests_total == 3
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "http_requests_total",
+ "help": "The total number of HTTP requests.",
+ "type": "counter",
+ "labels": {
+ "method": "post",
+ "code": "400"
+ },
+ "value": "3",
+ "line_raw": "http_requests_total{method="post",code="400"} 3 1395066363000"
+ }
+ ]
+---
+test case: 'Metrics of different type #2'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1"} 1027
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ http_requests_total{method="post",code="200"} 1027 1395066363000
+ http_requests_total{method="post",code="400"} 3 1395066363000
+ params: '{__name__=~".*",\value="1027"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu1",
+ "host": "host1"
+ },
+ "value": "1027",
+ "line_raw": "cpu_usage_system{cpu="cpu1",host="host1"} 1027"
+ }
+ ],
+ [
+ {
+ "name": "http_requests_total",
+ "help": "The total number of HTTP requests.",
+ "type": "counter",
+ "labels": {
+ "method": "post",
+ "code": "200"
+ },
+ "value": "1027",
+ "line_raw": "http_requests_total{method="post",code="200"} 1027 1395066363000"
+ }
+ ]
+---
+test case: 'Metrics of different type #3'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1",prio="normal"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host1",prio="high"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host1",prio="normal"} 1027
+ # HELP http_requests_total The total number of HTTP requests.
+ # TYPE http_requests_total counter
+ http_requests_total{method="post",code="200",prio="high"} 1027 1395066363000
+ http_requests_total{method="post",code="400",prio="normal"} 3 1395066363000
+ params: '{prio="normal"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total",
+ "host": "host1",
+ "prio": "normal"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total",host="host1",prio="normal"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu1",
+ "host": "host1",
+ "prio": "normal"
+ },
+ "value": "1027",
+ "line_raw": "cpu_usage_system{cpu="cpu1",host="host1",prio="normal"} 1027"
+ }
+ ],
+ [
+ {
+ "name": "http_requests_total",
+ "help": "The total number of HTTP requests.",
+ "type": "counter",
+ "labels": {
+ "method": "post",
+ "code": "400"
+ },
+ "value": "3",
+ "line_raw": "http_requests_total{method="post",code="400",prio="normal"} 3 1395066363000"
+ }
+ ]
+---
+test case: 'Get metric value using params: cpu_usage_system'
+in:
+ data: |
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1"} 1.1340298507220641
+ params: cpu_usage_system
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu-total"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu-total"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0"} 1.1940298507220641"
+ },
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu1"
+ },
+ "value": "1.1340298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu1"} 1.1340298507220641"
+ }
+ ]
+---
+test case: 'Different metrics #1'
+in:
+ data: |
+ wmi_os_timezone{timezone="MSK",host="host2"} 1
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641
+ params: '{host="host2"}'
+out:
+ result: succeed
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "timezone": "MSK",
+ "host": "host2"
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone="MSK",host="host2"} 1"
+ }
+ ],
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0",
+ "host": "host2"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641"
+ }
+ ]
+---
+test case: 'Different metrics #2'
+in:
+ data: |
+ wmi_os_timezone{timezone="MSK",host="host2"} 1
+
+ # HELP cpu_usage_system Telegraf collected metric
+ # TYPE cpu_usage_system gauge
+ cpu_usage_system{cpu="cpu-total",host="host1"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641
+ cpu_usage_system{cpu="cpu1",host="host3"} 1.1340298507220641
+ params: '{host="host2"}'
+out:
result: succeed
- output: TODO
+ output: |
+ [
+ {
+ "name": "wmi_os_timezone",
+ "help": "(null)",
+ "type": "(null)",
+ "labels": {
+ "timezone": "MSK",
+ "host": "host2"
+ },
+ "value": "1",
+ "line_raw": "wmi_os_timezone{timezone="MSK",host="host2"} 1"
+ }
+ ],
+ [
+ {
+ "name": "cpu_usage_system",
+ "help": "Telegraf collected metric",
+ "type": "gauge",
+ "labels": {
+ "cpu": "cpu0",
+ "host": "host2"
+ },
+ "value": "1.1940298507220641",
+ "line_raw": "cpu_usage_system{cpu="cpu0",host="host2"} 1.1940298507220641"
+ }
+ ]
...