-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Legger til metric for antall feilede tasks
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
prosessering-core/src/main/kotlin/no/nav/familie/prosessering/metrics/MetricService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package no.nav.tilleggsstonader.soknad.metrics | ||
|
||
import io.micrometer.core.instrument.Metrics | ||
import io.micrometer.core.instrument.MultiGauge | ||
import io.micrometer.core.instrument.Tag | ||
import io.micrometer.core.instrument.Tags | ||
import no.nav.familie.prosessering.config.ProsesseringInfoProvider | ||
import no.nav.familie.prosessering.metrics.TaskMetricRepository | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
internal class MetricService( | ||
private val taskMetricRepository: TaskMetricRepository, | ||
private val prosesseringInfoProvider: ProsesseringInfoProvider, | ||
) { | ||
|
||
private val feiledeTasks = MultiGauge.builder("prosessering_tasks_feilet").register(Metrics.globalRegistry) | ||
|
||
@Scheduled(initialDelay = FREKVENS_30_SEC, fixedDelay = FREKVENS_30_MIN) | ||
fun oppdatertFeiledeTasks() { | ||
if (prosesseringInfoProvider.isLeader() != false) { | ||
val rows = taskMetricRepository.finnAntallFeiledeTasksPerTypeOgStatus().map { | ||
MultiGauge.Row.of(Tags.of(Tag.of("type", it.type), Tag.of("status", it.status.name)), it.count) | ||
} | ||
feiledeTasks.register(rows, true) | ||
} | ||
} | ||
|
||
companion object { | ||
const val FREKVENS_30_SEC = 30 * 1000L | ||
const val FREKVENS_30_MIN = 30 * 60 * 1000L | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...essering-core/src/main/kotlin/no/nav/familie/prosessering/metrics/TaskMetricRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package no.nav.familie.prosessering.metrics | ||
|
||
import no.nav.familie.prosessering.domene.Status | ||
import no.nav.familie.prosessering.domene.Task | ||
import org.springframework.data.jdbc.repository.query.Query | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface TaskMetricRepository : org.springframework.data.repository.Repository<Task, String> { | ||
|
||
@Query( | ||
"""SELECT t.type, t.status, count(t.id) as count FROM task t | ||
WHERE t.status IN ('FEILET', 'MANUELL_OPPFØLGING') | ||
GROUP by t.type, t.status""", | ||
) | ||
fun finnAntallFeiledeTasksPerTypeOgStatus(): List<AntallTaskAvTypeOgStatus> | ||
} | ||
|
||
data class AntallTaskAvTypeOgStatus(val type: String, val status: Status, val count: Long) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ring-core/src/test/kotlin/no/nav/familie/prosessering/metrics/TaskMetricRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package no.nav.familie.prosessering.metrics | ||
|
||
import no.nav.familie.prosessering.IntegrationRunnerTest | ||
import no.nav.familie.prosessering.domene.Status | ||
import no.nav.familie.prosessering.domene.Task | ||
import no.nav.familie.prosessering.internal.TaskService | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class TaskMetricRepositoryTest : IntegrationRunnerTest() { | ||
|
||
@Autowired | ||
lateinit var taskService: TaskService | ||
|
||
@Autowired | ||
lateinit var taskMetricRepository: TaskMetricRepository | ||
|
||
@Test | ||
fun `skal beregne riktig`() { | ||
taskService.save(Task("type", "payload").copy(status = Status.FERDIG)) | ||
taskService.save(Task("type", "payload2").copy(status = Status.FEILET)) | ||
taskService.save(Task("type2", "payload2").copy(status = Status.FEILET)) | ||
taskService.save(Task("type", "payload3").copy(status = Status.MANUELL_OPPFØLGING)) | ||
taskService.save(Task("type", "payload4").copy(status = Status.MANUELL_OPPFØLGING)) | ||
|
||
val expected = listOf( | ||
AntallTaskAvTypeOgStatus("type", Status.FEILET, 1), | ||
AntallTaskAvTypeOgStatus("type2", Status.FEILET, 1), | ||
AntallTaskAvTypeOgStatus("type", Status.MANUELL_OPPFØLGING, 2), | ||
) | ||
assertThat(taskMetricRepository.finnAntallFeiledeTasksPerTypeOgStatus()).containsExactlyInAnyOrderElementsOf(expected) | ||
} | ||
} |