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 Redis under henting av data til preutfylling #829

Open
wants to merge 2 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
27 changes: 27 additions & 0 deletions .github/workflows/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy Redis

on:
push:
branches:
- main
# midlertidig for testing
- dev/**
paths:
- redis/**

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
# env: [dev, prod]
env: [dev]
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ matrix.env }}-gcp
RESOURCE: redis/config.yml
VARS: redis/${{ matrix.env }}.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,31 @@ object Routes {

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

embeddedServer(
factory = Netty,
port = 8080,
module = { apiModule(rapid, redisConnection) },
module = { apiModule(rapid, aivenRedisConnection, redisConnection) },
).start(wait = true)

rapid
.registerShutdownLifecycle {
aivenRedisConnection.close()
redisConnection.close()
}.start()
}

fun Application.apiModule(
rapid: RapidsConnection,
aivenRedisConnection: RedisConnection,
redisConnection: RedisConnection,
) {
val tilgangskontroll =
Expand Down Expand Up @@ -112,8 +121,8 @@ fun Application.apiModule(

authenticate {
route(Routes.PREFIX) {
hentForespoersel(rapid, tilgangskontroll, redisConnection)
hentForespoerselIdListe(rapid, tilgangskontroll, redisConnection)
hentForespoersel(rapid, tilgangskontroll, aivenRedisConnection)
hentForespoerselIdListe(rapid, tilgangskontroll, aivenRedisConnection)
inntektRoute(rapid, tilgangskontroll, redisConnection)
inntektSelvbestemtRoute(rapid, tilgangskontroll, redisConnection)
innsending(rapid, tilgangskontroll, redisConnection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ 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()

val url = "REDIS_URL".fromEnv()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AuthorizationTest : ApiTest() {
val path = "/test/auth"

application {
apiModule(mockk(relaxed = true), mockk())
apiModule(mockk(relaxed = true), mockk(), mockk())

routing {
authenticate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class ApiTest : MockAuthToken() {
fun testApi(block: suspend TestClient.() -> Unit): Unit =
testApplication {
application {
apiModule(mockk(relaxed = true), mockRedisConnection)
apiModule(mockk(relaxed = true), mockRedisConnection, mockRedisConnection)
}

val testClient = TestClient(this, ::mockAuthToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
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,
redisUri: String,
) {
private val client: RedisClient = RedisClient.create(redisUrl)
constructor(
host: String,
port: Int,
username: String,
password: String,
) : this(
RedisURI
.builder()
.withSsl(true)
.withHost(host)
.withPort(port)
.withAuthentication(username, password)
.withDatabase(0)
.build()
.toURI()
.toString(),
)

private val client: RedisClient = RedisClient.create(redisUri)
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
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()
}
1 change: 1 addition & 0 deletions config/api/dev-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ idportenEnabled: true
azure:
enabled: true
ingress: https://helsearbeidsgiver-im-api.intern.dev.nav.no
redisAccess: read
env:
- name: REDIS_URL
value: redis://helsearbeidsgiver-redis.helsearbeidsgiver.svc.cluster.local:6379/0
Expand Down
5 changes: 5 additions & 0 deletions config/nais.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ spec:
application:
enabled: {{ azure.enabled }}
{{/if}}
{{#if redisAccess}}
redis:
- instance: inntektsmelding
access: {{ redisAccess }}
{{/if}}
{{#if database}}
gcp:
sqlInstances:
Expand Down
6 changes: 1 addition & 5 deletions config/trengerservice/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
redisAccess: readwrite
11 changes: 11 additions & 0 deletions redis/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: aiven.io/v1alpha1
kind: Redis
metadata:
labels:
app: redis-inntektsmelding
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Denne linja er jeg ikke sikker på betydningen av.

team: helsearbeidsgiver
name: redis-helsearbeidsgiver-inntektsmelding
namespace: helsearbeidsgiver
spec:
project: {{ project }}
plan: {{ plan }}
2 changes: 2 additions & 0 deletions redis/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project: nav-dev
plan: hobbyist
Loading