Skip to content

Commit

Permalink
Small fixes, trace log
Browse files Browse the repository at this point in the history
  • Loading branch information
JMLindseth committed Nov 1, 2023
1 parent 0638da4 commit 68e86d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class VeilederTilgangskontrollClient(
?: throw RuntimeException("Failed to request access to list of persons: Failed to get OBO token")

try {
log.info("TRACE: Antall i listen: ${personIdentNumberList.size}, callId: $callId")
val requestTimer: Timer.Sample = Timer.start()

val url = getTilgangskontrollHost(pathTilgangTilBrukereOBO)
val url = getTilgangskontrollUrl(pathTilgangTilBrukereOBO)
val response: HttpResponse = httpClient.post(url) {
header(HttpHeaders.Authorization, bearerHeader(oboToken))
header(NAV_CALL_ID_HEADER, callId)
Expand All @@ -50,19 +51,22 @@ class VeilederTilgangskontrollClient(

requestTimer.stop(HISTOGRAM_ISTILGANGSKONTROLL_PERSONER)
COUNT_CALL_TILGANGSKONTROLL_PERSONS_SUCCESS.increment()
return response.body()
val body: List<String> = response.body()
log.info("TRACE: Antall i listen etter tilgangskontroll: ${body.size}, callId: $callId")

return body
} catch (e: ClientRequestException) {
return if (e.response.status == HttpStatusCode.Forbidden) {
log.warn("Forbidden to request access to list of person from syfo-tilgangskontroll")
log.warn("Forbidden to request access to list of person from istilgangskontroll")
null
} else {
COUNT_CALL_TILGANGSKONTROLL_PERSONS_FAIL.increment()
log.error("Error while requesting access to list of person from syfo-tilgangskontroll: ${e.message}", e)
log.error("Error while requesting access to list of person from istilgangskontroll: ${e.message}", e)
null
}
} catch (e: ServerResponseException) {
COUNT_CALL_TILGANGSKONTROLL_PERSONS_FAIL.increment()
log.error("Error while requesting access to list of person from syfo-tilgangskontroll: ${e.message}", e)
log.error("Error while requesting access to list of person from istilgangskontroll: ${e.message}", e)
return null
}
}
Expand All @@ -76,7 +80,7 @@ class VeilederTilgangskontrollClient(
?: throw RuntimeException("Failed to request preload of list of persons: Failed to get system token")

return try {
val response = httpClient.post(getTilgangskontrollHost(pathPreloadCache)) {
val response = httpClient.post(getTilgangskontrollUrl(pathPreloadCache)) {
header(HttpHeaders.Authorization, bearerHeader(systemToken))
header(NAV_CALL_ID_HEADER, UUID.randomUUID().toString())
accept(ContentType.Application.Json)
Expand All @@ -86,13 +90,13 @@ class VeilederTilgangskontrollClient(
HttpStatusCode.OK == response.status
} catch (e: ClientRequestException) {
if (e.response.status == HttpStatusCode.Forbidden) {
log.warn("Forbidden to request preload of list of person from syfo-tilgangskontroll")
log.warn("Forbidden to request preload of list of person from istilgangskontroll")
} else {
log.error("Error while requesting preload of list of person from syfo-tilgangskontroll: ${e.message}", e)
log.error("Error while requesting preload of list of person from istilgangskontroll: ${e.message}", e)
}
false
} catch (e: ServerResponseException) {
log.error("Error while requesting preload of list of person from syfo-tilgangskontroll: ${e.message}", e)
log.error("Error while requesting preload of list of person from istilgangskontroll: ${e.message}", e)
false
}
}
Expand All @@ -109,7 +113,7 @@ class VeilederTilgangskontrollClient(

try {
val requestTimer: Timer.Sample = Timer.start()
val url = getTilgangskontrollHost("$pathTilgangTilEnhetOBO/$enhet")
val url = getTilgangskontrollUrl("$pathTilgangTilEnhetOBO/$enhet")
val response: HttpResponse = httpClient.get(url) {
header(HttpHeaders.Authorization, bearerHeader(oboToken))
header(NAV_CALL_ID_HEADER, callId)
Expand All @@ -129,7 +133,7 @@ class VeilederTilgangskontrollClient(
}
}

private fun getTilgangskontrollHost(path: String): String {
private fun getTilgangskontrollUrl(path: String): String {
return "${istilgangskontrollEnv.baseUrl}/api/tilgang$path"
}
companion object {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/syfo/metric/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ const val KAFKA_CONSUMER_PDL_PERSONHENDELSE_UPDATES = "${KAFKA_CONSUMER_PDL_PERS
const val KAFKA_CONSUMER_PDL_PERSONHENDELSE_TOMBSTONE = "${KAFKA_CONSUMER_PDL_PERSONHENDELSE_BASE}_tombstone"

val COUNT_CALL_TILGANGSKONTROLL_PERSONS_SUCCESS: Counter = Counter.builder(CALL_TILGANGSKONTROLL_PERSONS_SUCCESS)
.description("Counts the number of successful calls to syfo-tilgangskontroll - persons")
.description("Counts the number of successful calls to tilgangskontroll - persons")
.register(METRICS_REGISTRY)
val COUNT_CALL_TILGANGSKONTROLL_PERSONS_FAIL: Counter = Counter.builder(CALL_TILGANGSKONTROLL_PERSONS_FAIL)
.description("Counts the number of failed calls to syfo-tilgangskontroll - persons")
.description("Counts the number of failed calls to tilgangskontroll - persons")
.register(METRICS_REGISTRY)

val COUNT_PERSONOVERSIKTSTATUS_ENHET_HENTET: Counter = Counter.builder(PERSONOVERSIKTSTATUS_ENHET_HENTET)
Expand Down

0 comments on commit 68e86d8

Please sign in to comment.