Skip to content

Commit

Permalink
fix: Set lower log level for health check ChatRooms. (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev authored Oct 30, 2024
1 parent d37bb3a commit bf90415
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.jxmpp.jid.EntityBareJid
import org.jxmpp.jid.EntityFullJid
import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.atomic.AtomicBoolean
import java.util.logging.Level

/** Wraps a Smack [XMPPConnection]. */
class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {
Expand Down Expand Up @@ -221,7 +222,7 @@ class XmppProvider(val config: XmppConnectionConfig, parentLogger: Logger) {

@Throws(RoomExistsException::class)
fun createRoom(name: EntityBareJid): ChatRoom = muc.createChatRoom(name)
fun findOrCreateRoom(name: EntityBareJid): ChatRoom = muc.findOrCreateRoom(name)
fun findOrCreateRoom(name: EntityBareJid, logLevel: Level): ChatRoom = muc.findOrCreateRoom(name, logLevel)

fun discoverFeatures(jid: EntityFullJid): Set<Features> {
if (!xmppConnection.isConnected) {
Expand Down Expand Up @@ -333,21 +334,21 @@ private class Muc(val xmppProvider: XmppProvider) {
private val rooms: MutableMap<EntityBareJid, ChatRoomImpl> = HashMap()

@Throws(RoomExistsException::class)
fun createChatRoom(roomJid: EntityBareJid): ChatRoom {
fun createChatRoom(roomJid: EntityBareJid, logLevel: Level = Level.ALL): ChatRoom {
synchronized(rooms) {
if (rooms.containsKey(roomJid)) {
throw RoomExistsException("Room '$roomJid' exists")
}
return ChatRoomImpl(xmppProvider, roomJid) { removeRoom(it) }.also {
return ChatRoomImpl(xmppProvider, roomJid, logLevel) { removeRoom(it) }.also {
rooms[roomJid] = it
}
}
}

fun findOrCreateRoom(roomJid: EntityBareJid): ChatRoom {
fun findOrCreateRoom(roomJid: EntityBareJid, logLevel: Level = Level.ALL): ChatRoom {
synchronized(rooms) {
try {
return rooms[roomJid] ?: createChatRoom(roomJid)
return rooms[roomJid] ?: createChatRoom(roomJid, logLevel)
} catch (e: RoomExistsException) {
throw RuntimeException("Unexpected RoomExistsException.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.jxmpp.jid.Jid
import org.jxmpp.jid.impl.JidCreate
import org.jxmpp.jid.parts.Resourcepart
import java.util.concurrent.ConcurrentHashMap
import java.util.logging.Level

@SuppressFBWarnings(
value = ["JLM_JSR166_UTILCONCURRENT_MONITORENTER"],
Expand All @@ -67,10 +68,12 @@ import java.util.concurrent.ConcurrentHashMap
class ChatRoomImpl(
override val xmppProvider: XmppProvider,
override val roomJid: EntityBareJid,
logLevel: Level,
/** Callback to call when the room is left. */
private val leaveCallback: (ChatRoomImpl) -> Unit
) : ChatRoom, PresenceListener {
private val logger = createLogger().apply {
level = logLevel
addContext("room", roomJid.toString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private void joinTheRoom()
{
logger.info("Joining " + roomName);

ChatRoom chatRoom = getClientXmppProvider().findOrCreateRoom(roomName);
ChatRoom chatRoom = getClientXmppProvider().findOrCreateRoom(roomName, logger.getLevel());
this.chatRoom = chatRoom;
chatRoom.addListener(chatRoomListener);

Expand Down Expand Up @@ -1875,7 +1875,7 @@ private String selectVisitorNode()
xmppProvider);

// Will call join after releasing the lock
chatRoomToJoin = xmppProvider.findOrCreateRoom(visitorMucJid);
chatRoomToJoin = xmppProvider.findOrCreateRoom(visitorMucJid, logger.getLevel());

chatRoomToJoin.addListener(new VisitorChatRoomListenerImpl(chatRoomToJoin));

Expand Down
3 changes: 2 additions & 1 deletion jicofo/src/test/kotlin/org/jitsi/jicofo/DebugStateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.jitsi.xmpp.extensions.colibri.ColibriStatsExtension
import org.json.simple.parser.JSONParser
import org.jxmpp.jid.EntityFullJid
import org.jxmpp.jid.impl.JidCreate
import java.util.logging.Level

/**
* All debugState interfaces should produce valid JSON.
Expand All @@ -50,7 +51,7 @@ class DebugStateTest : ShouldSpec() {
context("ChatRoomImpl and members") {
val conferenceJid = JidCreate.entityBareFrom("conference@example.com")

val chatRoom = ChatRoomImpl(mockk(relaxed = true), conferenceJid) { }
val chatRoom = ChatRoomImpl(mockk(relaxed = true), conferenceJid, Level.INFO) { }
chatRoom.debugState.shouldBeValidJson()

val member = ChatRoomMemberImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MockXmppProvider(val xmppConnection: AbstractXMPPConnection = MockXmppConn
val chatRooms = mutableMapOf<EntityBareJid, MockChatRoom>()
val xmppProvider = mockk<XmppProvider>(relaxed = true) {
every { registered } returns true
every { findOrCreateRoom(any()) } answers { getRoom(arg(0)).chatRoom }
every { findOrCreateRoom(any(), any()) } answers { getRoom(arg(0)).chatRoom }
every { xmppConnection } returns this@MockXmppProvider.xmppConnection
}

Expand Down

0 comments on commit bf90415

Please sign in to comment.