better monitor PMs sent

pull/8200/head
Thibault Duplessis 2021-02-17 17:08:07 +01:00
parent 77dbf8a845
commit 822054e36b
4 changed files with 16 additions and 5 deletions

View File

@ -178,8 +178,14 @@ final class Clas(
Reasonable(clas, students, "notify") {
val url = routes.Clas.show(clas.id.value).url
val full = if (text contains url) text else s"$text\n\n${env.net.baseUrl}$url"
env.msg.api.multiPost(me, Source(students.map(_.user.id)), full) inject
Redirect(routes.Clas.show(clas.id.value)).flashSuccess
env.msg.api
.multiPost(me, Source(students.map(_.user.id)), full)
.addEffect { nb =>
lila.mon.msg.clasBulk(clas.id.value).record(nb).unit
}
.inject {
Redirect(routes.Clas.show(clas.id.value)).flashSuccess
}
}
}
)

View File

@ -516,7 +516,7 @@ You received this because you are subscribed to messages of the team $url."""
env.msg.api
.multiPost(me, env.team.memberStream.subscribedIds(team, MaxPerSecond(50)), full)
.addEffect { nb =>
lila.mon.team.massPm(team.id).record(nb).unit
lila.mon.msg.teamBulk(team.id).record(nb).unit
}
funit // we don't wait for the stream to complete, it would make lichess time out
}(funit)

View File

@ -420,8 +420,12 @@ object mon {
}
def reaction(r: String) = counter("forum.reaction").withTag("reaction", r)
}
object team {
def massPm(teamId: String) = histogram("team.mass-pm").withTag("from", teamId)
object msg {
def post(verdict: String, isNew: Boolean, multi: Boolean) = counter("msg.post").withTags(
Map("verdict" -> verdict, "isNew" -> isNew, "multi" -> multi)
)
def teamBulk(teamId: String) = histogram("msg.bulk.team").withTag("id", teamId)
def clasBulk(clasId: String) = histogram("msg.bulk.clas").withTag("id", clasId)
}
object puzzle {
object selector {

View File

@ -86,6 +86,7 @@ final class MsgApi(
contacts <- userRepo.contacts(orig, dest) orFail s"Missing convo contact user $orig->$dest"
isNew <- !colls.thread.exists($id(threadId))
verdict <- security.can.post(contacts, msgPre.text, isNew, unlimited = multi)
_ = lila.mon.msg.post(verdict.toString, isNew = isNew, multi = multi).increment()
res <- verdict match {
case MsgSecurity.Limit => fuccess(PostResult.Limited)
case _: MsgSecurity.Reject => fuccess(PostResult.Bounced)