Skip to content

Commit

Permalink
Merge pull request #329 from Altinity/fix_github_issues
Browse files Browse the repository at this point in the history
fix #319
  • Loading branch information
Slach authored Mar 22, 2021
2 parents cdcba9f + bf2ad08 commit d92ff14
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 11 deletions.
16 changes: 8 additions & 8 deletions dist/MANIFEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Hash: SHA512
"signedByOrgName": "Vertamedia",
"plugin": "vertamedia-clickhouse-datasource",
"version": "2.2.3",
"time": 1613546387194,
"time": 1616428452130,
"keyId": "7e4d0c6a708866e7",
"files": {
"img/annotations.png": "09cc19df992fede5c4dd830f7b3c7a783702feced07ea9693d417ec127077b00",
"img/clickhouse_logo.svg": "111c2048c9bad4a11b0273cf17839696d98968c04cdcc5ea0716bdc973f2e8e4",
"img/datasource.png": "8d6dcdddfad512abed8c251404f652383f63ad17bc5c7cbe3e67ad9e6fa0327f",
"img/query_editor.png": "b8d50f644d413b15aaf0d7b71fdfa4423f1a045761ec368b19a15e3d1aaf9308",
"LICENSE": "a434fc6dd97d5c425c6edbeff0276afd60ab5fffab3ed2c563f95a389502d074",
"module.js": "3c7c7e44b69f8ce10a6727a5896452f270ba8edda0adfd01ee7cf67c4b8c41e7",
"module.js.map": "b42c39c5041378a3bd66ad99acc2d453d030af94aadb5331ef241ecb4c2a934f",
"module.js": "75b8a1ba9b3f3a8a130b7e2f0a1ad317959f38d1608bfeddd3c80f1b6a6df805",
"module.js.map": "019fbc5abcc3237523dfd891c3f4f5c486908b11076dab214d2e4f6808a5ac74",
"partials/annotations.editor.html": "14d2d5add7f13c7c722e33bbc53ef83750fb624e5f7d6efee4a9568addc2ab78",
"partials/config.html": "51ba130304c63c1a00590a9dc94c8351ff6277e4cf695720de57bff87aeec744",
"partials/query.editor.html": "eb9ab7af412a922ea2ce09c86b99a75ba70000977a5fd882b8e327a2a27e1904",
Expand All @@ -34,9 +34,9 @@ Hash: SHA512
Version: OpenPGP.js v4.10.1
Comment: https://openpgpjs.org

wqEEARMKAAYFAmAsw5MACgkQfk0ManCIZucH7AIInTOR3xlAzk/Iu7PhAZQI
j9G4bACbwjFUcRBZiWiIcr6hW7XuVYu4vTEst1RVGuIesCbq611UYCOED1Co
fT5Zk5sCCQE/Hb0xVqA2gNj2AExBo7/9ZaqYlsbpfO6Plw1wmYJJhnSXmRkf
AUi5If4qqVLGa7vrUrRNBosEgYdNVSiWrwHcgQ==
=WLWv
wqEEARMKAAYFAmBYvaQACgkQfk0ManCIZuc8TQIHexvZdffPosVRSeh6H7ro
r7UXTgpVh58RFPatYgnDVp1ryP9MA6WHind2DZhRLjL9oggwt3BoO+mcyXtc
JCsaMtACCQG7WtoY/w4YZHX9Sj2RoboliNhdkaumMj4Hkh0fOzqLIApJIdIz
6jnFOer1TFaSKM3BwZVGNQfFFVDo11leSjUhyg==
=ehE9
-----END PGP SIGNATURE-----
2 changes: 1 addition & 1 deletion dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
volumes:
- /var/log/clickhouse-server
- ./docker/clickhouse/init_schema.sql:/docker-entrypoint-initdb.d/init_schema.sql
- ./docker/clickhouse/postgres_dictionary.xml:/etc/clickhouse-server/postgres_dictionary.xml

postgres:
image: postgres:latest
Expand Down
43 changes: 43 additions & 0 deletions docker/clickhouse/postgres_dictionary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<yandex>
<dictionary>
<name>postgres_dict</name>
<structure>
<key>
<attribute>
<name>service_name</name>
<type>String</type>
</attribute>
</key>
<attribute>
<name>service_type</name>
<type>String</type>
<null_value></null_value>
</attribute>
</structure>

<source>
<postgresql>
<host>postgres</host>
<port>5432</port>
<user>grafana</user>
<password>grafana</password>
<database>grafana</database>
<table>test_grafana_dict</table>
<replica>
<host>postgres</host>
</replica>
<where>service_name='mysql'</where>
<invalidate_query>SELECT now()</invalidate_query>
</postgresql>
</source>

<layout>
<complex_key_hashed/>
</layout>

<lifetime>
<min>10</min>
<max>20</max>
</lifetime>
</dictionary>
</yandex>
148 changes: 148 additions & 0 deletions docker/grafana/dashboards/columns_union_all_with.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 14,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "clickhouse",
"description": "fix https://github.com/Vertamedia/clickhouse-grafana/issues/319",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 9,
"w": 12,
"x": 0,
"y": 0
},
"hiddenSeries": false,
"id": 2,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"database": "default",
"dateColDataType": "",
"dateLoading": false,
"dateTimeColDataType": "event_time",
"dateTimeType": "DATETIME",
"datetimeLoading": false,
"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": "$columns(\n service_name, \n sum(agg_value) as value\n)\nFROM (\n\n SELECT\n $timeSeries as t,\n service_name,\n sum(too_big_value) as agg_value\n FROM $table\n WHERE $timeFilter\n GROUP BY t,service_name\n \n UNION ALL\n \n WITH (SELECT sum(too_big_value) FROM $table) AS total_value\n SELECT\n $timeSeries as t,\n service_name,\n sum(too_big_value) / total_value as agg_value\n FROM $table\n WHERE $timeFilter\n GROUP BY t,service_name\n)",
"queryType": "randomWalk",
"rawQuery": "SELECT t, groupArray((service_name, value)) AS groupArr FROM ( SELECT (intDiv(toUInt32(event_time), 20) * 20) * 1000 AS t, service_name, sum(agg_value) as value FROM default.test_grafana) AS total_value\n SELECT\n (intDiv(toUInt32(event_time), 20) * 20) * 1000 as t,\n service_name,\n sum(too_big_value) / total_value as agg_value\n FROM default.test_grafana\n WHERE event_time >= toDateTime(1616397355) AND event_time >= toDateTime(1616397355)\n GROUP BY t,service_name\n) GROUP BY t, service_name ORDER BY t, service_name) GROUP BY t ORDER BY t",
"refId": "A",
"round": "0s",
"skip_comments": true,
"table": "test_grafana",
"tableLoading": false
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "$columns + union all + with",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"schemaVersion": 27,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "$columns + union all + with",
"uid": "qcnq8TQMk",
"version": 1
}
6 changes: 6 additions & 0 deletions docker/postgres/init_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ INSERT INTO test_grafana(event_time, service_name, too_big_value) SELECT to_time
INSERT INTO test_grafana(event_time, service_name, too_big_value) SELECT to_timestamp(extract(epoch from now()) + ((500+generate_series)*10)) AS event_time, 'postgresql' AS service_name, 1000000000.05 AS too_big_value FROM generate_series(1,1000);

