metricstore 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Metricstore
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -16,6 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Metricstore::VERSION
17
17
 
18
18
  gem.add_dependency "couchbase", "~> 1.1.1"
19
+ gem.add_dependency "eventmachine", "~> 1.0.0.beta.1"
20
+ gem.add_dependency "em-synchrony", "~> 1.0.1"
19
21
 
20
22
  gem.add_development_dependency "rspec", "~> 2.9.0"
21
23
  gem.add_development_dependency "simplecov", "~> 0.6.1"
@@ -23,4 +25,6 @@ Gem::Specification.new do |gem|
23
25
  gem.add_development_dependency "guard", "~> 1.0.1"
24
26
  gem.add_development_dependency "guard-bundler", "~> 0.1.3"
25
27
  gem.add_development_dependency "guard-rspec", "~> 0.7.0"
28
+ gem.add_development_dependency "timecop", "~> 0.3.5"
29
+ gem.add_development_dependency "ruby-prof", "~> 0.10.8"
26
30
  end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ #require 'ruby-prof'
3
+
4
+ module Metricstore
5
+ describe Client do
6
+ context "supposing the current time is 17:05 UTC on April 13, 2012" do
7
+ around(:each) do |spec|
8
+ Timecop.travel(Time.utc(2012,4,13,17,5)) do
9
+ @mock_key_value_client = MockKeyValueClient.new
10
+ @client = Metricstore::Client.new(
11
+ :kvstore => @mock_key_value_client,
12
+ :sleep_interval => 0.001,
13
+ :max_healthy_errors => 0,
14
+ :max_unhandled_errors => 0,
15
+ :max_retry_delay_in_seconds => 60.0
16
+ )
17
+ @client.max_ttl_of_dimension[:session_id] = 60
18
+ @client.run do
19
+ @n = 10
20
+ # profile_data = RubyProf.profile do
21
+ @n.times do
22
+ @client.counter(:what => "logins", :where => {:user => 'joe', :ip => '10.20.30.40'})
23
+ @client.counter(:what => "logins", :where => {:user => 'bob', :ip => '10.20.30.40'})
24
+ @client.counter(:what => "logins", :where => {:user => 'joe', :ip => '10.20.30.50'})
25
+ @client.counter(:what => "logouts", :where => {:user => 'joe', :ip => '10.20.30.40'})
26
+
27
+ @client.measure(:what => "load_time", :value => 340, :where => {:page => '/welcome/', :session_id => "h0zhmb1c-u1xfgw305e"})
28
+ @client.measure(:what => "load_time", :value => 501, :where => {:page => '/welcome/', :session_id => "h0zhmb2q-643dotlcgd"})
29
+ @client.measure(:what => "load_time", :value => 212, :where => {:page => '/welcome/', :session_id => "h0zhmb1c-u1xfgw305e"})
30
+ @client.measure(:what => "load_time", :value => 343, :where => {:page => '/welcome/', :session_id => "h0zhmb2q-643dotlcgd"})
31
+ end
32
+ # end
33
+
34
+ @client.list_threshold = 10
35
+
36
+ @sheep_count = @client.list_threshold + 1
37
+ @sheep_count.times do
38
+ @client.counter(:what => 'sheep', :where => {:id => rand(2**128).to_s(36)})
39
+ end
40
+
41
+ # result_path = Pathname.new(__FILE__).join('..','..','..','..','profile').expand_path
42
+ # result_path.join('calltree.data').open('w') do |f|
43
+ # RubyProf::CallTreePrinter.new(profile_data).print(f)
44
+ # end
45
+ # result_path.join('graph.html').open('w') do |f|
46
+ # RubyProf::GraphHtmlPrinter.new(profile_data).print(f)
47
+ # end
48
+ end
49
+
50
+ @client.run do
51
+ spec.run
52
+ end
53
+
54
+ @mock_key_value_client = nil
55
+ @client = nil
56
+ end
57
+ end
58
+
59
+ it "should work like the README says it does" do
60
+ @client.count(:hour => '2012-04-13-17', :what => "logins").should == 3 * @n
61
+ @client.list(:hour => '2012-04-13-17', :what => "logins", :list => :user).should == ['joe', 'bob']
62
+ @client.count(:hour => '2012-04-13-17', :what => "logins", :where => {:user => 'joe'}).should == 2 * @n
63
+ @client.count(:hour => '2012-04-13-17', :what => "logins", :where => {:user => 'bob'}).should == 1 * @n
64
+ @client.list(:hour => '2012-04-13-17', :what => "logins", :where => {:user => 'joe'}, :list => :ip).should == ['10.20.30.40', '10.20.30.50']
65
+ @client.list(:hour => '2012-04-13-17', :what => "logins", :where => {:user => 'bob'}, :list => :ip).should == ['10.20.30.40']
66
+ @client.count(:hour => '2012-04-13-17', :what => "logins", :where => {:user => 'joe', :ip => '10.20.30.40'}).should == 1 * @n
67
+
68
+ @client.count(:hour => "2012-04-13-17", :what => "load_time").should == 4 * @n
69
+ @client.sum(:hour => "2012-04-13-17", :what => "load_time").should == 1396 * @n
70
+ @client.average(:hour => "2012-04-13-17", :what => "load_time").should == 349.0
71
+ @client.maximum(:hour => "2012-04-13-17", :what => "load_time").should == 501
72
+ @client.minimum(:hour => "2012-04-13-17", :what => "load_time").should == 212
73
+ @client.stddev(:hour => "2012-04-13-17", :what => "load_time").should be_within(0.00000001).of 102.45730818248154
74
+ @client.list(:hour => "2012-04-13-17", :what => "load_time", :list => :page).should == ['/welcome/']
75
+
76
+ @client.count_of_groups(:hour => "2012-04-13-17", :what => "load_time", :group => :session_id).should == 2
77
+ @client.sum_of_ranges(:hour => "2012-04-13-17", :what => "load_time", :group => :session_id).should == 286
78
+ @client.average_range(:hour => "2012-04-13-17", :what => "load_time", :group => :session_id).should == 143
79
+ @client.maximum_range(:hour => "2012-04-13-17", :what => "load_time", :group => :session_id).should == 158
80
+ @client.minimum_range(:hour => "2012-04-13-17", :what => "load_time", :group => :session_id).should == 128
81
+ @client.stddev_of_ranges(:hour => "2012-04-13-17", :what => "load_time", :group => :session_id).should == 15.0
82
+
83
+ @client.estimated_list_size(:hour => "2012-04-13-17", :what => "load_time", :list => :session_id).should == 2
84
+
85
+ expect { @client.list(:hour => "2012-04-13-17", :what => "sheep", :list => :id) }.to raise_exception(Metricstore::DataLossError)
86
+
87
+ @client.estimated_list_size(:hour => "2012-04-13-17", :what => "sheep", :list => :id).should be_within((1.05 * Client::CARDINALITY_ESTIMATOR_ERROR_RATE * @sheep_count).ceil).of (@sheep_count)
88
+ end
89
+ end
90
+ end
91
+ end
File without changes
File without changes
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+
7
+ Bundler.require(:default, :test, :development)
@@ -0,0 +1,5 @@
1
+ desc "Open development console"
2
+ task :console do
3
+ puts "Loading development console..."
4
+ system "irb -r #{File.join('.', 'lib', 'metricstore')}"
5
+ end
@@ -0,0 +1,10 @@
1
+ desc "Generate and open coverage report"
2
+ task :coverage do
3
+ system 'rake spec'
4
+ system 'open coverage/index.html'
5
+ end
6
+
7
+ desc "Generate and open coverage report"
8
+ task :rcov do
9
+ system 'rake coverage'
10
+ end
@@ -0,0 +1,4 @@
1
+ desc "Load the environment"
2
+ task :environment do
3
+ require File.expand_path('../../lib/metricstore', __FILE__)
4
+ end
@@ -0,0 +1,12 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc "Run all specs"
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = [
6
+ '-c',
7
+ '--format documentation',
8
+ '-r ./spec/spec_helper.rb',
9
+ '--backtrace'
10
+ ]
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metricstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: couchbase
16
- requirement: &70120781282620 !ruby/object:Gem::Requirement
16
+ requirement: &70241196652060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,32 @@ dependencies:
21
21
  version: 1.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70120781282620
