leafy 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +8 -0
- data/LICENSE +201 -0
- data/README.md +109 -0
- data/leafy.gemspec +28 -0
- data/lib/leafy/core/adder.rb +28 -0
- data/lib/leafy/core/clock.rb +29 -0
- data/lib/leafy/core/console_reporter.rb +157 -0
- data/lib/leafy/core/counter.rb +33 -0
- data/lib/leafy/core/ewma.rb +95 -0
- data/lib/leafy/core/gauge.rb +26 -0
- data/lib/leafy/core/histogram.rb +40 -0
- data/lib/leafy/core/meter.rb +92 -0
- data/lib/leafy/core/metric_registry.rb +213 -0
- data/lib/leafy/core/ratio_gauge.rb +56 -0
- data/lib/leafy/core/scheduled_reporter.rb +170 -0
- data/lib/leafy/core/sliding_window_reservoir.rb +42 -0
- data/lib/leafy/core/snapshot.rb +58 -0
- data/lib/leafy/core/timer.rb +105 -0
- data/lib/leafy/core/uniform_snapshot.rb +114 -0
- data/lib/leafy/core/version.rb +5 -0
- data/puma.rb +22 -0
- data/spec/console_reporter_spec.rb +362 -0
- data/spec/counter_spec.rb +50 -0
- data/spec/ewma_spec.rb +208 -0
- data/spec/histogram_spec.rb +20 -0
- data/spec/meter_spec.rb +40 -0
- data/spec/metric_registry_spec.rb +168 -0
- data/spec/ratio_gauge_spec.rb +47 -0
- data/spec/scheduled_reporter_spec.rb +135 -0
- data/spec/sliging_window_reservoir_spec.rb +22 -0
- data/spec/spec_helper.rb +123 -0
- data/spec/timer_spec.rb +100 -0
- data/spec/uniform_snapshot_spec.rb +126 -0
- metadata +120 -16
data/spec/timer_spec.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'leafy/core/timer'
|
2
|
+
require 'concurrent/atomic/atomic_boolean'
|
3
|
+
|
4
|
+
RSpec.describe Leafy::Core::Timer do
|
5
|
+
|
6
|
+
let(:clock) do
|
7
|
+
clock = Leafy::Core::Clock.new
|
8
|
+
# a mock clock that increments its ticker by 50msec per call
|
9
|
+
def clock.tick
|
10
|
+
@ticks = @ticks.to_i + 50000000
|
11
|
+
end
|
12
|
+
clock
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:reservoir) { double('Reservoir') }
|
16
|
+
|
17
|
+
let(:timer) { Leafy::Core::Timer.new(reservoir, clock) }
|
18
|
+
|
19
|
+
it 'hasRates' do
|
20
|
+
expect(timer.count).to eq 0
|
21
|
+
|
22
|
+
expect(timer.mean_rate).to eq 0
|
23
|
+
|
24
|
+
expect(timer.one_minute_rate).to eq 0
|
25
|
+
|
26
|
+
expect(timer.five_minute_rate).to eq 0
|
27
|
+
|
28
|
+
expect(timer.fifteen_minute_rate).to eq 0
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
it 'updatesTheCountOnUpdates' do
|
33
|
+
allow(reservoir).to receive(:update).with(2000000000)
|
34
|
+
expect(timer.count).to eq 0
|
35
|
+
|
36
|
+
timer.update(2)
|
37
|
+
|
38
|
+
expect(timer.count).to eq 1
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it 'timesCallableInstances' do
|
43
|
+
allow(reservoir).to receive(:update).with(50000000)
|
44
|
+
|
45
|
+
value = timer.time { "one" }
|
46
|
+
|
47
|
+
expect(timer.count).to eq 1
|
48
|
+
|
49
|
+
expect(value).to eq 'one'
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it 'timesRunnableInstances' do
|
54
|
+
allow(reservoir).to receive(:update).with(50000000)
|
55
|
+
|
56
|
+
called = Concurrent::AtomicBoolean.new(false)
|
57
|
+
timer.time { called.value = true }
|
58
|
+
|
59
|
+
expect(timer.count).to eq 1
|
60
|
+
|
61
|
+
expect(called.value).to eq true
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
it 'timesContexts' do
|
66
|
+
allow(reservoir).to receive(:update).with(50000000)
|
67
|
+
timer.context.stop
|
68
|
+
|
69
|
+
expect(timer.count).to eq 1
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
it 'returnsTheSnapshotFromTheReservoir' do
|
74
|
+
snapshot = Object.new
|
75
|
+
allow(reservoir).to receive(:snapshot).and_return(snapshot)
|
76
|
+
|
77
|
+
expect(timer.snapshot).to eq snapshot
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
it 'ignoresNegativeValues' do
|
82
|
+
timer.update(-1)
|
83
|
+
|
84
|
+
expect(timer.count).to eq 0
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
it 'tryWithResourcesWork' do
|
89
|
+
allow(reservoir).to receive(:update).with(50000000)
|
90
|
+
expect(timer.count).to eq 0
|
91
|
+
|
92
|
+
dummy = 0
|
93
|
+
timer.context do |context|
|
94
|
+
#expect(context).isNotNull();
|
95
|
+
dummy += 1
|
96
|
+
end
|
97
|
+
expect(dummy).to eq 1
|
98
|
+
expect(timer.count).to eq 1
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'leafy/core/sliding_window_reservoir'
|
2
|
+
|
3
|
+
RSpec.describe Leafy::Core::UniformSnapshot do
|
4
|
+
|
5
|
+
let(:snapshot) { Leafy::Core::UniformSnapshot.new(5, 1, 2, 3, 4) }
|
6
|
+
let(:empty_snapshot) { subject }
|
7
|
+
|
8
|
+
it 'smallQuantilesAreTheFirstValue' do
|
9
|
+
expect(Number[snapshot.value(0.0)]).to eql Number[1, 0.1]
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it 'bigQuantilesAreTheLastValue' do
|
14
|
+
expect(Number[snapshot.value(1.0)]).to eql Number[5, 0.1]
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'disallowsNotANumberQuantile' do
|
18
|
+
expect { snapshot.value('asd') }.to raise_error ArgumentError
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'disallowsNegativeQuantile' do
|
22
|
+
expect { snapshot.value(-0.5) }.to raise_error ArgumentError
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'disallowsQuantileOverOne' do
|
26
|
+
expect { snapshot.value(1.5) }.to raise_error ArgumentError
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
it 'hasAMedian' do
|
31
|
+
expect(Number[snapshot.median]).to eql Number[3, 0.1]
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
it 'hasAp75' do
|
36
|
+
expect(Number[snapshot.get_75th_percentile]).to eql Number[4.5, 0.1]
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
it 'hasAp95' do
|
41
|
+
expect(Number[snapshot.get_95th_percentile]).to eql Number[5.0, 0.1]
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it 'hasAp98' do
|
46
|
+
expect(Number[snapshot.get_98th_percentile]).to eql Number[5.0, 0.1]
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
it 'hasAp99' do
|
51
|
+
expect(Number[snapshot.get_99th_percentile]).to eql Number[5.0, 0.1]
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
it 'hasAp999' do
|
56
|
+
expect(Number[snapshot.get_999th_percentile]).to eql Number[5.0, 0.1]
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
it 'hasValues' do
|
61
|
+
expect(snapshot.values).to match_array [1,2,3,4,5]
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
it 'hasASize' do
|
66
|
+
expect(snapshot.size).to eq 5
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
it 'dumpsToAStream' do
|
72
|
+
output = StringIO.new
|
73
|
+
|
74
|
+
snapshot.dump(output);
|
75
|
+
|
76
|
+
expect(output.string).to eq "1\n2\n3\n4\n5\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
it 'calculatesTheMinimumValue' do
|
81
|
+
expect(snapshot.min).to eq 1
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
it 'calculatesTheMaximumValue' do
|
86
|
+
expect(snapshot.max).to eq 5
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
it 'calculatesTheMeanValue' do
|
91
|
+
expect(snapshot.mean).to eq 3.0
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
it 'calculatesTheStdDev' do
|
96
|
+
expect(Number[snapshot.std_dev]).to eql Number[1.5811, 0.01]
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
it 'calculatesAMinOfZeroForAnEmptySnapshot' do
|
101
|
+
expect(empty_snapshot.min).to eq 0.0
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
it 'calculatesAMaxOfZeroForAnEmptySnapshot' do
|
106
|
+
expect(empty_snapshot.max).to eq 0.0
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
it 'calculatesAMeanOfZeroForAnEmptySnapshot' do
|
111
|
+
expect(empty_snapshot.mean).to eq 0.0
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
it 'calculatesAStdDevOfZeroForAnEmptySnapshot' do
|
116
|
+
expect(empty_snapshot.std_dev).to eq 0.0
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
it 'calculatesAStdDevOfZeroForASingletonSnapshot' do
|
121
|
+
singleItemSnapshot = Leafy::Core::UniformSnapshot.new(1)
|
122
|
+
|
123
|
+
expect(singleItemSnapshot.std_dev).to eq 0.0
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
metadata
CHANGED
@@ -1,26 +1,118 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leafy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- ''
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
11
|
+
date: 2017-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
description: Port of Dropwizards metrics-core to pure ruby
|
70
|
+
email:
|
71
|
+
- ''
|
15
72
|
executables: []
|
16
73
|
extensions: []
|
17
74
|
extra_rdoc_files: []
|
18
|
-
files:
|
19
|
-
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- leafy.gemspec
|
83
|
+
- lib/leafy/core/adder.rb
|
84
|
+
- lib/leafy/core/clock.rb
|
85
|
+
- lib/leafy/core/console_reporter.rb
|
86
|
+
- lib/leafy/core/counter.rb
|
87
|
+
- lib/leafy/core/ewma.rb
|
88
|
+
- lib/leafy/core/gauge.rb
|
89
|
+
- lib/leafy/core/histogram.rb
|
90
|
+
- lib/leafy/core/meter.rb
|
91
|
+
- lib/leafy/core/metric_registry.rb
|
92
|
+
- lib/leafy/core/ratio_gauge.rb
|
93
|
+
- lib/leafy/core/scheduled_reporter.rb
|
94
|
+
- lib/leafy/core/sliding_window_reservoir.rb
|
95
|
+
- lib/leafy/core/snapshot.rb
|
96
|
+
- lib/leafy/core/timer.rb
|
97
|
+
- lib/leafy/core/uniform_snapshot.rb
|
98
|
+
- lib/leafy/core/version.rb
|
99
|
+
- puma.rb
|
100
|
+
- spec/console_reporter_spec.rb
|
101
|
+
- spec/counter_spec.rb
|
102
|
+
- spec/ewma_spec.rb
|
103
|
+
- spec/histogram_spec.rb
|
104
|
+
- spec/meter_spec.rb
|
105
|
+
- spec/metric_registry_spec.rb
|
106
|
+
- spec/ratio_gauge_spec.rb
|
107
|
+
- spec/scheduled_reporter_spec.rb
|
108
|
+
- spec/sliging_window_reservoir_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/timer_spec.rb
|
111
|
+
- spec/uniform_snapshot_spec.rb
|
112
|
+
homepage: https://github.com/leafy-metrics/leafy
|
20
113
|
licenses:
|
21
|
-
-
|
22
|
-
metadata:
|
23
|
-
source_code_uri: https://github.com/example/example
|
114
|
+
- APL2
|
115
|
+
metadata: {}
|
24
116
|
post_install_message:
|
25
117
|
rdoc_options: []
|
26
118
|
require_paths:
|
@@ -29,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
121
|
requirements:
|
30
122
|
- - ">="
|
31
123
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
124
|
+
version: 2.2.0
|
33
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
126
|
requirements:
|
35
127
|
- - ">="
|
@@ -37,8 +129,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
129
|
version: '0'
|
38
130
|
requirements: []
|
39
131
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.5.1
|
41
133
|
signing_key:
|
42
134
|
specification_version: 4
|
43
|
-
summary:
|
44
|
-
test_files:
|
135
|
+
summary: Port of Dropwizards metrics-core to pure ruby
|
136
|
+
test_files:
|
137
|
+
- spec/console_reporter_spec.rb
|
138
|
+
- spec/counter_spec.rb
|
139
|
+
- spec/ewma_spec.rb
|
140
|
+
- spec/histogram_spec.rb
|
141
|
+
- spec/meter_spec.rb
|
142
|
+
- spec/metric_registry_spec.rb
|
143
|
+
- spec/ratio_gauge_spec.rb
|
144
|
+
- spec/scheduled_reporter_spec.rb
|
145
|
+
- spec/sliging_window_reservoir_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- spec/timer_spec.rb
|
148
|
+
- spec/uniform_snapshot_spec.rb
|