Skip to content

Commit 119aac3

Browse files
committed
better monitor mod actions and reports closed
to move charts from lichess to grafana
1 parent ad5c055 commit 119aac3

4 files changed

Lines changed: 20 additions & 19 deletions

File tree

modules/mod/src/main/AssessApi.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ final class AssessApi(
150150
.getTitle(userId)
151151
.flatMap:
152152
case None =>
153-
modApi
154-
.autoMark(
155-
SuspectId(userId),
156-
playerAggregateAssessment.reportText(3)
157-
)(using UserId.lichessAsMe)
153+
modApi.autoMark(
154+
SuspectId(userId),
155+
playerAggregateAssessment.reportText(3)
156+
)(using UserId.lichessAsMe)
158157
case Some(_) =>
159158
reportApi.autoCheatReport(userId, playerAggregateAssessment.reportText(3))
160159
case AccountAction.Report(_) =>

modules/mod/src/main/ModlogApi.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ final class ModlogApi(repo: ModlogRepo, userRepo: UserRepo, ircApi: IrcApi, pres
403403
case u => u
404404

405405
private def add(m: Modlog): Funit =
406-
lila.mon.mod.log.create.increment()
406+
lila.mon.mod.log.create(m.mod.userId, m.action).increment()
407407
lila.log("mod").info(m.toString)
408408
m.notable.so:
409409
coll.insert.one {
410410
bsonWriteObjTry[Modlog](m).get ++ (!m.isLichess).so($doc("human" -> true))
411-
} >> (m.notableZulip.so(zulipMonitor(m)))
411+
} >> m.notableZulip.so(zulipMonitor(m))
412412

413413
private def zulipMonitor(m: Modlog): Funit =
414414
import lila.mod.Modlog as M

modules/mon/src/main/mon.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ object actor:
258258
object mod:
259259
object report:
260260
val highest = gauge("mod.report.highest").withoutTags()
261-
val close = counter("mod.report.close").withoutTags()
261+
def close(mod: UserId, room: String) = counter("mod.report.close").withTags:
262+
tags("mod" -> mod, "room" -> room)
262263
def create(reason: String, score: Int) =
263264
counter("mod.report.create").withTags:
264265
tags("reason" -> reason, "score" -> score)
@@ -268,7 +269,8 @@ object mod:
268269
val imageRequest = future("mod.report.automod.image.request")
269270
def imageFlagged(v: Boolean) = counter("mod.report.automod.image.flagged").withTag("flagged", v)
270271
object log:
271-
val create = counter("mod.log.create").withoutTags()
272+
def create(mod: UserId, action: String) = counter("mod.log.create").withTags:
273+
tags("mod" -> mod, "action" -> action)
272274
object irwin:
273275
val report = counter("mod.report.irwin.report").withoutTags()
274276
val mark = counter("mod.report.irwin.mark").withoutTags()

modules/report/src/main/ReportApi.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,16 @@ final class ReportApi(
314314
deletedAppeal <- deleteIfAppealInquiry(report)
315315
_ <- (!deletedAppeal).so:
316316
doProcessReport($id(report.id), unsetInquiry = true)
317-
yield onReportClose()
317+
yield onReportClose(report.room)
318318

319319
def autoProcess(sus: Suspect, rooms: Set[Room])(using MyId): Funit =
320-
val selector = $doc(
321-
"user" -> sus.user.id,
322-
"room".$in(rooms),
323-
"open" -> true
324-
)
325-
for _ <- doProcessReport(selector, unsetInquiry = true)
326-
yield onReportClose()
320+
val selector = $doc("user" -> sus.user.id, "room".$in(rooms), "open" -> true)
321+
for
322+
reports <- coll.list[Report](selector)
323+
_ <- reports.sequentiallyVoid: report =>
324+
onReportClose(report.room)
325+
doProcessReport($id(report.id), unsetInquiry = true)
326+
yield ()
327327

328328
def automodComms(
329329
userText: String,
@@ -373,9 +373,9 @@ final class ReportApi(
373373
logger.warn(s"Comms automod failed for ${me.username} on $url: ${e.getMessage}", e)
374374
funit
375375

376-
private def onReportClose() =
376+
private def onReportClose(room: Room)(using me: MyId) =
377377
maxScoreCache.invalidateUnit()
378-
lila.mon.mod.report.close.increment()
378+
lila.mon.mod.report.close(me, room.key).increment()
379379

380380
private def deleteIfAppealInquiry(report: Report)(using me: MyId): Fu[Boolean] =
381381
if report.isAppealInquiryByMe

0 commit comments

Comments
 (0)