Skip to content

Commit aacd24d

Browse files
authored
refactor: decouple clickhouse client into browser.ts and node.ts (#1119)
- Fixed the issue where the @clickhouse/client module wasn’t bundled. It’s also cleaner to keep non-shared methods decoupled between node and browser environments - Bumped the default request timeout to 1hr Ref: HDX-2294
1 parent 91a8509 commit aacd24d

File tree

21 files changed

+277
-211
lines changed

21 files changed

+277
-211
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/api": patch
4+
"@hyperdx/app": patch
5+
---
6+
7+
refactor: decouple clickhouse client into browser.ts and node.ts

.changeset/popular-geese-sin.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/api": patch
4+
"@hyperdx/app": patch
5+
---
6+
7+
bump: default request_timeout to 1hr

packages/api/src/clickhouse/__tests__/renderChartConfig.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// TODO: we might want to move this test file to common-utils package
22

3-
import { ChSql, ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse';
3+
import { ChSql } from '@hyperdx/common-utils/dist/clickhouse';
4+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
45
import { getMetadata } from '@hyperdx/common-utils/dist/metadata';
56
import { renderChartConfig } from '@hyperdx/common-utils/dist/renderChartConfig';
67
import {

packages/api/src/fixtures.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getJSNativeCreateClient } from '@hyperdx/common-utils/dist/clickhouse';
1+
import { createNativeClient } from '@hyperdx/common-utils/dist/clickhouse/node';
22
import {
33
DisplayType,
44
SavedChartConfig,
@@ -38,8 +38,7 @@ let clickhouseClient: any;
3838

3939
const getClickhouseClient = async () => {
4040
if (!clickhouseClient) {
41-
const createClient = await getJSNativeCreateClient();
42-
clickhouseClient = createClient({
41+
clickhouseClient = createNativeClient({
4342
url: config.CLICKHOUSE_HOST,
4443
username: config.CLICKHOUSE_USER,
4544
password: config.CLICKHOUSE_PASSWORD,

packages/api/src/routers/external-api/__tests__/charts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse';
1+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
22
import { SourceKind } from '@hyperdx/common-utils/dist/types';
33
import { MetricsDataType } from '@hyperdx/common-utils/dist/types';
44
import { ObjectId } from 'mongodb';

packages/api/src/routers/external-api/v2/charts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse';
1+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
22
import { getMetadata } from '@hyperdx/common-utils/dist/metadata';
33
import {
44
ChartConfigWithOptDateRange,

packages/api/src/tasks/__tests__/checkAlerts.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as clickhouse from '@hyperdx/common-utils/dist/clickhouse';
1+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
22
import mongoose from 'mongoose';
33
import ms from 'ms';
44

@@ -725,7 +725,7 @@ describe('checkAlerts', () => {
725725
savedSearch,
726726
};
727727

728-
const clickhouseClient = new clickhouse.ClickhouseClient({
728+
const clickhouseClient = new ClickhouseClient({
729729
host: connection.host,
730730
username: connection.username,
731731
password: connection.password,
@@ -965,7 +965,7 @@ describe('checkAlerts', () => {
965965
dashboard,
966966
};
967967

968-
const clickhouseClient = new clickhouse.ClickhouseClient({
968+
const clickhouseClient = new ClickhouseClient({
969969
host: connection.host,
970970
username: connection.username,
971971
password: connection.password,
@@ -1195,7 +1195,7 @@ describe('checkAlerts', () => {
11951195
dashboard,
11961196
};
11971197

1198-
const clickhouseClient = new clickhouse.ClickhouseClient({
1198+
const clickhouseClient = new ClickhouseClient({
11991199
host: connection.host,
12001200
username: connection.username,
12011201
password: connection.password,
@@ -1404,7 +1404,7 @@ describe('checkAlerts', () => {
14041404
dashboard,
14051405
};
14061406

1407-
const clickhouseClient = new clickhouse.ClickhouseClient({
1407+
const clickhouseClient = new ClickhouseClient({
14081408
host: connection.host,
14091409
username: connection.username,
14101410
password: connection.password,

packages/api/src/tasks/__tests__/singleInvocationAlert.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as clickhouse from '@hyperdx/common-utils/dist/clickhouse';
1+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
22
import { createServer } from 'http';
33
import mongoose from 'mongoose';
44
import ms from 'ms';
@@ -188,7 +188,7 @@ describe('Single Invocation Alert Test', () => {
188188
taskType: AlertTaskType.SAVED_SEARCH,
189189
savedSearch,
190190
};
191-
const clickhouseClient = new clickhouse.ClickhouseClient({
191+
const clickhouseClient = new ClickhouseClient({
192192
host: connection.host,
193193
username: connection.username,
194194
password: connection.password,
@@ -404,7 +404,7 @@ describe('Single Invocation Alert Test', () => {
404404
dashboard,
405405
};
406406

407-
const clickhouseClient = new clickhouse.ClickhouseClient({
407+
const clickhouseClient = new ClickhouseClient({
408408
host: connection.host,
409409
username: connection.username,
410410
password: connection.password,

packages/api/src/tasks/checkAlerts.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// --------------------------------------------------------
44
import PQueue from '@esm2cjs/p-queue';
55
import * as clickhouse from '@hyperdx/common-utils/dist/clickhouse';
6+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
67
import { getMetadata, Metadata } from '@hyperdx/common-utils/dist/metadata';
78
import {
89
ChartConfigWithOptDateRange,
@@ -67,7 +68,7 @@ const fireChannelEvent = async ({
6768
alert: IAlert;
6869
alertProvider: AlertProvider;
6970
attributes: Record<string, string>; // TODO: support other types than string
70-
clickhouseClient: clickhouse.ClickhouseClient;
71+
clickhouseClient: ClickhouseClient;
7172
dashboard?: IDashboard | null;
7273
endTime: Date;
7374
group?: string;
@@ -138,7 +139,7 @@ const fireChannelEvent = async ({
138139
export const processAlert = async (
139140
now: Date,
140141
details: AlertDetails,
141-
clickhouseClient: clickhouse.ClickhouseClient,
142+
clickhouseClient: ClickhouseClient,
142143
connectionId: string,
143144
alertProvider: AlertProvider,
144145
) => {
@@ -397,7 +398,7 @@ export default class CheckAlertTask implements HdxTask<CheckAlertsTaskArgs> {
397398
});
398399
}
399400

400-
const clickhouseClient = new clickhouse.ClickhouseClient({
401+
const clickhouseClient = new ClickhouseClient({
401402
host: conn.host,
402403
username: conn.username,
403404
password: conn.password,

packages/api/src/tasks/template.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as clickhouse from '@hyperdx/common-utils/dist/clickhouse';
2+
import { ClickhouseClient } from '@hyperdx/common-utils/dist/clickhouse/node';
23
import { Metadata } from '@hyperdx/common-utils/dist/metadata';
34
import { renderChartConfig } from '@hyperdx/common-utils/dist/renderChartConfig';
45
import {
@@ -357,7 +358,7 @@ export const renderAlertTemplate = async ({
357358
team,
358359
}: {
359360
alertProvider: AlertProvider;
360-
clickhouseClient: clickhouse.ClickhouseClient;
361+
clickhouseClient: ClickhouseClient;
361362
metadata: Metadata;
362363
template?: string | null;
363364
title: string;

0 commit comments

Comments
 (0)