Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bruk Aiven Valkey #829

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
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 @@ -15,7 +15,7 @@ abstract class ContainerTest {
private val topic = "helsearbeidsgiver.inntektsmelding"

private val kafkaContainer = KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.7.2"))
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
Loading