Skip to content

Commit 28c0bef

Browse files
authored
Merge branch 'main' into docs/puppeteer
2 parents 25255a1 + 79624c1 commit 28c0bef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4866
-137
lines changed

.changeset/config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": "@changesets/cli/changelog",
3+
"changelog": [
4+
"@remix-run/changelog-github",
5+
{
6+
"repo": "triggerdotdev/trigger.dev"
7+
}
8+
],
49
"commit": false,
510
"fixed": [
611
[

.changeset/real-bags-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
Puppeteer extension: set the PUPPETEER_EXECUTABLE_PATH env var

.changeset/short-tomatoes-beam.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 otel propagation headers "below" the API fetch span, to attribute the child runs with the proper parent span ID

.changeset/yellow-knives-attack.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/pr_checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: 🤖 PR Checks
33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
6+
paths-ignore:
7+
- "docs/**"
68

79
concurrency:
810
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

apps/kubernetes-provider/src/index.ts

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import * as k8s from "@kubernetes/client-node";
2+
import {
3+
EnvironmentType,
4+
MachinePreset,
5+
PostStartCauses,
6+
PreStopCauses,
7+
} from "@trigger.dev/core/v3";
28
import {
39
ProviderShell,
10+
SimpleLogger,
411
TaskOperations,
512
TaskOperationsCreateOptions,
613
TaskOperationsIndexOptions,
714
TaskOperationsPrePullDeploymentOptions,
815
TaskOperationsRestoreOptions,
916
} from "@trigger.dev/core/v3/apps";
10-
import { SimpleLogger } from "@trigger.dev/core/v3/apps";
11-
import {
12-
MachinePreset,
13-
PostStartCauses,
14-
PreStopCauses,
15-
EnvironmentType,
16-
} from "@trigger.dev/core/v3";
17-
import { TaskMonitor } from "./taskMonitor";
1817
import { PodCleaner } from "./podCleaner";
18+
import { TaskMonitor } from "./taskMonitor";
1919
import { UptimeHeartbeat } from "./uptimeHeartbeat";
2020

2121
const RUNTIME_ENV = process.env.KUBERNETES_PORT ? "kubernetes" : "local";
2222
const NODE_NAME = process.env.NODE_NAME || "local";
2323
const OTEL_EXPORTER_OTLP_ENDPOINT =
2424
process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318";
25+
const COORDINATOR_HOST = process.env.COORDINATOR_HOST ?? undefined;
26+
const COORDINATOR_PORT = process.env.COORDINATOR_PORT ?? undefined;
27+
const KUBERNETES_NAMESPACE = process.env.KUBERNETES_NAMESPACE ?? "default";
2528

2629
const POD_CLEANER_INTERVAL_SECONDS = Number(process.env.POD_CLEANER_INTERVAL_SECONDS || "300");
2730

@@ -45,19 +48,22 @@ type ResourceQuantities = {
4548
};
4649

4750
class KubernetesTaskOperations implements TaskOperations {
48-
#namespace: Namespace;
51+
#namespace: Namespace = {
52+
metadata: {
53+
name: "default",
54+
},
55+
};
56+
4957
#k8sApi: {
5058
core: k8s.CoreV1Api;
5159
batch: k8s.BatchV1Api;
5260
apps: k8s.AppsV1Api;
5361
};
5462

55-
constructor(namespace = "default") {
56-
this.#namespace = {
57-
metadata: {
58-
name: namespace,
59-
},
60-
};
63+
constructor(opts: { namespace?: string } = {}) {
64+
if (opts.namespace) {
65+
this.#namespace.metadata.name = opts.namespace;
66+
}
6167

6268
this.#k8sApi = this.#createK8sApi();
6369
}
@@ -229,16 +235,7 @@ class KubernetesTaskOperations implements TaskOperations {
229235
imagePullPolicy: "IfNotPresent",
230236
command: ["/bin/sh", "-c"],
231237
args: ["printenv COORDINATOR_HOST | tee /etc/taskinfo/coordinator-host"],
232-
env: [
233-
{
234-
name: "COORDINATOR_HOST",
235-
valueFrom: {
236-
fieldRef: {
237-
fieldPath: "status.hostIP",
238-
},
239-
},
240-
},
241-
],
238+
env: this.#coordinatorEnvVars,
242239
volumeMounts: [
243240
{
244241
name: "taskinfo",
@@ -409,6 +406,41 @@ class KubernetesTaskOperations implements TaskOperations {
409406
};
410407
}
411408

409+
get #coordinatorHostEnvVar(): k8s.V1EnvVar {
410+
return COORDINATOR_HOST
411+
? {
412+
name: "COORDINATOR_HOST",
413+
value: COORDINATOR_HOST,
414+
}
415+
: {
416+
name: "COORDINATOR_HOST",
417+
valueFrom: {
418+
fieldRef: {
419+
fieldPath: "status.hostIP",
420+
},
421+
},
422+
};
423+
}
424+
425+
get #coordinatorPortEnvVar(): k8s.V1EnvVar | undefined {
426+
if (COORDINATOR_PORT) {
427+
return {
428+
name: "COORDINATOR_PORT",
429+
value: COORDINATOR_PORT,
430+
};
431+
}
432+
}
433+
434+
get #coordinatorEnvVars(): k8s.V1EnvVar[] {
435+
const envVars = [this.#coordinatorHostEnvVar];
436+
437+
if (this.#coordinatorPortEnvVar) {
438+
envVars.push(this.#coordinatorPortEnvVar);
439+
}
440+
441+
return envVars;
442+
}
443+
412444
#getSharedEnv(envId: string): k8s.V1EnvVar[] {
413445
return [
414446
{
@@ -435,14 +467,6 @@ class KubernetesTaskOperations implements TaskOperations {
435467
},
436468
},
437469
},
438-
{
439-
name: "COORDINATOR_HOST",
440-
valueFrom: {
441-
fieldRef: {
442-
fieldPath: "status.hostIP",
443-
},
444-
},
445-
},
446470
{
447471
name: "MACHINE_NAME",
448472
valueFrom: {
@@ -451,6 +475,7 @@ class KubernetesTaskOperations implements TaskOperations {
451475
},
452476
},
453477
},
478+
...this.#coordinatorEnvVars,
454479
];
455480
}
456481

@@ -623,7 +648,9 @@ class KubernetesTaskOperations implements TaskOperations {
623648
}
624649

625650
const provider = new ProviderShell({
626-
tasks: new KubernetesTaskOperations(),
651+
tasks: new KubernetesTaskOperations({
652+
namespace: KUBERNETES_NAMESPACE,
653+
}),
627654
type: "kubernetes",
628655
});
629656

@@ -663,7 +690,7 @@ taskMonitor.start();
663690

664691
const podCleaner = new PodCleaner({
665692
runtimeEnv: RUNTIME_ENV,
666-
namespace: "default",
693+
namespace: KUBERNETES_NAMESPACE,
667694
intervalInSeconds: POD_CLEANER_INTERVAL_SECONDS,
668695
});
669696

@@ -672,7 +699,7 @@ podCleaner.start();
672699
if (UPTIME_HEARTBEAT_URL) {
673700
const uptimeHeartbeat = new UptimeHeartbeat({
674701
runtimeEnv: RUNTIME_ENV,
675-
namespace: "default",
702+
namespace: KUBERNETES_NAMESPACE,
676703
intervalInSeconds: UPTIME_INTERVAL_SECONDS,
677704
pingUrl: UPTIME_HEARTBEAT_URL,
678705
maxPendingRuns: UPTIME_MAX_PENDING_RUNS,

apps/webapp/app/models/orgIntegration.server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ export class OrgIntegrationRepository {
6969
return new WebClient(
7070
options?.forceBotToken
7171
? secret.botAccessToken
72-
: secret.userAccessToken ?? secret.botAccessToken
72+
: secret.userAccessToken ?? secret.botAccessToken,
73+
{
74+
retryConfig: {
75+
retries: 2,
76+
randomize: true,
77+
maxTimeout: 5000,
78+
maxRetryTime: 10000,
79+
},
80+
}
7381
) as AuthenticatedClientForIntegration<TService>;
7482
}
7583
default: {

apps/webapp/app/routes/api.v1.tasks.$taskId.batch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
8888
const service = new BatchTriggerTaskService();
8989

9090
const traceContext =
91-
traceparent ?? isFromWorker // If the request is from a worker, we should pass the trace context
91+
traceparent && isFromWorker // If the request is from a worker, we should pass the trace context
9292
? { traceparent, tracestate }
9393
: undefined;
9494

apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
8080

8181
try {
8282
const traceContext =
83-
traceparent ?? isFromWorker /// If the request is from a worker, we should pass the trace context
83+
traceparent && isFromWorker /// If the request is from a worker, we should pass the trace context
8484
? { traceparent, tracestate }
8585
: undefined;
8686

apps/webapp/app/v3/eventRepository.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@ export class EventRepository {
835835
options: TraceEventOptions & { incomplete?: boolean },
836836
callback: (
837837
e: EventBuilder,
838-
traceContext: Record<string, string | undefined>
838+
traceContext: Record<string, string | undefined>,
839+
traceparent?: { traceId: string; spanId: string }
839840
) => Promise<TResult>
840841
): Promise<TResult> {
841842
const propagatedContext = extractContextFromCarrier(options.context ?? {});
@@ -892,7 +893,7 @@ export class EventRepository {
892893
},
893894
};
894895

895-
const result = await callback(eventBuilder, traceContext);
896+
const result = await callback(eventBuilder, traceContext, propagatedContext?.traceparent);
896897

897898
const duration = process.hrtime.bigint() - start;
898899

0 commit comments

Comments
 (0)