Skip to content

Commit

Permalink
La til endepunkt for å hente ut debug info fra kafka-keygen
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmsa committed Oct 17, 2024
1 parent 8110700 commit 8b881cb
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/kafka-key-generator/nais/nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ spec:
- application: paw-arbeidssoekerregisteret-api-bekreftelse
- application: paw-arbeidssoekerregisteret-bekreftelse-tjeneste
- application: paw-arbeidssoekerregisteret-bekreftelse-min-side-varsler
- application: paw-brukerstotte
1 change: 1 addition & 0 deletions apps/kafka-key-generator/nais/nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ spec:
- application: paw-arbeidssoekerregisteret-utgang-pdl
- application: paw-microfrontend-toggler
- application: paw-arbeidssoekerregisteret-hendelselogg-backup
- application: paw-brukerstotte
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,38 @@ package no.nav.paw.kafkakeygenerator
import io.opentelemetry.instrumentation.annotations.WithSpan
import no.nav.paw.kafkakeygenerator.FailureCode.CONFLICT
import no.nav.paw.kafkakeygenerator.FailureCode.DB_NOT_FOUND
import no.nav.paw.kafkakeygenerator.api.v2.*
import no.nav.paw.kafkakeygenerator.pdl.PdlIdentitesTjeneste
import no.nav.paw.kafkakeygenerator.vo.ArbeidssoekerId
import no.nav.paw.kafkakeygenerator.vo.CallId
import no.nav.paw.kafkakeygenerator.vo.Identitetsnummer
import kotlin.math.absoluteValue

class Applikasjon(
private val kafkaKeys: KafkaKeys,
private val identitetsTjeneste: PdlIdentitesTjeneste
) {

@WithSpan
suspend fun hentInfo(callId: CallId, identitet: Identitetsnummer): Either<Failure, InfoResponse> {
val pdlIdInfo = identitetsTjeneste.hentIdentInformasjon(callId, identitet)
return kafkaKeys.hent(identitet)
.map { arbeidssoekerId ->
LokalIdData(
arbeidsoekerId = arbeidssoekerId.value,
recordKey = publicTopicKeyFunction(arbeidssoekerId).value
)
}.map { lokalIdData ->
InfoResponse(
lagretData = lokalIdData,
pdlData = pdlIdInfo.fold(
{ PdlData(error = it.code.name, id = null) },
{ PdlData(error = null, id = it.map { identInfo -> PdlId(identInfo.gruppe.name, identInfo.ident) })}
)
)
}
}

@WithSpan
suspend fun hent(callId: CallId, identitet: Identitetsnummer): Either<Failure, ArbeidssoekerId> {
return kafkaKeys.hent(identitet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,34 @@ fun Routing.konfigurerApiV2(
val logger = LoggerFactory.getLogger("api")
authenticate(autentiseringKonfigurasjon.kafkaKeyApiAuthProvider) {
post("/api/v2/hentEllerOpprett") {
handleRequest(applikasjon, logger)
hentEllerOpprett(applikasjon, logger)
}
post("/api/v2/info") {
hentEllerOpprett(applikasjon, logger)
}
}
}

@WithSpan
suspend fun PipelineContext<Unit, ApplicationCall>.hentInfo(
applikasjon: Applikasjon,
logger: Logger
) {
val callId = call.request.headers["traceparent"]
?.let { CallId(it) }
?: CallId(UUID.randomUUID().toString())
val request = call.receive<RequestV2>()
when (val resultat = applikasjon.hentInfo(callId, Identitetsnummer(request.ident))) {
is Left -> call.respond(
status = InternalServerError,
message = resultat.left.code.name
)
is Right -> call.respond(resultat.right)
}
}

@WithSpan
private suspend fun PipelineContext<Unit, ApplicationCall>.handleRequest(
private suspend fun PipelineContext<Unit, ApplicationCall>.hentEllerOpprett(
applikasjon: Applikasjon,
logger: Logger
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package no.nav.paw.kafkakeygenerator.api.v2

data class InfoResponse(
val lagretData: LokalIdData?,
val pdlData: PdlData
)

data class LokalIdData(
val arbeidsoekerId: Long,
val recordKey: Long
)

data class PdlData(
val error: String?,
val id: List<PdlId>?
)

data class PdlId(
val gruppe: String,
val id: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import no.nav.paw.kafkakeygenerator.vo.Identitetsnummer
import no.nav.paw.kafkakeygenerator.vo.CallId
import no.nav.paw.pdl.PdlClient
import no.nav.paw.pdl.PdlException
import no.nav.paw.pdl.graphql.generated.hentidenter.IdentInformasjon
import no.nav.paw.pdl.hentIdenter

private const val consumerId = "paw-arbeidssoekerregisteret"
private const val behandlingsnummer = "B452"

class PdlIdentitesTjeneste(private val pdlKlient: PdlClient) {
suspend fun hentIdentiter(
suspend fun hentIdentInformasjon(
callId: CallId,
identitet: Identitetsnummer
): Either<Failure, List<String>> {
): Either<Failure, List<IdentInformasjon>> {
return suspendeableAttempt {
pdlKlient
.hentIdenter(identitet.value, callId.value, consumerId, behandlingsnummer)
?.map { it.ident }
}.mapToFailure { exception ->
when (exception) {
is PdlException -> mapPdlException(exception)
Expand All @@ -33,6 +33,12 @@ class PdlIdentitesTjeneste(private val pdlKlient: PdlClient) {
}
}

suspend fun hentIdentiter(
callId: CallId,
identitet: Identitetsnummer
): Either<Failure, List<String>> = hentIdentInformasjon(callId, identitet)
.map { liste -> liste.map { it.ident } }

private fun mapPdlException(ex: PdlException): Failure {
return if (ex.errors?.any { it.message.contains("Fant ikke person") } == true) {
Failure("pdl", FailureCode.PDL_NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,63 @@ info:
description: "paw_kafka_key_generator API"
version: "1.0.0"
servers:
- url: "https://paw_kafka_key_generator"
- url: "https://paw_kafka_key_generator"
paths:
/api/v2/info:
post:
description: ""
parameters:
- name: "traceparent"
in: "header"
required: false
schema:
type: "string"
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/RequestV2"
required: true
responses:
"400":
description: "Bad Request"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "Bad request"
"500":
description: "Internal Server Error"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "En uventet feil oppstod"
"200":
description: ""
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "Intern feil, prøv igjen senere"
'*/*':
schema:
$ref: "#/components/schemas/InfoResponse"
/api/v2/hentEllerOpprett:
post:
description: ""
parameters:
- name: "traceparent"
in: "header"
required: false
schema:
type: "string"
- name: "traceparent"
in: "header"
required: false
schema:
type: "string"
requestBody:
content:
'*/*':
Expand Down Expand Up @@ -54,13 +100,34 @@ paths:
$ref: "#/components/schemas/ResponseV2"
components:
schemas:
InfoResponse:
type: "object"
properties:
lagretData:
type: "object"
properties:
arbeidssoekerId:
type: "integer"
format: "int64"
recordKey:
type: "integer"
format: "int64"
pdlData:
type: "object"
properties:
error:
type: "string"
id:
type: "array"
items:
type: "string"
RequestV2:
type: "object"
properties:
ident:
type: "string"
required:
- "ident"
- "ident"
ResponseV2:
type: "object"
properties:
Expand Down

0 comments on commit 8b881cb

Please sign in to comment.