Skip to content

Commit

Permalink
La til error ID i feilhåndtering, benytte IP i query-oppsett i bekref…
Browse files Browse the repository at this point in the history
…telse-api
  • Loading branch information
naviktthomas committed Oct 4, 2024
1 parent 62c5b91 commit 7b666d9
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apps/bekreftelse-api/nais/nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ spec:
image: {{ image }}
port: 8080
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KAFKA_STREAMS_ID_SUFFIX
value: "v2"
- name: KAFKA_PAW_ARBEIDSSOKER_BEKREFTELSE_TOPIC
Expand Down
4 changes: 4 additions & 0 deletions apps/bekreftelse-api/nais/nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ spec:
image: {{ image }}
port: 8080
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KAFKA_STREAMS_ID_SUFFIX
value: "v1"
- name: KAFKA_PAW_ARBEIDSSOKER_BEKREFTELSE_TOPIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ fun main() {
val applicationContext = ApplicationContext.create()
val appName = applicationContext.serverConfig.runtimeEnvironment.appNameOrDefaultForLocal()

logger.info("Starter: $appName")

with(applicationContext.serverConfig) {
logger.info("Starter $appName med IP $ip og port $port")

embeddedServer(Netty, port = port) {
module(applicationContext)
}.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import no.nav.paw.config.env.currentRuntimeEnvironment
const val SERVER_CONFIG_FILE_NAME = "server_config.toml"

data class ServerConfig(
val port: Int,
val ip: String,
val host: String,
val port: Int,
val callGroupSize: Int,
val workerGroupSize: Int,
val connectionGroupSize: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fun buildKafkaStreams(
)
.withDefaultKeySerde(Serdes.Long()::class)
.withDefaultValueSerde(SpecificAvroSerde::class)
.withServerConfig(serverConfig.host, serverConfig.port)
.withServerConfig(serverConfig.ip, serverConfig.port)

val kafkaStreams = KafkaStreams(
topology,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
port = 8080
ip = "127.0.0.1"
host = "localhost"
port = 8080
callGroupSize = 16
workerGroupSize = 8
connectionGroupSize = 8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ip = "${POD_IP}"
host = "${HOSTNAME}"
port = 8080
host = "${OTEL_POD_IP}"
callGroupSize = 16
workerGroupSize = 8
connectionGroupSize = 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import no.nav.paw.error.model.build500Error
import no.nav.paw.error.model.buildError
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.slf4j.MDC

private val logger: Logger = LoggerFactory.getLogger("no.nav.paw.logger.error.http")

suspend fun ApplicationCall.handleException(throwable: Throwable) {
val problemDetails = resolveProblemDetails(request, throwable)
MDC.put("x_error_id", problemDetails.id.toString())
MDC.put("x_error_code", problemDetails.code)
logger.error(problemDetails.detail, throwable)
respond(problemDetails.status, problemDetails)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize
import io.ktor.http.HttpStatusCode
import no.nav.paw.error.serialize.HttpStatusCodeDeserializer
import no.nav.paw.error.serialize.HttpStatusCodeSerializer
import java.util.*

/**
* Object som inneholder detaljer om en oppstått feilsituasjon, basert på RFC 9457.
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9457">IETF RFC 9457</a>
*/
data class ProblemDetails(
val id: UUID = UUID.randomUUID(),
val code: String, // Maskinelt lesbar feilkode
val title: String,
@JsonSerialize(using = HttpStatusCodeSerializer::class) @JsonDeserialize(using = HttpStatusCodeDeserializer::class) val status: HttpStatusCode,
Expand Down

0 comments on commit 7b666d9

Please sign in to comment.