24
+ version_requirements: *70241196652060
25
+ - !ruby/object:Gem::Dependency
26
+ name: eventmachine
27
+ requirement: &70241196572240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0.beta.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70241196572240
36
+ - !ruby/object:Gem::Dependency
37
+ name: em-synchrony
38
+ requirement: &70241196571740 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.1
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70241196571740
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: rspec
27
- requirement: &70120781281880 !ruby/object:Gem::Requirement
49
+ requirement: &70241196571280 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ~>
@@ -32,10 +54,10 @@ dependencies:
32
54
  version: 2.9.0
33
55
  type: :development
34
56
  prerelease: false
35
- version_requirements: *70120781281880
57
+ version_requirements: *70241196571280
36
58
  - !ruby/object:Gem::Dependency
37
59
  name: simplecov
38
- requirement: &70120781281280 !ruby/object:Gem::Requirement
60
+ requirement: &70241196570700 !ruby/object:Gem::Requirement
39
61
  none: false
40
62
  requirements:
41
63
  - - ~>
@@ -43,10 +65,10 @@ dependencies:
43
65
  version: 0.6.1
44
66
  type: :development
45
67
  prerelease: false
46
- version_requirements: *70120781281280
68
+ version_requirements: *70241196570700
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: rb-fsevent
49
- requirement: &70120781280640 !ruby/object:Gem::Requirement
71
+ requirement: &70241196570060 !ruby/object:Gem::Requirement
50
72
  none: false
