diff --git a/.github/workflows/deploy-redis.yaml b/.github/workflows/deploy-redis.yaml new file mode 100644 index 0000000..843be72 --- /dev/null +++ b/.github/workflows/deploy-redis.yaml @@ -0,0 +1,29 @@ +name: Deploy Redis + +on: + push: + paths: ['nais/redis-dev.yaml', 'nais/redis-prod.yaml'] + workflow_dispatch: + +jobs: + deploy-redis-dev-gcp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: nais/deploy/actions/deploy@v1 + env: + APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} + CLUSTER: dev-gcp + RESOURCE: nais/redis-dev-gcp.yaml + + deploy-redis-prod-gcp: + if: github.ref == 'refs/heads/main' + needs: deploy-redis-dev-gcp + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: nais/deploy/actions/deploy@v1 + env: + APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} + CLUSTER: prod-gcp + RESOURCE: nais/redis-prod-gcp.yaml \ No newline at end of file diff --git a/nais/redis-dev.yaml b/nais/redis-dev.yaml new file mode 100644 index 0000000..f5529f8 --- /dev/null +++ b/nais/redis-dev.yaml @@ -0,0 +1,11 @@ +apiVersion: aiven.io/v1alpha1 +kind: Redis +metadata: + labels: + app: oppfolgingsplan-backend-redis + team: team-esyfo + name: redis-team-esyfo-oppfolgingsplan-backend + namespace: team-esyfo +spec: + plan: startup-4 + project: nav-dev \ No newline at end of file diff --git a/nais/redis-prod.yaml b/nais/redis-prod.yaml new file mode 100644 index 0000000..981d7da --- /dev/null +++ b/nais/redis-prod.yaml @@ -0,0 +1,11 @@ +apiVersion: aiven.io/v1alpha1 +kind: Redis +metadata: + labels: + app: oppfolgingsplan-backend-redis + team: team-esyfo + name: redis-team-esyfo-oppfolgingsplan-backend + namespace: team-esyfo +spec: + plan: startup-4 + project: nav-prod \ No newline at end of file diff --git a/src/main/kotlin/no/nav/syfo/config/CacheConfig.kt b/src/main/kotlin/no/nav/syfo/config/CacheConfig.kt deleted file mode 100644 index 8174553..0000000 --- a/src/main/kotlin/no/nav/syfo/config/CacheConfig.kt +++ /dev/null @@ -1,54 +0,0 @@ -package no.nav.syfo.config - -import org.springframework.cache.CacheManager -import org.springframework.cache.annotation.EnableCaching -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Profile -import org.springframework.data.redis.cache.RedisCacheConfiguration -import org.springframework.data.redis.cache.RedisCacheManager -import org.springframework.data.redis.connection.RedisConnectionFactory -import java.time.Duration - -@Configuration -@EnableCaching -@Profile("remote") -class CacheConfig { - @Bean - fun cacheManager(redisConnectionFactory: RedisConnectionFactory): CacheManager { - val defaultConfig: RedisCacheConfiguration = RedisCacheConfiguration - .defaultCacheConfig() - .entryTtl(Duration.ofHours(1L)) - - val cacheConfigurations = listOf( - CACHENAME_AKTOER_ID, - CACHENAME_AKTOER_FNR, - CACHENAME_GJELDENDE_FNR, - CACHENAME_ANSATTE, - CACHENAME_DKIF_FNR, - CACHENAME_EREG_VIRKSOMHETSNAVN, - CACHENAME_LEDER, - CACHENAME_ARBEIDSFORHOLD_AT, - CACHENAME_TILGANG_TIL_IDENT, - CACHENAME_FELLESKODEVERK_BETYDNINGER - ).associateWith { defaultConfig } - - return RedisCacheManager.builder(redisConnectionFactory) - .cacheDefaults(RedisCacheConfiguration.defaultCacheConfig()) - .withInitialCacheConfigurations(cacheConfigurations) - .build() - } - - companion object { - const val CACHENAME_AKTOER_ID = "aktoerid" - const val CACHENAME_AKTOER_FNR = "aktoerfnr" - const val CACHENAME_GJELDENDE_FNR = "gjeldendefnr" - const val CACHENAME_ANSATTE = "lederansatte" - const val CACHENAME_DKIF_FNR = "dkif_fnr" - const val CACHENAME_EREG_VIRKSOMHETSNAVN = "virksomhetsnavn" - const val CACHENAME_LEDER = "narmesteleder" - const val CACHENAME_ARBEIDSFORHOLD_AT = "arbeidsforholdAT" - const val CACHENAME_TILGANG_TIL_IDENT = "tilgangtilident" - const val CACHENAME_FELLESKODEVERK_BETYDNINGER = "felleskodeverkBetydninger" - } -} diff --git a/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt b/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt index 94d2363..af2cf7b 100644 --- a/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt +++ b/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt @@ -1,7 +1,6 @@ package no.nav.syfo.kontaktinfo import no.nav.syfo.auth.azure.AzureAdTokenClient -import no.nav.syfo.config.CacheConfig import no.nav.syfo.metric.Metrikk import no.nav.syfo.util.NAV_CALL_ID_HEADER import no.nav.syfo.util.NAV_PERSONIDENT_HEADER @@ -26,7 +25,7 @@ class KrrClient @Autowired constructor( @Value("\${krr.scope}") private val krrScope: String, @Value("\${krr.url}") val krrUrl: String, ) { - @Cacheable(cacheNames = [CacheConfig.CACHENAME_DKIF_FNR], key = "#fnr", condition = "#fnr != null") + @Cacheable(cacheNames = ["krr_fnr"], key = "#fnr", condition = "#fnr != null") fun kontaktinformasjon(fnr: String): DigitalKontaktinfo { val accessToken = "Bearer ${azureAdTokenConsumer.getSystemToken(krrScope)}" val response = RestTemplate().exchange( diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 680ad2e..a170271 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -18,6 +18,22 @@ spring: hikari: minimum-idle: 1 maximum-pool-size: 5 + data: + redis: + url: ${REDIS_URI_OPPFOLGINGSPLAN:} + username: ${REDIS_USERNAME_OPPFOLGINGSPLAN:} + password: ${REDIS_PASSWORD_OPPFOLGINGSPLAN:} + timeout: 2000 + lettuce: + pool: + max-active: 16 + min-idle: 8 + enabled: true + time-between-eviction-runs: 10000 + cache: + redis: + time-to-live: 3600 + enable-statistics: true management: endpoint: