DEV: attempt to aggressively clear connections

DEV: attempt to aggressively clear connections

There are some strange boot issues that cause connection pool to go funny very hard to repro in dev, putting this patch in place to make sure we always start with a clean connection pool

diff --git a/lib/reporter/global.rb b/lib/reporter/global.rb
index 2040e31..180aba0 100644
--- a/lib/reporter/global.rb
+++ b/lib/reporter/global.rb
@@ -2,17 +2,29 @@
 
 module DiscoursePrometheus::Reporter
   class Global
+    def self.clear_connections!
+      ActiveRecord::Base.connection_handler.clear_active_connections!
+    rescue => e
+      begin
+        Discourse.warn_exception(e, message: "Failed to clear active connections")
+      rescue => e1
+        # never crash this thread
+        STDERR.puts "ERR failed to log warning: #{e1}"
+      end
+    end
 
     def self.start(client)
       global_collector = new
       Thread.new do
+        clear_connections!
         while true
           begin
             metric = global_collector.collect
             client.send_json metric
           rescue => e
-            Rails.logger.warn("Prometheus Discourse Failed To Collect Global Stats #{e}")
+            Discourse.warn_exception(e, message: "Prometheus Discourse Failed To Collect Global Stats")
           ensure
+            clear_connections!
             sleep 5
           end
         end

GitHub sha: 13ec1c27