mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 03:05:45 +08:00
No more of these ``` E, [2026-04-13T13:40:33.862133 #2069] ERROR -- : Prometheus Exporter, failed to send message Connection refused - connect(2) for "localhost" port 9405 ```
30 lines
1.1 KiB
Ruby
Vendored
30 lines
1.1 KiB
Ruby
Vendored
# 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) unless Rails.env.test? # rubocop:disable Style/GlobalVars
|
|
end
|
|
end
|
|
end
|
|
end
|