From 598cd09d03427a84efc7caf9bcc76ff9b9986584 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Tue, 24 May 2022 11:51:36 +0300 Subject: [PATCH] Improve ClickHouse error logging (#55) --- .../operations/providers/clickhouse-client.ts | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/services/api/src/modules/operations/providers/clickhouse-client.ts b/packages/services/api/src/modules/operations/providers/clickhouse-client.ts index b7b74ccce..41284cf6f 100644 --- a/packages/services/api/src/modules/operations/providers/clickhouse-client.ts +++ b/packages/services/api/src/modules/operations/providers/clickhouse-client.ts @@ -15,11 +15,7 @@ export interface QueryResponse { }; } -export type RowOf> = T extends QueryResponse< - infer R -> - ? R - : never; +export type RowOf> = T extends QueryResponse ? R : never; const agentConfig: Agent.HttpOptions = { // Keep sockets around in a pool to be used by other requests in the future @@ -68,11 +64,9 @@ export class ClickHouse { op: queryId, }); const startedAt = Date.now(); - const endpoint = `${this.config.protocol ?? 'https'}://${ - this.config.host - }:${this.config.port}`; + const endpoint = `${this.config.protocol ?? 'https'}://${this.config.host}:${this.config.port}`; - this.logger.debug(`Execution ClickHouse Query: %s`, query); + this.logger.debug(`Executing ClickHouse Query: %s`, query); const response = await this.httpClient .post>( @@ -99,7 +93,7 @@ export class ClickHouse { request: timeout, }, retry: { - calculateDelay: (info) => { + calculateDelay: info => { if (info.attemptCount >= 6) { // After 5 retries, stop. return 0; @@ -107,6 +101,8 @@ export class ClickHouse { const delayBy = info.attemptCount * 250; + this.logger.error(`Failed to run ClickHouse query, error is: `, info.error); + this.logger.debug( `Retry (delay=%s, attempt=%s, reason=%s, queryId=%s)`, delayBy, @@ -139,13 +135,7 @@ export class ClickHouse { return response; } - translateWindow({ - value, - unit, - }: { - value: number; - unit: 'd' | 'h' | 'm'; - }): string { + translateWindow({ value, unit }: { value: number; unit: 'd' | 'h' | 'm' }): string { const unitMap = { d: 'DAY', h: 'HOUR',