Skip to content

Commit c3d5469

Browse files
committed
fixed types
1 parent d2082f6 commit c3d5469

File tree

8 files changed

+96
-36
lines changed

8 files changed

+96
-36
lines changed

apps/webapp/scripts/profile-runs-replication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function loadConfig(options: any): Promise<HarnessConfig> {
3333
if (options.config) {
3434
console.log(`Loading config from: ${options.config}`);
3535
const configFile = await fs.readFile(options.config, "utf-8");
36-
const fileConfig = JSON.parse(configFile);
36+
const fileConfig = JSON.parse(configFile) as Partial<HarnessConfig>;
3737
config = { ...config, ...fileConfig };
3838
}
3939

apps/webapp/test/performance/clickhouse-mock.ts

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
import type { RawTaskRunPayloadV1, TaskRunV2 } from "@internal/clickhouse";
1+
import type { ClickHouse, TaskRunInsertArray, PayloadInsertArray } from "@internal/clickhouse";
2+
3+
// Minimal InsertResult type to avoid dependency on @clickhouse/client
4+
interface InsertResult {
5+
executed: boolean;
6+
query_id: string;
7+
summary?: {
8+
read_rows: string;
9+
read_bytes: string;
10+
written_rows: string;
11+
written_bytes: string;
12+
total_rows_to_read: string;
13+
result_rows: string;
14+
result_bytes: string;
15+
elapsed_ns: string;
16+
};
17+
response_headers: Record<string, string>;
18+
}
219

320
/**
421
* Mock ClickHouse client for CPU-only profiling.
@@ -12,30 +29,64 @@ export class MockClickHouse {
1229
constructor(private readonly insertDelayMs: number = 0) {}
1330

1431
taskRuns = {
15-
insert: async (
16-
runs: TaskRunV2[],
32+
insertCompactArrays: async (
33+
rows: TaskRunInsertArray[],
1734
options?: any
18-
): Promise<[Error | null, { rows: number } | null]> => {
35+
): Promise<[Error | null, InsertResult | null]> => {
1936
if (this.insertDelayMs > 0) {
2037
await new Promise((resolve) => setTimeout(resolve, this.insertDelayMs));
2138
}
2239

23-
this.insertCount += runs.length;
40+
this.insertCount += rows.length;
2441

25-
return [null, { rows: runs.length }];
42+
return [
43+
null,
44+
{
45+
executed: true,
46+
query_id: "mock",
47+
summary: {
48+
read_rows: "0",
49+
read_bytes: "0",
50+
written_rows: String(rows.length),
51+
written_bytes: "0",
52+
total_rows_to_read: "0",
53+
result_rows: "0",
54+
result_bytes: "0",
55+
elapsed_ns: "0",
56+
},
57+
response_headers: {},
58+
},
59+
];
2660
},
2761

28-
insertPayloads: async (
29-
payloads: RawTaskRunPayloadV1[],
62+
insertPayloadsCompactArrays: async (
63+
rows: PayloadInsertArray[],
3064
options?: any
31-
): Promise<[Error | null, { rows: number } | null]> => {
65+
): Promise<[Error | null, InsertResult | null]> => {
3266
if (this.insertDelayMs > 0) {
3367
await new Promise((resolve) => setTimeout(resolve, this.insertDelayMs));
3468
}
3569

36-
this.payloadInsertCount += payloads.length;
70+
this.payloadInsertCount += rows.length;
3771

38-
return [null, { rows: payloads.length }];
72+
return [
73+
null,
74+
{
75+
executed: true,
76+
query_id: "mock",
77+
summary: {
78+
read_rows: "0",
79+
read_bytes: "0",
80+
written_rows: String(rows.length),
81+
written_bytes: "0",
82+
total_rows_to_read: "0",
83+
result_rows: "0",
84+
result_bytes: "0",
85+
elapsed_ns: "0",
86+
},
87+
response_headers: {},
88+
},
89+
];
3990
},
4091
};
4192

@@ -51,3 +102,8 @@ export class MockClickHouse {
51102
this.payloadInsertCount = 0;
52103
}
53104
}
105+
106+
// Type assertion helper for use with RunsReplicationService
107+
export function asMockClickHouse(mock: MockClickHouse): Pick<ClickHouse, "taskRuns"> {
108+
return mock as unknown as Pick<ClickHouse, "taskRuns">;
109+
}

apps/webapp/test/performance/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RedisOptions } from "ioredis";
2-
import { RuntimeEnvironmentType } from "~/database-types";
2+
import type { RuntimeEnvironmentType } from "@trigger.dev/database";
33
import { config as loadEnv } from "dotenv";
44
import path from "path";
55

apps/webapp/test/performance/consumer-runner.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env tsx
22

3+
import type { ClickHouse } from "@internal/clickhouse";
34
import { RunsReplicationService } from "~/services/runsReplicationService.server";
4-
import { MockClickHouse } from "./clickhouse-mock";
5+
import { MockClickHouse, asMockClickHouse } from "./clickhouse-mock";
56
import type { ConsumerConfig } from "./config";
67
import fs from "fs";
78
import path from "path";
@@ -16,7 +17,7 @@ async function main() {
1617
}
1718

1819
// Parse configuration from environment variable
19-
const config: ConsumerConfig = JSON.parse(process.env.CONSUMER_CONFIG!);
20+
const config = JSON.parse(process.env.CONSUMER_CONFIG!) as ConsumerConfig;
2021

2122
// Create shutdown signal file path
2223
const shutdownFilePath = path.join(config.outputDir || "/tmp", ".shutdown-signal");
@@ -29,9 +30,9 @@ async function main() {
2930
});
3031

3132
// Create ClickHouse client (real or mocked)
32-
let clickhouse;
33+
let clickhouse: Pick<ClickHouse, "taskRuns">;
3334
if (config.useMockClickhouse) {
34-
clickhouse = new MockClickHouse(config.mockClickhouseDelay);
35+
clickhouse = asMockClickHouse(new MockClickHouse(config.mockClickhouseDelay));
3536
} else {
3637
// Use dynamic import to avoid module resolution issues with tsx
3738
const { ClickHouse } = await import("@internal/clickhouse");
@@ -47,7 +48,7 @@ async function main() {
4748

4849
// Create replication service
4950
const service = new RunsReplicationService({
50-
clickhouse,
51+
clickhouse: clickhouse as ClickHouse,
5152
pgConnectionUrl: config.pgConnectionUrl,
5253
serviceName: "runs-replication-profiling",
5354
slotName: config.slotName,
@@ -89,7 +90,8 @@ async function main() {
8990
// Send periodic metrics to parent (if IPC available)
9091
const metricsInterval = setInterval(() => {
9192
const memUsage = process.memoryUsage();
92-
const elu = performance.eventLoopUtilization();
93+
const { eventLoopUtilization } = require("perf_hooks").performance;
94+
const elu = eventLoopUtilization ? eventLoopUtilization() : { utilization: 0 };
9395

9496
if (hasIPC) {
9597
process.send!({

apps/webapp/test/performance/consumer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class ConsumerProcessManager {
5252
if (isProfiling && this.process.stdout) {
5353
this.process.stdout.on("data", (data: Buffer) => {
5454
const output = data.toString();
55-
process.stdout.write(data); // Still show output
55+
process.stdout.write(output); // Still show output
5656
if (output.includes("Consumer process ready")) {
5757
this.ready = true;
5858
console.log("Consumer process is ready (detected from stdout)");
@@ -62,7 +62,7 @@ export class ConsumerProcessManager {
6262

6363
if (isProfiling && this.process.stderr) {
6464
this.process.stderr.on("data", (data: Buffer) => {
65-
process.stderr.write(data); // Show stderr
65+
process.stderr.write(data.toString()); // Show stderr
6666
});
6767
}
6868

apps/webapp/test/performance/data-generator.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Prisma } from "@trigger.dev/database";
1+
import { Prisma, RuntimeEnvironmentType, TaskRunStatus } from "@trigger.dev/database";
22
import { nanoid } from "nanoid";
3-
import { RuntimeEnvironmentType, TaskRunStatus } from "~/database-types";
43
import superjson from "superjson";
54

65
export interface DataGeneratorOptions {
@@ -41,15 +40,15 @@ export class TaskRunDataGenerator {
4140

4241
constructor(private readonly options: DataGeneratorOptions) {}
4342

44-
generateBatch(count: number): Prisma.TaskRunCreateInput[] {
45-
const batch: Prisma.TaskRunCreateInput[] = [];
43+
generateBatch(count: number): Prisma.TaskRunCreateManyInput[] {
44+
const batch: Prisma.TaskRunCreateManyInput[] = [];
4645
for (let i = 0; i < count; i++) {
4746
batch.push(this.generateInsert());
4847
}
4948
return batch;
5049
}
5150

52-
generateInsert(): Prisma.TaskRunCreateInput {
51+
generateInsert(): Prisma.TaskRunCreateManyInput {
5352
this.counter++;
5453
const id = nanoid();
5554
const friendlyId = `run_${this.counter}_${nanoid(8)}`;
@@ -59,17 +58,19 @@ export class TaskRunDataGenerator {
5958
const workerQueue = this.workerQueues[Math.floor(Math.random() * this.workerQueues.length)];
6059

6160
const payload = this.generatePayload();
62-
const payloadType = this.options.includeComplexPayloads && Math.random() > 0.7
63-
? "application/super+json"
64-
: "application/json";
61+
const payloadType =
62+
this.options.includeComplexPayloads && Math.random() > 0.7
63+
? "application/super+json"
64+
: "application/json";
6565

6666
return {
6767
id,
6868
friendlyId,
6969
taskIdentifier,
70-
payload: payloadType === "application/super+json"
71-
? superjson.stringify(payload)
72-
: JSON.stringify(payload),
70+
payload:
71+
payloadType === "application/super+json"
72+
? superjson.stringify(payload)
73+
: JSON.stringify(payload),
7374
payloadType,
7475
traceId: nanoid(),
7576
spanId: nanoid(),

apps/webapp/test/performance/harness.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ export class RunsReplicationHarness {
267267
const cleanProfilingUrl = this.profilingDatabaseUrl.split("?")[0];
268268

269269
// Dump schema only (no data) from main database
270-
execSync(`pg_dump "${cleanBaseUrl}" --schema-only --no-owner --no-acl | psql "${cleanProfilingUrl}" > /dev/null 2>&1`, {
271-
shell: true,
272-
});
270+
execSync(
271+
`pg_dump "${cleanBaseUrl}" --schema-only --no-owner --no-acl | psql "${cleanProfilingUrl}" > /dev/null 2>&1`,
272+
{ shell: "/bin/bash" }
273+
);
273274

274275
console.log("✅ Schema copied successfully");
275276
} catch (error) {

apps/webapp/test/performance/producer-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function main() {
1111
}
1212

1313
// Parse configuration from environment variable
14-
const config: ProducerConfig = JSON.parse(process.env.PRODUCER_CONFIG!);
14+
const config = JSON.parse(process.env.PRODUCER_CONFIG!) as ProducerConfig;
1515

1616
console.log("Producer process starting with config:", {
1717
targetThroughput: config.targetThroughput,

0 commit comments

Comments
 (0)