From 83f2945e4e2de800fcf5ab812feeede0f29d3eea Mon Sep 17 00:00:00 2001 From: Ugur Alpay Cenar Date: Tue, 10 Oct 2023 14:12:33 +0200 Subject: [PATCH] =?UTF-8?q?Cache=20config=20dokumentmaler=20skille=20p?= =?UTF-8?q?=C3=A5=20dev=20og=20prod=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Cache config dokumentmaler skille på dev og prod * Cache config dokumentmaler skille på dev og prod --- .nais/feature.yaml | 1 - .nais/main.yaml | 1 - .nais/prod.yaml | 1 - .../dokument/forsendelse/config/CacheConfig.kt | 15 ++++++++++++--- .../hendelse/ForsendelseSkedulering.kt | 17 +++++------------ 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.nais/feature.yaml b/.nais/feature.yaml index a0f72d9a..6c1d3773 100644 --- a/.nais/feature.yaml +++ b/.nais/feature.yaml @@ -41,7 +41,6 @@ env: OPPDATER_STATUS_DOKUMENTER_CRON: "1 * * * * ?" REBESTILL_DOKUMENTER_UNDER_PRODUKSJON_SCHEDULE: "0 */10 * * * *" REBESTILL_DOKUMENTER_BESTILLING_FEILET_SCHEDULE: "0 */10 * * * *" - OPPDATER_DIST_STATUS_ENABLED: true KAFKA_MAX_RETRY: 5 GCP_BUCKET_DOCUMENT_KMS_KEY_PATH: projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/bucket-dokument-encryption GCP_DOCUMENT_CLIENTSIDE_KMS_KEY_PATH: gcp-kms://projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/clientside_document_encryption diff --git a/.nais/main.yaml b/.nais/main.yaml index d2820100..6c5124ca 100644 --- a/.nais/main.yaml +++ b/.nais/main.yaml @@ -39,7 +39,6 @@ env: OPPDATER_STATUS_DOKUMENTER_CRON: "1 * * * * ?" REBESTILL_DOKUMENTER_UNDER_PRODUKSJON_SCHEDULE: "0 */10 * * * *" REBESTILL_DOKUMENTER_BESTILLING_FEILET_SCHEDULE: "0 */10 * * * *" - OPPDATER_DIST_STATUS_ENABLED: true KAFKA_MAX_RETRY: 5 GCP_BUCKET_DOCUMENT_KMS_KEY_PATH: projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/bucket-dokument-encryption GCP_DOCUMENT_CLIENTSIDE_KMS_KEY_PATH: gcp-kms://projects/bidrag-dev-45a9/locations/europe-north1/keyRings/bidrag-dokument-forsendelse-feature/cryptoKeys/clientside_document_encryption diff --git a/.nais/prod.yaml b/.nais/prod.yaml index 5b71d749..0d9a83c4 100644 --- a/.nais/prod.yaml +++ b/.nais/prod.yaml @@ -39,7 +39,6 @@ env: OPPDATER_STATUS_DOKUMENTER_CRON: "* */10 * * * ?" REBESTILL_DOKUMENTER_UNDER_PRODUKSJON_SCHEDULE: "0 */10 * * * *" REBESTILL_DOKUMENTER_BESTILLING_FEILET_SCHEDULE: "0 * * * * *" - OPPDATER_DIST_STATUS_ENABLED: true GCP_DOCUMENT_CLIENTSIDE_KMS_KEY_PATH: gcp-kms://projects/bidrag-prod-8f72/locations/europe-north1/keyRings/bidrag-dokument-forsendelse/cryptoKeys/clientside_document_encryption JAVA_OPTS: -Xmx1028m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0 diff --git a/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/config/CacheConfig.kt b/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/config/CacheConfig.kt index b96fc484..a5200441 100644 --- a/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/config/CacheConfig.kt +++ b/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/config/CacheConfig.kt @@ -1,8 +1,10 @@ package no.nav.bidrag.dokument.forsendelse.config import com.github.benmanes.caffeine.cache.Caffeine +import mu.KotlinLogging import no.nav.bidrag.commons.cache.EnableUserCache import no.nav.bidrag.commons.cache.InvaliderCacheFørStartenAvArbeidsdag +import org.springframework.beans.factory.annotation.Value import org.springframework.cache.CacheManager import org.springframework.cache.annotation.EnableCaching import org.springframework.cache.caffeine.CaffeineCacheManager @@ -11,6 +13,8 @@ import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Profile import java.util.concurrent.TimeUnit +private val log = KotlinLogging.logger {} + @Configuration @EnableCaching @Profile(value = ["!test"]) // Ignore cache on tests @@ -31,15 +35,20 @@ class CacheConfig { } @Bean - fun cacheManager(): CacheManager { + fun cacheManager(@Value("\${NAIS_CLUSTER_NAME:dev-gcp}") clusterName: String): CacheManager { + val isProd = clusterName.startsWith("prod") val caffeineCacheManager = CaffeineCacheManager() caffeineCacheManager.registerCustomCache( PERSON_SPRAAK_CACHE, Caffeine.newBuilder().expireAfter(InvaliderCacheFørStartenAvArbeidsdag()).build() ) + val dokumentMalerCache = if (isProd) Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS) + else Caffeine.newBuilder().expireAfterWrite(2, TimeUnit.MINUTES) + + log.info { "Bruker cache $dokumentMalerCache for dokumentmaler. Kjører i cluster $clusterName" } caffeineCacheManager.registerCustomCache(PERSON_CACHE, Caffeine.newBuilder().expireAfter(InvaliderCacheFørStartenAvArbeidsdag()).build()) - caffeineCacheManager.registerCustomCache(DOKUMENTMALER_CACHE, Caffeine.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build()) - caffeineCacheManager.registerCustomCache(DOKUMENTMALDETALJER_CACHE, Caffeine.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build()) + caffeineCacheManager.registerCustomCache(DOKUMENTMALER_CACHE, dokumentMalerCache.build()) + caffeineCacheManager.registerCustomCache(DOKUMENTMALDETALJER_CACHE, dokumentMalerCache.build()) caffeineCacheManager.registerCustomCache(TILGANG_TEMA_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build()) caffeineCacheManager.registerCustomCache(TILGANG_PERSON_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build()) caffeineCacheManager.registerCustomCache(TILGANG_SAK_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build()) diff --git a/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/hendelse/ForsendelseSkedulering.kt b/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/hendelse/ForsendelseSkedulering.kt index 3c82740f..bc8d6163 100644 --- a/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/hendelse/ForsendelseSkedulering.kt +++ b/src/main/kotlin/no/nav/bidrag/dokument/forsendelse/hendelse/ForsendelseSkedulering.kt @@ -24,8 +24,7 @@ class ForsendelseSkedulering( private val forsendelseTjeneste: ForsendelseTjeneste, private val distribusjonService: DistribusjonService, private val forsendelseHendelseBestilling: ForsendelseHendelseBestillingService, - @Value("\${LAGRE_DIST_INFO_PAGE_SIZE:10}") private val distInfoPageSize: Int, - @Value("\${OPPDATER_DIST_STATUS_ENABLED:true}") private val forsendelseDistStatusEnabled: Boolean + @Value("\${LAGRE_DIST_INFO_PAGE_SIZE:10}") private val distInfoPageSize: Int ) { @Scheduled(cron = "\${LAGRE_DIST_INFO_CRON}") @@ -58,13 +57,7 @@ class ForsendelseSkedulering( ?.let { distInfo -> LOGGER.info { "Forsendelse ${forsendelse.forsendelseId} har status ${ForsendelseStatus.FERDIGSTILT} men journalpost ${forsendelse.journalpostIdFagarkiv} er distribuert med status ${distInfo.journalstatus} og kanal ${distInfo.kanal}. " + - "Oppdaterer forsendelsestatus til ${ForsendelseStatus.DISTRIBUERT}" - } - if (!forsendelseDistStatusEnabled) { - LOGGER.info { - "Oppdatering av Forsendelse status er ikke skrudd på. Oppdaterer ikke forsendelse" - } - return + "Oppdaterer forsendelsestatus til ${ForsendelseStatus.DISTRIBUERT}" } val kanal = DistribusjonKanal.valueOf(distInfo.kanal) forsendelseTjeneste.lagre( @@ -106,9 +99,9 @@ class ForsendelseSkedulering( distribusjonService.hentDistribusjonInfo(forsendelse.journalpostIdFagarkiv)?.let { distInfo -> LOGGER.info { "Lagrer forsendelse distribusjon info for forsendelse ${forsendelse.forsendelseId} " + - "med JOARK journalpostId ${forsendelse.journalpostIdFagarkiv}, " + - "${forsendelse.dokumenter.size} dokumenter, " + - "kanal ${distInfo.kanal} og status ${distInfo.journalstatus}" + "med JOARK journalpostId ${forsendelse.journalpostIdFagarkiv}, " + + "${forsendelse.dokumenter.size} dokumenter, " + + "kanal ${distInfo.kanal} og status ${distInfo.journalstatus}" } forsendelseTjeneste.lagre( forsendelse.copy(