diff --git a/plugin.rb b/plugin.rb index 5191655..942f104 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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) diff --git a/spec/lib/worker_timeout_spec.rb b/spec/lib/worker_timeout_spec.rb new file mode 100644 index 0000000..fc8d9dc --- /dev/null +++ b/spec/lib/worker_timeout_spec.rb @@ -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