rhcf-timeseries 0.0.3 → 0.0.4

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWQ4ZTdkNzAzNDA4YWQ4YWUzOGM1NDYxM2QwZWQ5OTJmMDBjZTI4Nw==
4
+ YTZjZTY2NzI1MjUxNjZjZWUzYzE2OTA4ODQ5NTU0YmFkYmVhMzQ4OA==
5
5
  data.tar.gz: !binary |-
6
- MTkwZGY4OWM3NzM0MDRlZTY1ZjlhNTM4YzVmNWYyM2JiMTdlY2YzZA==
6
+ ZTNkMTkwNzA5OTQzYjBkMmIwNzU3YmRjYzQ1ODhlNTNkYTQ1OTYwYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWUxMjM2Y2RjNDdhYzdiYTA5MmM4NTkyZjIxODkzOTM3OGE0NWM2OWRlZmFk
10
- ZmRjZjYxZWIwMjBlN2VjYmVhNjk1NmM2OGI5NmZjNTNkNmM1NjE5ZWFlM2M4
11
- NzNmNzhiZDM0YmI4YzBkNDNiN2I4YjE4YzZiZjg5NDRkOWQzNTA=
9
+ MDA0MjRlZTBmNTNjYzNiY2ExMGEzZGM4ZjJlMzc0MmI1YjdjMmIwZTkzZDUw
10
+ Mjg4MDA2ODVhNDE3YzEzMWE1YzkwNDQ0OGZjZDVlMjZjOGViMGNkZWEzNDQ2
11
+ NTMyMThkNzdkZDQ2Y2YyMDJkYzAyOWQ5YzEwZGU5M2Y1NmM3ODM=
12
12
  data.tar.gz: !binary |-
13
- MDU0Yzk5MGE4ZjdmOTA1MWUyMGQ0NDA1MzA5YjIwYjYyYjAzMGIxYjViOGM4
14
- YTg5NzcxNjY3ZTgwY2RhMTI1NzU1YmI1ODQyMmY5YWYwMmQwMDUzOTUzNWE0
15
- ODMxODQ3MTlhMzRiYzM5YTM1YTQ5Mzk5YjdkNjQ5Y2IzYzgxMmI=
13
+ MmIxMzBlMTJhYWI5ZDAxNjkzM2M2ZDdmMTFmYzVjMDRlMTljODNjYTBjNmEw
14
+ ZDI5ZWM2YjcwYjdjOWJhM2Y1NDIwMjU3ZmFiZTY4NjRmZDcwYWRjYTJiOTE1
15
+ ZmM5YmM4ZWJmMTI0NjUwYjZhZmU0NjU0NjllNjllODU5NDkyZjQ=
@@ -1,6 +1,3 @@
1
- #require 'active_support/core_ext/numeric/time'
2
-
3
- require 'micon'
4
1
  require 'date'
5
2
 
6
3
  class Fixnum
@@ -42,7 +39,7 @@ module Rhcf
42
39
  class Result
43
40
  def initialize(subject, from, to, series)
44
41
  if from > to
45
- raise ArgumentError, "Argument 'from' can not be bigger then 'to'"
42
+ fail ArgumentError, "Argument 'from' can not be bigger then 'to'"
46
43
  end
47
44
  @series = series
48
45
  @subject = subject
@@ -100,13 +97,12 @@ module Rhcf
100
97
  span = @to - @from
101
98
  resolutions = @series.resolutions.sort_by{|h| h[:span]}.reverse
102
99
  better = resolutions.find{|r| r[:span] < span / 5} || resolutions.last
100
+ return better
103
101
  end
104
102
  end
105
103
 
106
104
 
107
105
  class Redis
108
- inject :logger
109
- inject :redis_connection
110
106
 
111
107
  RESOLUTIONS_MAP={
112
108
  :ever => {span:Float::INFINITY, formatter: "ever", ttl: (2 * 366).days},
@@ -123,25 +119,26 @@ module Rhcf
123
119
 
124
120
  }
125
121
  DEFAULT_RESOLUTIONS = RESOLUTIONS_MAP.keys
126
- DEFAULT_MAX_POINTS = 1_024
127
122
  NAMESPACE_SEPARATOR = '|'
128
123
 
124
+ attr_reader :logger
129
125
 
130
- def initialize(options = {})
126
+ def initialize(logger, redis, options = {})
131
127
  @resolution_ids = options[:resolutions] || DEFAULT_RESOLUTIONS
132
- @max_points = options[:max_points] || DEFAULT_MAX_POINTS
133
128
  @prefix = options[:prefix] || self.class.name
134
- @connection_to_use = nil
129
+ @logger = logger
130
+ @connection_to_use = redis
135
131
  end
136
132
 
