From c228d482358dce19a1eeeddbbaa28fb526488c0e Mon Sep 17 00:00:00 2001 From: OleksandrChmyrNAV Date: Thu, 19 Dec 2024 10:51:11 +0100 Subject: [PATCH] Flytte maximumPoolSize innstillingen til NAIS config (#72) * Flyttet maximumPoolSize innstilling til NAIS config fil * Flyttet innstillinger til riktig tjenesten --- .nais/cpa-repo-dev.yaml | 4 ++++ .nais/cpa-repo-prod.yaml | 4 ++++ .nais/ebms-provider-dev.yaml | 4 ++++ .nais/ebms-provider-prod.yaml | 4 ++++ .../no/nav/emottak/cpa/persistence/DBConfiguration.kt | 6 +++++- .../no/nav/emottak/ebms/persistence/DatabaseConfig.kt | 7 +++++-- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.nais/cpa-repo-dev.yaml b/.nais/cpa-repo-dev.yaml index b13d934b..a21354fd 100644 --- a/.nais/cpa-repo-dev.yaml +++ b/.nais/cpa-repo-dev.yaml @@ -93,3 +93,7 @@ spec: value: truststore_test.p12 - name: EMOTTAK_LOGGING_LEVEL value: DEBUG + - name: MAX_CONNECTION_POOL_SIZE_FOR_USER + value: "4" + - name: MAX_CONNECTION_POOL_SIZE_FOR_ADMIN + value: "1" diff --git a/.nais/cpa-repo-prod.yaml b/.nais/cpa-repo-prod.yaml index 47ffa517..9fd86800 100644 --- a/.nais/cpa-repo-prod.yaml +++ b/.nais/cpa-repo-prod.yaml @@ -82,3 +82,7 @@ spec: value: jdbc:postgresql://A01DBVL037.adeo.no:5432/ - name: TRUSTSTORE_PATH value: truststore_prod.p12 + - name: MAX_CONNECTION_POOL_SIZE_FOR_USER + value: "10" + - name: MAX_CONNECTION_POOL_SIZE_FOR_ADMIN + value: "2" diff --git a/.nais/ebms-provider-dev.yaml b/.nais/ebms-provider-dev.yaml index 7c642c85..bab9c4a0 100644 --- a/.nais/ebms-provider-dev.yaml +++ b/.nais/ebms-provider-dev.yaml @@ -68,6 +68,10 @@ spec: value: /var/run/secrets/ebms-keystore-signering/signering-key.p12 - name: EMOTTAK_LOGGING_LEVEL value: DEBUG + - name: MAX_CONNECTION_POOL_SIZE_FOR_USER + value: "4" + - name: MAX_CONNECTION_POOL_SIZE_FOR_ADMIN + value: "1" envFrom: - secret: ebms-payload-secret filesFrom: diff --git a/.nais/ebms-provider-prod.yaml b/.nais/ebms-provider-prod.yaml index 25bfa667..f16713aa 100644 --- a/.nais/ebms-provider-prod.yaml +++ b/.nais/ebms-provider-prod.yaml @@ -76,3 +76,7 @@ spec: value: key.decrypt.p12.b64.2022 - name: VIRKSOMHETSSERTIFIKAT_CREDENTIALS value: credentials.2022 + - name: MAX_CONNECTION_POOL_SIZE_FOR_USER + value: "4" + - name: MAX_CONNECTION_POOL_SIZE_FOR_ADMIN + value: "2" diff --git a/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/persistence/DBConfiguration.kt b/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/persistence/DBConfiguration.kt index 535c98d7..0412b20e 100644 --- a/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/persistence/DBConfiguration.kt +++ b/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/persistence/DBConfiguration.kt @@ -46,11 +46,15 @@ data class VaultConfig( ) fun VaultConfig.configure(role: String): HikariConfig { + val maxPoolSizeForUser = getEnvVar("MAX_CONNECTION_POOL_SIZE_FOR_USER", "4").toInt() + val maxPoolSizeForAdmin = getEnvVar("MAX_CONNECTION_POOL_SIZE_FOR_ADMIN", "1").toInt() + val hikariConfig = HikariConfig().apply { jdbcUrl = this@configure.jdbcUrl + databaseName driverClassName = "org.postgresql.Driver" + this.maximumPoolSize = maxPoolSizeForUser if (role == "admin") { - this.maximumPoolSize = 2 + this.maximumPoolSize = maxPoolSizeForAdmin val vault = VaultUtil.getInstance().client val path: String = this@configure.vaultMountPath + "/creds/$databaseName-$role" log.info("Fetching database credentials for role admin") diff --git a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/persistence/DatabaseConfig.kt b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/persistence/DatabaseConfig.kt index 36404211..6b441041 100644 --- a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/persistence/DatabaseConfig.kt +++ b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/persistence/DatabaseConfig.kt @@ -26,12 +26,15 @@ data class VaultConfig( ) fun VaultConfig.configure(role: String): HikariConfig { + val maxPoolSizeForUser = getEnvVar("MAX_CONNECTION_POOL_SIZE_FOR_USER", "4").toInt() + val maxPoolSizeForAdmin = getEnvVar("MAX_CONNECTION_POOL_SIZE_FOR_ADMIN", "1").toInt() + val hikariConfig = HikariConfig().apply { jdbcUrl = this@configure.jdbcUrl + databaseName driverClassName = "org.postgresql.Driver" - this.maximumPoolSize = 4 + this.maximumPoolSize = maxPoolSizeForUser if (role == "admin") { - this.maximumPoolSize = 1 + this.maximumPoolSize = maxPoolSizeForAdmin val vault = VaultUtil.getInstance().client val path: String = this@configure.vaultMountPath + "/creds/$databaseName-$role" log.info("Fetching database credentials for role admin")