()
| 2250 | * failed queries (it can embed row predicates) and keep only the exception. |
| 2251 | */ |
| 2252 | async function getClickhouseLogs(): Promise<JSONObject> { |
| 2253 | const result: JSONObject = { |
| 2254 | connected: false, |
| 2255 | note: "Recent ClickHouse errors and (when enabled) server log lines. For the full container log use `kubectl logs` / `docker logs` on the ClickHouse pod.", |
| 2256 | errors: [], |
| 2257 | recentLogEntries: [], |
| 2258 | failedQueries: [], |
| 2259 | crashes: [], |
| 2260 | }; |
| 2261 | |
| 2262 | try { |
| 2263 | const client: ReturnType<typeof ClickhouseAppInstance.getDataSource> = |
| 2264 | ClickhouseAppInstance.getDataSource(); |
| 2265 | |
| 2266 | if (!client) { |
| 2267 | return result; |
| 2268 | } |
| 2269 | |
| 2270 | result["connected"] = true; |
| 2271 | |
| 2272 | // system.errors — always available; aggregated error counters. |
| 2273 | try { |
| 2274 | const errorsResult: ClickhouseJsonResult = (await ( |
| 2275 | await client.query({ |
| 2276 | query: |
| 2277 | "SELECT name, code, value AS count, toString(last_error_time) AS last_error_time, substring(last_error_message, 1, 1000) AS last_error_message FROM system.errors WHERE value > 0 ORDER BY last_error_time DESC LIMIT 100" + |
| 2278 | CH_DIAG_QUERY_SETTINGS, |
| 2279 | format: "JSON", |
| 2280 | }) |
| 2281 | ).json()) as ClickhouseJsonResult; |
| 2282 | |
| 2283 | result["errors"] = (errorsResult.data || []).map( |
| 2284 | (row: JSONObject): JSONObject => { |
| 2285 | return { |
| 2286 | name: String(row["name"]), |
| 2287 | code: toNumberOrNull(row["code"]), |
| 2288 | count: toNumberOrNull(row["count"]), |
| 2289 | lastErrorTime: toIsoOrNull(row["last_error_time"]), |
| 2290 | lastErrorMessage: row["last_error_message"] |
| 2291 | ? scrubSecretsFromText(String(row["last_error_message"])) |
| 2292 | : null, |
| 2293 | }; |
| 2294 | }, |
| 2295 | ); |
| 2296 | } catch (err) { |
| 2297 | logger.debug("AdminHealth: system.errors unavailable"); |
| 2298 | logger.debug(err); |
| 2299 | } |
| 2300 | |
| 2301 | // system.text_log — recent server log lines (Warning and above). |
| 2302 | try { |
| 2303 | const textLogResult: ClickhouseJsonResult = (await ( |
| 2304 | await client.query({ |
| 2305 | query: |
| 2306 | "SELECT toString(event_time) AS event_time, level, logger_name, substring(message, 1, 1000) AS message FROM system.text_log WHERE level IN ('Fatal','Critical','Error','Warning') ORDER BY event_time DESC LIMIT 200" + |
| 2307 | CH_DIAG_QUERY_SETTINGS, |
| 2308 | format: "JSON", |
| 2309 | }) |
no test coverage detected