console/deployment/services/usage-estimation.ts

58 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-28 19:22:54 +00:00
import { ServiceDeployment } from '../utils/service-deployment';
2022-05-18 07:26:57 +00:00
import { Clickhouse } from './clickhouse';
import { DbMigrations } from './db-migrations';
2024-03-04 12:56:12 +00:00
import { Docker } from './docker';
import { Environment } from './environment';
2024-04-07 08:57:03 +00:00
import { Observability } from './observability';
2024-03-04 12:56:12 +00:00
import { Sentry } from './sentry';
2022-05-18 07:26:57 +00:00
export type UsageEstimator = ReturnType<typeof deployUsageEstimation>;
export function deployUsageEstimation({
image,
2024-03-04 12:56:12 +00:00
docker,
environment,
2022-05-18 07:26:57 +00:00
clickhouse,
dbMigrations,
2024-03-04 12:56:12 +00:00
sentry,
2024-04-07 08:57:03 +00:00
observability,
2022-05-18 07:26:57 +00:00
}: {
2024-04-07 08:57:03 +00:00
observability: Observability;
image: string;
2024-03-04 12:56:12 +00:00
docker: Docker;
environment: Environment;
2022-05-18 07:26:57 +00:00
clickhouse: Clickhouse;
dbMigrations: DbMigrations;
2024-03-04 12:56:12 +00:00
sentry: Sentry;
2022-05-18 07:26:57 +00:00
}) {
return new ServiceDeployment(
2022-05-18 07:26:57 +00:00
'usage-estimator',
{
image,
2024-03-04 12:56:12 +00:00
imagePullSecret: docker.secret,
replicas: environment.isProduction ? 3 : 1,
2022-05-18 07:26:57 +00:00
readinessProbe: '/_readiness',
livenessProbe: '/_health',
startupProbe: '/_health',
2022-05-18 07:26:57 +00:00
env: {
2024-03-04 12:56:12 +00:00
...environment.envVars,
SENTRY: sentry.enabled ? '1' : '0',
2024-04-07 08:57:03 +00:00
OPENTELEMETRY_COLLECTOR_ENDPOINT:
observability.enabled && observability.tracingEndpoint
? observability.tracingEndpoint
: '',
2022-05-18 07:26:57 +00:00
},
exposesMetrics: true,
port: 4000,
},
[dbMigrations],
2024-03-04 12:56:12 +00:00
)
.withSecret('CLICKHOUSE_HOST', clickhouse.secret, 'host')
.withSecret('CLICKHOUSE_PORT', clickhouse.secret, 'port')
.withSecret('CLICKHOUSE_USERNAME', clickhouse.secret, 'username')
.withSecret('CLICKHOUSE_PASSWORD', clickhouse.secret, 'password')
.withSecret('CLICKHOUSE_PROTOCOL', clickhouse.secret, 'protocol')
.withConditionalSecret(sentry.enabled, 'SENTRY_DSN', sentry.secret, 'dsn')
.deploy();
2022-05-18 07:26:57 +00:00
}