137
133
  def on_connection(conn)
134
+ old_connection = @connection_to_use
138
135
  @connection_to_use = conn
139
136
  yield self
140
- @connection_to_use = nil
137
+ @connection_to_use = old_connection
141
138
  end
142
139
 
143
140
  def redis_connection_to_use
144
- @connection_to_use || redis_connection
141
+ @connection_to_use || fail("No redis connection given")
145
142
  end
146
143
 
147
144
  def store(subject, event_point_hash, moment = Time.now)
@@ -180,7 +177,7 @@ module Rhcf
180
177
  when Proc
181
178
  time_resolution_formater.call(moment)
182
179
  else
183
- raise ArgumentError, "Unexpected moment formater type #{time_resolution_formater.class}"
180
+ fail ArgumentError, "Unexpected moment formater type #{time_resolution_formater.class}"
184
181
  end
185
182
  end
186
183
 
@@ -226,7 +223,7 @@ module Rhcf
226
223
  end
227
224
 
228
225
  def keys(*a_key)
229
- raise "GIVEUP"
226
+ fail "GIVEUP"
230
227
  a_key = [@prefix, a_key].flatten.join(NAMESPACE_SEPARATOR)
231
228
  logger.debug("FINDING KEY #{a_key}")
232
229
  redis_connection_to_use.keys(a_key).collect{|k| k.split(NAMESPACE_SEPARATOR)[1,1000].join(NAMESPACE_SEPARATOR) }
@@ -241,7 +238,7 @@ module Rhcf
241
238
 
242
239
  def resolution(id)
243
240
  res = RESOLUTIONS_MAP[id]
244
- raise ArgumentError, "Invalid resolution name #{id} for this time series" if res.nil?
241
+ fail ArgumentError, "Invalid resolution name #{id} for this time series" if res.nil?
245
242
  res.merge(:id => id)
246
243
  end
247
244
  def resolutions
@@ -1,5 +1,5 @@
1
1
  module Rhcf
2
2
  module Timeseries
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -28,5 +28,4 @@ Gem::Specification.new do |spec|
28
28
  #spec.add_development_dependency "simplecov"
29
29
  spec.add_development_dependency "timecop"
30
30
  #spec.add_dependency "activesupport"
31
- spec.add_dependency "micon"
32
31
  end
@@ -1,16 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'timecop'
3
3
  require 'redis'
4
- require 'micon'
5
4
  require 'rhcf/timeseries/redis'
6
5
  require 'benchmark'
7
6
  require 'logger'
8
- micon.register(:logger){Logger.new('/dev/null')}
9
- #micon.register(:logger){Logger.new(STDOUT)}
10
- micon.register(:redis_connection){Redis.new}
11
-
12
7
 
13
8
  describe Rhcf::Timeseries::Redis do
9
+ let(:null_logger){Logger.new('/dev/null')}
10
+ let(:redis_connection){Redis.new}
11
+ subject{Rhcf::Timeseries::Redis.new(null_logger, redis_connection)}
14
12
 
15
13
  before(:each) do
16
14
  Timecop.return
@@ -21,16 +19,16 @@ describe Rhcf::Timeseries::Redis do
21
19
  subject.flush!
22
20
  total = 0
23
21
  start_time = Time.now
24
-
22
+
25
23
  bench = Benchmark.measure {
26
- 10000.times do
27
- total +=1
28
- subject.store("a", {"b" => 1} ) #, time)
29
- end
24
+ 10000.times do
25
+ total +=1
26
+ subject.store("a", {"b" => 1} ) #, time)
27
+ end
30
28
  }
31
29
 
32
-
33
- #pp subject.find("a", start_time - 11100, Time.now + 11100).points(:second)
30
+
31
+ #pp subject.find("a", start_time - 11100, Time.now + 11100).points(:second)
34
32
  qbench = Benchmark.measure {
35
33
  subject.find("a", start_time - 11100, Time.now + 11100).total['b'].to_i.should == total
36
34
  }
@@ -38,7 +36,7 @@ describe Rhcf::Timeseries::Redis do
38
36
  qbench_year = Benchmark.measure {
39
37
  subject.find("a", start_time - 100000, Time.now + 100000).total(:year)['b'].to_i.should == total
40
38
  }
41
-
39
+
42
40
  puts "Write speed %d points/seg | points:%d, duration:%0.3fs | query_time %0.3fs" % [speed = (1.0 * total / (bench.total + 0.00000001)), total, bench.total, qbench.total]
43
41
  speed.should > 400
44
42
  end
@@ -62,7 +60,7 @@ describe Rhcf::Timeseries::Redis do
62
60
 
63
61
  Timecop.travel(15.minutes) #00:00:00
