Skip to content

Commit

Permalink
Lengre timeout på kall fra behandling til brev-api for forhåndsvisnin…
Browse files Browse the repository at this point in the history
…g. (#7150)

* Lengre timeout på kall fra behandling til brev-api for forhåndsvisning.

* Fjerner timeout som vi ikke skulle ha med.

* Installerer plugin for å sette timeout på httpClient.
  • Loading branch information
tvsignal authored Feb 27, 2025
1 parent a8fa479 commit ca3735a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.michaelbull.result.mapBoth
import com.github.michaelbull.result.mapError
import com.typesafe.config.Config
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpTimeout
import no.nav.etterlatte.behandling.objectMapper
import no.nav.etterlatte.brev.BrevParametre
import no.nav.etterlatte.brev.BrevPayload
Expand All @@ -27,6 +28,7 @@ import no.nav.etterlatte.libs.ktor.ktor.ktorobo.DownstreamResourceClient
import no.nav.etterlatte.libs.ktor.ktor.ktorobo.Resource
import no.nav.etterlatte.libs.ktor.route.SAKID_CALL_PARAMETER
import no.nav.etterlatte.libs.ktor.token.BrukerTokenInfo
import java.time.Duration
import java.util.UUID

interface BrevApiKlient {
Expand Down Expand Up @@ -372,6 +374,10 @@ class BrevApiKlientObo(
?: throw InternfeilException("Feil ved generering av pdf vedtaksbrev")
},
brukerTokenInfo = brukerTokenInfo,
timeoutConfig = {
socketTimeoutMillis = Duration.ofSeconds(30).toMillis()
requestTimeoutMillis = Duration.ofSeconds(30).toMillis()
},
)

override suspend fun tilbakestillVedtaksbrev(
Expand Down Expand Up @@ -416,11 +422,13 @@ class BrevApiKlientObo(
url: String,
onSuccess: (Resource) -> T,
brukerTokenInfo: BrukerTokenInfo,
timeoutConfig: (HttpTimeout.HttpTimeoutCapabilityConfiguration.() -> Unit)? = null,
): T =
downstreamResourceClient
.get(
resource = Resource(clientId = clientId, url = url),
brukerTokenInfo = brukerTokenInfo,
timeoutConfig = timeoutConfig,
).mapBoth(
success = onSuccess,
failure = { throwableErrorMessage -> throw throwableErrorMessage },
Expand Down
2 changes: 2 additions & 0 deletions libs/etterlatte-ktor/src/main/kotlin/HttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.engine.okhttp.OkHttpConfig
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
Expand Down Expand Up @@ -59,6 +60,7 @@ fun httpClient(
ekstraJacksoninnstillinger(objectMapper)
}
install(ClientCallLogging)
install(HttpTimeout)

auth.invoke(this)
defaultRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.andThen
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.timeout
import io.ktor.client.request.accept
import io.ktor.client.request.bearerAuth
import io.ktor.client.request.delete
Expand Down Expand Up @@ -33,9 +35,16 @@ class DownstreamResourceClient(
suspend fun get(
resource: Resource,
brukerTokenInfo: BrukerTokenInfo,
timeoutConfig: (HttpTimeout.HttpTimeoutCapabilityConfiguration.() -> Unit)? = null,
) = medToken(resource, brukerTokenInfo) { token ->
httpClient.get(resource.url) {
bearerAuth(token.accessToken)
timeoutConfig?.let { config ->
timeout {
apply(config)
}
}

resource.additionalHeaders?.forEach { headers.append(it.key, it.value) }
}
}
Expand Down

0 comments on commit ca3735a

Please sign in to comment.