From 707e97a10c69b4931ceffbf4becaa293752d651c Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Wed, 30 Oct 2024 13:23:02 -0500 Subject: [PATCH] fix: Set lower log level for health check ChatRooms. --- .../main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt | 11 ++++++----- .../kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomImpl.kt | 3 +++ .../jicofo/conference/JitsiMeetConferenceImpl.java | 4 ++-- .../test/kotlin/org/jitsi/jicofo/DebugStateTest.kt | 3 ++- .../kotlin/org/jitsi/jicofo/mock/MockXmppProvider.kt | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt index 532c98135b..f5fc5a040d 100644 --- a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt +++ b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/XmppProvider.kt @@ -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) { @@ -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 { if (!xmppConnection.isConnected) { @@ -333,21 +334,21 @@ private class Muc(val xmppProvider: XmppProvider) { private val rooms: MutableMap = 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.") } diff --git a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomImpl.kt b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomImpl.kt index 5f361cd414..7a30d510c7 100644 --- a/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomImpl.kt +++ b/jicofo-common/src/main/kotlin/org/jitsi/jicofo/xmpp/muc/ChatRoomImpl.kt @@ -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"], @@ -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()) } diff --git a/jicofo/src/main/java/org/jitsi/jicofo/conference/JitsiMeetConferenceImpl.java b/jicofo/src/main/java/org/jitsi/jicofo/conference/JitsiMeetConferenceImpl.java index d4e1503354..536fac83d6 100644 --- a/jicofo/src/main/java/org/jitsi/jicofo/conference/JitsiMeetConferenceImpl.java +++ b/jicofo/src/main/java/org/jitsi/jicofo/conference/JitsiMeetConferenceImpl.java @@ -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); @@ -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)); diff --git a/jicofo/src/test/kotlin/org/jitsi/jicofo/DebugStateTest.kt b/jicofo/src/test/kotlin/org/jitsi/jicofo/DebugStateTest.kt index ed869a9798..3bfcc2c933 100644 --- a/jicofo/src/test/kotlin/org/jitsi/jicofo/DebugStateTest.kt +++ b/jicofo/src/test/kotlin/org/jitsi/jicofo/DebugStateTest.kt @@ -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. @@ -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( diff --git a/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/MockXmppProvider.kt b/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/MockXmppProvider.kt index af85365acd..36ea13953d 100644 --- a/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/MockXmppProvider.kt +++ b/jicofo/src/test/kotlin/org/jitsi/jicofo/mock/MockXmppProvider.kt @@ -25,7 +25,7 @@ class MockXmppProvider(val xmppConnection: AbstractXMPPConnection = MockXmppConn val chatRooms = mutableMapOf() val xmppProvider = mockk(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 }