Skip to content

Commit

Permalink
Merge pull request #702 from Altinity/issue-642-test
Browse files Browse the repository at this point in the history
test annotations support
  • Loading branch information
Slach authored Dec 27, 2024
2 parents 507d632 + dfb796a commit 77e3cff
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docker/clickhouse/init_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ INSERT INTO default.test_grafana(event_time, service_name, from_user, country, t
INSERT INTO default.test_grafana(event_time, service_name, from_user, country, too_big_value) SELECT toDateTime(now()+(number*10)) AS event_time, 'mysql' AS service_name, if(rand() % 2 = 1,'bob','alice') AS from_user, multiIf(rand() % 10= 1,'RU', rand() % 10= 2,'DE', rand() % 10= 3,'CN', rand() % 10= 4,'UK', rand() % 10= 5,'NL', rand() % 10= 6,'EU', rand() % 10= 7,'TK', rand() % 10= 8,'AR', rand() % 10= 9,'FR', 'US') AS country, 1000000000.05 AS too_big_value FROM numbers(1000);
INSERT INTO default.test_grafana(event_time, service_name, from_user, country, too_big_value) SELECT toDateTime(now()+((500+number)*10)) AS event_time, 'postgresql' AS service_name, if(rand() % 2 = 1,'bob','alice') AS from_user, multiIf(rand() % 10= 1,'RU', rand() % 10= 2,'DE', rand() % 10= 3,'CN', rand() % 10= 4,'UK', rand() % 10= 5,'NL', rand() % 10= 6,'EU', rand() % 10= 7,'TK', rand() % 10= 8,'AR', rand() % 10= 9,'FR', 'US') AS country, 1000000000.05 AS too_big_value FROM numbers(1000);

DROP TABLE IF EXISTS default.test_grafana_random;
CREATE TABLE IF NOT EXISTS default.test_grafana_random
(
event_time DateTime,
service_name LowCardinality(String),
from_user LowCardinality(String),
country LowCardinality(String),
too_big_value Float64,
random UInt32
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(event_time)
ORDER BY (event_time, service_name);

INSERT INTO default.test_grafana_random(event_time, service_name, from_user, country, too_big_value, random) SELECT toDateTime(now()-(number*10)) AS event_time, if(rand() % 2 = 1,'mysql','postgresql') AS service_name, if(rand() % 2 = 1,'bob','alice') AS from_user, multiIf(rand() % 10= 1,'RU', rand() % 10= 2,'DE', rand() % 10= 3,'CN', rand() % 10= 4,'UK', rand() % 10= 5,'NL', rand() % 10= 6,'EU', rand() % 10= 7,'TK', rand() % 10= 8,'AR', rand() % 10= 9,'FR', 'US') AS country, 1000000000.05 AS too_big_value, rand() as random FROM numbers(1000);
INSERT INTO default.test_grafana_random(event_time, service_name, from_user, country, too_big_value, random) SELECT toDateTime(now()+(number*10)) AS event_time, 'mysql' AS service_name, if(rand() % 2 = 1,'bob','alice') AS from_user, multiIf(rand() % 10= 1,'RU', rand() % 10= 2,'DE', rand() % 10= 3,'CN', rand() % 10= 4,'UK', rand() % 10= 5,'NL', rand() % 10= 6,'EU', rand() % 10= 7,'TK', rand() % 10= 8,'AR', rand() % 10= 9,'FR', 'US') AS country, 1000000000.05 AS too_big_value, rand() as random FROM numbers(1000);
INSERT INTO default.test_grafana_random(event_time, service_name, from_user, country, too_big_value, random) SELECT toDateTime(now()+((500+number)*10)) AS event_time, 'postgresql' AS service_name, if(rand() % 2 = 1,'bob','alice') AS from_user, multiIf(rand() % 10= 1,'RU', rand() % 10= 2,'DE', rand() % 10= 3,'CN', rand() % 10= 4,'UK', rand() % 10= 5,'NL', rand() % 10= 6,'EU', rand() % 10= 7,'TK', rand() % 10= 8,'AR', rand() % 10= 9,'FR', 'US') AS country, 1000000000.05 AS too_big_value, rand() as random FROM numbers(1000);

DROP TABLE IF EXISTS default.test_logs;
CREATE TABLE IF NOT EXISTS default.test_logs
(
Expand Down
323 changes: 323 additions & 0 deletions docker/grafana/dashboards/issue-642-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
},
{
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"enable": true,
"filter": {
"exclude": false,
"ids": [
2
]
},
"hide": false,
"iconColor": "red",
"name": "annotation_2",
"target": {
"adHocFilters": [],
"adHocValuesQuery": "",
"add_metadata": true,
"contextWindowSize": "10",
"editorMode": "builder",
"extrapolate": true,
"format": "ANNOTATION",
"formattedQuery": "SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"interval": "",
"intervalFactor": 1,
"query": "SELECT \n toUInt64(event_time) * 1000 AS time,\n (toUInt64(event_time) + (random % 600)) * 1000 AS time_end,\n if(random % 2 = 1, '[alert] title', '[annotation] title') AS title,\n if(random % 2 = 1, '[alert] description', '[annotation] description') AS text,\n arrayStringConcat(['test1', 'test2', service_name],',') AS tags\nFROM default.test_grafana_random\nWHERE\n random % 100 IN (1,50) AND\n toUInt64(event_time) >= $from AND toUInt64(event_time) < $to",
"rawQuery": "/* grafana dashboard=Annotation event_time, user=1 */\nSELECT \n toUInt64(event_time) * 1000 AS time,\n (toUInt64(event_time ) + (random % 600)) * 1000 AS time_end,\n if(random % 2 = 1, '[alert] title', '[annotation] title') AS title,\n if(random % 2 = 1, '[alert] description', '[annotation] description') AS text,\n arrayStringConcat(['test1', 'test2', service_name],',') AS tags\nFROM default.test_grafana_random\nWHERE\n random % 100 IN (1,50) AND\n toUInt64(event_time) >= 1735290823 AND toUInt64(event_time) < 1735312423",
"refId": "Anno",
"round": "0s",
"skip_comments": true,
"useWindowFuncForMacros": true
}
},
{
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"enable": true,
"filter": {
"exclude": false,
"ids": [
1
]
},
"hide": false,
"iconColor": "red",
"name": "annotation_1",
"target": {
"adHocFilters": [],
"adHocValuesQuery": "",
"add_metadata": true,
"contextWindowSize": "10",
"editorMode": "builder",
"extrapolate": true,
"format": "ANNOTATION",
"formattedQuery": "SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"interval": "",
"intervalFactor": 1,
"query": "SELECT \n event_time AS time,\n event_time + INTERVAL (random % 600) SECONDS AS time_end,\n if(random % 2 = 1, '[alert] title', '[annotation] title') AS title,\n if(random % 2 = 1, '[alert] description', '[annotation] description') AS text,\n arrayStringConcat(['test1', 'test2', service_name],',') AS tags\nFROM default.test_grafana_random\nWHERE\n random % 100 IN (1,50) AND\n toUInt64(event_time) >= $from AND toUInt64(event_time) < $to",
"rawQuery": "/* grafana dashboard=Annotation event_time, user=1 */\nSELECT \n event_time AS time,\n event_time + INTERVAL (random % 600) SECONDS AS time_end,\n if(random % 2 = 1, '[alert] title', '[annotation] title') AS title,\n if(random % 2 = 1, '[alert] description', '[annotation] description') AS text,\n arrayStringConcat(['test1', 'test2', service_name],',') AS tags\nFROM default.test_grafana_random\nWHERE\n random % 100 IN (1,50) AND\n toUInt64(event_time) >= 1735287755 AND toUInt64(event_time) < 1735309355",
"refId": "Anno",
"round": "0s",
"skip_comments": true,
"useWindowFuncForMacros": true
}
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 15,
"links": [],
"panels": [
{
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "11.4.0",
"targets": [
{
"adHocFilters": [],
"adHocValuesQuery": "",
"add_metadata": true,
"contextWindowSize": "10",
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"editorMode": "builder",
"extrapolate": true,
"format": "time_series",
"formattedQuery": "SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"interval": "",
"intervalFactor": 1,
"query": "select now(), 1",
"rawQuery": "/* grafana dashboard=Annotation event_time, user=1 */\nselect now(), 1",
"refId": "A",
"round": "0s",
"skip_comments": true,
"useWindowFuncForMacros": true
}
],
"title": "event_time",
"type": "timeseries"
},
{
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "11.4.0",
"targets": [
{
"adHocFilters": [],
"adHocValuesQuery": "",
"add_metadata": true,
"contextWindowSize": "10",
"datasource": {
"type": "vertamedia-clickhouse-datasource",
"uid": "P7E099F39B84EA795"
},
"editorMode": "builder",
"extrapolate": true,
"format": "time_series",
"formattedQuery": "SELECT $timeSeries as t, count() FROM $table WHERE $timeFilter GROUP BY t ORDER BY t",
"interval": "",
"intervalFactor": 1,
"query": "select now(), 1",
"rawQuery": "/* grafana dashboard=Annotation event_time, user=1 */\nselect now(), 1",
"refId": "A",
"round": "0s",
"skip_comments": true,
"useWindowFuncForMacros": true
}
],
"title": "toUInt64",
"type": "timeseries"
}
],
"preload": false,
"schemaVersion": 40,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Annotation event_time",
"uid": "be86tq72ew3k0d",
"version": 1,
"weekStart": ""
}
15 changes: 15 additions & 0 deletions tests/testflows/steps/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ def compare_screenshots(self, screenshot_name_1, screenshot_name_2):
return image_1 == image_2


@TestStep(Then)
def compare_screenshots_percent(self, screenshot_name_1, screenshot_name_2):
"""Check that screenshots are similar."""
image_1 = Image.open(os.path.join(self.context.project_root_dir, 'tests', 'testflows', 'screenshots', f"{screenshot_name_1}.png"))
image_2 = Image.open(os.path.join(self.context.project_root_dir, 'tests', 'testflows', 'screenshots', f"{screenshot_name_2}.png"))
difference = np.array(image_1) == np.array(image_2)
overlap = 0
for i in difference:
for j in i:
for k in j:
overlap += k
note(f"overlap percent: {overlap/(difference.shape[0] * difference.shape[1] * difference.shape[2])}")
return overlap/(difference.shape[0] * difference.shape[1] * difference.shape[2])


@TestStep(Given)
def create_dashboard(self, dashboard_name, open_it=True, finally_save_dashboard=True):
"""Create new dashboard named {dashboard_name} and open it."""
Expand Down
4 changes: 4 additions & 0 deletions tests/testflows/steps/panel/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,9 @@ def refresh_button(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid RefreshPicker run button"]')

def annotation_toggle(self, annotation_name):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH, f'//label[@data-testid="data-testid Dashboard template variables submenu Label {annotation_name}"]/..//label[@aria-label="Toggle switch"]')


locators = Locators()
Loading

0 comments on commit 77e3cff

Please sign in to comment.