Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions iac/modules/job-api/jobs/api.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ job "api" {
SANDBOX_ACCESS_TOKEN_HASH_SEED = "${sandbox_access_token_hash_seed}"

POSTGRES_CONNECTION_STRING = "${postgres_connection_string}"
DB_MAX_OPEN_CONNECTIONS = "${db_max_open_connections}"
DB_MIN_IDLE_CONNECTIONS = "${db_min_idle_connections}"
AUTH_DB_CONNECTION_STRING = "${postgres_connection_string}"
AUTH_DB_READ_REPLICA_CONNECTION_STRING = "${postgres_read_replica_connection_string}"
AUTH_DB_MAX_OPEN_CONNECTIONS = "${auth_db_max_open_connections}"
AUTH_DB_MIN_IDLE_CONNECTIONS = "${auth_db_min_idle_connections}"
SUPABASE_JWT_SECRETS = "${supabase_jwt_secrets}"

LOKI_URL = "${loki_url}"
Expand Down
4 changes: 4 additions & 0 deletions iac/modules/job-api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ resource "nomad_job" "api" {
redis_url = var.redis_url
redis_cluster_url = var.redis_cluster_url
redis_tls_ca_base64 = var.redis_tls_ca_base64
db_max_open_connections = var.db_max_open_connections
db_min_idle_connections = var.db_min_idle_connections
auth_db_max_open_connections = var.auth_db_max_open_connections
auth_db_min_idle_connections = var.auth_db_min_idle_connections
redis_pool_size = var.redis_pool_size
clickhouse_connection_string = var.clickhouse_connection_string
loki_url = var.loki_url
Expand Down
20 changes: 20 additions & 0 deletions iac/modules/job-api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ variable "redis_tls_ca_base64" {
sensitive = true
}

variable "db_max_open_connections" {
type = number
default = 40
}

variable "db_min_idle_connections" {
type = number
default = 5
}

variable "auth_db_max_open_connections" {
type = number
default = 20
}

variable "auth_db_min_idle_connections" {
type = number
default = 5
}

variable "redis_pool_size" {
type = number
default = 160
Expand Down
6 changes: 5 additions & 1 deletion iac/provider-aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ tf_vars := AWS_PROFILE=$(AWS_PROFILE) AWS_REGION=$(AWS_REGION) \
$(call tfvar, BUILD_SERVER_MACHINE_TYPE) \
$(call tfvar, BUILD_SERVER_NESTED_VIRTUALIZATION) \
$(call tfvar, AWS_ACCOUNT_ID) \
$(call tfvar, AWS_REGION)
$(call tfvar, AWS_REGION) \
$(call tfvar, DB_MAX_OPEN_CONNECTIONS) \
$(call tfvar, DB_MIN_IDLE_CONNECTIONS) \
$(call tfvar, AUTH_DB_MAX_OPEN_CONNECTIONS) \
$(call tfvar, AUTH_DB_MIN_IDLE_CONNECTIONS)

.PHONY: provider-login
provider-login:
Expand Down
5 changes: 5 additions & 0 deletions iac/provider-aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ module "nomad" {
clickhouse_migrator_repository_name = module.init.clickhouse_migrator_repository_name

launch_darkly_api_key = module.init.launch_darkly_api_key

db_max_open_connections = var.db_max_open_connections
db_min_idle_connections = var.db_min_idle_connections
auth_db_max_open_connections = var.auth_db_max_open_connections
auth_db_min_idle_connections = var.auth_db_min_idle_connections
}

resource "aws_security_group" "cluster_node" {
Expand Down
4 changes: 4 additions & 0 deletions iac/provider-aws/nomad/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ module "api" {
db_migrator_docker_image = "${var.aws_account_id}.dkr.ecr.${var.aws_region}.amazonaws.com/${var.db_migrator_repository_name}:latest"
loki_url = "http://loki.service.consul:${var.loki_port}"
launch_darkly_api_key = var.launch_darkly_api_key
db_max_open_connections = var.db_max_open_connections
db_min_idle_connections = var.db_min_idle_connections
auth_db_max_open_connections = var.auth_db_max_open_connections
auth_db_min_idle_connections = var.auth_db_min_idle_connections
}

data "aws_s3_object" "orchestrator" {
Expand Down
16 changes: 16 additions & 0 deletions iac/provider-aws/nomad/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,19 @@ variable "launch_darkly_api_key" {
default = ""
sensitive = true
}

variable "db_max_open_connections" {
type = number
}

variable "db_min_idle_connections" {
type = number
}

variable "auth_db_max_open_connections" {
type = number
}

variable "auth_db_min_idle_connections" {
type = number
}
20 changes: 20 additions & 0 deletions iac/provider-aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,23 @@ variable "control_server_cluster_size" {
type = number
default = 3
}

variable "db_max_open_connections" {
type = number
default = 40
}

variable "db_min_idle_connections" {
type = number
default = 5
}

variable "auth_db_max_open_connections" {
type = number
default = 20
}

variable "auth_db_min_idle_connections" {
type = number
default = 5
}
6 changes: 5 additions & 1 deletion iac/provider-gcp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ tf_vars := \
$(call tfvar, LOKI_USE_V13_SCHEMA_FROM) \
$(call tfvar, DASHBOARD_API_COUNT) \
$(call tfvar, DEFAULT_PERSISTENT_VOLUME_TYPE) \
$(call tfvar, PERSISTENT_VOLUME_TYPES)
$(call tfvar, PERSISTENT_VOLUME_TYPES) \
$(call tfvar, DB_MAX_OPEN_CONNECTIONS) \
$(call tfvar, DB_MIN_IDLE_CONNECTIONS) \
$(call tfvar, AUTH_DB_MAX_OPEN_CONNECTIONS) \
$(call tfvar, AUTH_DB_MIN_IDLE_CONNECTIONS)

.PHONY: init
init:
Expand Down
4 changes: 4 additions & 0 deletions iac/provider-gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ module "nomad" {
redis_tls_ca_base64_secret_version = module.init.redis_tls_ca_base64_secret_version
sandbox_access_token_hash_seed = random_password.sandbox_access_token_hash_seed.result
sandbox_storage_backend = var.sandbox_storage_backend
db_max_open_connections = var.db_max_open_connections
db_min_idle_connections = var.db_min_idle_connections
auth_db_max_open_connections = var.auth_db_max_open_connections
auth_db_min_idle_connections = var.auth_db_min_idle_connections

# Click Proxy
client_proxy_count = var.client_proxy_count
Expand Down
4 changes: 4 additions & 0 deletions iac/provider-gcp/nomad/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ module "api" {
loki_url = local.loki_url
sandbox_access_token_hash_seed = var.sandbox_access_token_hash_seed
sandbox_storage_backend = var.sandbox_storage_backend
db_max_open_connections = var.db_max_open_connections
db_min_idle_connections = var.db_min_idle_connections
auth_db_max_open_connections = var.auth_db_max_open_connections
auth_db_min_idle_connections = var.auth_db_min_idle_connections
db_migrator_docker_image = data.google_artifact_registry_docker_image.db_migrator_image.self_link
launch_darkly_api_key = trimspace(data.google_secret_manager_secret_version.launch_darkly_api_key.secret_data)
default_persistent_volume_type = var.default_persistent_volume_type
Expand Down
16 changes: 16 additions & 0 deletions iac/provider-gcp/nomad/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ variable "sandbox_storage_backend" {
default = "memory"
}

variable "db_max_open_connections" {
type = number
}

variable "db_min_idle_connections" {
type = number
}

variable "auth_db_max_open_connections" {
type = number
}

variable "auth_db_min_idle_connections" {
type = number
}

variable "environment" {
type = string
}
Expand Down
20 changes: 20 additions & 0 deletions iac/provider-gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,26 @@ variable "sandbox_storage_backend" {
default = ""
}

variable "db_max_open_connections" {
type = number
default = 40
}

variable "db_min_idle_connections" {
type = number
default = 5
}

variable "auth_db_max_open_connections" {
type = number
default = 20
}

variable "auth_db_min_idle_connections" {
type = number
default = 5
}

variable "loki_use_v13_schema_from" {
type = string
description = "This should be a date soon after you deploy. Format = YYYY-MM-DD"
Expand Down
2 changes: 2 additions & 0 deletions packages/api/internal/cfg/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type Config struct {
NomadToken string `env:"NOMAD_TOKEN"`

PostgresConnectionString string `env:"POSTGRES_CONNECTION_STRING,required,notEmpty"`
DBMaxOpenConnections int32 `env:"DB_MAX_OPEN_CONNECTIONS" envDefault:"40"`
DBMinIdleConnections int32 `env:"DB_MIN_IDLE_CONNECTIONS" envDefault:"5"`

AuthDBConnectionString string `env:"AUTH_DB_CONNECTION_STRING"`
AuthDBReadReplicaConnectionString string `env:"AUTH_DB_READ_REPLICA_CONNECTION_STRING"`
Expand Down
2 changes: 1 addition & 1 deletion packages/api/internal/handlers/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type APIStore struct {
func NewAPIStore(ctx context.Context, tel *telemetry.Client, config cfg.Config, serviceName string) *APIStore {
logger.L().Info(ctx, "Initializing API store and services")

sqlcDB, err := sqlcdb.NewClient(ctx, config.PostgresConnectionString, pool.WithMaxConnections(40), pool.WithMinIdle(5))
sqlcDB, err := sqlcdb.NewClient(ctx, config.PostgresConnectionString, pool.WithMaxConnections(config.DBMaxOpenConnections), pool.WithMinIdle(config.DBMinIdleConnections))
if err != nil {
logger.L().Fatal(ctx, "Initializing SQLC client", zap.Error(err))
}
Expand Down