ClickHouse/utils/tests-visualizer/index.html

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

215 lines
5.7 KiB
HTML
Raw Normal View History

2022-01-06 21:35:02 +00:00
<html id="html">
<head>
<meta charset="UTF-8">
2022-01-06 21:35:02 +00:00
<style>
body {
color: white;
background: black;
font-family: sans-serif;
}
2022-01-07 09:26:17 +00:00
.hide {
display: none;
}
2022-01-06 21:35:02 +00:00
#loading {
margin-top: 1em;
}
#loading img {
width: 130px;
display: block;
margin: 30px auto;
-webkit-animation: spin 2s ease-in-out infinite;
-moz-animation: spin 2s ease-in-out infinite;
animation: spin 2s ease-in-out infinite;
}
2022-01-07 09:26:17 +00:00
h1 {
2022-01-06 21:35:02 +00:00
text-align: center;
}
#info {
position: sticky;
top: 1rem;
z-index: 1;
margin: 1rem;
float: right;
font-size: 16pt;
padding: 0.5rem;
2022-01-07 19:20:47 +00:00
border: 1px solid #111;
2022-01-06 21:35:02 +00:00
}
canvas {
position: absolute;
cursor: pointer;
}
@-moz-keyframes spin {
100% { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
100% { transform:rotate(360deg); }
}
</style>
</head>
2022-01-06 21:35:02 +00:00
<body>
2022-01-07 09:26:17 +00:00
<pre id="info" class="hide"></pre>
<h1 id="fail-message" class="hide">Data not load</h1>
2022-01-06 21:35:02 +00:00
<div id="loading">
2022-08-10 02:46:43 +00:00
<img src="https://presentations.clickhouse.com/images/logo.svg">
2022-01-07 11:59:07 +00:00
<h1>Loading (~10 seconds, ~20 MB)</h1>
2022-01-06 21:35:02 +00:00
</div>
<canvas id="canvas"></canvas>
<script type="text/javascript">
2022-01-06 21:35:02 +00:00
///////////////////////
// GLOBAL VARIABLES
///////////////////////
let start_date = '2020-06-13';
2022-01-06 21:35:02 +00:00
const canvasNode = document.getElementById('canvas');
const infoNode = document.getElementById('info');
const loadingNode = document.getElementById('loading');
2022-01-07 09:26:17 +00:00
const failMessageNode = document.getElementById('fail-message');
2022-01-06 21:35:02 +00:00
///////////////////////
// QUERIES
///////////////////////
let render_data_query = `
WITH '${start_date}'::Date AS start_date
SELECT groupArray([d, n, fail]) FROM
(
SELECT n, check_start_time::Date - start_date AS d, max(test_status LIKE 'F%' OR test_status LIKE 'E%') AS fail
2022-03-30 10:55:49 +00:00
FROM "default".checks
INNER JOIN
(
SELECT test_name, toUInt16(rowNumberInAllBlocks()) AS n FROM
(
SELECT DISTINCT test_name
2022-03-30 10:55:49 +00:00
FROM "default".checks
WHERE match(test_name, '^\\d+_') AND check_name ILIKE '%stateless%' AND check_start_time > now() - INTERVAL 1 DAY
ORDER BY test_name
)
) AS nums
USING (test_name)
WHERE
check_name ILIKE '%stateless%'
AND pull_request_number = 0
AND check_start_time >= start_date
GROUP BY d, n
ORDER BY d, n
)
FORMAT TSV`;
2022-01-06 21:35:02 +00:00
let test_names_query = `
SELECT test_name, toUInt16(rowNumberInAllBlocks()) AS n FROM
(
SELECT DISTINCT test_name
2022-03-30 10:55:49 +00:00
FROM "default".checks
2022-01-06 21:35:02 +00:00
WHERE match(test_name, '^\\d+_') AND check_name ILIKE '%stateless%' AND check_start_time > now() - INTERVAL 1 DAY
ORDER BY test_name
2022-01-07 09:26:17 +00:00
) FORMAT JSONCompact`;
2022-01-06 21:35:02 +00:00
///////////////////////
// MAIN
///////////////////////
2022-01-07 09:26:17 +00:00
(async () => {
try {
const [render_data, test_names_data] = await Promise.all([
loadDataByQuery(render_data_query),
loadDataByQuery(test_names_query),
]);
// we good
renderResponse(render_data);
saveTestNames(test_names_data);
} catch (e) {
alert(e);
showFailMessage();
} finally {
hideLoader();
}
})()
2022-01-06 21:35:02 +00:00
///////////////////////
// SPECIAL FUNCTIONS
///////////////////////
async function loadDataByQuery(query) {
const response = await fetch(
2022-04-03 02:52:54 +00:00
"https://play.clickhouse.com?user=play&add_http_cors_header=1",
{ method: "POST", body: query }
)
2022-01-06 21:35:02 +00:00
if (!response.ok) throw new Error(`Data download failed\nHTTP status ${response.status}`);
const json = await response.json();
return json;
}
2022-01-06 21:35:02 +00:00
function renderResponse(data) {
const last_pixel = data[data.length - 1];
2022-01-06 21:35:02 +00:00
canvasNode.width = last_pixel[0] + 1;
canvasNode.height = last_pixel[1] + 1;
2022-01-06 21:35:02 +00:00
document.getElementById('html').style.height = canvasNode.height + 10 + 'px';
document.body.style.height = canvasNode.height + 10 + 'px';
2022-01-06 21:35:02 +00:00
let ctx = canvasNode.getContext('2d');
let image = ctx.createImageData(canvasNode.width, canvasNode.height);
let {data: pixels} = image;
data.map(elem => {
let x = elem[0];
2022-01-06 21:35:02 +00:00
let y = canvasNode.height - elem[1];
2022-01-06 21:35:02 +00:00
pixels[(x + y * canvasNode.width) * 4 + 0] = elem[2] ? 255 : 0; // r
pixels[(x + y * canvasNode.width) * 4 + 1] = elem[2] ? 0 : 100; // g
pixels[(x + y * canvasNode.width) * 4 + 2] = 0; // b
pixels[(x + y * canvasNode.width) * 4 + 3] = 255; // a
});
ctx.putImageData(image, 0, 0);
}
2022-01-06 21:35:02 +00:00
function saveTestNames(data) {
let {data: test_names} = data;
2022-01-06 21:35:02 +00:00
canvasNode.addEventListener('mousemove', (event) => {
2022-01-07 11:59:07 +00:00
infoNode.style.display = 'block';
2022-01-06 21:35:02 +00:00
const x = event.layerX;
const y = event.layerY;
2022-01-06 21:35:02 +00:00
let date = new Date(start_date);
date.setDate(date.getDate() + x);
[date] = date.toISOString().split('T');
let [test] = test_names[canvasNode.height - y];
let {data: pixel} = canvasNode.getContext('2d').getImageData(x, y, 1, 1);
2022-01-07 11:59:07 +00:00
2022-01-06 21:35:02 +00:00
updateInfo(date, test, pixel);
})
}
2022-01-06 21:35:02 +00:00
function updateInfo(date, test, pixel) {
infoNode.innerText = `${date}, ${test}`;
infoNode.style.background = pixel[0] > 0 ? '#F00' : (pixel[3] > 0 ? '#006400' : '#000');
}
2022-01-06 21:35:02 +00:00
function hideLoader() {
loadingNode.style.display = 'none';
}
2022-01-07 09:26:17 +00:00
function showFailMessage() {
failMessageNode.style.display = 'block';
}
</script>
</body>
</html>