Skip to content

Commit

Permalink
Merge pull request #224 from nextcloud/fix/metrics-with-rooms
Browse files Browse the repository at this point in the history
fix: Properly handle metrics aggregation with room data
  • Loading branch information
grnd-alt authored Oct 14, 2024
2 parents 6862a67 + 917111a commit beb1b08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion websocket_server/LRUCacheStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import StorageStrategy from './StorageStrategy.js'
import { LRUCache } from 'lru-cache'
import Room from './Room.js'

export default class LRUCacheStrategy extends StorageStrategy {

Expand Down Expand Up @@ -52,7 +53,9 @@ export default class LRUCacheStrategy extends StorageStrategy {
}

getRooms() {
return this.cache
const rooms = Array.from(this.cache.values()).filter((room) => room instanceof Room)

return rooms
}

}
2 changes: 1 addition & 1 deletion websocket_server/RedisStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class RedisStrategy extends StorageStrategy {
const rooms = new Map()
for (const key of keys) {
const room = await this.get(key)
if (room) rooms.set(key, room)
if (room && !key.startsWith('token:') && !key.startsWith('socket:')) rooms.set(key, room)
}
return rooms
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions websocket_server/SystemMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export default class SystemMonitor {
getRoomStats(rooms) {
return {
activeRooms: rooms.size,
totalUsers: Array.from(rooms.values()).reduce((sum, room) => sum + Object.keys(room.users).length, 0),
totalUsers: Array.from(rooms.values()).reduce((sum, room) => sum + Object.keys(room?.users ?? {}).length, 0),
totalDataSize: this.formatBytes(Array.from(rooms.values()).reduce((sum, room) => sum + (room.data ? JSON.stringify(room.data).length : 0), 0)),
}
}

getRoomsData(rooms) {
return Array.from(rooms.entries()).map(([roomId, room]) => ({
id: roomId,
return Array.from(rooms).map((room) => ({
id: room.id,
users: Object.keys(room.users),
lastEditedUser: room.lastEditedUser,
lastActivity: new Date(room.lastActivity).toISOString(),
lastActivity: room.lastActivity ? new Date(room.lastActivity).toISOString() : null,
dataSize: this.formatBytes(JSON.stringify(room.data).length),
data: room.data, // Be cautious with this if the data is very large
}))
Expand Down

0 comments on commit beb1b08

Please sign in to comment.