51
73
  requirements:
52
74
  - - ~>
@@ -54,10 +76,10 @@ dependencies:
54
76
  version: 0.9.1
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *70120781280640
79
+ version_requirements: *70241196570060
58
80
  - !ruby/object:Gem::Dependency
59
81
  name: guard
60
- requirement: &70120781279980 !ruby/object:Gem::Requirement
82
+ requirement: &70241196569400 !ruby/object:Gem::Requirement
61
83
  none: false
62
84
  requirements:
63
85
  - - ~>
@@ -65,10 +87,10 @@ dependencies:
65
87
  version: 1.0.1
66
88
  type: :development
67
89
  prerelease: false
68
- version_requirements: *70120781279980
90
+ version_requirements: *70241196569400
69
91
  - !ruby/object:Gem::Dependency
70
92
  name: guard-bundler
71
- requirement: &70120781279340 !ruby/object:Gem::Requirement
93
+ requirement: &70241196568880 !ruby/object:Gem::Requirement
72
94
  none: false
73
95
  requirements:
74
96
  - - ~>
@@ -76,10 +98,10 @@ dependencies:
76
98
  version: 0.1.3
77
99
  type: :development
78
100
  prerelease: false
79
- version_requirements: *70120781279340
101
+ version_requirements: *70241196568880
80
102
  - !ruby/object:Gem::Dependency
81
103
  name: guard-rspec
82
- requirement: &70120781278700 !ruby/object:Gem::Requirement
104
+ requirement: &70241196568320 !ruby/object:Gem::Requirement
83
105
  none: false
84
106
  requirements:
85
107
  - - ~>
@@ -87,7 +109,29 @@ dependencies:
87
109
  version: 0.7.0
88
110
  type: :development
89
111
  prerelease: false
90
- version_requirements: *70120781278700
112
+ version_requirements: *70241196568320
113
+ - !ruby/object:Gem::Dependency
114
+ name: timecop
115
+ requirement: &70241196567400 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: 0.3.5
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70241196567400
124
+ - !ruby/object:Gem::Dependency
125
+ name: ruby-prof
126
+ requirement: &70241196566820 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.10.8
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *70241196566820
91
135
  description: Metrics in a key-value store.
92
136
  email:
93
137
  - chris@kindkid.com
@@ -98,14 +142,37 @@ files:
98
142
  - .gitignore