ALTER TABLE test_grafana OWNER TO grafana;

DROP TABLE IF EXISTS test_grafana_dict;
CREATE TABLE IF NOT EXISTS test_grafana_dict(service_name VARCHAR(100), service_type VARCHAR(100));
ALTER TABLE test_grafana_dict OWNER TO grafana;

INSERT INTO test_grafana_dict(service_name, service_type) VALUES ('mysql','sql'),('postgresql','sql');
61 changes: 61 additions & 0 deletions spec/query_specs.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,64 @@ describe("comments and $rate and from in field name", () => {
expect(SqlQuery.applyMacros(query, scanner.toAST() )).toBe(expQuery);
});
});

/* fix https://github.com/Vertamedia/clickhouse-grafana/issues/319 */
describe("columns + union all + with", () => {
const query = "$columns(\n" +
" service_name, \n" +
" sum(agg_value) as value\n" +
")\n" +
"FROM (\n" +
"\n" +
" SELECT\n" +
" $timeSeries as t,\n" +
" service_name,\n" +
" sum(too_big_value) as agg_value\n" +
" FROM $table\n" +
" WHERE $timeFilter\n" +
" GROUP BY t,service_name\n" +
" \n" +
" UNION ALL\n" +
" \n" +
" WITH (SELECT sum(too_big_value) FROM $table) AS total_value\n" +
" SELECT\n" +
" $timeSeries as t,\n" +
" service_name,\n" +
" sum(too_big_value) / total_value as agg_value\n" +
" FROM $table\n" +
" WHERE $timeFilter\n" +
" GROUP BY t,service_name\n" +
")";
const expQuery = "SELECT t, groupArray((service_name, value)) AS groupArr FROM ( SELECT $timeSeries AS t, service_name, sum(agg_value) as value FROM (\n" +
"\n" +
" SELECT\n" +
" $timeSeries as t,\n" +
" service_name,\n" +
" sum(too_big_value) as agg_value\n" +
" FROM $table\n" +
" WHERE $timeFilter AND $timeFilter\n" +
" GROUP BY t,service_name\n" +
" \n" +
" UNION ALL\n" +
" \n" +
" WITH (SELECT sum(too_big_value) FROM $table) AS total_value\n" +
" SELECT\n" +
" $timeSeries as t,\n" +
" service_name,\n" +
" sum(too_big_value) / total_value as agg_value\n" +
" FROM $table\n" +
" WHERE $timeFilter\n" +
" GROUP BY t,service_name\n" +
") GROUP BY t, service_name ORDER BY t, service_name) GROUP BY t ORDER BY t";
const scanner = new Scanner(query);
let templateSrv: any;
const options = {
rangeRaw: {
from: "now-10m",
to: "now"
}
};
it("gets replaced with right FROM query", () => {
expect(SqlQuery.applyMacros(query, scanner.toAST() )).toBe(expQuery);
});
});
Loading

0 comments on commit d92ff14

Please sign in to comment.