Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ module ::DiscoursePrometheus

on(:image_processing_finished) { |payload| image_processing_reporter.report(payload) }

on(:web_worker_timeout) do
metric = DiscoursePrometheus::InternalMetric::Custom.new
metric.type = "Counter"
metric.name = "pitchfork_worker_timeouts_total"
metric.description = "Total number of Pitchfork soft worker timeouts"
metric.value = 1

$prometheus_client.send_json_sync(metric.to_h)
end

register_demon_process(DiscoursePrometheus::CollectorDemon)
register_demon_process(DiscoursePrometheus::GlobalReporterDemon)

Expand Down
22 changes: 22 additions & 0 deletions spec/lib/worker_timeout_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "prometheus_exporter/server"
require_relative "../../lib/collector"

RSpec.describe DiscoursePrometheus do
describe ":web_worker_timeout" do
it "increments the timeout counter through the shared client" do
collector = DiscoursePrometheus::Collector.new
allow($prometheus_client).to receive(:send_json_sync) do |metric|
collector.process(Oj.dump(metric, mode: :object))
end

2.times { DiscourseEvent.trigger(:web_worker_timeout) }

expect(collector.prometheus_metrics_text).to include(
"pitchfork_worker_timeouts_total counter",
"pitchfork_worker_timeouts_total 2",
)
end
end
end
Loading