Skip to content

Commit

Permalink
Vil legge til statusendepunkt for at statusplattform skal kunne hente… (
Browse files Browse the repository at this point in the history
#1102)

* Vil legge til statusendepunkt for at statusplattform skal kunne hente info om mottak.

* Vil skille mellom gul og rød status og skrive forståelige statusmeldinger.
  • Loading branch information
ma10s authored Feb 9, 2024
1 parent ef14987 commit 51a6b77
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .deploy/nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ spec:
- application: familie-prosessering
namespace: teamfamilie
cluster: dev-gcp
- application: statuspoll
namespace: navdig
outbound:
rules:
- application: familie-ef-maler
Expand Down
2 changes: 2 additions & 0 deletions .deploy/nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ spec:
- application: familie-prosessering
namespace: teamfamilie
cluster: prod-gcp
- application: statuspoll
namespace: navdig
outbound:
rules:
- application: familie-ef-maler
Expand Down
70 changes: 70 additions & 0 deletions src/main/kotlin/no/nav/familie/ef/mottak/api/StatusController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package no.nav.familie.ef.mottak.api

import no.nav.familie.ef.mottak.repository.SøknadRepository
import no.nav.security.token.support.core.api.Unprotected
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.time.Duration
import java.time.LocalDateTime

@RestController
@RequestMapping(path = ["/api/status"], produces = [MediaType.APPLICATION_JSON_VALUE])
class StatusController(valknadRepository: SøknadRepository) {

@GetMapping()
@Unprotected
fun status(): StatusDto {
val søknad = søknadRepository.finnSisteLagredeSøknad()
val tidSidenSisteLagredeSøknad = Duration.between(LocalDateTime.now(), søknad.opprettetTid)

when {
erNatt() -> {
return StatusDto(status = Plattformstatus.OK, description = "Alt er bra", logLink = null)
}

tidSidenSisteLagredeSøknad.toHours() > 24 -> {
return StatusDto(
status = Plattformstatus.DOWN,
description = "Det er over 24 timer siden vi mottok en søknad",
)
}

tidSidenSisteLagredeSøknad.toHours() > 5 -> {
return StatusDto(
status = Plattformstatus.ISSUE,
description = "Det er over 5 timer siden vi mottok en søknad",
)
}

tidSidenSisteLagredeSøknad.toHours() > 1 -> {
return StatusDto(
status = Plattformstatus.ISSUE,
description = "Det er over 1 time siden vi mottok en søknad",
)
}

tidSidenSisteLagredeSøknad.toMinutes() > 20 -> {
return StatusDto(
status = Plattformstatus.ISSUE,
description = "Det er over 20 minutter siden siste søknad ble mottatt",
)
}

else -> {
return StatusDto(status = Plattformstatus.OK, description = "Alt er bra", logLink = null)
}
}
}
}

const val LOG_URL = "https://logs.adeo.no/app/discover#/view/a3e93b80-c1a5-11ee-a029-75a0ed43c092?_g=()"

data class StatusDto(val status: Plattformstatus, val description: String? = null, val logLink: String? = LOG_URL)

enum class Plattformstatus {
OK, ISSUE, DOWN
}

fun erNatt() = LocalDateTime.now().hour !in 8..21
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ interface SøknadRepository :
)
fun finnSisteSøknadenPerStønadtype(fnr: String): List<Søknad>

@Query(
"""
SELECT * FROM soknad ORDER BY opprettet_tid DESC LIMIT 1
""",
)
fun finnSisteLagredeSøknad(): Søknad

@Query(
"""
SELECT * FROM soknad WHERE fnr=:fnr AND dokumenttype=:stønadstype ORDER BY opprettet_tid DESC LIMIT 1
Expand Down

0 comments on commit 51a6b77

Please sign in to comment.