From 0ca4141f5a48e9189c97c6d4a63c218813af24e4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 13 Oct 2024 14:54:04 +1300 Subject: [PATCH] Metrics were not that useful. --- async-pool.gemspec | 1 - lib/async/pool/controller.rb | 54 +++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/async-pool.gemspec b/async-pool.gemspec index 142faa3..abc4d75 100644 --- a/async-pool.gemspec +++ b/async-pool.gemspec @@ -26,6 +26,5 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 3.1" spec.add_dependency "async", ">= 1.25" - spec.add_dependency "metrics", "~> 0.11" spec.add_dependency "traces" end diff --git a/lib/async/pool/controller.rb b/lib/async/pool/controller.rb index daa54e7..13a6ffa 100644 --- a/lib/async/pool/controller.rb +++ b/lib/async/pool/controller.rb @@ -12,7 +12,6 @@ require "async/semaphore" require "traces" -require "metrics" module Async module Pool @@ -39,7 +38,7 @@ def initialize(constructor, limit: nil, concurrency: (limit || 1), policy: nil, @policy = policy @gardener = nil - @tags = Metrics::Tags.normalize(tags) + @tags = tags # All available resources: @resources = {} @@ -393,43 +392,58 @@ def create_resource(...) concurrency: @guard.limit, size: @resources.size, limit: @limit, - tags: @tags, } - Traces.trace("async.pool.create", attributes: attributes) {super} + @attributes.merge!(@tags) if @tags + + Traces.trace('async.pool.create', attributes: attributes) {super} end def drain(...) attributes = { size: @resources.size, - tags: @tags, } - Traces.trace("async.pool.drain", attributes: attributes) {super} + @attributes.merge!(@tags) if @tags + + Traces.trace('async.pool.drain', attributes: attributes) {super} end - end - - Metrics::Provider(self) do - ACQUIRE_COUNT = Metrics.metric("async.pool.acquire", :counter, description: "Number of times a resource was invoked.") - RELEASE_COUNT = Metrics.metric("async.pool.release", :counter, description: "Number of times a resource was released.") - RETIRE_COUNT = Metrics.metric("async.pool.retire", :counter, description: "Number of times a resource was retired.") def acquire(...) - ACQUIRE_COUNT.emit(1, tags: @tags) + attributes = { + concurrency: @guard.limit, + size: @resources.size, + limit: @limit, + } + + @attributes.merge!(@tags) if @tags - super + Traces.trace('async.pool.acquire', attributes: attributes) {super} end def release(...) - super.tap do - RELEASE_COUNT.emit(1, tags: @tags) - end + attributes = { + concurrency: @guard.limit, + size: @resources.size, + limit: @limit, + } + + @attributes.merge!(@tags) if @tags + + Traces.trace('async.pool.release', attributes: attributes) {super} end def retire(...) - super.tap do - RETIRE_COUNT.emit(1, tags: @tags) - end + attributes = { + concurrency: @guard.limit, + size: @resources.size, + limit: @limit, + **@tags, + } + + @attributes.merge!(@tags) if @tags + + Traces.trace('async.pool.retire', attributes: attributes) {super} end end end