FIX: improve active record support (#161)

FIX: improve active record support (#161)

  • Use released Rails 6.1 for apparisals
  • Soften bundler requements
  • Fix ActiveRecord instrumentation
diff --git a/Appraisals b/Appraisals
index e322ffd..54cc4e5 100644
--- a/Appraisals
+++ b/Appraisals
@@ -6,5 +6,5 @@ appraise "ar-60" do
 end
 
 appraise "ar-61" do
-  gem "activerecord", "~> 6.1.0.rc2"
+  gem "activerecord", "~> 6.1.1"
 end
diff --git a/lib/prometheus_exporter/instrumentation/active_record.rb b/lib/prometheus_exporter/instrumentation/active_record.rb
index 8d4201a..3e49576 100644
--- a/lib/prometheus_exporter/instrumentation/active_record.rb
+++ b/lib/prometheus_exporter/instrumentation/active_record.rb
@@ -81,15 +81,13 @@ module PrometheusExporter::Instrumentation
     private
 
     def labels(pool)
-      if pool.respond_to?(:spec) # ActiveRecord <= 6.0
+      if ::ActiveRecord.version < Gem::Version.new("6.1.0.rc1")
         @metric_labels.merge(pool_name: pool.spec.name).merge(pool.spec.config
           .select { |k, v| @config_labels.include? k }
           .map { |k, v| [k.to_s.dup.prepend("dbconfig_"), v] }.to_h)
-      elsif pool.respond_to?(:db_config) # ActiveRecord >= 6.1.rc1
+      else
         @metric_labels.merge(pool_name: pool.db_config.name).merge(
           @config_labels.each_with_object({}) { |l, acc| acc["dbconfig_#{l}"] = pool.db_config.public_send(l) })
-      else
-        raise "Unsupported connection pool"
       end
     end
   end
diff --git a/prometheus_exporter.gemspec b/prometheus_exporter.gemspec
index f85f1bd..1537e6f 100644
--- a/prometheus_exporter.gemspec
+++ b/prometheus_exporter.gemspec
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
   spec.add_dependency "webrick"
 
   spec.add_development_dependency "rubocop", ">= 0.69"
-  spec.add_development_dependency "bundler", ">= 2.2.2"
+  spec.add_development_dependency "bundler", ">= 2.1.4"
   spec.add_development_dependency "rake", "~> 13.0"
   spec.add_development_dependency "minitest", "~> 5.0"
   spec.add_development_dependency "guard", "~> 2.0"

GitHub sha: e9511e40

This commit appears in #161 which was merged by SamSaffron.