64
62
  subject.store("views/product/11", {"web/ie/5" => 2})
65
-
63
+
66
64
  Timecop.travel(15.minutes) #00:00:15
67
65
  subject.store("views/product/11", {"web/chrome/11"=> 4})
68
66
 
@@ -70,7 +68,7 @@ describe Rhcf::Timeseries::Redis do
70
68
  subject.store("views/product/11", {"web/chrome/11"=> 2})
71
69
 
72
70
  subject.find("views/product", start_time, start_time + 55.minutes).total(:ever).should == {
73
- "web" => 16.0,
71
+ "web" => 16.0,
74
72
  "web/chrome" => 6.0,
75
73
  "web/chrome/11" => 6.0,
76
74
  "web/firefox" => 3.0,
@@ -81,7 +79,7 @@ describe Rhcf::Timeseries::Redis do
81
79
  }
82
80
 
83
81
  subject.find("views/product", start_time, start_time + 55.minutes).total(:year).should == {
84
- "web" => 16.0,
82
+ "web" => 16.0,
85
83
  "web/chrome" => 6.0,
86
84
  "web/chrome/11" => 6.0,
87
85
  "web/firefox" => 3.0,
@@ -127,40 +125,40 @@ describe Rhcf::Timeseries::Redis do
127
125
  ]
128
126
 
129
127
  subject.find("views", start_time).points(:hour).should == [{:moment=>"2000-01-01T00",
130
- :values=>
131
- {"web/ie"=>5.0,
132
- "web"=>8.0,
133
- "web/firefox"=>3.0,
134
- "web/ie/6"=>5.0,
135
- "web/firefox/3"=>3.0}},
136
- {:moment=>"2000-01-01T01",
137
- :values=>
138
- {"web/ie"=>2.0,
139
- "web/chrome"=>6.0,
140
- "web/chrome/11"=>6.0,
141
- "web"=>8.0,
142
- "web/ie/5"=>2.0}}]
128
+ :values=>
129
+ {"web/ie"=>5.0,
130
+ "web"=>8.0,
131
+ "web/firefox"=>3.0,
132
+ "web/ie/6"=>5.0,
133
+ "web/firefox/3"=>3.0}},
134
+ {:moment=>"2000-01-01T01",
135
+ :values=>
136
+ {"web/ie"=>2.0,
137
+ "web/chrome"=>6.0,
138
+ "web/chrome/11"=>6.0,
139
+ "web"=>8.0,
140
+ "web/ie/5"=>2.0}}]
143
141
 
144
142
 
145
143
  end
146
144
 
147
- it "causes no stack overflow" do
148
- params_hash = {
149
- sender_domain: 'example.com',
150
- realm: 'realm',
151
- destination_domain: 'lvh.me',
152
- mail_server: 'aserver',
153
- bind_interface: '11.1.1.11'
154
- }
155
-
156
- {
157
- 'sender_domain' => '%{sender_domain}',
158
- 'realm_and_sender_domain' => '%{realm}/%{sender_domain}',
159
- 'mail_server_and_interface' => '%{mail_server}/%{bind_interface}',
160
- 'realm_and_destination_domain' => '%{realm}/%{destination_domain}',
161
- 'destination_domain' => '%{destination_domain}'
162
- }.each do |known, unknown|
163
- subject.store(known % params_hash, {[(unknown % params_hash),'sent'].join('/') => 1})
145
+ it "causes no stack overflow" do
146
+ params_hash = {
147
+ sender_domain: 'example.com',
148
+ realm: 'realm',
149
+ destination_domain: 'lvh.me',
150
+ mail_server: 'aserver',
151
+ bind_interface: '11.1.1.11'
152
+ }
153
+
154
+ {
155
+ 'sender_domain' => '%{sender_domain}',
156
+ 'realm_and_sender_domain' => '%{realm}/%{sender_domain}',
157
+ 'mail_server_and_interface' => '%{mail_server}/%{bind_interface}',
158
+ 'realm_and_destination_domain' => '%{realm}/%{destination_domain}',
159
+ 'destination_domain' => '%{destination_domain}'
160
+ }.each do |known, unknown|
161
+ subject.store(known % params_hash, {[(unknown % params_hash),'sent'].join('/') => 1})
164
162
  end
165
163
  end
166
164
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,8 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  #require 'simplecov'
8
- #SimpleCov.start
8
+ #SimpleCov.start_with?
9
+ require 'timecop'
9
10
  RSpec.configure do |config|
10
11
  config.treat_symbols_as_metadata_keys_with_true_values = true
11
12
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhcf-timeseries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romeu Fonseca
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: micon
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ! '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  description: Gem to allow your system to keep record of time series on rhcf
98
84
  email:
99
85
  - romeu.hcf@gmail.com