Skip to content
Snippets Groups Projects
Commit d36547a6 authored by Christoph Alt's avatar Christoph Alt
Browse files

fixed the variable encoding/escaping within the generated queries

parent b0a7a2fc
Branches
Tags
No related merge requests found
Pipeline #61321 passed with stages
in 1 minute and 55 seconds
......@@ -60,7 +60,7 @@ def get_variable_condition(variable_name: str, *, tag_key: str = None) -> str:
clean_lhs = clean_rhs
if not clean_rhs:
raise ValueError("Empty variable name")
return f'"{clean_lhs}" =~ /^${clean_rhs}$/'
return f'"{clean_lhs}" =~ /^${{{clean_rhs}:regex}}$/'
def join_conditions(conditions: List[str], operators: Union[List[str], str]):
......
......@@ -15,7 +15,7 @@ measurment_name = 'UniformGridGPU'
q1 = Query(
select_='mlupsPerProcess',
from_=measurment_name,
where_='"collisionSetup" =~ /^$collisionSetup$/ AND "host" =~ /^$host$/ AND "cellsPerBlock_0" =~ /^$cellsPerBlock_0$/',
where_='"collisionSetup" =~ /^${collisionSetup:regex}$/ AND "host" =~ /^${host:regex}$/ AND "cellsPerBlock_0" =~ /^${cellsPerBlock_0:regex}$/',
group_by=[
"blocks_0",
"blocks_1",
......
import pytest
from dashboards.influx_queries import (Query, get_variable_condition,
join_conditions, show_tag_values)
from dashboards.influx_queries import (
Query,
get_variable_condition,
join_conditions,
show_tag_values,
)
def test_query():
q = Query(
select_='mlupsPerProcess',
from_='UniformGridGPU',
where_='"host" =~ /^$host$/ AND "collisionSetup" =~ /^$collisionSetup$/',
select_="mlupsPerProcess",
from_="UniformGridGPU",
where_='"host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/',
group_by=[
"blocks_0",
"blocks_1",
......@@ -21,28 +25,30 @@ def test_query():
"gpuBlockSize_2",
"collisionSetup",
"stencil",
"streamingPattern"
]
"streamingPattern",
],
)
q1 = ('SELECT "mlupsPerProcess" '
'FROM "UniformGridGPU" '
'WHERE ("host" =~ /^$host$/ AND "collisionSetup" =~ /^$collisionSetup$/) AND $timeFilter '
'GROUP BY "blocks_0", "blocks_1", "blocks_2", '
'"cellsPerBlock_0", "cellsPerBlock_1", "cellsPerBlock_2", '
'"gpuBlockSize_0", "gpuBlockSize_1", "gpuBlockSize_2", '
'"collisionSetup", "stencil", "streamingPattern"')
q1 = (
'SELECT "mlupsPerProcess" '
'FROM "UniformGridGPU" '
'WHERE ("host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/) AND $timeFilter '
'GROUP BY "blocks_0", "blocks_1", "blocks_2", '
'"cellsPerBlock_0", "cellsPerBlock_1", "cellsPerBlock_2", '
'"gpuBlockSize_0", "gpuBlockSize_1", "gpuBlockSize_2", '
'"collisionSetup", "stencil", "streamingPattern"'
)
assert q1 == str(q)
def test_show_tag_values():
s = show_tag_values("UniformGridGPU", "host")
assert s == 'SHOW TAG VALUES FROM \"UniformGridGPU\" WITH key = \"host\"'
assert s == 'SHOW TAG VALUES FROM "UniformGridGPU" WITH key = "host"'
def test_get_variable_condtion():
assert get_variable_condition("host") == '"host" =~ /^$host$/'
assert get_variable_condition(" host ") == '"host" =~ /^$host$/'
assert get_variable_condition("host") == '"host" =~ /^${host:regex}$/'
assert get_variable_condition(" host ") == '"host" =~ /^${host:regex}$/'
with pytest.raises(ValueError):
get_variable_condition("")
with pytest.raises(ValueError):
......@@ -55,21 +61,24 @@ def test_join_conditions_two():
h = get_variable_condition("host")
c = get_variable_condition("collisionSetup")
actual = join_conditions([h, c], "AND")
excpected = '"host" =~ /^$host$/ AND "collisionSetup" =~ /^$collisionSetup$/'
excpected = '"host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/'
assert actual == excpected
def test_join_conditions_three():
conds = [get_variable_condition(name) for name in ["host",
"collisionSetup",
"cellsPerBlock_0"]]
conds = [
get_variable_condition(name)
for name in ["host", "collisionSetup", "cellsPerBlock_0"]
]
# excpected = '"host" =~ /^$host$/ AND "collisionSetup" =~ /^$collisionSetup$/'
assert join_conditions(conds, "AND") == " AND ".join(conds)
assert join_conditions(conds, ["AND", "AND"]) == " AND ".join(conds)
assert join_conditions(conds, ["AND"]) == " AND ".join(conds)
assert join_conditions(conds, ["OR"]) == " OR ".join(conds)
excpected = ('"host" =~ /^$host$/ '
'AND "collisionSetup" =~ /^$collisionSetup$/ '
'OR "cellsPerBlock_0" =~ /^$cellsPerBlock_0$/')
excpected = (
'"host" =~ /^${host:regex}$/ '
'AND "collisionSetup" =~ /^${collisionSetup:regex}$/ '
'OR "cellsPerBlock_0" =~ /^${cellsPerBlock_0:regex}$/'
)
assert join_conditions(conds, ["AND", "OR"]) == excpected
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment