Skip to content

Commit fd0b825

Browse files
authored
fix(deployment): adjust cpu limit/requests config for pods (#7931)
1 parent 574a5d8 commit fd0b825

8 files changed

Lines changed: 70 additions & 34 deletions

File tree

deployment/services/environment.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export function prepareEnvironment(input: {
5050
},
5151
envoy: {
5252
replicas: isProduction || isStaging ? 3 : 1,
53-
cpuLimit: isProduction ? '1500m' : '120m',
54-
memoryLimit: isProduction ? '2Gi' : '200Mi',
53+
cpuLimit: isProduction || isStaging ? '1500m' : '120m',
54+
memoryLimit: isProduction || isStaging ? '2Gi' : '200Mi',
5555
timeouts: {
5656
idleTimeout: 905,
5757
},
@@ -61,26 +61,30 @@ export function prepareEnvironment(input: {
6161
},
6262
usageService: {
6363
replicas: isProduction || isStaging ? 6 : 1,
64-
cpuLimit: isProduction ? '1000m' : '100m',
64+
cpuMin: isProduction || isStaging ? '200m' : '100m',
65+
cpuMax: isProduction || isStaging ? '1000m' : '100m',
6566
maxReplicas: isProduction || isStaging ? 6 : 1,
6667
cpuAverageToScale: 60,
6768
},
6869
usageIngestorService: {
6970
replicas: isProduction || isStaging ? 6 : 1,
70-
cpuLimit: isProduction ? '1000m' : '100m',
71+
cpuMax: isProduction || isStaging ? '1000m' : '100m',
72+
cpuMin: isProduction || isStaging ? '300m' : '100m',
7173
maxReplicas: isProduction || isStaging ? /* numberOfPartitions */ 16 : 2,
7274
cpuAverageToScale: 60,
7375
},
7476
redis: {
75-
memoryLimit: isProduction ? '4Gi' : '100Mi',
76-
cpuLimit: isProduction ? '1000m' : '50m',
77+
memoryLimit: isProduction || isStaging ? '4Gi' : '100Mi',
78+
cpuMax: isProduction || isStaging ? '1000m' : '100m',
79+
cpuMin: isProduction || isStaging ? '100m' : '50m',
7780
},
7881
internalObservability: {
7982
cpuLimit: isProduction ? '512m' : '150m',
8083
memoryLimit: isProduction ? '1000Mi' : '300Mi',
8184
},
8285
tracingCollector: {
83-
cpuLimit: isProduction || isStaging ? '1000m' : '100m',
86+
cpuMax: isProduction || isStaging ? '1000m' : '300m',
87+
cpuMin: '100m',
8488
memoryLimit: isProduction || isStaging ? '1000Mi' : '512Mi',
8589
maxReplicas: isProduction || isStaging ? 3 : 1,
8690
replicas: 1,

deployment/services/otel-collector.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ export function deployOTELCollector(args: {
4040
pdb: true,
4141
availabilityOnEveryNode: true,
4242
port: 4318,
43-
memoryLimit: args.environment.podsConfig.tracingCollector.memoryLimit,
43+
memory: {
44+
limit: args.environment.podsConfig.tracingCollector.memoryLimit,
45+
},
46+
cpu: {
47+
limit: args.environment.podsConfig.tracingCollector.cpuMax,
48+
requests: args.environment.podsConfig.tracingCollector.cpuMin,
49+
},
4450
autoScaling: {
4551
maxReplicas: args.environment.podsConfig.tracingCollector.maxReplicas,
46-
cpu: {
47-
limit: args.environment.podsConfig.tracingCollector.cpuLimit,
48-
cpuAverageToScale: 80,
49-
},
52+
cpuAverageToScale: 80,
5053
},
5154
},
5255
[args.clickhouse.deployment, args.clickhouse.service, args.dbMigrations],

deployment/services/redis.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export function deployRedis(input: { environment: Environment }) {
2121
}).deploy({
2222
limits: {
2323
memory: input.environment.podsConfig.redis.memoryLimit,
24-
cpu: input.environment.podsConfig.redis.cpuLimit,
24+
cpu: input.environment.podsConfig.redis.cpuMax,
25+
},
26+
requests: {
27+
cpu: input.environment.podsConfig.redis.cpuMin,
2528
},
2629
});
2730

deployment/services/schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export function deploySchema({
5353
startupProbe: '/_health',
5454
exposesMetrics: true,
5555
replicas: environment.podsConfig.general.replicas,
56-
memoryLimit: environment.podsConfig.schemaService.memoryLimit,
56+
memory: {
57+
limit: environment.podsConfig.schemaService.memoryLimit,
58+
},
5759
pdb: true,
5860
},
5961
[redis.deployment, redis.service],

deployment/services/usage-ingestor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ export function deployUsageIngestor({
6161
exposesMetrics: true,
6262
port: 4000,
6363
pdb: true,
64+
cpu: {
65+
limit: environment.podsConfig.usageIngestorService.cpuMax,
66+
requests: environment.podsConfig.usageIngestorService.cpuMin,
67+
},
6468
autoScaling: {
65-
cpu: {
66-
cpuAverageToScale: environment.podsConfig.usageIngestorService.cpuAverageToScale,
67-
limit: environment.podsConfig.usageIngestorService.cpuLimit,
68-
},
69+
cpuAverageToScale: environment.podsConfig.usageIngestorService.cpuAverageToScale,
6970
maxReplicas: environment.podsConfig.usageIngestorService.maxReplicas,
7071
},
7172
},

deployment/services/usage.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ export function deployUsage({
8181
exposesMetrics: true,
8282
port: 4000,
8383
pdb: true,
84+
cpu: {
85+
limit: environment.podsConfig.usageService.cpuMax,
86+
requests: environment.podsConfig.usageService.cpuMin,
87+
},
8488
autoScaling: {
85-
cpu: {
86-
cpuAverageToScale: environment.podsConfig.usageService.cpuAverageToScale,
87-
limit: environment.podsConfig.usageService.cpuLimit,
88-
},
89+
cpuAverageToScale: environment.podsConfig.usageService.cpuAverageToScale,
8990
maxReplicas: environment.podsConfig.usageService.maxReplicas,
9091
},
9192
},

deployment/utils/redis.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ export class Redis {
1818
},
1919
) {}
2020

21-
deploy(input: { limits: { memory: string; cpu: string } }) {
21+
deploy(input: { limits: { memory: string; cpu: string }; requests: { cpu: string } }) {
2222
const redisService = getLocalComposeConfig().service('redis');
2323
const name = 'redis-store';
2424
const limits: k8s.types.input.core.v1.ResourceRequirements['limits'] = {
2525
memory: input.limits.memory,
2626
cpu: input.limits.cpu,
2727
};
28+
const requests: k8s.types.input.core.v1.ResourceRequirements['requests'] = {
29+
cpu: input.requests.cpu,
30+
};
2831

2932
const env: k8s.types.input.core.v1.EnvVar[] = normalizeEnv(this.options.env ?? {}).concat([
3033
{
@@ -100,6 +103,7 @@ export class Redis {
100103
ports: [{ containerPort: REDIS_PORT, protocol: 'TCP' }],
101104
resources: {
102105
limits,
106+
requests,
103107
},
104108
livenessProbe: {
105109
initialDelaySeconds: 3,
@@ -139,6 +143,10 @@ export class Redis {
139143
cpu: '200m',
140144
memory: '200Mi',
141145
},
146+
requests: {
147+
cpu: '100m',
148+
memory: '100Mi',
149+
},
142150
},
143151
},
144152
],

deployment/utils/service-deployment.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ export class ServiceDeployment {
4646
livenessProbe?: string | ProbeConfig;
4747
readinessProbe?: string | ProbeConfig;
4848
startupProbe?: string | ProbeConfig;
49-
memoryLimit?: string;
49+
memory?: {
50+
limit?: string;
51+
requests?: string;
52+
};
53+
cpu?: {
54+
limit?: string;
55+
requests?: string;
56+
};
5057
volumes?: k8s.types.input.core.v1.Volume[];
5158
volumeMounts?: k8s.types.input.core.v1.VolumeMount[];
5259
/**
@@ -58,10 +65,7 @@ export class ServiceDeployment {
5865
autoScaling?: {
5966
minReplicas?: number;
6067
maxReplicas: number;
61-
cpu: {
62-
limit: string;
63-
cpuAverageToScale: number;
64-
};
68+
cpuAverageToScale: number;
6569
};
6670
availabilityOnEveryNode?: boolean;
6771
command?: pulumi.Input<pulumi.Input<string>[]>;
@@ -205,14 +209,23 @@ export class ServiceDeployment {
205209
});
206210
}
207211

208-
const resourcesLimits: Record<string, string> = {};
212+
const resourcesLimits: { cpu?: string; memory?: string } = {};
213+
const resourcesRequests: { cpu?: string; memory?: string } = {};
214+
215+
if (this.options?.cpu?.limit) {
216+
resourcesLimits.cpu = this.options?.cpu?.limit;
217+
}
218+
219+
if (this.options?.cpu?.requests) {
220+
resourcesRequests.cpu = this.options?.cpu?.requests;
221+
}
209222

210-
if (this.options?.autoScaling?.cpu.limit) {
211-
resourcesLimits.cpu = this.options.autoScaling.cpu.limit;
223+
if (this.options?.memory?.limit) {
224+
resourcesLimits.memory = this.options?.memory?.limit;
212225
}
213226

214-
if (this.options.memoryLimit) {
215-
resourcesLimits.memory = this.options.memoryLimit;
227+
if (this.options?.memory?.requests) {
228+
resourcesRequests.memory = this.options?.memory?.requests;
216229
}
217230

218231
const pb = new PodBuilder({
@@ -248,6 +261,7 @@ export class ServiceDeployment {
248261
image: this.options.image,
249262
resources: {
250263
limits: resourcesLimits,
264+
requests: resourcesRequests,
251265
},
252266
args: this.options.args,
253267
ports: {
@@ -342,7 +356,7 @@ export class ServiceDeployment {
342356
name: 'cpu',
343357
target: {
344358
type: 'Utilization',
345-
averageUtilization: this.options.autoScaling.cpu.cpuAverageToScale,
359+
averageUtilization: this.options.autoScaling.cpuAverageToScale,
346360
},
347361
},
348362
},

0 commit comments

Comments
 (0)