Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vil legge til statusendepunkt for at statusplattform skal kunne hente… #1102

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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(val søknadRepository: 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