diff options
Diffstat (limited to 'ui/tests/unit/include/classes/parsers/CPrometheusPatternParserTest.php')
-rw-r--r-- | ui/tests/unit/include/classes/parsers/CPrometheusPatternParserTest.php | 169 |
1 files changed, 164 insertions, 5 deletions
diff --git a/ui/tests/unit/include/classes/parsers/CPrometheusPatternParserTest.php b/ui/tests/unit/include/classes/parsers/CPrometheusPatternParserTest.php index 7dab378ef7d..80be830b43e 100644 --- a/ui/tests/unit/include/classes/parsers/CPrometheusPatternParserTest.php +++ b/ui/tests/unit/include/classes/parsers/CPrometheusPatternParserTest.php @@ -233,6 +233,62 @@ class CPrometheusPatternParserTest extends TestCase { ] ], [ + '{label1="{$MACRO}"}', 0, [], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{$MACRO}"}' + ] + ], + [ + '{label1="{$MACRO} abc {$MACRO2}"}', 0, [], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{$MACRO} abc {$MACRO2}"}' + ] + ], + [ + '{label1="{$MACRO}"}', 0, ['usermacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{$MACRO}"}' + ] + ], + [ + '{label1="{$MACRO} abc {$MACRO2}"}', 0, ['usermacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{$MACRO} abc {$MACRO2}"}' + ] + ], + [ + '{label1="{#LLD_MACRO}"}', 0, [], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{#LLD_MACRO}"}' + ] + ], + [ + '{label1="{#LLD_MACRO} abc {#LLD_MACRO2}"}', 0, [], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{#LLD_MACRO} abc {#LLD_MACRO2}"}' + ] + ], + [ + '{label1="{#LLD_MACRO}"}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{#LLD_MACRO}"}' + ] + ], + [ + '{label1="{#LLD_MACRO} abc {#LLD_MACRO2}"}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{label1="{#LLD_MACRO} abc {#LLD_MACRO2}"}' + ] + ], + [ '{label1="value1"}==666', 0, [], [ 'rc' => CParser::PARSE_SUCCESS, @@ -344,6 +400,34 @@ class CPrometheusPatternParserTest extends TestCase { 'match' => '{#LLD1}{{#LLD2}="value1"}=={#LLD3}' ] ], + [ + '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}' + ] + ], + [ + 'metric == {{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => 'metric == {{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)}' + ] + ], + [ + 'metric{{#LLD_MACRO}="value1"} == Nan', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => 'metric{{#LLD_MACRO}="value1"} == Nan' + ] + ], + [ + 'metric{{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)} = "value1"} == Nan', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => 'metric{{{#LLD_MACRO}.regsub("(.*)_([0-9]+)", \1)} = "value1"} == Nan' + ] + ], // Label value can by anything, no user macro enabling flag is required. [ '{label1="{$M}"}', 0, [], @@ -382,6 +466,13 @@ class CPrometheusPatternParserTest extends TestCase { 'match' => '{label1!~"value1"}' ] ], + [ + '{#LLD} {label1="value1"} == {{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS, + 'match' => '{#LLD} {label1="value1"} == {{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")}' + ] + ], // partial success [ 'metric=1.e1', 0, [], @@ -559,12 +650,36 @@ class CPrometheusPatternParserTest extends TestCase { 'match' => 'metric' ] ], - // Functional macros are not supported. + // Incorrect syntax of functional LLD macros in label. [ - '{#LLD} {label1="value1"} == {{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")}', 0, ['lldmacros' => true], + 'metric {{{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")="value1"} == Nan', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS_CONT, + 'match' => 'metric' + ] + ], + // Multiple macros for metric. + [ + '{#LLD_MACRO}{#LLD_MACRO2}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS_CONT, + 'match' => '{#LLD_MACRO}' + ] + ], + // Multiple macros for label. + [ + 'metric{{#LLD_MACRO}{#LLD_MACRO2} = "value"}', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_SUCCESS_CONT, - 'match' => '{#LLD} {label1="value1"}' + 'match' => 'metric' + ] + ], + // Multiple macros for value. + [ + 'metric{label = "value"} == {#LLD_MACRO}{#LLD_MACRO2}', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_SUCCESS_CONT, + 'match' => 'metric{label = "value"} == {#LLD_MACRO}' ] ], // fail @@ -759,6 +874,34 @@ class CPrometheusPatternParserTest extends TestCase { 'match' => '' ] ], + [ + '{label1={$MACRO}}==""', 0, [], + [ + 'rc' => CParser::PARSE_FAIL, + 'match' => '' + ] + ], + [ + '{label1={$MACRO}}==""', 0, ['usermacros' => true], + [ + 'rc' => CParser::PARSE_FAIL, + 'match' => '' + ] + ], + [ + '{label1={#LLD_MACRO}}==""', 0, [], + [ + 'rc' => CParser::PARSE_FAIL, + 'match' => '' + ] + ], + [ + '{label1={#LLD_MACRO}}==""', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_FAIL, + 'match' => '' + ] + ], // LLD macros are not enabled. [ '{#LLD}{label1="value1"}=={#LLD}', 0, ['usermacros' => true], @@ -767,9 +910,25 @@ class CPrometheusPatternParserTest extends TestCase { 'match' => '' ] ], - // Functional macros are not supported. + // Multiple LLD macros in label. + [ + '{{#LLD_MACRO}{#LLD_MACRO2}="value1"}==Inf', 0, ['usermacros' => true], + [ + 'rc' => CParser::PARSE_FAIL, + 'match' => '' + ] + ], + // Incorrect syntax of functional LLD macros in metric. + [ + '{{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1") {label1="value1"} == value', 0, ['lldmacros' => true], + [ + 'rc' => CParser::PARSE_FAIL, + 'match' => '' + ] + ], + // Incorrect syntax of functional LLD macros in metric. [ - '{{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")} {label1="value1"} == {{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")}', 0, ['lldmacros' => true], + '{{{#LLD}.regsub("^([0-9]+)", "{#LLD}: \1")="value1"} == value', 0, ['lldmacros' => true], [ 'rc' => CParser::PARSE_FAIL, 'match' => '' |