Skip to content

Commit

Permalink
La til oppholdstillatelse stats i utgangs-pdl
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmsa committed Sep 23, 2024
1 parent f59d283 commit fdf0f18
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fun scheduleAvsluttPerioder(
emptyList()
} else {
pdlHentPersonResults.processPdlResultsV2(
prometheusMeterRegistry = prometheusMeterRegistry,
regler = regler,
chunk = chunk,
logger = logger
Expand Down Expand Up @@ -114,12 +115,28 @@ fun Set<Opplysning>.toDomeneOpplysninger() = this
.toSet()

fun List<HentPersonBolkResult>.processPdlResultsV2(
prometheusMeterRegistry: PrometheusMeterRegistry,
regler: Regler,
chunk: List<KeyValue<UUID, HendelseState>>,
logger: Logger
): List<EvalueringResultat> =
this.filter { result -> isPdlResultOK(result.code, logger) }
.mapNotNull { result -> getHendelseStateAndPerson(result, chunk, logger) }
.onEach { (person, _) ->
runCatching {
val oppholdsInfo = person.opphold.firstOrNull()?.let { opphold ->
statsOppholdstilatelse(
fra = opphold.oppholdFra,
til = opphold.oppholdTil,
type = opphold.type.name
)
}
val personFakta = genererPersonFakta(person.toPerson())
prometheusMeterRegistry.oppholdstillatelseStats(oppholdsInfo, personFakta)
}.onFailure { ex ->
logger.warn("Feil under stats generering", ex)
}
}
.map { (person, hendelseState) ->
val registreringsOpplysninger = hendelseState.opplysninger.toDomeneOpplysninger()
val gjeldeneOpplysninger = genererPersonFakta(person.toPerson())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.micrometer.prometheusmetrics.PrometheusConfig
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import io.mockk.mockk
import io.mockk.verify
import no.nav.paw.arbeidssoekerregisteret.utgang.pdl.kafka.filterValidHendelseStates
Expand All @@ -24,7 +26,7 @@ import java.time.Instant
import java.util.*

class ProcessPdlResultsTest : FreeSpec({

val prometheusMeterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
"processPdlResults should correctly set avsluttPeriode to true if multiple problems in pdlEvaluering" {
val person = getPerson(
foedsel = Foedsel("2014-01-01"),
Expand Down Expand Up @@ -56,7 +58,7 @@ class ProcessPdlResultsTest : FreeSpec({

val logger = mockk<Logger>(relaxed = true)

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
output[0].avsluttPeriode shouldBe true
Expand Down Expand Up @@ -89,7 +91,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
val chunk = listOf(KeyValue(hendelseState.periodeId, hendelseState))

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
val evalueringResultat = output.first()
Expand Down Expand Up @@ -123,7 +125,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
val chunk = listOf(KeyValue(hendelseState.periodeId, hendelseState))

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
val evalueringResultat = output.first()
Expand Down Expand Up @@ -157,7 +159,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
val chunk = listOf(KeyValue(hendelseState.periodeId, hendelseState))

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
val evalueringResultat = output.first()
Expand Down Expand Up @@ -193,7 +195,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
val chunk = listOf(KeyValue(hendelseState.periodeId, hendelseState))

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
val evalueringResultat = output.first()
Expand Down Expand Up @@ -227,7 +229,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
val chunk = listOf(KeyValue(hendelseState.periodeId, hendelseState))

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
val evalueringResultat = output.first()
Expand Down Expand Up @@ -264,7 +266,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
val chunk = listOf(KeyValue(hendelseState.periodeId, hendelseState))

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldHaveSize(1)
val evalueringResultat = output.first()
Expand All @@ -287,7 +289,7 @@ class ProcessPdlResultsTest : FreeSpec({

val chunk = listOf<KeyValue<UUID, HendelseState>>()

val output = results.processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = results.processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldBeEmpty()
verify(exactly = 2) { logger.error(any()) }
Expand All @@ -313,7 +315,7 @@ class ProcessPdlResultsTest : FreeSpec({
)
)

val output = listOf(result).processPdlResultsV2(InngangsReglerV3, chunk, logger)
val output = listOf(result).processPdlResultsV2(prometheusMeterRegistry, InngangsReglerV3, chunk, logger)

output.shouldBeEmpty()
verify { logger.error("Person er null for periodeId: $periodeId") }
Expand Down

0 comments on commit fdf0f18

Please sign in to comment.