console/deployment/services/usage.ts

88 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-05-18 07:26:57 +00:00
import * as pulumi from '@pulumi/pulumi';
2022-12-28 19:22:54 +00:00
import { serviceLocalEndpoint } from '../utils/local-endpoint';
import { ServiceDeployment } from '../utils/service-deployment';
import { DbMigrations } from './db-migrations';
2024-03-04 12:56:12 +00:00
import { Docker } from './docker';
import { Environment } from './environment';
2022-05-18 07:26:57 +00:00
import { Kafka } from './kafka';
import { RateLimitService } from './rate-limit';
2024-03-04 12:56:12 +00:00
import { Sentry } from './sentry';
2022-12-28 19:22:54 +00:00
import { Tokens } from './tokens';
2022-05-18 07:26:57 +00:00
export type Usage = ReturnType<typeof deployUsage>;
export function deployUsage({
2024-03-04 12:56:12 +00:00
environment,
2022-05-18 07:26:57 +00:00
tokens,
kafka,
dbMigrations,
rateLimit,
image,
2024-03-04 12:56:12 +00:00
docker,
sentry,
2022-05-18 07:26:57 +00:00
}: {
image: string;
2024-03-04 12:56:12 +00:00
environment: Environment;
2022-05-18 07:26:57 +00:00
tokens: Tokens;
kafka: Kafka;
dbMigrations: DbMigrations;
rateLimit: RateLimitService;
2024-03-04 12:56:12 +00:00
docker: Docker;
sentry: Sentry;
2022-05-18 07:26:57 +00:00
}) {
2024-03-04 12:56:12 +00:00
const replicas = environment.isProduction ? 3 : 1;
const cpuLimit = environment.isProduction ? '600m' : '300m';
const maxReplicas = environment.isProduction ? 6 : 2;
const kafkaBufferDynamic =
kafka.config.bufferDynamic === 'true' || kafka.config.bufferDynamic === '1' ? '1' : '0';
return new ServiceDeployment(
2022-05-18 07:26:57 +00:00
'usage-service',
{
image,
2024-03-04 12:56:12 +00:00
imagePullSecret: docker.secret,
replicas,
2022-05-18 07:26:57 +00:00
readinessProbe: '/_readiness',
livenessProbe: '/_health',
startupProbe: '/_health',
availabilityOnEveryNode: true,
2022-05-18 07:26:57 +00:00
env: {
2024-03-04 12:56:12 +00:00
...environment.envVars,
SENTRY: sentry.enabled ? '1' : '0',
REQUEST_LOGGING: '0',
2022-05-18 07:26:57 +00:00
KAFKA_BUFFER_SIZE: kafka.config.bufferSize,
2024-03-04 12:56:12 +00:00
KAFKA_SASL_MECHANISM: kafka.config.saslMechanism,
KAFKA_CONCURRENCY: kafka.config.concurrency,
2022-05-18 07:26:57 +00:00
KAFKA_BUFFER_INTERVAL: kafka.config.bufferInterval,
feat: clean app env (#422) * feat: document environment variables * more env documentation * wip * add noop for backend env * typo * feat: embed environment validation/parsing in built app * fix the sentry integration 😌 * feat: use env * feat: decode the usage service environment * feat: decode the webhooks service environment * feat: disallow process.env * feat: decode the tokens service environment * feat: decode the stripe-billing service environment * feat: decode server service environment * feat: decode schema service environment * feat: decode rate-limit service environment * feat: decode usage-estimator service environment * feat: decode emails service environment * adjust env * remove commented out code * adjust env variable name * use separate env variables * env fixes * more environmental stuff :) * ... * replace POSTGRES_CONNECTION_STRING with specific environment variables * handle optional clickhouse (for now :) * add missing POSTGRES_DB environment variable * make ENVIRONMENT optional * the other matters lol * feat: support delivering mails via SMTP (#412) * feat: optional CDN (#410) * feat: optional CDN * enable CDN in deployment * enable the CDN in integration tests * add sendmail provider * remove unused env variables from the deployment * only show login alert when legacy auth0 migration is enabled * feat: make TOKENS_ENDPOINT mandatory and RATE_LIMIT_ENDPOINT optional for usage service * feat: upgrade supertokens and enable server side email confirmation (#423) * feat: upgrade supertokens and enable server side email confirmation * feat: opt into required email verification * docs: self hosting (#428) * docs: self-hosting quick start * Update packages/web/docs/pages/self-hosting/get-started.mdx Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com> Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com> Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com> * feat: optional GitHub and Slack environment variables (#440) * feat: optional github integration environment variables * feat: optional slack integration (#441) * use latest stable supertokens Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com>
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-05-18 07:26:57 +00:00
TOKENS_ENDPOINT: serviceLocalEndpoint(tokens.service),
RATE_LIMIT_ENDPOINT: serviceLocalEndpoint(rateLimit.service),
},
exposesMetrics: true,
port: 4000,
pdb: true,
autoScaling: {
cpu: {
cpuAverageToScale: 60,
limit: cpuLimit,
},
maxReplicas,
},
2022-05-18 07:26:57 +00:00
},
[
dbMigrations,
tokens.deployment,
tokens.service,
rateLimit.deployment,
rateLimit.service,
].filter(Boolean),
2024-03-04 12:56:12 +00:00
)
.withSecret('KAFKA_SASL_USERNAME', kafka.secret, 'saslUsername')
.withSecret('KAFKA_SASL_PASSWORD', kafka.secret, 'saslPassword')
.withSecret('KAFKA_SSL', kafka.secret, 'ssl')
.withSecret('KAFKA_BROKER', kafka.secret, 'endpoint')
.withConditionalSecret(sentry.enabled, 'SENTRY_DSN', sentry.secret, 'dsn')
.deploy();
2022-05-18 07:26:57 +00:00
}