Skip to content

Commit

Permalink
Bruk Aiven Valkey (#829)
Browse files Browse the repository at this point in the history
* Bruk Aiven Redis under henting av data til preutfylling

* Bygg Redis-URI selv

* Bruk Aiven Redis overalt

* Fjern unødvendig linje i konfig

* Legg til prod-konfig

* Bytt fra Redis til Valkey

* Endre konfigurasjon til å bruke valkey istedenfor redis

* Fiks appkonfigurasjon

* Fjern midlertidig workflow trigger

---------

Co-authored-by: Morten Byhring <[email protected]>
  • Loading branch information
bjerga and mortenbyhring authored Feb 5, 2025
1 parent 217ead4 commit 76e6a23
Show file tree
Hide file tree
Showing 47 changed files with 192 additions and 122 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/valkey.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy Valkey

on:
push:
branches:
- main
paths:
- valkey/**

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
env: [dev, prod]
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ matrix.env }}-gcp
RESOURCE: valkey/config.yml
VARS: valkey/${{ matrix.env }}.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-aktiveorgnrservice".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.aktiveorgnrservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
1 change: 0 additions & 1 deletion apps/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ tasks {
test {
environment("IDPORTEN_WELL_KNOWN_URL", "http://localhost:6666/idporten-issuer/.well-known/openid-configuration")
environment("IDPORTEN_AUDIENCE", "aud-localhost")
environment("REDIS_URL", "redis://test_url:6379/0")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ object Routes {

fun main() {
val rapid = RapidApplication.create(System.getenv())
val redisConnection = RedisConnection(Env.Redis.url)
val redisConnection =
RedisConnection(
host = Env.Redis.host,
port = Env.Redis.port,
username = Env.Redis.username,
password = Env.Redis.password,
)

embeddedServer(
factory = Netty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
object Auth {
val discoveryUrl: String = "IDPORTEN_WELL_KNOWN_URL".fromEnv()
val acceptedAudience: List<String> = "IDPORTEN_AUDIENCE".fromEnv().let(::listOf)
val discoveryUrl = "IDPORTEN_WELL_KNOWN_URL".fromEnv()
val acceptedAudience = "IDPORTEN_AUDIENCE".fromEnv().let(::listOf)
}

object Redis {
val url: String = "REDIS_URL".fromEnv()
val host = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val port = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val username = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val password = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package no.nav.helsearbeidsgiver.felles.rapidsrivers.redis

import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import io.lettuce.core.api.StatefulRedisConnection
import io.lettuce.core.api.sync.RedisCommands
import no.nav.helsearbeidsgiver.utils.collection.mapValuesNotNull

class RedisConnection(
redisUrl: String,
host: String,
port: Int,
username: String,
password: String,
) {
private val client: RedisClient = RedisClient.create(redisUrl)
private val client: RedisClient =
RedisURI
.builder()
.withSsl(true)
.withHost(host)
.withPort(port)
.withAuthentication(username, password)
.withDatabase(0)
.build()
.let(RedisClient::create)
private val connection: StatefulRedisConnection<String, String> = client.connect()
private val syncCommands: RedisCommands<String, String> = connection.sync()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.helsearbeidsgiver.felles.test.mock

import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import io.lettuce.core.api.sync.RedisCommands
import io.mockk.every
import io.mockk.mockk
Expand All @@ -16,8 +17,8 @@ class MockRedis(
private val mockCommands = mockk<RedisCommands<String, String>>()
private val redis =
mockStatic(RedisClient::class) {
every { RedisClient.create(any<String>()) } returns mockRedisClient(mockCommands)
RedisConnection("")
every { RedisClient.create(any<RedisURI>()) } returns mockRedisClient(mockCommands)
RedisConnection("host", 0, "username", "password")
}

val store: RedisStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.helsearbeidsgiver.felles.test.mock

import io.lettuce.core.KeyValue
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import io.lettuce.core.api.StatefulRedisConnection
import io.lettuce.core.api.sync.RedisCommands
import io.mockk.every
Expand All @@ -13,8 +14,8 @@ import no.nav.helsearbeidsgiver.utils.test.mock.mockStatic
fun redisWithMockRedisClient(mockStorageInit: Map<String, String?>): RedisConnection {
val mockCommands = mockk<RedisCommands<String, String>>().setupMock(mockStorageInit)
return mockStatic(RedisClient::class) {
every { RedisClient.create(any<String>()) } returns mockRedisClient(mockCommands)
RedisConnection("")
every { RedisClient.create(any<RedisURI>()) } returns mockRedisClient(mockCommands)
RedisConnection("host", 0, "username", "password")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-innsending".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.innsending
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-inntektselvbestemtservice".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.inntektselvbestemtservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-inntektservice".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.inntektservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class ContainerTest {
private val topic = "helsearbeidsgiver.inntektsmelding"

private val kafkaContainer = ConfluentKafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.8.0"))
val redisContainer = RedisContainer(DockerImageName.parse("redis:7"))
val redisContainer = RedisContainer(DockerImageName.parse("redis:latest"))
val postgresContainerOne = postgresContainer()
val postgresContainerTwo = postgresContainer()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.integrasjonstest.utils
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageProblems
import io.kotest.matchers.nulls.shouldNotBeNull
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisURI
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import io.mockk.clearAllMocks
import io.mockk.coEvery
Expand Down Expand Up @@ -70,6 +72,7 @@ import no.nav.helsearbeidsgiver.utils.json.parseJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.test.date.august
import no.nav.helsearbeidsgiver.utils.test.date.mai
import no.nav.helsearbeidsgiver.utils.test.mock.mockStatic
import no.nav.helsearbeidsgiver.utils.test.wrapper.genererGyldig
import no.nav.helsearbeidsgiver.utils.wrapper.Fnr
import org.intellij.lang.annotations.Language
Expand Down Expand Up @@ -156,7 +159,11 @@ abstract class EndToEndTest : ContainerTest() {
return@lazy withRetries(
feilmelding = "Klarte ikke koble til Redis.",
) {
RedisConnection(redisContainer.redisURI)
// Hijacker RedisClient her pga. vanskeligheter med å sette opp RedisContainer med SSL og autentisering
mockStatic(RedisClient::class) {
every { RedisClient.create(any<RedisURI>()) } returns RedisClient.create(redisContainer.redisURI)
RedisConnection("host", 0, "username", "password")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "im-selvbestemt-hent-im-service".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.selvbestemthentimservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "im-selvbestemt-lagre-im-service".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.selvbestemtlagreimservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-tilgangservice".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.tilgangservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-hent-forespoersel-service".logger()

fun main() {
val redisConnection = RedisConnection(Env.redisUrl)
val redisConnection =
RedisConnection(
host = Env.redisHost,
port = Env.redisPort,
username = Env.redisUsername,
password = Env.redisPassword,
)

RapidApplication
.create(System.getenv())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package no.nav.helsearbeidsgiver.inntektsmelding.trengerservice
import no.nav.helsearbeidsgiver.felles.utils.fromEnv

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisHost = "REDIS_HOST_INNTEKTSMELDING".fromEnv()
val redisPort = "REDIS_PORT_INNTEKTSMELDING".fromEnv().toInt()
val redisUsername = "REDIS_USERNAME_INNTEKTSMELDING".fromEnv()
val redisPassword = "REDIS_PASSWORD_INNTEKTSMELDING".fromEnv()
}
6 changes: 1 addition & 5 deletions config/aktiveorgnrservice/dev-gcp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
kafkaPool: nav-dev
env:
- name: REDIS_URL
value: redis://helsearbeidsgiver-redis.helsearbeidsgiver.svc.cluster.local:6379/0
apps:
- name: helsearbeidsgiver-redis
valkeyAccess: readwrite
6 changes: 1 addition & 5 deletions config/aktiveorgnrservice/prod-gcp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
kafkaPool: nav-prod
env:
- name: REDIS_URL
value: redis://helsearbeidsgiver-redis.helsearbeidsgiver.svc.cluster.local:6379/0
apps:
- name: helsearbeidsgiver-redis
valkeyAccess: readwrite
Loading

0 comments on commit 76e6a23

Please sign in to comment.