Skip to content

Commit 338a442

Browse files
committed
disable resource monitor for now
1 parent 2234fb8 commit 338a442

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

apps/supervisor/src/env.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ const Env = z.object({
4949
KUBERNETES_IMAGE_PULL_SECRETS: z.string().optional(), // csv
5050

5151
// Used by the resource monitor
52-
OVERRIDE_CPU_TOTAL: z.coerce.number().optional(),
53-
OVERRIDE_MEMORY_TOTAL_GB: z.coerce.number().optional(),
52+
RESOURCE_MONITOR_ENABLED: BoolEnv.default(false),
53+
RESOURCE_MONITOR_OVERRIDE_CPU_TOTAL: z.coerce.number().optional(),
54+
RESOURCE_MONITOR_OVERRIDE_MEMORY_TOTAL_GB: z.coerce.number().optional(),
5455

5556
// Kubernetes specific settings
5657
KUBERNETES_FORCE_ENABLED: BoolEnv.default(false),

apps/supervisor/src/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type DequeuedMessage } from "@trigger.dev/core/v3";
99
import {
1010
DockerResourceMonitor,
1111
KubernetesResourceMonitor,
12+
NoopResourceMonitor,
1213
type ResourceMonitor,
1314
} from "./resourceMonitor.js";
1415
import { KubernetesWorkloadManager } from "./workloadManager/kubernetes.js";
@@ -69,6 +70,16 @@ class ManagedSupervisor {
6970
dockerAutoremove: env.RUNNER_DOCKER_AUTOREMOVE,
7071
} satisfies WorkloadManagerOptions;
7172

73+
this.resourceMonitor = env.RESOURCE_MONITOR_ENABLED
74+
? this.isKubernetes
75+
? new KubernetesResourceMonitor(createK8sApi(), env.TRIGGER_WORKER_INSTANCE_NAME)
76+
: new DockerResourceMonitor(new Docker())
77+
: new NoopResourceMonitor();
78+
79+
this.workloadManager = this.isKubernetes
80+
? new KubernetesWorkloadManager(workloadManagerOptions)
81+
: new DockerWorkloadManager(workloadManagerOptions);
82+
7283
if (this.isKubernetes) {
7384
if (env.POD_CLEANER_ENABLED) {
7485
this.logger.log("🧹 Pod cleaner enabled", {
@@ -99,15 +110,6 @@ class ManagedSupervisor {
99110
} else {
100111
this.logger.warn("Failed pod handler disabled");
101112
}
102-
103-
this.resourceMonitor = new KubernetesResourceMonitor(
104-
createK8sApi(),
105-
env.TRIGGER_WORKER_INSTANCE_NAME
106-
);
107-
this.workloadManager = new KubernetesWorkloadManager(workloadManagerOptions);
108-
} else {
109-
this.resourceMonitor = new DockerResourceMonitor(new Docker());
110-
this.workloadManager = new DockerWorkloadManager(workloadManagerOptions);
111113
}
112114

113115
this.workerSession = new SupervisorSession({
@@ -123,12 +125,17 @@ class ManagedSupervisor {
123125
runNotificationsEnabled: env.TRIGGER_WORKLOAD_API_ENABLED,
124126
heartbeatIntervalSeconds: env.TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS,
125127
preDequeue: async () => {
128+
if (!env.RESOURCE_MONITOR_ENABLED) {
129+
return {};
130+
}
131+
126132
if (this.isKubernetes) {
127133
// Not used in k8s for now
128134
return {};
129135
}
130136

131137
const resources = await this.resourceMonitor.getNodeResources();
138+
132139
return {
133140
maxResources: {
134141
cpu: resources.cpuAvailable,

apps/supervisor/src/resourceMonitor.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ export abstract class ResourceMonitor {
7070
}
7171

7272
protected applyOverrides(resources: NodeResources): NodeResources {
73-
if (!env.OVERRIDE_CPU_TOTAL && !env.OVERRIDE_MEMORY_TOTAL_GB) {
73+
if (
74+
!env.RESOURCE_MONITOR_OVERRIDE_CPU_TOTAL &&
75+
!env.RESOURCE_MONITOR_OVERRIDE_MEMORY_TOTAL_GB
76+
) {
7477
return resources;
7578
}
7679

7780
logger.debug("[ResourceMonitor] 🛡️ Applying resource overrides", {
78-
cpuTotal: env.OVERRIDE_CPU_TOTAL,
79-
memoryTotalGb: env.OVERRIDE_MEMORY_TOTAL_GB,
81+
cpuTotal: env.RESOURCE_MONITOR_OVERRIDE_CPU_TOTAL,
82+
memoryTotalGb: env.RESOURCE_MONITOR_OVERRIDE_MEMORY_TOTAL_GB,
8083
});
8184

82-
const cpuTotal = env.OVERRIDE_CPU_TOTAL ?? resources.cpuTotal;
83-
const memoryTotal = env.OVERRIDE_MEMORY_TOTAL_GB
84-
? this.gbToBytes(env.OVERRIDE_MEMORY_TOTAL_GB)
85+
const cpuTotal = env.RESOURCE_MONITOR_OVERRIDE_CPU_TOTAL ?? resources.cpuTotal;
86+
const memoryTotal = env.RESOURCE_MONITOR_OVERRIDE_MEMORY_TOTAL_GB
87+
? this.gbToBytes(env.RESOURCE_MONITOR_OVERRIDE_MEMORY_TOTAL_GB)
8588
: resources.memoryTotal;
8689

8790
const cpuDiff = cpuTotal - resources.cpuTotal;
@@ -212,6 +215,21 @@ export class KubernetesResourceMonitor extends ResourceMonitor {
212215
}
213216
}
214217

218+
export class NoopResourceMonitor extends ResourceMonitor {
219+
constructor() {
220+
super(NoopResourceParser);
221+
}
222+
223+
async getNodeResources(): Promise<NodeResources> {
224+
return {
225+
cpuTotal: 0,
226+
cpuAvailable: Infinity,
227+
memoryTotal: 0,
228+
memoryAvailable: Infinity,
229+
};
230+
}
231+
}
232+
215233
abstract class ResourceParser {
216234
abstract cpu(cpu: number | string): number;
217235
abstract memory(memory: number | string): number;
@@ -248,3 +266,13 @@ class KubernetesResourceParser extends ResourceParser {
248266
return parseInt(memory);
249267
}
250268
}
269+
270+
class NoopResourceParser extends ResourceParser {
271+
cpu(cpu: number): number {
272+
return cpu;
273+
}
274+
275+
memory(memory: number): number {
276+
return memory;
277+
}
278+
}

0 commit comments

Comments
 (0)