Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: add conditionally clickhouse options

Carl-Gerhard Lindesvärd8b31e4cfba18
diff --git a/packages/db/src/clickhouse/client.ts b/packages/db/src/clickhouse/client.ts
index a4d048c3f..50cfbb177 100644
--- a/packages/db/src/clickhouse/client.ts
+++ b/packages/db/src/clickhouse/client.ts
@@ -12,6 +12,7 @@ export { createClient };
const logger = createLogger({ name: 'clickhouse' });
import type { Logger } from '@clickhouse/client';
+import { getSafeJson } from '@openpanel/json';
// All three LogParams types are exported by the client
interface LogParams {
@@ -83,6 +84,22 @@ export function getReplicatedTableName(tableName: string): string {
return tableName;
}
+function getClickhouseSettings(): ClickHouseSettings {
+ const additionalSettings =
+ getSafeJson<ClickHouseSettings>(process.env.CLICKHOUSE_SETTINGS || '{}') ||
+ {};
+
+ return {
+ date_time_input_format: 'best_effort',
+ ...(!process.env.CLICKHOUSE_SETTINGS_REMOVE_CONVERT_ANY_JOIN
+ ? {
+ query_plan_convert_any_join_to_semi_or_anti_join: 0,
+ }
+ : {}),
+ ...additionalSettings,
+ };
+}
+
export const CLICKHOUSE_OPTIONS: NodeClickHouseClientConfigOptions = {
max_open_connections: 30,
request_timeout: 300000,
@@ -93,16 +110,15 @@ export const CLICKHOUSE_OPTIONS: NodeClickHouseClientConfigOptions = {
compression: {
request: true,
},
- clickhouse_settings: {
- date_time_input_format: 'best_effort',
- query_plan_convert_any_join_to_semi_or_anti_join: 0,
- },
+ clickhouse_settings: getClickhouseSettings(),
log: {
LoggerClass: CustomLogger,
level: ClickHouseLogLevel.DEBUG,
},
};
+logger.info('Clickhouse options', CLICKHOUSE_OPTIONS);
+
export const originalCh = createClient({
url: process.env.CLICKHOUSE_URL,
...CLICKHOUSE_OPTIONS,