Skip to content

Commit

Permalink
Monitor for exceptions and dropped events (#23)
Browse files Browse the repository at this point in the history
* fix: Log exceptions from the queue (e.g. from jebml).

* Add metrics and assert no exceptions or dropped events during tests.
  • Loading branch information
bgrozev authored Dec 17, 2024
1 parent 5c16366 commit 1b50721
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/kotlin/org/jitsi/recorder/MediaJsonMkaRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.jitsi.recorder.opus.GapTooLargeException
import org.jitsi.recorder.opus.OpusPacket
import org.jitsi.recorder.opus.PacketLossConcealmentInserter
import org.jitsi.utils.logging2.Logger
import org.jitsi.utils.queue.ErrorHandler
import org.jitsi.utils.queue.PacketQueue
import java.io.File
import java.time.Clock
Expand All @@ -43,6 +44,17 @@ class MediaJsonMkaRecorder(directory: File, parentLogger: Logger) : MediaJsonRec
val queue = EventQueue {
handleEvent(it)
true
}.also {
it.setErrorHandler(object : ErrorHandler {
override fun packetDropped() {
logger.warn("Dropped an event.")
RecorderMetrics.instance.queueEventsDropped.inc()
}
override fun packetHandlingFailed(t: Throwable) {
logger.error("Error handling event: ", t)
RecorderMetrics.instance.queueExceptions.inc()
}
})
}
private val trackRecorders = mutableMapOf<String, TrackRecorder>()

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/jitsi/recorder/RecorderMetrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class RecorderMetrics private constructor() : MetricsContainer(namespace = "jits
"plc_milliseconds",
"Duration of recorded packet concealment packets in milliseconds"
)
val queueEventsDropped = registerCounter("queue_events_dropped", "Number of events dropped")
val queueExceptions = registerCounter("queue_exceptions", "Number of exceptions from the event queue")

companion object {
/**
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/org/jitsi/recorder/KotestProjectConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.jitsi.recorder

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.matchers.shouldBe
import org.jitsi.metaconfig.MetaconfigSettings

class KotestProjectConfig : AbstractProjectConfig() {
Expand All @@ -26,4 +27,8 @@ class KotestProjectConfig : AbstractProjectConfig() {
// freely modify the config without affecting other tests executing afterwards).
MetaconfigSettings.cacheEnabled = false
}
override suspend fun afterProject() = super.afterProject().also {
RecorderMetrics.instance.queueExceptions.get() shouldBe 0
RecorderMetrics.instance.queueEventsDropped.get() shouldBe 0
}
}

0 comments on commit 1b50721

Please sign in to comment.