Skip to content

Commit d9b9912

Browse files
committed
fix: Initialize Prometheus healthy/recording metrics with current status
The `jitsi_jibri_healthy` and `jitsi_jibri_recording` Prometheus gauges default to 0 and only update on status transitions via publishStatus(). Since Jibri starts healthy with no transition, the metrics remain at 0 even though the instance is healthy. Seed the metrics with the current status immediately after registering the status handler so they reflect the actual state from startup. Fixes #590
1 parent 5522961 commit d9b9912

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/main/kotlin/org/jitsi/jibri/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fun main(args: Array<String>) {
8181
jibriStatusManager.addStatusHandler {
8282
jibriManager.jibriMetrics.updateStatus(it)
8383
}
84+
jibriManager.jibriMetrics.updateStatus(jibriStatusManager.overallStatus)
8485
webhookSubscribers.forEach(webhookClient::addSubscriber)
8586
val statusUpdaterTask = TaskPools.recurringTasksPool.scheduleAtFixedRate(
8687
1,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright @ 2024-Present 8x8, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package org.jitsi.jibri.metrics
18+
19+
import io.kotest.core.spec.style.ShouldSpec
20+
import io.kotest.matchers.shouldBe
21+
import org.jitsi.jibri.status.ComponentBusyStatus
22+
import org.jitsi.jibri.status.ComponentHealthStatus
23+
import org.jitsi.jibri.status.JibriStatus
24+
import org.jitsi.jibri.status.JibriStatusManager
25+
import org.jitsi.jibri.status.OverallHealth
26+
27+
class JibriMetricsTest : ShouldSpec({
28+
context("Prometheus healthy metric") {
29+
should("reflect healthy status when seeded with initial state") {
30+
val metrics = JibriMetrics()
31+
val statusManager = JibriStatusManager()
32+
33+
// Register handler (like Main.kt does)
34+
statusManager.addStatusHandler {
35+
metrics.updateStatus(it)
36+
}
37+
38+
// Without the fix, healthy stays at 0.0 because no status
39+
// transition has occurred. With the fix, we seed the initial state:
40+
metrics.updateStatus(statusManager.overallStatus)
41+
42+
JibriMetrics.healthy.get() shouldBe true
43+
JibriMetrics.recording.get() shouldBe false
44+
}
45+
46+
should("report 0 when unhealthy") {
47+
val metrics = JibriMetrics()
48+
val status = JibriStatus(
49+
busyStatus = ComponentBusyStatus.IDLE,
50+
health = OverallHealth(
51+
healthStatus = ComponentHealthStatus.UNHEALTHY,
52+
details = emptyMap()
53+
)
54+
)
55+
metrics.updateStatus(status)
56+
57+
JibriMetrics.healthy.get() shouldBe false
58+
}
59+
60+
should("report recording=1 when busy") {
61+
val metrics = JibriMetrics()
62+
val status = JibriStatus(
63+
busyStatus = ComponentBusyStatus.BUSY,
64+
health = OverallHealth(
65+
healthStatus = ComponentHealthStatus.HEALTHY,
66+
details = emptyMap()
67+
)
68+
)
69+
metrics.updateStatus(status)
70+
71+
JibriMetrics.healthy.get() shouldBe true
72+
JibriMetrics.recording.get() shouldBe true
73+
}
74+
}
75+
})

0 commit comments

Comments
 (0)