Skip to content

Commit 7c59347

Browse files
committed
Merge remote-tracking branch 'origin/main' into preview-branches-docs
2 parents 9eee02a + ff157e5 commit 7c59347

File tree

31 files changed

+342
-121
lines changed

31 files changed

+342
-121
lines changed

.changeset/fuzzy-snakes-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/core": patch
3+
---
4+
5+
Add supervisor http client option to disable debug logs

apps/supervisor/src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const Env = z.object({
8787

8888
// Debug
8989
DEBUG: BoolEnv.default(false),
90+
SEND_RUN_DEBUG_LOGS: BoolEnv.default(false),
9091
});
9192

9293
export const env = Env.parse(stdEnv);

apps/supervisor/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ManagedSupervisor {
130130
maxConsumerCount: env.TRIGGER_DEQUEUE_MAX_CONSUMER_COUNT,
131131
runNotificationsEnabled: env.TRIGGER_WORKLOAD_API_ENABLED,
132132
heartbeatIntervalSeconds: env.TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS,
133+
sendRunDebugLogs: env.SEND_RUN_DEBUG_LOGS,
133134
preDequeue: async () => {
134135
if (!env.RESOURCE_MONITOR_ENABLED) {
135136
return {};

apps/supervisor/src/workloadServer/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { HttpServer, type CheckpointClient } from "@trigger.dev/core/v3/serverOnly";
2525
import { type IncomingMessage } from "node:http";
2626
import { register } from "../metrics.js";
27+
import { env } from "../env.js";
2728

2829
// Use the official export when upgrading to [email protected]
2930
interface DefaultEventsMap {
@@ -374,6 +375,10 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
374375
handler: async ({ req, reply, params, body }) => {
375376
reply.empty(204);
376377

378+
if (!env.SEND_RUN_DEBUG_LOGS) {
379+
return;
380+
}
381+
377382
await this.workerClient.sendDebugLog(
378383
params.runFriendlyId,
379384
body,

apps/webapp/app/components/environments/EnvironmentLabel.tsx

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from "~/assets/icons/EnvironmentIcons";
77
import type { RuntimeEnvironment } from "~/models/runtimeEnvironment.server";
88
import { cn } from "~/utils/cn";
9+
import { SimpleTooltip } from "~/components/primitives/Tooltip";
10+
import { useEffect, useRef, useState } from "react";
911

1012
type Environment = Pick<RuntimeEnvironment, "type"> & { branchName?: string | null };
1113

@@ -56,7 +58,10 @@ export function EnvironmentCombo({
5658
}) {
5759
return (
5860
<span className={cn("flex items-center gap-1.5 text-sm text-text-bright", className)}>
59-
<EnvironmentIcon environment={environment} className={cn("size-4.5", iconClassName)} />
61+
<EnvironmentIcon
62+
environment={environment}
63+
className={cn("size-4.5 shrink-0", iconClassName)}
64+
/>
6065
<EnvironmentLabel environment={environment} />
6166
</span>
6267
);
@@ -69,11 +74,55 @@ export function EnvironmentLabel({
6974
environment: Environment;
7075
className?: string;
7176
}) {
72-
return (
73-
<span className={cn(environmentTextClassName(environment), className)}>
74-
{environment.branchName ? environment.branchName : environmentFullTitle(environment)}
77+
const spanRef = useRef<HTMLSpanElement>(null);
78+
const [isTruncated, setIsTruncated] = useState(false);
79+
const text = environment.branchName ? environment.branchName : environmentFullTitle(environment);
80+
81+
useEffect(() => {
82+
const checkTruncation = () => {
83+
if (spanRef.current) {
84+
const isTruncated = spanRef.current.scrollWidth > spanRef.current.clientWidth;
85+
setIsTruncated(isTruncated);
86+
}
87+
};
88+
89+
checkTruncation();
90+
// Add resize observer to recheck on window resize
91+
const resizeObserver = new ResizeObserver(checkTruncation);
92+
if (spanRef.current) {
93+
resizeObserver.observe(spanRef.current);
94+
}
95+
96+
return () => resizeObserver.disconnect();
97+
}, [text]);
98+
99+
const content = (
100+
<span
101+
ref={spanRef}
102+
className={cn("truncate text-left", environmentTextClassName(environment), className)}
103+
>
104+
{text}
75105
</span>
76106
);
107+
108+
if (isTruncated) {
109+
return (
110+
<SimpleTooltip
111+
asChild
112+
button={content}
113+
content={
114+
<span ref={spanRef} className={cn("text-left", environmentTextClassName(environment))}>
115+
{text}
116+
</span>
117+
}
118+
side="right"
119+
variant="dark"
120+
sideOffset={34}
121+
/>
122+
);
123+
}
124+
125+
return content;
77126
}
78127

79128
export function environmentTitle(environment: Environment, username?: string) {

apps/webapp/app/components/primitives/Tooltip.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function SimpleTooltip({
6262
className,
6363
buttonClassName,
6464
asChild = false,
65+
sideOffset,
6566
}: {
6667
button: React.ReactNode;
6768
content: React.ReactNode;
@@ -72,6 +73,7 @@ function SimpleTooltip({
7273
className?: string;
7374
buttonClassName?: string;
7475
asChild?: boolean;
76+
sideOffset?: number;
7577
}) {
7678
return (
7779
<TooltipProvider disableHoverableContent={disableHoverableContent}>
@@ -82,6 +84,7 @@ function SimpleTooltip({
8284
<TooltipContent
8385
side={side}
8486
hidden={hidden}
87+
sideOffset={sideOffset}
8588
className={cn("text-xs", className)}
8689
variant={variant}
8790
>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export class ScheduleListPresenter extends BasePresenter {
6969
type: true,
7070
slug: true,
7171
branchName: true,
72+
archivedAt: true,
7273
orgMember: {
7374
select: {
7475
user: {

apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.$slug.import.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ export async function action({ params, request }: ActionFunctionArgs) {
4747
})),
4848
});
4949

50+
if (environment.parentEnvironmentId && body.parentVariables) {
51+
const parentResult = await repository.create(environment.project.id, {
52+
override: typeof body.override === "boolean" ? body.override : false,
53+
environmentIds: [environment.parentEnvironmentId],
54+
variables: Object.entries(body.parentVariables).map(([key, value]) => ({
55+
key,
56+
value,
57+
})),
58+
});
59+
60+
let childFailure = !result.success ? result : undefined;
61+
let parentFailure = !parentResult.success ? parentResult : undefined;
62+
63+
if (result.success || parentResult.success) {
64+
return json({ success: true });
65+
} else {
66+
return json(
67+
{
68+
error: childFailure?.error || parentFailure?.error || "Unknown error",
69+
variableErrors: childFailure?.variableErrors || parentFailure?.variableErrors,
70+
},
71+
{ status: 400 }
72+
);
73+
}
74+
}
75+
5076
if (result.success) {
5177
return json({ success: true });
5278
} else {

apps/webapp/app/routes/api.v1.waitpoints.tokens.$waitpointFriendlyId.callback.$hash.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
4343
environment: {
4444
select: {
4545
apiKey: true,
46+
parentEnvironment: {
47+
select: {
48+
apiKey: true,
49+
},
50+
},
4651
},
4752
},
4853
},
@@ -52,7 +57,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
5257
return json({ error: "Waitpoint not found" }, { status: 404 });
5358
}
5459

55-
if (!verifyHttpCallbackHash(waitpoint.id, hash, waitpoint.environment.apiKey)) {
60+
if (
61+
!verifyHttpCallbackHash(
62+
waitpoint.id,
63+
hash,
64+
waitpoint.environment.parentEnvironment?.apiKey ?? waitpoint.environment.apiKey
65+
)
66+
) {
5667
return json({ error: "Invalid URL, hash doesn't match" }, { status: 401 });
5768
}
5869

apps/webapp/app/routes/engine.v1.dev.runs.$runFriendlyId.logs.debug.ts

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,69 @@ import { logger } from "~/services/logger.server";
1111
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
1212
import { recordRunDebugLog } from "~/v3/eventRepository.server";
1313

14-
const { action } = createActionApiRoute(
15-
{
16-
params: z.object({
17-
runFriendlyId: z.string(),
18-
}),
19-
body: WorkerApiDebugLogBody,
20-
method: "POST",
21-
},
22-
async ({
23-
authentication,
24-
body,
25-
params,
26-
}): Promise<TypedResponse<WorkerApiRunAttemptStartResponseBody>> => {
27-
const { runFriendlyId } = params;
14+
// const { action } = createActionApiRoute(
15+
// {
16+
// params: z.object({
17+
// runFriendlyId: z.string(),
18+
// }),
19+
// body: WorkerApiDebugLogBody,
20+
// method: "POST",
21+
// },
22+
// async ({
23+
// authentication,
24+
// body,
25+
// params,
26+
// }): Promise<TypedResponse<WorkerApiRunAttemptStartResponseBody>> => {
27+
// const { runFriendlyId } = params;
2828

29-
try {
30-
const run = await prisma.taskRun.findFirst({
31-
where: {
32-
friendlyId: params.runFriendlyId,
33-
runtimeEnvironmentId: authentication.environment.id,
34-
},
35-
});
29+
// try {
30+
// const run = await prisma.taskRun.findFirst({
31+
// where: {
32+
// friendlyId: params.runFriendlyId,
33+
// runtimeEnvironmentId: authentication.environment.id,
34+
// },
35+
// });
3636

37-
if (!run) {
38-
throw new Response("You don't have permissions for this run", { status: 401 });
39-
}
37+
// if (!run) {
38+
// throw new Response("You don't have permissions for this run", { status: 401 });
39+
// }
4040

41-
const eventResult = await recordRunDebugLog(
42-
RunId.fromFriendlyId(runFriendlyId),
43-
body.message,
44-
{
45-
attributes: {
46-
properties: body.properties,
47-
},
48-
startTime: body.time,
49-
}
50-
);
41+
// const eventResult = await recordRunDebugLog(
42+
// RunId.fromFriendlyId(runFriendlyId),
43+
// body.message,
44+
// {
45+
// attributes: {
46+
// properties: body.properties,
47+
// },
48+
// startTime: body.time,
49+
// }
50+
// );
5151

52-
if (eventResult.success) {
53-
return new Response(null, { status: 204 });
54-
}
52+
// if (eventResult.success) {
53+
// return new Response(null, { status: 204 });
54+
// }
5555

56-
switch (eventResult.code) {
57-
case "FAILED_TO_RECORD_EVENT":
58-
return new Response(null, { status: 400 }); // send a 400 to prevent retries
59-
case "RUN_NOT_FOUND":
60-
return new Response(null, { status: 404 });
61-
default:
62-
return assertExhaustive(eventResult.code);
63-
}
64-
} catch (error) {
65-
logger.error("Failed to record dev log", {
66-
environmentId: authentication.environment.id,
67-
error,
68-
});
69-
throw error;
70-
}
71-
}
72-
);
56+
// switch (eventResult.code) {
57+
// case "FAILED_TO_RECORD_EVENT":
58+
// return new Response(null, { status: 400 }); // send a 400 to prevent retries
59+
// case "RUN_NOT_FOUND":
60+
// return new Response(null, { status: 404 });
61+
// default:
62+
// return assertExhaustive(eventResult.code);
63+
// }
64+
// } catch (error) {
65+
// logger.error("Failed to record dev log", {
66+
// environmentId: authentication.environment.id,
67+
// error,
68+
// });
69+
// throw error;
70+
// }
71+
// }
72+
// );
7373

74-
export { action };
74+
// export { action };
75+
76+
// Create a generic JSON action in remix
77+
export function action() {
78+
return new Response(null, { status: 204 });
79+
}

apps/webapp/app/routes/healthcheck.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LoaderFunction } from "@remix-run/node";
33

44
export const loader: LoaderFunction = async ({ request }) => {
55
try {
6-
await prisma.user.count();
6+
await prisma.$queryRaw`SELECT 1`;
77
return new Response("OK");
88
} catch (error: unknown) {
99
console.log("healthcheck ❌", { error });

apps/webapp/app/routes/metrics.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
1313
}
1414
}
1515

16-
const prismaMetrics = await prisma.$metrics.prometheus();
16+
// We need to remove empty lines from the prisma metrics, grafana doesn't like them
17+
const prismaMetrics = (await prisma.$metrics.prometheus()).replace(/^\s*[\r\n]/gm, "");
1718
const coreMetrics = await metricsRegister.metrics();
1819

19-
return new Response(coreMetrics + prismaMetrics, {
20+
// Order matters, core metrics end with `# EOF`, prisma metrics don't
21+
const metrics = prismaMetrics + coreMetrics;
22+
23+
return new Response(metrics, {
2024
headers: {
2125
"Content-Type": metricsRegister.contentType,
2226
},

0 commit comments

Comments
 (0)