generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathspam_metric.rb
30 lines (26 loc) · 1.01 KB
/
spam_metric.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true
module DiscourseAi
module AiModeration
class SpamMetric
def self.update(new_status, reviewable)
return if !defined?(::DiscoursePrometheus)
ai_spam_log = AiSpamLog.find_by(reviewable:)
return if ai_spam_log.nil?
increment("scanned")
increment("is_spam") if new_status == :approved && ai_spam_log.is_spam
increment("false_positive") if new_status == :rejected && ai_spam_log.is_spam
increment("false_negative") if new_status == :rejected && !ai_spam_log.is_spam
end
private
def self.increment(type, value = 1)
metric = ::DiscoursePrometheus::InternalMetric::Custom.new
metric.name = "discourse_ai_spam_detection"
metric.type = "Counter"
metric.description = "AI spam scanning statistics"
metric.labels = { db: RailsMultisite::ConnectionManagement.current_db, type: }
metric.value = value
$prometheus_client.send_json(metric.to_h)
end
end
end
end