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 ae27c71
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 59 deletions.
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,37 @@
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,
): Runnable {
return Thread.ofVirtual()
.name("prosesser-brev-thread")
.start(
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,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 @@ -58,13 +58,17 @@ class GodskrivOpptjeningConfig {
godskrivProcessingMetricsFeilmåling: GodskrivProcessingMetricsFeilmåling,
datasourceReadinessCheck: DatasourceReadinessCheck,
): Runnable {
return GodskrivOpptjeningProcessingThread(
service = service,
unleash = unleash,
godskrivProcessingMetricsMåling = godskrivProcessingMetricsMåling,
godskrivProcessingMetricsFeilmåling = godskrivProcessingMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)
return Thread.ofVirtual()
.name("prosesser-godskriv-opptjening-thread")
.start(
GodskrivOpptjeningProcessingThread(
service = service,
unleash = unleash,
godskrivProcessingMetricsMåling = godskrivProcessingMetricsMåling,
godskrivProcessingMetricsFeilmåling = godskrivProcessingMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)
)
}

@Bean
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,16 +60,20 @@ class KontrollConfig {
}

@Bean
@Profile("dev-gcp", "prod-gcp")
@Profile("dev-gcp", "prod-gcp","kafkaIntegrationTest")
fun kontrollProcessingThread(
service: KontrollbehandlingProcessingService,
unleash: Unleash,
datasourceReadinessCheck: DatasourceReadinessCheck,
): Runnable {
return KontrollbehandlingProcessingThread(
service = service,
unleash = unleash,
datasourceReadinessCheck = datasourceReadinessCheck
)
return Thread.ofVirtual()
.name("prosesser-persongrunnlag-kontrollbehandling-thread")
.start(
KontrollbehandlingProcessingThread(
service = service,
unleash = unleash,
datasourceReadinessCheck = datasourceReadinessCheck
)
)
}
}
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,37 @@
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,
): Runnable {
return Thread.ofVirtual()
.name("prosesser-oppgave-thread")
.start(
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 @@ -72,13 +72,17 @@ class PersongrunnlagConfig {
omsorgsarbeidMetricsFeilmåling: OmsorgsarbeidProcessingMetricsFeilmåling,
datasourceReadinessCheck: DatasourceReadinessCheck,
): Runnable {
return PersongrunnlagMeldingProcessingThread(
service = service,
unleash = unleash,
omsorgsarbeidMetricsMåling = omsorgsarbeidMetricsMåling,
omsorgsarbeidMetricsFeilmåling = omsorgsarbeidMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)
return Thread.ofVirtual()
.name("prosesser-persongrunnlag-melding-thread")
.start(
PersongrunnlagMeldingProcessingThread(
service = service,
unleash = unleash,
omsorgsarbeidMetricsMåling = omsorgsarbeidMetricsMåling,
omsorgsarbeidMetricsFeilmåling = omsorgsarbeidMetricsFeilmåling,
datasourceReadinessCheck = datasourceReadinessCheck
)
)
}

@Bean
Expand Down

0 comments on commit ae27c71

Please sign in to comment.