99
143
  - .rvmrc
100
144
  - Gemfile
145
+ - Guardfile
101
146
  - LICENSE
102
147
  - README.md
103
148
  - Rakefile
104
149
  - lib/metricstore.rb
105
- - lib/metricstore/base_client.rb
150
+ - lib/metricstore/client.rb
106
151
  - lib/metricstore/couchbase_client.rb
152
+ - lib/metricstore/count_incrementer.rb
153
+ - lib/metricstore/exceptions.rb
154
+ - lib/metricstore/hyper_log_log.rb
155
+ - lib/metricstore/incrementer.rb
156
+ - lib/metricstore/inserter.rb
157
+ - lib/metricstore/mock_key_value_client.rb
158
+ - lib/metricstore/monkey_patches.rb
159
+ - lib/metricstore/range_updater.rb
160
+ - lib/metricstore/updater.rb
107
161
  - lib/metricstore/version.rb
108
162
  - metricstore.gemspec
163
+ - spec/lib/metricstore/client_spec.rb
164
+ - spec/lib/metricstore/couchbase_client_spec.rb
165
+ - spec/lib/metricstore/incrementer_spec.rb
166
+ - spec/lib/metricstore/inserter_spec.rb
167
+ - spec/lib/metricstore/monkey_patches_spec.rb
168
+ - spec/lib/metricstore/range_updater_spec.rb
169
+ - spec/lib/metricstore/updater_spec.rb
170
+ - spec/lib/metricstore_spec.rb
171
+ - spec/spec_helper.rb
172
+ - tasks/console.rake
173
+ - tasks/coverage.rake
174
+ - tasks/environment.rake
175
+ - tasks/spec.rake
109
176
  homepage: https://github.com/kindkid/metricstore
110
177
  licenses: []
111
178
  post_install_message:
@@ -118,12 +185,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
185
  - - ! '>='
119
186
  - !ruby/object:Gem::Version
120
187
  version: '0'
188
+ segments:
189
+ - 0
190
+ hash: -1169059704362478148
121
191
  required_rubygems_version: !ruby/object:Gem::Requirement
122
192
  none: false
123
193
  requirements:
124
194
  - - ! '>='
125
195
  - !ruby/object:Gem::Version
126
196
  version: '0'
197
+ segments:
198
+ - 0
199
+ hash: -1169059704362478148
127
200
  requirements: []
128
201
  rubyforge_project:
129
202
  rubygems_version: 1.8.10
@@ -131,4 +204,13 @@ signing_key:
131
204
  specification_version: 3
132
205
  summary: Metrics in a key-value store. Accepts, summarizes, and stores continuous
133
206
  metrics updates to a key-value store. Answers queries in constant time.
134
- test_files: []
207
+ test_files:
208
+ - spec/lib/metricstore/client_spec.rb
209
+ - spec/lib/metricstore/couchbase_client_spec.rb
210
+ - spec/lib/metricstore/incrementer_spec.rb
211
+ - spec/lib/metricstore/inserter_spec.rb
212
+ - spec/lib/metricstore/monkey_patches_spec.rb
213
+ - spec/lib/metricstore/range_updater_spec.rb
214
+ - spec/lib/metricstore/updater_spec.rb
215
+ - spec/lib/metricstore_spec.rb
216
+ - spec/spec_helper.rb
@@ -1,24 +0,0 @@
1
- module Metricstore
2
- module BaseClient
3
-
4
- def initialize
5
- @ttl_of_hours = 31_556_926 # 1 year
6
- @ttl_of_minutes = 86_400 # 24 hours
7
- @ttl_of_group_members = 7200 # 2 hours
8
- @list_threshold = 1000
9
- end
10
-
11
- attr_accessor :ttl_of_hours
12
- attr_accessor :ttl_of_minutes
13
- attr_accessor :ttl_of_group_members
14
- attr_accessor :list_threshold
15
-
16
- def counter(args={})
17
- #TODO
18
- end
19
-
20
- def measure(args={})
21
- #TODO
22
- end
23
- end
24
- end