Skip to content

Commit b2089c2

Browse files
committed
Errors switched to using org-specific clickhouses
1 parent 2174f56 commit b2089c2

File tree

3 files changed

+30
-17
lines changed
  • apps/webapp/app

3 files changed

+30
-17
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors.$fingerprint/route.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ import {
2727
import { type NextRunList } from "~/presenters/v3/NextRunListPresenter.server";
2828
import { $replica } from "~/db.server";
2929
import {
30+
clickhouseFactory,
3031
getDefaultClickhouseClient,
3132
getDefaultLogsClickhouseClient,
3233
} from "~/services/clickhouse/clickhouseFactory.server";
33-
34-
const clickhouseClient = getDefaultClickhouseClient();
35-
const logsClickhouseClient = getDefaultLogsClickhouseClient();
3634
import { NavBar, PageTitle } from "~/components/primitives/PageHeader";
3735
import { PageBody } from "~/components/layout/AppLayout";
3836
import {
@@ -169,6 +167,11 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
169167
let occurrenceCountAtIgnoreTime: number | undefined;
170168

171169
if (submission.value.totalOccurrences) {
170+
const clickhouseClient = await clickhouseFactory.getClickhouseForOrganization(
171+
environment.organizationId,
172+
"query"
173+
);
174+
172175
const qb = clickhouseClient.errors.listQueryBuilder();
173176
qb.where("organization_id = {organizationId: String}", {
174177
organizationId: project.organizationId,
@@ -242,7 +245,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
242245
const directionRaw = url.searchParams.get("direction") ?? undefined;
243246
const direction = directionRaw ? DirectionSchema.parse(directionRaw) : undefined;
244247

245-
const presenter = new ErrorGroupPresenter($replica, logsClickhouseClient, clickhouseClient);
248+
const clickhouseClient = await clickhouseFactory.getClickhouseForOrganization(
249+
environment.organizationId,
250+
"query"
251+
);
252+
253+
const presenter = new ErrorGroupPresenter($replica, clickhouseClient, clickhouseClient);
246254

247255
const detailPromise = presenter
248256
.call(project.organizationId, environment.id, {

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.errors._index/route.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
123123
const plan = await getCurrentPlan(project.organizationId);
124124
const retentionLimitDays = plan?.v3Subscription?.plan?.limits.logRetentionDays.number ?? 30;
125125

126-
const logsClickhouse = await clickhouseFactory.getClickhouseForOrganization(project.organizationId, "logs");
127-
const presenter = new ErrorsListPresenter($replica, logsClickhouse);
126+
const queryClickhouse = await clickhouseFactory.getClickhouseForOrganization(
127+
project.organizationId,
128+
"query"
129+
);
130+
const presenter = new ErrorsListPresenter($replica, queryClickhouse);
128131

129132
const listPromise = presenter
130133
.call(project.organizationId, environment.id, {

apps/webapp/app/v3/services/alerts/errorAlertEvaluator.server.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
} from "@trigger.dev/database";
88
import { $replica, prisma } from "~/db.server";
99
import { ErrorAlertConfig } from "~/models/projectAlert.server";
10-
import { getDefaultClickhouseClient } from "~/services/clickhouse/clickhouseFactory.server";
11-
12-
const clickhouseClient = getDefaultClickhouseClient();
10+
import { clickhouseFactory } from "~/services/clickhouse/clickhouseFactory.server";
1311
import { logger } from "~/services/logger.server";
1412
import { alertsWorker } from "~/v3/alertsWorker.server";
1513

@@ -47,8 +45,7 @@ const DEFAULT_INTERVAL_MS = 300_000;
4745
export class ErrorAlertEvaluator {
4846
constructor(
4947
protected readonly _prisma: PrismaClientOrTransaction = prisma,
50-
protected readonly _replica: PrismaClientOrTransaction = $replica,
51-
protected readonly _clickhouse: ClickHouse = clickhouseClient
48+
protected readonly _replica: PrismaClientOrTransaction = $replica
5249
) {}
5350

5451
async evaluate(projectId: string, scheduledAt: number): Promise<void> {
@@ -247,10 +244,7 @@ export class ErrorAlertEvaluator {
247244
}
248245
}
249246

250-
if (
251-
state.ignoredUntilTotalOccurrences != null &&
252-
state.ignoredAtOccurrenceCount != null
253-
) {
247+
if (state.ignoredUntilTotalOccurrences != null && state.ignoredAtOccurrenceCount != null) {
254248
const occurrencesSinceIgnored =
255249
context.totalOccurrenceCount - Number(state.ignoredAtOccurrenceCount);
256250
if (occurrencesSinceIgnored >= state.ignoredUntilTotalOccurrences) {
@@ -337,7 +331,11 @@ export class ErrorAlertEvaluator {
337331
envIds: string[],
338332
scheduledAt: number
339333
): Promise<ActiveErrorsSinceQueryResult[]> {
340-
const qb = this._clickhouse.errors.activeErrorsSinceQueryBuilder();
334+
const queryClickhouse = await clickhouseFactory.getClickhouseForOrganization(
335+
organizationId,
336+
"query"
337+
);
338+
const qb = queryClickhouse.errors.activeErrorsSinceQueryBuilder();
341339
qb.where("organization_id = {organizationId: String}", { organizationId });
342340
qb.where("project_id = {projectId: String}", { projectId });
343341
qb.where("environment_id IN {envIds: Array(String)}", { envIds });
@@ -391,7 +389,11 @@ export class ErrorAlertEvaluator {
391389
occurrences_since: number;
392390
}>
393391
> {
394-
const qb = this._clickhouse.errors.occurrenceCountsSinceQueryBuilder();
392+
const queryClickhouse = await clickhouseFactory.getClickhouseForOrganization(
393+
organizationId,
394+
"query"
395+
);
396+
const qb = queryClickhouse.errors.occurrenceCountsSinceQueryBuilder();
395397
qb.where("organization_id = {organizationId: String}", { organizationId });
396398
qb.where("project_id = {projectId: String}", { projectId });
397399
qb.where("environment_id IN {envIds: Array(String)}", { envIds });

0 commit comments

Comments
 (0)