Skip to content

Commit

Permalink
Bruk Aiven Redis under henting av data til preutfylling
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga committed Jan 15, 2025
1 parent fff42b9 commit 5675876
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 14 deletions.
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,25 @@ object Routes {

fun main() {
val rapid = RapidApplication.create(System.getenv())
val aivenRedisConnection = RedisConnection(Env.Redis.aivenUri)
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 +115,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 @@ -9,6 +9,7 @@ object Env {
}

object Redis {
val aivenUri: String = "REDIS_URI_INNTEKTSMELDING".fromEnv()
val url: String = "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
Expand Up @@ -6,9 +6,9 @@ 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)
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,7 @@ 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(Env.redisUri)

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

object Env {
val redisUrl = "REDIS_URL".fromEnv()
val redisUri = "REDIS_URI_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
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

0 comments on commit 5675876

Please sign in to comment.