Skip to content

Commit

Permalink
Test virtual threads
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-meidell committed Oct 18, 2024
1 parent 30b1315 commit febc107
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 45 deletions.
2 changes: 1 addition & 1 deletion nais/dev-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ spec:
memory: "4096Mi"
requests:
cpu: "500m"
memory: "2048Mi"
memory: "4096Mi"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration
import pensjon.opptjening.azure.ad.client.TokenProvider

@Configuration
class BrevConfig {
class BrevClientConfig {

@Bean
fun brevClient(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model

import io.getunleash.Unleash
import jakarta.annotation.PostConstruct
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.metrics.BrevProcessingMetricsFeilmåling
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.metrics.BrevProcessingMetrikker
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.unleash.NavUnleashConfig
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Component
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")
class BrevProcessingThread(
private val service: BrevService,
private val unleash: Unleash,
Expand All @@ -24,11 +19,8 @@ class BrevProcessingThread(
private val log = LoggerFactory.getLogger(this::class.java)!!
}

@PostConstruct
fun init() {
val name = "prosesser-brev-thread"
log.info("Starting new thread:$name to process brev")
Thread(this, name).start()
init {
log.info("Starting new thread to process brev")
}

override fun run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.spring

import io.getunleash.Unleash
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.metrics.BrevProcessingMetricsFeilmåling
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.metrics.BrevProcessingMetrikker
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.BrevProcessingThread
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.BrevService
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile

@Configuration
class BrevConfig {

@Bean
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")
fun brevProcessingThread(
service: BrevService,
unleash: Unleash,
brevProcessingMetricsMåling: BrevProcessingMetrikker,
brevProcessingMetricsFeilmåling: BrevProcessingMetricsFeilmåling,
datasourceReadinessCheck: DatasourceReadinessCheck,
): BrevProcessingThread {
return BrevProcessingThread(
service = service,
unleash = unleash,
brevProcessingMetricsMåling = brevProcessingMetricsMåling,
brevProcessingMetricsFeilmåling = brevProcessingMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.spring

import com.zaxxer.hikari.HikariDataSource
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.BrevProcessingThread
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.godskriv.model.GodskrivOpptjeningProcessingThread
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.kontrollbehandling.KontrollbehandlingProcessingThread
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.model.OppgaveProcessingThread
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.persongrunnlag.model.PersongrunnlagMeldingProcessingThread
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import java.util.concurrent.Executors

@Configuration
class Config {
Expand All @@ -14,4 +21,24 @@ class Config {
): DatasourceReadinessCheck {
return DatasourceReadinessCheck(hikariDataSource)
}
}

@Configuration
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")
internal class ThreadsConfig(
oppgaveProcessingThread: OppgaveProcessingThread,
brevProcessingThread: BrevProcessingThread,
persongrunnlagMeldingProcessingThread: PersongrunnlagMeldingProcessingThread,
kontrollbehandlingProcessingThread: KontrollbehandlingProcessingThread,
godskrivOpptjeningProcessingThread: GodskrivOpptjeningProcessingThread
) {
init {
Executors.newVirtualThreadPerTaskExecutor().let {
it.submit(oppgaveProcessingThread)
it.submit(brevProcessingThread)
it.submit(persongrunnlagMeldingProcessingThread)
it.submit(kontrollbehandlingProcessingThread)
it.submit(godskrivOpptjeningProcessingThread)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.godskriv.model

import io.getunleash.Unleash
import jakarta.annotation.PostConstruct
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.godskriv.metrics.GodskrivProcessingMetricsFeilmåling
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.godskriv.metrics.GodskrivProcessingMetrikker
Expand All @@ -20,11 +19,8 @@ internal class GodskrivOpptjeningProcessingThread(
private val log = LoggerFactory.getLogger(this::class.java)!!
}

@PostConstruct
fun init() {
val name = "prosesser-godskriv-opptjening-thread"
log.info("Starting new thread:$name to process godskriv opptjening")
Thread(this, name).start()
init {
log.info("Starting new thread to process godskriv opptjening")
}

override fun run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class GodskrivOpptjeningConfig {

@Bean
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")
fun godskrivOpptjeningProcessingThread(
internal fun godskrivOpptjeningProcessingThread(
service: GodskrivOpptjeningProcessingService,
unleash: Unleash,
godskrivProcessingMetricsMåling: GodskrivProcessingMetrikker,
godskrivProcessingMetricsFeilmåling: GodskrivProcessingMetricsFeilmåling,
datasourceReadinessCheck: DatasourceReadinessCheck,
): Runnable {
): GodskrivOpptjeningProcessingThread {
return GodskrivOpptjeningProcessingThread(
service = service,
unleash = unleash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ class KontrollbehandlingProcessingThread(
) : Runnable {

init {
val name = "prosesser-persongrunnlag-kontrollbehandling-thread"
log.info("Starting new thread:$name to process kontrollbehandlinger")
Thread(this, name).start()
log.info("Starting new thread to process kontrollbehandlinger")
}


companion object {
private val log = LoggerFactory.getLogger(this::class.java)!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class KontrollConfig {
}

@Bean
@Profile("dev-gcp", "prod-gcp")
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")
fun kontrollProcessingThread(
service: KontrollbehandlingProcessingService,
unleash: Unleash,
datasourceReadinessCheck: DatasourceReadinessCheck,
): Runnable {
): KontrollbehandlingProcessingThread {
return KontrollbehandlingProcessingThread(
service = service,
unleash = unleash,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.model

import io.getunleash.Unleash
import jakarta.annotation.PostConstruct
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.metrics.OppgaveProcessingMetricsFeilmåling
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.metrics.OppgaveProcessingMetrikker
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.unleash.NavUnleashConfig
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Component
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")

class OppgaveProcessingThread(
private val service: OppgaveService,
private val unleash: Unleash,
Expand All @@ -24,11 +20,8 @@ class OppgaveProcessingThread(
private val log = LoggerFactory.getLogger(this::class.java)!!
}

@PostConstruct
fun init() {
val name = "prosesser-oppgave-thread"
log.info("Starting new thread:$name to process oppgaver")
Thread(this, name).start()
init {
log.info("Starting new thread to process oppgaver")
}

override fun run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.model.spring

import io.getunleash.Unleash
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.metrics.OppgaveProcessingMetricsFeilmåling
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.metrics.OppgaveProcessingMetrikker
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.model.OppgaveProcessingThread
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.oppgave.model.OppgaveService
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile

@Configuration
class OppgaveConfig {

@Bean
@Profile("dev-gcp", "prod-gcp", "kafkaIntegrationTest")
fun oppgaveProcessingThread(
service: OppgaveService,
unleash: Unleash,
oppgaveProcessingMetricsMåling: OppgaveProcessingMetrikker,
oppgaveProcessingMetricsFeilmåling: OppgaveProcessingMetricsFeilmåling,
datasourceReadinessCheck: DatasourceReadinessCheck,
): OppgaveProcessingThread {
return OppgaveProcessingThread(
service = service,
unleash = unleash,
oppgaveProcessingMetricsMåling = oppgaveProcessingMetricsMåling,
oppgaveProcessingMetricsFeilmåling = oppgaveProcessingMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.persongrunnlag.model

import io.getunleash.Unleash
import jakarta.annotation.PostConstruct
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.config.DatasourceReadinessCheck
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.omsorgsarbeid.metrics.OmsorgsarbeidProcessingMetricsFeilmåling
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.omsorgsarbeid.metrics.OmsorgsarbeidProcessingMetrikker
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.unleash.NavUnleashConfig
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

class PersongrunnlagMeldingProcessingThread(
private val service: PersongrunnlagMeldingProcessingService,
Expand All @@ -22,11 +19,8 @@ class PersongrunnlagMeldingProcessingThread(
private val log = LoggerFactory.getLogger(this::class.java)!!
}

@PostConstruct
fun init() {
val name = "prosesser-persongrunnlag-melding-thread"
log.info("Starting new thread:$name to process persongrunnlag")
Thread(this, name).start()
init {
log.info("Starting new thread to process persongrunnlag")
}

override fun run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ class PersongrunnlagConfig {
omsorgsarbeidMetricsMåling: OmsorgsarbeidProcessingMetrikker,
omsorgsarbeidMetricsFeilmåling: OmsorgsarbeidProcessingMetricsFeilmåling,
datasourceReadinessCheck: DatasourceReadinessCheck,
): Runnable {
): PersongrunnlagMeldingProcessingThread {
return PersongrunnlagMeldingProcessingThread(
service = service,
unleash = unleash,
omsorgsarbeidMetricsMåling = omsorgsarbeidMetricsMåling,
omsorgsarbeidMetricsFeilmåling = omsorgsarbeidMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)

}

@Bean
Expand Down

0 comments on commit febc107

Please sign in to comment.