-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch.compat.js
154 lines (147 loc) · 4.65 KB
/
ch.compat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const axios = require('axios');
const fs = require('fs');
const {exec} = require('child_process')
const composeYaml = `version: '2.1'
services:
clickhouse-seed:
image: clickhouse/clickhouse-server:__CH_VER__
container_name: clickhouse-seed
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8123 || exit 1
interval: 2s
retries: 5
start_period: 2s
timeout: 10s
qryn:
image: qxip/qryn:__QRYN_VER__
container_name: loki
ports:
- "127.0.0.1:3100:3100"
environment:
- CLICKHOUSE_SERVER=clickhouse-seed
- DEBUG=true
depends_on:
clickhouse-seed:
condition: service_healthy
`
const imageVer = async (name, size, verlen) => {
let versions = {}
await Promise.all(new Array(10).fill(0).map(async (v, pg) => {
let tags;
try {
tags = await axios.get(
`https://registry.hub.docker.com/v2/repositories/${name}/tags/?page_size=1000&page=${pg + 1}`
)
} catch (e) {
return
}
const verRe = new Array(verlen).fill('\\d+').join('\\.')
tags.data.results
.filter(t => t.name.match(new RegExp(`^${verRe}$`)))
.forEach((v) => {
versions[v.name.match(new RegExp(`^${verRe}`))[0]] = true
})
}))
versions = Object.keys(versions)
versions.sort((a,b) => {
const _a = a.split('.').map(v => parseInt(v))
const _b = b.split('.').map(v => parseInt(v))
return _b[0] - _a[0] || _b[1] - _a[1]
})
versions = versions.slice(0, size)
return versions
}
const execAsync = async (cmd, env, logfile) => {
env = env || process.env
let child
await new Promise((f, r) => {
child = exec(cmd, { env }, (error, stdout, stderr) => {
if (logfile) {
fs.writeFileSync(`${logfile}.stdout.log`, stdout)
fs.writeFileSync(`${logfile}.stderr.log`, stderr)
}
if (child.exitCode!== 0) {
return r(new Error(`${cmd} exited with code ${child.exitCode}`))
}
f();
})
})
}
const restoreState = (qrynVersions, chVersions) => {
if (fs.existsSync('ch.compat.state.json')) {
const contents = fs.readFileSync('ch.compat.state.json')
const res = JSON.parse(new TextDecoder().decode(contents))
while (res.length < (chVersions + 1)) {
res.push(new Array(qrynVersions + 1).fill('0'))
}
for (let i = 0; i < res.length; i++) {
while (res[i].length < (qrynVersions + 1)) {
res[i].push('0')
}
}
return res
}
return new Array(chVersions+1)
.fill(0)
.map(() => new Array(qrynVersions+1).fill('0'))
}
const saveState = (table) => {
fs.writeFileSync('ch.compat.state.json', new TextEncoder().encode(JSON.stringify(table)))
}
(async () => {
let qrynVersions = parseInt(process.env.QRYN_VERSIONS_LEN) || 5
let chVersions = parseInt(process.env.CH_VERSIONS_LEN) || 15
const {markdownTable} = await import('markdown-table')
const chVer = await imageVer('clickhouse/clickhouse-server', chVersions, 2)
const qrynVer = await imageVer('qxip/qryn', qrynVersions, 3)
console.log(`CH versions: ${chVer.join(', ')}`)
console.log(`QRYN versions: ${qrynVer.join(', ')}`)
const table = restoreState(qrynVersions, chVersions)
table[0][0] = 'CH \\ qryn'
for (const [i, _chVer] of chVer.entries()) {
table[i+1][0] = `${_chVer}`
for (const [j, _qrynVer] of qrynVer.entries()) {
table[0][j+1] = `${_qrynVer}`
if (table[i+1][j+1] !== '0') {
continue
}
await execAsync(`mkdir -p logs/${_chVer}/${_qrynVer}`)
try {
fs.writeFileSync('docker-compose.yml', composeYaml
.replace('__CH_VER__', _chVer)
.replace('__QRYN_VER__', _qrynVer))
await execAsync('docker-compose up -d')
await new Promise((f) => setTimeout(f, 10000))
await execAsync('npm test', {
...process.env,
INTEGRATION_E2E: 1,
CLOKI_EXT_URL: '127.0.0.1:3100'
}, `logs/${_chVer}/${_qrynVer}/jest`)
table[i+1][j+1] = 'OK'
} catch (e){
console.log(`TEST FAILED: CH:${_chVer} Q:${_qrynVer}`)
console.log(e)
table[i+1][j+1] = 'X'
} finally {
let i = 0
while (true) {
try {
await execAsync(`docker logs loki`, null, `logs/${_chVer}/${_qrynVer}/qryn`)
await execAsync('docker-compose down')
break
} catch (e) {
if (i < 5) {
i++
await new Promise((f) => setTimeout(f, 2000))
} else {
throw e
}
}
}
saveState(table)
}
}
try { await execAsync(`docker rmi clickhouse/clickhouse-server:${_chVer}`)} catch (e) {}
}
console.log(markdownTable(table))
})()