Skip to content

Commit 3cbbece

Browse files
authored
Run completed at fix and engine API rate limit whitelist (#1899)
* Use completedAt instead of updatedAt * Disable verbose SSE logs * Engine rate limiter: whitelist engine worker-actions * Show the compute column in the runs table * The compute column should be invocation + compute cost
1 parent 79d6044 commit 3cbbece

7 files changed

+17
-12
lines changed

apps/webapp/app/components/run/RunTimeline.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function buildTimelineItems(run: TimelineSpanRun): TimelineItem[] {
248248
items.push({
249249
type: "line",
250250
id: "executing",
251-
title: formatDuration(run.executedAt, run.updatedAt),
251+
title: formatDuration(run.executedAt, run.completedAt ?? run.updatedAt),
252252
state,
253253
shouldRender: true,
254254
variant: "normal",
@@ -271,7 +271,7 @@ function buildTimelineItems(run: TimelineSpanRun): TimelineItem[] {
271271
items.push({
272272
type: "line",
273273
id: "legacy-executing",
274-
title: formatDuration(run.startedAt, run.updatedAt),
274+
title: formatDuration(run.startedAt, run.completedAt ?? run.updatedAt),
275275
state,
276276
shouldRender: true,
277277
variant: "normal",
@@ -296,7 +296,7 @@ function buildTimelineItems(run: TimelineSpanRun): TimelineItem[] {
296296
type: "event",
297297
id: "finished",
298298
title: "Finished",
299-
date: run.updatedAt,
299+
date: run.completedAt ?? run.updatedAt,
300300
previousDate: run.executedAt ?? run.startedAt ?? undefined,
301301
state,
302302
shouldRender: true,

apps/webapp/app/components/runs/v3/TaskRunsTable.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ export function TaskRunsTable({
7373
allowSelection = false,
7474
variant = "dimmed",
7575
}: RunsTableProps) {
76-
const user = useUser();
7776
const organization = useOrganization();
7877
const project = useProject();
7978
const environment = useEnvironment();
8079
const checkboxes = useRef<(HTMLInputElement | null)[]>([]);
8180
const { selectedItems, has, hasAll, select, deselect, toggle } = useSelectedItems(allowSelection);
8281
const { isManagedCloud } = useFeatures();
8382

84-
const showCompute = user.admin && isManagedCloud;
83+
const showCompute = isManagedCloud;
8584

8685
const navigateCheckboxes = useCallback(
8786
(event: React.KeyboardEvent<HTMLInputElement>, index: number) => {
@@ -371,7 +370,9 @@ export function TaskRunsTable({
371370
</TableCell>
372371
{showCompute && (
373372
<TableCell to={path} className="tabular-nums">
374-
{run.costInCents > 0 ? formatCurrencyAccurate(run.costInCents / 100) : "–"}
373+
{run.costInCents > 0
374+
? formatCurrencyAccurate((run.costInCents + run.baseCostInCents) / 100)
375+
: "–"}
375376
</TableCell>
376377
)}
377378
<TableCell to={path}>

apps/webapp/app/presenters/v3/RunListPresenter.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export class RunListPresenter extends BasePresenter {
209209
lockedAt: Date | null;
210210
delayUntil: Date | null;
211211
updatedAt: Date;
212+
completedAt: Date | null;
212213
isTest: boolean;
213214
spanId: string;
214215
idempotencyKey: string | null;
@@ -238,6 +239,7 @@ export class RunListPresenter extends BasePresenter {
238239
tr."delayUntil" AS "delayUntil",
239240
tr."lockedAt" AS "lockedAt",
240241
tr."updatedAt" AS "updatedAt",
242+
tr."completedAt" AS "completedAt",
241243
tr."isTest" AS "isTest",
242244
tr."spanId" AS "spanId",
243245
tr."idempotencyKey" AS "idempotencyKey",
@@ -383,7 +385,9 @@ WHERE
383385
startedAt: startedAt ? startedAt.toISOString() : undefined,
384386
delayUntil: run.delayUntil ? run.delayUntil.toISOString() : undefined,
385387
hasFinished,
386-
finishedAt: hasFinished ? run.updatedAt.toISOString() : undefined,
388+
finishedAt: hasFinished
389+
? run.completedAt?.toISOString() ?? run.updatedAt.toISOString()
390+
: undefined,
387391
isTest: run.isTest,
388392
status: run.status,
389393
version: run.version,

apps/webapp/app/routes/engine.v1.dev.presence.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createSSELoader } from "~/utils/sse";
88
export const loader = createSSELoader({
99
timeout: env.DEV_PRESENCE_SSE_TIMEOUT,
1010
interval: env.DEV_PRESENCE_TTL_MS * 0.8,
11-
debug: true,
11+
debug: false,
1212
handler: async ({ id, controller, debug, request }) => {
1313
const authentication = await authenticateApiRequestWithFailure(request);
1414

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.dev.presence.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createSSELoader, type SendFunction } from "~/utils/sse";
99
export const loader = createSSELoader({
1010
timeout: env.DEV_PRESENCE_SSE_TIMEOUT,
1111
interval: env.DEV_PRESENCE_POLL_MS,
12-
debug: true,
12+
debug: false,
1313
handler: async ({ id, controller, debug, request, params }) => {
1414
const userId = await requireUserId(request);
1515
const { organizationSlug, projectParam } = ProjectParamSchema.parse(params);

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues.stream.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createSSELoader } from "~/utils/sse";
88
export const loader = createSSELoader({
99
timeout: env.QUEUE_SSE_AUTORELOAD_TIMEOUT_MS,
1010
interval: env.QUEUE_SSE_AUTORELOAD_INTERVAL_MS,
11-
debug: true,
11+
debug: false,
1212
handler: async ({ request, params }) => {
1313
const userId = await requireUserId(request);
1414
const { projectParam, envParam } = EnvironmentParamSchema.parse(params);

apps/webapp/app/services/engineRateLimit.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const engineRateLimiter = authorizationRateLimitMiddleware({
2424
stale: 60_000 * 20, // Date is stale after 20 minutes
2525
},
2626
pathMatchers: [/^\/engine/],
27-
// Allow /api/v1/tasks/:id/callback/:secret
28-
pathWhiteList: [],
27+
// Regex allow any path starting with /engine/v1/worker-actions/
28+
pathWhiteList: [/^\/engine\/v1\/worker-actions\/.*/],
2929
log: {
3030
rejections: env.RUN_ENGINE_RATE_LIMIT_REJECTION_LOGS_ENABLED === "1",
3131
requests: env.RUN_ENGINE_RATE_LIMIT_REQUEST_LOGS_ENABLED === "1",

0 commit comments

Comments
 (0)