2022-12-28 19:22:54 +00:00
|
|
|
import * as k8s from '@pulumi/kubernetes';
|
2022-05-18 07:26:57 +00:00
|
|
|
import * as pulumi from '@pulumi/pulumi';
|
|
|
|
|
import { DeploymentEnvironment } from '../types';
|
2022-12-28 19:22:54 +00:00
|
|
|
import { isProduction } from '../utils/helpers';
|
|
|
|
|
import { serviceLocalEndpoint } from '../utils/local-endpoint';
|
|
|
|
|
import { ServiceDeployment } from '../utils/service-deployment';
|
|
|
|
|
import { DbMigrations } from './db-migrations';
|
2022-05-18 07:26:57 +00:00
|
|
|
import { Kafka } from './kafka';
|
|
|
|
|
import { RateLimitService } from './rate-limit';
|
2022-12-28 19:22:54 +00:00
|
|
|
import { Tokens } from './tokens';
|
2022-05-18 07:26:57 +00:00
|
|
|
|
|
|
|
|
const commonConfig = new pulumi.Config('common');
|
|
|
|
|
const commonEnv = commonConfig.requireObject<Record<string, string>>('env');
|
|
|
|
|
|
|
|
|
|
export type Usage = ReturnType<typeof deployUsage>;
|
|
|
|
|
|
|
|
|
|
export function deployUsage({
|
|
|
|
|
deploymentEnv,
|
|
|
|
|
tokens,
|
|
|
|
|
kafka,
|
|
|
|
|
dbMigrations,
|
|
|
|
|
rateLimit,
|
2022-12-20 14:34:46 +00:00
|
|
|
image,
|
|
|
|
|
release,
|
|
|
|
|
imagePullSecret,
|
2022-05-18 07:26:57 +00:00
|
|
|
}: {
|
2022-12-20 14:34:46 +00:00
|
|
|
image: string;
|
|
|
|
|
release: string;
|
2022-05-18 07:26:57 +00:00
|
|
|
deploymentEnv: DeploymentEnvironment;
|
|
|
|
|
tokens: Tokens;
|
|
|
|
|
kafka: Kafka;
|
|
|
|
|
dbMigrations: DbMigrations;
|
|
|
|
|
rateLimit: RateLimitService;
|
2022-12-20 14:34:46 +00:00
|
|
|
imagePullSecret: k8s.core.v1.Secret;
|
2022-05-18 07:26:57 +00:00
|
|
|
}) {
|
2023-02-02 18:35:59 +00:00
|
|
|
const replicas = isProduction(deploymentEnv) ? 2 : 1;
|
2022-05-19 10:18:36 +00:00
|
|
|
const cpuLimit = isProduction(deploymentEnv) ? '600m' : '300m';
|
2023-01-23 16:26:45 +00:00
|
|
|
const maxReplicas = isProduction(deploymentEnv) ? 6 : 2;
|
2022-12-22 12:00:10 +00:00
|
|
|
const kafkaBufferDynamic =
|
|
|
|
|
kafka.config.bufferDynamic === 'true' || kafka.config.bufferDynamic === '1' ? '1' : '0';
|
2022-05-19 10:18:36 +00:00
|
|
|
|
2022-12-20 14:34:46 +00:00
|
|
|
return new ServiceDeployment(
|
2022-05-18 07:26:57 +00:00
|
|
|
'usage-service',
|
|
|
|
|
{
|
2022-12-20 14:34:46 +00:00
|
|
|
image,
|
|
|
|
|
imagePullSecret,
|
2022-05-19 10:18:36 +00:00
|
|
|
replicas,
|
2022-05-18 07:26:57 +00:00
|
|
|
readinessProbe: '/_readiness',
|
|
|
|
|
livenessProbe: '/_health',
|
|
|
|
|
env: {
|
|
|
|
|
...deploymentEnv,
|
|
|
|
|
...commonEnv,
|
2022-12-22 12:00:10 +00:00
|
|
|
...kafka.connectionEnv,
|
2023-01-24 16:04:13 +00:00
|
|
|
SENTRY: commonEnv.SENTRY_ENABLED,
|
|
|
|
|
REQUEST_LOGGING: '0', // disabled
|
2022-05-18 07:26:57 +00:00
|
|
|
KAFKA_BROKER: kafka.config.endpoint,
|
|
|
|
|
KAFKA_BUFFER_SIZE: kafka.config.bufferSize,
|
|
|
|
|
KAFKA_BUFFER_INTERVAL: kafka.config.bufferInterval,
|
2022-10-04 12:30:21 +00:00
|
|
|
KAFKA_BUFFER_DYNAMIC: kafkaBufferDynamic,
|
2022-09-26 12:30:15 +00:00
|
|
|
KAFKA_TOPIC: kafka.config.topic,
|
2022-12-20 14:34:46 +00:00
|
|
|
RELEASE: release,
|
2022-05-18 07:26:57 +00:00
|
|
|
TOKENS_ENDPOINT: serviceLocalEndpoint(tokens.service),
|
|
|
|
|
RATE_LIMIT_ENDPOINT: serviceLocalEndpoint(rateLimit.service),
|
|
|
|
|
},
|
|
|
|
|
exposesMetrics: true,
|
|
|
|
|
port: 4000,
|
2022-11-18 09:15:14 +00:00
|
|
|
pdb: true,
|
2022-05-19 10:18:36 +00:00
|
|
|
autoScaling: {
|
|
|
|
|
cpu: {
|
|
|
|
|
cpuAverageToScale: 60,
|
|
|
|
|
limit: cpuLimit,
|
|
|
|
|
},
|
2022-12-28 20:38:03 +00:00
|
|
|
maxReplicas,
|
2022-05-19 10:18:36 +00:00
|
|
|
},
|
2022-05-18 07:26:57 +00:00
|
|
|
},
|
2022-12-22 12:00:10 +00:00
|
|
|
[
|
|
|
|
|
dbMigrations,
|
|
|
|
|
tokens.deployment,
|
|
|
|
|
tokens.service,
|
|
|
|
|
rateLimit.deployment,
|
|
|
|
|
rateLimit.service,
|
|
|
|
|
kafka.deployment,
|
|
|
|
|
kafka.service,
|
|
|
|
|
].filter(Boolean),
|
2022-05-18 07:26:57 +00:00
|
|
|
).deploy();
|
|
|
|
|
}
|