Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docker/docker-compose.end2end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ services:
ports:
- '6379:6379'

usage-ingestor:
environment:
# Wait for the async insert to flush before acking, so a reported operation is queryable in
# Insights immediately instead of racing ClickHouse's non-deterministic async-insert timer
# (the source of usage e2e flakiness). Prod keeps the default fire-and-forget behavior.
CLICKHOUSE_WAIT_FOR_ASYNC_INSERT: '1'

server:
environment:
SUPERTOKENS_RATE_LIMIT: '0'
Expand Down
4 changes: 2 additions & 2 deletions e2e/helpers/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@

return page.getByRole('link').filter({ hasText: operationName }).count();
},
{ timeout: 60_000, intervals: [2_000] },
{ timeout: 30_000, intervals: [2_000] },
)
.toBeGreaterThan(0);

Check failure on line 95 in e2e/helpers/usage.ts

View workflow job for this annotation

GitHub Actions / test / e2e

[chromium] › e2e/specs/usage.spec.ts:156:3 › usage reporting › usage report with missing and "unknown" client names should be visible in Insights

3) [chromium] › e2e/specs/usage.spec.ts:156:3 › usage reporting › usage report with missing and "unknown" client names should be visible in Insights Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBeGreaterThan(expected) Expected: > 0 Received: 0 Call Log: - Timeout 30000ms exceeded while waiting on the predicate at ../helpers/usage.ts:95 93 | { timeout: 30_000, intervals: [2_000] }, 94 | ) > 95 | .toBeGreaterThan(0); | ^ 96 | }, 97 | async expectInsightVersion(version) { 98 | await expect at Object.expectInsightOperation (/home/runner/work/console/console/e2e/helpers/usage.ts:95:10) at /home/runner/work/console/console/e2e/specs/usage.spec.ts:222:17
},
async expectInsightVersion(version) {
await expect
Expand All @@ -102,9 +102,9 @@

return page.getByText(version, { exact: true }).count();
},
{ timeout: 60_000, intervals: [2_000] },
{ timeout: 30_000, intervals: [2_000] },
)
.toBeGreaterThan(0);

Check failure on line 107 in e2e/helpers/usage.ts

View workflow job for this annotation

GitHub Actions / test / e2e

[chromium] › e2e/specs/usage.spec.ts:133:3 › usage reporting › usage report with missing client name should be visible in Insights

2) [chromium] › e2e/specs/usage.spec.ts:133:3 › usage reporting › usage report with missing client name should be visible in Insights Error: expect(received).toBeGreaterThan(expected) Expected: > 0 Received: 0 Call Log: - Timeout 30000ms exceeded while waiting on the predicate at ../helpers/usage.ts:107 105 | { timeout: 30_000, intervals: [2_000] }, 106 | ) > 107 | .toBeGreaterThan(0); | ^ 108 | }, 109 | }; 110 | } at Object.expectInsightVersion (/home/runner/work/console/console/e2e/helpers/usage.ts:107:10) at /home/runner/work/console/console/e2e/specs/usage.spec.ts:153:17
},
};
}
2 changes: 1 addition & 1 deletion e2e/specs/usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { UsageHelper } from '../helpers/usage';
// Each test waits on ClickHouse ingestion through several stacked polls (see helpers/usage.ts).
// Keep the timeout above the sum of those poll budgets so a slow-but-succeeding poll isn't cut
// off mid-wait by the per-test deadline.
test.describe.configure({ mode: 'serial', timeout: 180_000 });
test.describe.configure({ mode: 'serial', timeout: 120_000 });

type UsageReport = {
size: number;
Expand Down
13 changes: 11 additions & 2 deletions integration-tests/testkit/oidc-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export async function createOIDCIntegration(args: {

const rawBody = await result.json();

const body = z
const parsed = z
.object({
user: z.object({
id: z.string(),
Expand All @@ -311,7 +311,16 @@ export async function createOIDCIntegration(args: {
),
}),
})
.parse(rawBody);
.safeParse(rawBody);

if (!parsed.success) {
// SuperTokens answers 200 with a non-OK status (e.g. SIGN_IN_UP_NOT_ALLOWED) and no
// `user`. Surface the actual body so a flaky sign-in is diagnosable instead of a bare
// ZodError that hides why it failed.
throw new Error('Unexpected signinup response: ' + JSON.stringify(rawBody));
}

const body = parsed.data;
const cookies = setCookie.parse(result.headers.getSetCookie());
return {
accessToken: cookies.find(c => c.name === 'sAccessToken')?.value ?? '',
Expand Down
6 changes: 6 additions & 0 deletions packages/services/usage-ingestor/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ const ClickHouseModel = zod.object({
CLICKHOUSE_PASSWORD: zod.string(),
CLICKHOUSE_ASYNC_INSERT_BUSY_TIMEOUT_MS: emptyString(NumberFromString.optional()),
CLICKHOUSE_ASYNC_INSERT_MAX_DATA_SIZE: emptyString(NumberFromString.optional()),
// Whether ClickHouse waits for the async insert to flush before acking. Defaults to 0
// (fire-and-forget) for throughput; e2e sets it to 1 so reports are queryable immediately.
CLICKHOUSE_WAIT_FOR_ASYNC_INSERT: emptyString(
zod.union([zod.literal('0'), zod.literal('1')]).optional(),
),
});

const PrometheusModel = zod.object({
Expand Down Expand Up @@ -238,6 +243,7 @@ export const env = {
password: clickhouse.CLICKHOUSE_PASSWORD,
async_insert_busy_timeout_ms: clickhouse.CLICKHOUSE_ASYNC_INSERT_BUSY_TIMEOUT_MS ?? 30_000,
async_insert_max_data_size: clickhouse.CLICKHOUSE_ASYNC_INSERT_MAX_DATA_SIZE ?? 200_000_000,
wait_for_async_insert: clickhouse.CLICKHOUSE_WAIT_FOR_ASYNC_INSERT === '1' ? 1 : 0,
},
heartbeat: base.HEARTBEAT_ENDPOINT ? { endpoint: base.HEARTBEAT_ENDPOINT } : null,
sentry: sentry.SENTRY === '1' ? { dsn: sentry.SENTRY_DSN } : null,
Expand Down
3 changes: 2 additions & 1 deletion packages/services/usage-ingestor/src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ClickHouseConfig {
password: string;
async_insert_busy_timeout_ms: number;
async_insert_max_data_size: number;
wait_for_async_insert: number;
}

const operationsFields = operationsOrder.join(', ');
Expand Down Expand Up @@ -153,7 +154,7 @@ async function writeCsv(
searchParams: {
query,
async_insert: 1,
wait_for_async_insert: 0,
wait_for_async_insert: config.wait_for_async_insert,
async_insert_busy_timeout_ms: config.async_insert_busy_timeout_ms,
async_insert_max_data_size: config.async_insert_max_data_size,
},
Expand Down
Loading