@ -71,6 +71,72 @@ describe('buildVisualQueryFromString', () => {
) ;
} ) ;
describe ( 'nested binary operation errors in visual query editor' , ( ) = > {
// Visual query builder does not currently have support for nested binary operations, for now we should throw an error in the UI letting users know that their query will be misinterpreted
it ( 'throws error when visual query parse is ambiguous' , ( ) = > {
expect (
buildVisualQueryFromString ( 'topk(5, node_arp_entries / node_arp_entries{cluster="dev-eu-west-2"})' )
) . toMatchObject ( {
errors : [
{
from : 8 ,
text : 'Query parsing is ambiguous.' ,
to : 68 ,
} ,
] ,
} ) ;
} ) ;
it ( 'throws error when visual query parse with aggregation is ambiguous (scalar)' , ( ) = > {
expect ( buildVisualQueryFromString ( 'topk(5, 1 / 2)' ) ) . toMatchObject ( {
errors : [
{
from : 8 ,
text : 'Query parsing is ambiguous.' ,
to : 13 ,
} ,
] ,
} ) ;
} ) ;
it ( 'throws error when visual query parse with functionCall is ambiguous' , ( ) = > {
expect (
buildVisualQueryFromString (
'clamp_min(sum by(cluster)(rate(X{le="2.5"}[5m]))+sum by (cluster) (rate(X{le="5"}[5m])), 0.001)'
)
) . toMatchObject ( {
errors : [
{
from : 10 ,
text : 'Query parsing is ambiguous.' ,
to : 87 ,
} ,
] ,
} ) ;
} ) ;
it ( 'does not throw error when visual query parse is unambiguous' , ( ) = > {
expect (
buildVisualQueryFromString ( 'topk(5, node_arp_entries) / node_arp_entries{cluster="dev-eu-west-2"}' )
) . toMatchObject ( {
errors : [ ] ,
} ) ;
} ) ;
it ( 'does not throw error when visual query parse is unambiguous (scalar)' , ( ) = > {
// Note this topk query with scalars is not valid in prometheus, but it does not currently throw an error during parse
expect ( buildVisualQueryFromString ( 'topk(5, 1) / 2' ) ) . toMatchObject ( {
errors : [ ] ,
} ) ;
} ) ;
it ( 'does not throw error when visual query parse is unambiguous, function call' , ( ) = > {
// Note this topk query with scalars is not valid in prometheus, but it does not currently throw an error during parse
expect (
buildVisualQueryFromString (
'clamp_min(sum by(cluster) (rate(X{le="2.5"}[5m])), 0.001) + sum by(cluster) (rate(X{le="5"}[5m]))'
)
) . toMatchObject ( {
errors : [ ] ,
} ) ;
} ) ;
} ) ;
it ( 'parses query with rate and interval' , ( ) = > {
expect ( buildVisualQueryFromString ( 'rate(counters_logins{app="frontend"}[5m])' ) ) . toEqual (
noErrors ( {