Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/instrumentation/connection_pool.rb')
-rw-r--r--lib/gitlab/instrumentation/connection_pool.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/instrumentation/connection_pool.rb b/lib/gitlab/instrumentation/connection_pool.rb
new file mode 100644
index 00000000000..76e6af34054
--- /dev/null
+++ b/lib/gitlab/instrumentation/connection_pool.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Instrumentation
+ # rubocop:disable Gitlab/ModuleWithInstanceVariables -- this module patches ConnectionPool to instrument it
+ module ConnectionPool
+ def initialize(options = {}, &block)
+ @name = options.fetch(:name, 'unknown')
+
+ super
+ end
+
+ def checkout(options = {})
+ conn = super
+
+ connection_class = conn.class.to_s
+ track_available_connections(connection_class)
+ track_pool_size(connection_class)
+
+ conn
+ end
+
+ def track_pool_size(connection_class)
+ # this means that the size metric for this pool key has been sent
+ return if @size_gauge
+
+ @size_gauge ||= ::Gitlab::Metrics.gauge(:gitlab_connection_pool_size, 'Size of connection pool', {}, :all)
+ @size_gauge.set({ pool_name: @name, pool_key: @key, connection_class: connection_class }, @size)
+ end
+
+ def track_available_connections(connection_class)
+ @available_gauge ||= ::Gitlab::Metrics.gauge(:gitlab_connection_pool_available_count,
+ 'Number of available connections in the pool', {}, :all)
+
+ @available_gauge.set({ pool_name: @name, pool_key: @key, connection_class: connection_class }, available)
+ end
+ end
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
+ end
+end