async-utilization 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/utilization/metric.rb +20 -12
- data/lib/async/utilization/registry.rb +15 -5
- data/lib/async/utilization/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data/test/async/utilization/metric.rb +51 -4
- data/test/async/utilization/registry.rb +4 -4
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10d5277f8a02e1f72a8466b86dae5245d8beacf60f7310b5f4b2fbbe829ad2b2
|
|
4
|
+
data.tar.gz: 8e1519b41206468ffcd4c5197aecd0843882e5c637db9db24fce67f87fd34386
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aff8c89a734ee90bb716186f4a9133373bc222c26a0b4bb089152a9bce6bd2d76105a91a6c99f3a5333be4afef83ba3c88637e64b69a2629ab185e94b6035a4a
|
|
7
|
+
data.tar.gz: 853481053488156d6baa7be3cff2f7c19e9bad60028e44649f96bfc978c07c173065bb0d8bd17105ae1248204d569bc115fcc0e146ce3ee25886b8efcc2580e9
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -43,30 +43,38 @@ module Async
|
|
|
43
43
|
@cached_buffer = nil
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# Increment the metric value
|
|
46
|
+
# Increment the metric value.
|
|
47
47
|
#
|
|
48
48
|
# Uses the fast path (direct buffer write) when cache is valid and observer is available.
|
|
49
49
|
#
|
|
50
|
-
# @yield Optional block - if provided, decrements the field after the block completes.
|
|
51
50
|
# @returns [Integer] The new value of the field.
|
|
52
|
-
def increment
|
|
51
|
+
def increment
|
|
53
52
|
@guard.synchronize do
|
|
54
53
|
@value += 1
|
|
55
54
|
write_direct(@value)
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
if block_given?
|
|
59
|
-
begin
|
|
60
|
-
yield
|
|
61
|
-
ensure
|
|
62
|
-
# Decrement after block completes
|
|
63
|
-
decrement
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
57
|
@value
|
|
68
58
|
end
|
|
69
59
|
|
|
60
|
+
# Track an operation: increment before the block, decrement after it completes.
|
|
61
|
+
#
|
|
62
|
+
# Returns the block's return value. Use for active/count metrics that should
|
|
63
|
+
# reflect the number of operations currently in progress.
|
|
64
|
+
#
|
|
65
|
+
# @yield The operation to track.
|
|
66
|
+
# @returns [Object] The block's return value.
|
|
67
|
+
def track(&block)
|
|
68
|
+
raise ArgumentError, "block required" unless block_given?
|
|
69
|
+
|
|
70
|
+
increment
|
|
71
|
+
begin
|
|
72
|
+
yield
|
|
73
|
+
ensure
|
|
74
|
+
decrement
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
70
78
|
# Decrement the metric value.
|
|
71
79
|
#
|
|
72
80
|
# Uses the fast path (direct buffer write) when cache is valid and observer is available.
|
|
@@ -22,7 +22,7 @@ module Async
|
|
|
22
22
|
#
|
|
23
23
|
# # Emit metrics - values tracked in registry
|
|
24
24
|
# registry.increment(:total_requests)
|
|
25
|
-
# registry.
|
|
25
|
+
# registry.track(:active_requests) do
|
|
26
26
|
# # Handle request - auto-decrements when block completes
|
|
27
27
|
# end
|
|
28
28
|
#
|
|
@@ -93,15 +93,25 @@ module Async
|
|
|
93
93
|
metric(field).set(value)
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
# Increment a field value
|
|
96
|
+
# Increment a field value.
|
|
97
97
|
#
|
|
98
98
|
# Delegates to the metric instance for the given field.
|
|
99
99
|
#
|
|
100
100
|
# @parameter field [Symbol] The field name to increment.
|
|
101
|
-
# @yield Optional block - if provided, decrements the field after the block completes.
|
|
102
101
|
# @returns [Integer] The new value of the field.
|
|
103
|
-
def increment(field
|
|
104
|
-
metric(field).increment
|
|
102
|
+
def increment(field)
|
|
103
|
+
metric(field).increment
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Track an operation: increment before the block, decrement after it completes.
|
|
107
|
+
#
|
|
108
|
+
# Delegates to the metric instance for the given field.
|
|
109
|
+
#
|
|
110
|
+
# @parameter field [Symbol] The field name to track.
|
|
111
|
+
# @yield The operation to track.
|
|
112
|
+
# @returns [Object] The block's return value.
|
|
113
|
+
def track(field, &block)
|
|
114
|
+
metric(field).track(&block)
|
|
105
115
|
end
|
|
106
116
|
|
|
107
117
|
# Decrement a field value.
|
data/readme.md
CHANGED
|
@@ -14,6 +14,10 @@ Please see the [project documentation](https://socketry.github.io/async-utilizat
|
|
|
14
14
|
|
|
15
15
|
Please see the [project releases](https://socketry.github.io/async-utilization/releases/index) for all releases.
|
|
16
16
|
|
|
17
|
+
### v0.3.0
|
|
18
|
+
|
|
19
|
+
- Introduce `Metric#track{...}` for increment -\> decrement.
|
|
20
|
+
|
|
17
21
|
### v0.1.0
|
|
18
22
|
|
|
19
23
|
- Initial implementation.
|
data/releases.md
CHANGED
|
@@ -80,23 +80,62 @@ describe Async::Utilization::Metric do
|
|
|
80
80
|
expect(metric.value).to be == 100
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
it "can
|
|
83
|
+
it "can track an operation with auto-decrement" do
|
|
84
84
|
registry.observer = observer
|
|
85
85
|
metric = registry.metric(:active_requests)
|
|
86
86
|
|
|
87
|
-
metric.
|
|
87
|
+
metric.track do
|
|
88
88
|
expect(metric.value).to be == 1
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
expect(metric.value).to be == 0
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
it "
|
|
94
|
+
it "returns the metric value when increment is called" do
|
|
95
|
+
registry.observer = observer
|
|
96
|
+
metric = registry.metric(:total_requests)
|
|
97
|
+
|
|
98
|
+
result = metric.increment
|
|
99
|
+
expect(result).to be == 1
|
|
100
|
+
expect(result).to be == metric.value
|
|
101
|
+
|
|
102
|
+
result = metric.increment
|
|
103
|
+
expect(result).to be == 2
|
|
104
|
+
expect(result).to be == metric.value
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "returns the block's return value when track is called" do
|
|
108
|
+
registry.observer = observer
|
|
109
|
+
metric = registry.metric(:active_requests)
|
|
110
|
+
|
|
111
|
+
# Block returns a string
|
|
112
|
+
result = metric.track do
|
|
113
|
+
"connection_object"
|
|
114
|
+
end
|
|
115
|
+
expect(result).to be == "connection_object"
|
|
116
|
+
expect(metric.value).to be == 0 # Should be decremented after block
|
|
117
|
+
|
|
118
|
+
# Block returns an integer
|
|
119
|
+
result = metric.track do
|
|
120
|
+
42
|
|
121
|
+
end
|
|
122
|
+
expect(result).to be == 42
|
|
123
|
+
expect(metric.value).to be == 0 # Should be decremented after block
|
|
124
|
+
|
|
125
|
+
# Block returns nil
|
|
126
|
+
result = metric.track do
|
|
127
|
+
nil
|
|
128
|
+
end
|
|
129
|
+
expect(result).to be == nil
|
|
130
|
+
expect(metric.value).to be == 0 # Should be decremented after block
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "decrements even if track block raises an error" do
|
|
95
134
|
registry.observer = observer
|
|
96
135
|
metric = registry.metric(:active_requests)
|
|
97
136
|
|
|
98
137
|
begin
|
|
99
|
-
metric.
|
|
138
|
+
metric.track do
|
|
100
139
|
raise "Test error"
|
|
101
140
|
end
|
|
102
141
|
rescue => error
|
|
@@ -106,6 +145,14 @@ describe Async::Utilization::Metric do
|
|
|
106
145
|
expect(metric.value).to be == 0
|
|
107
146
|
end
|
|
108
147
|
|
|
148
|
+
it "raises ArgumentError when track is called without a block" do
|
|
149
|
+
metric = registry.metric(:active_requests)
|
|
150
|
+
|
|
151
|
+
expect do
|
|
152
|
+
metric.track
|
|
153
|
+
end.to raise_exception(ArgumentError, message: be == "block required")
|
|
154
|
+
end
|
|
155
|
+
|
|
109
156
|
it "writes directly to shared memory when observer is set" do
|
|
110
157
|
registry.observer = observer
|
|
111
158
|
metric = registry.metric(:total_requests)
|
|
@@ -37,17 +37,17 @@ describe Async::Utilization::Registry do
|
|
|
37
37
|
expect(registry.values[:test_field]).to be == 42
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
it "can auto-decrement
|
|
41
|
-
registry.
|
|
40
|
+
it "can track an operation with auto-decrement" do
|
|
41
|
+
registry.track(:test_field) do
|
|
42
42
|
expect(registry.values[:test_field]).to be == 1
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
expect(registry.values[:test_field]).to be == 0
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
it "decrements even if block raises an error" do
|
|
48
|
+
it "decrements even if track block raises an error" do
|
|
49
49
|
begin
|
|
50
|
-
registry.
|
|
50
|
+
registry.track(:test_field) do
|
|
51
51
|
raise "Error!"
|
|
52
52
|
end
|
|
53
53
|
rescue
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: async-utilization
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
97
97
|
requirements:
|
|
98
98
|
- - ">="
|
|
99
99
|
- !ruby/object:Gem::Version
|
|
100
|
-
version: '3.
|
|
100
|
+
version: '3.3'
|
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
|
103
103
|
- - ">="
|
metadata.gz.sig
CHANGED
|
Binary file
|