Skip to content

Commit

Permalink
Metrics were not that useful.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 13, 2024
1 parent 930370c commit 0ca4141
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
1 change: 0 additions & 1 deletion async-pool.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 34 additions & 20 deletions lib/async/pool/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require "async/semaphore"

require "traces"
require "metrics"

module Async
module Pool
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ca4141

Please sign in to comment.