@@ -29,7 +29,7 @@ def self.wrap(**options, &block)
29
29
# @parameter limit [Integer | Nil] The maximum number of resources that this pool can have at any given time. If nil, the pool can have an unlimited number of resources.
30
30
# @parameter concurrency [Integer] The maximum number of concurrent tasks that can be creating a new resource.
31
31
# @parameter policy [Policy] The pool policy.
32
- def initialize ( constructor , limit : nil , concurrency : ( limit || 1 ) , policy : nil )
32
+ def initialize ( constructor , limit : nil , concurrency : ( limit || 1 ) , policy : nil , tags : nil )
33
33
@constructor = constructor
34
34
@limit = limit
35
35
@@ -39,6 +39,8 @@ def initialize(constructor, limit: nil, concurrency: (limit || 1), policy: nil)
39
39
@policy = policy
40
40
@gardener = nil
41
41
42
+ @tags = Metrics ::Tags . normalize ( tags )
43
+
42
44
# All available resources:
43
45
@resources = { }
44
46
@@ -96,6 +98,9 @@ def concurrency= value
96
98
# @attribute [Hash(Resource, Integer)] all allocated resources, and their associated usage.
97
99
attr :resources
98
100
101
+ # @attribute [Array(String)] The name of the pool.
102
+ attr_accessor :tags
103
+
99
104
# The number of resources in the pool.
100
105
def size
101
106
@resources . size
@@ -388,6 +393,7 @@ def create_resource(...)
388
393
concurrency : @guard . limit ,
389
394
size : @resources . size ,
390
395
limit : @limit ,
396
+ tags : @tags ,
391
397
}
392
398
393
399
Traces . trace ( 'async.pool.create' , attributes : attributes ) { super }
@@ -396,6 +402,7 @@ def create_resource(...)
396
402
def drain ( ...)
397
403
attributes = {
398
404
size : @resources . size ,
405
+ tags : @tags ,
399
406
}
400
407
401
408
Traces . trace ( 'async.pool.drain' , attributes : attributes ) { super }
@@ -408,20 +415,20 @@ def drain(...)
408
415
RETIRE_COUNT = Metrics . metric ( 'async.pool.retire' , :counter , description : 'Number of times a resource was retired.' )
409
416
410
417
def acquire ( ...)
411
- ACQUIRE_COUNT . emit ( 1 )
418
+ ACQUIRE_COUNT . emit ( 1 , tags : @tags )
412
419
413
420
super
414
421
end
415
422
416
423
def release ( ...)
417
424
super . tap do
418
- RELEASE_COUNT . emit ( 1 )
425
+ RELEASE_COUNT . emit ( 1 , tags : @tags )
419
426
end
420
427
end
421
428
422
429
def retire ( ...)
423
430
super . tap do
424
- RETIRE_COUNT . emit ( 1 )
431
+ RETIRE_COUNT . emit ( 1 , tags : @tags )
425
432
end
426
433
end
427
434
end
0 commit comments