logworm_amqp 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGELOG +3 -0
  2. data/Rakefile +1 -1
  3. data/lib/base/db.rb +47 -51
  4. data/logworm_amqp.gemspec +2 -2
  5. metadata +4 -4
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.8.6
2
+ Now retrieve amqp_url remotely for better security.
3
+
1
4
  v0.8.5
2
5
  Started logging amqp usage statistics to our servers (randomly) for better QA.
3
6
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'echoe'
2
- Echoe.new('logworm_amqp', '0.8.5') do |p|
2
+ Echoe.new('logworm_amqp', '0.8.6') do |p|
3
3
  p.description = "logworm logging tool"
4
4
  p.url = "http://www.logworm.com"
5
5
  p.author = "Pomelo, LLC"
data/lib/base/db.rb CHANGED
@@ -18,6 +18,10 @@ module Logworm
18
18
 
19
19
  URL_FORMAT = /logworm:\/\/([^:]+):([^@]+)@([^\/]+)\/([^\/]+)\/([^\/]+)\//
20
20
  # URI: logworm://<consumer_key>:<consumer_secret>@db.logworm.com/<access_token>/<access_token_secret>/
21
+
22
+ MIN_AQMP = 500
23
+ STATS_FREQ = 300
24
+ RETRY_FREQUENCY = 60
21
25
 
22
26
  attr_reader :host, :consumer_key, :consumer_secret, :token, :token_secret
23
27
 
@@ -27,12 +31,7 @@ module Logworm
27
31
  raise ForbiddenAccessException.new("Incorrect URL Format #{url}") unless match and match.size == 6
28
32
  @consumer_key, @consumer_secret, @host, @token, @token_secret = match[1..5]
29
33
  @connection = OAuth::AccessToken.new(OAuth::Consumer.new(@consumer_key, @consumer_secret), @token, @token_secret)
30
- Minion.amqp_url = "amqp://logworm-producer:4tX.z.rC@pomelo-1.dotcloud.com/"
31
- @current_day = Time.now.yday
32
- @total_time = 0
33
- @tock = 0
34
- @amqp_min = 500
35
- @amqp_max = 0
34
+ reset_stats
36
35
  end
37
36
 
38
37
  def self.with_tokens(token, token_secret)
@@ -79,7 +78,7 @@ module Logworm
79
78
  DB.make_url(@host, @consumer_key, @consumer_secret, @token, @token_secret)
80
79
  end
81
80
 
82
- def self.example_url
81
+ def self.example_url()
83
82
  self.make_url("db.logworm.com", "Ub5sOstT9w", "GZi0HciTVcoFHEoIZ7", "OzO71hEvWYDmncbf3C", "J7wq4X06MihhZgqDeB")
84
83
  end
85
84
 
@@ -109,60 +108,57 @@ module Logworm
109
108
  def escape(value)
110
109
  CGI.escape(value.to_s).gsub("%7E", '~').gsub("+", "%20")
111
110
  end
112
-
113
- def set_minion_url()
114
- #updates amqp_url potentially once a day.
115
- day_now = Time.now.yday
116
- if day_now != @current_day
117
- url = nil
118
- begin
119
- res = db_call(:get, "#{host_with_protocol}/amqp_url")
120
- url = res["url"] if res and res["url"]
121
- rescue Exception
111
+
112
+ def get_amqp_url()
113
+ if @amqp_url.nil? and (@last_attempt.nil? or (Time.now - @last_attempt) > RETRY_FREQUENCY)
114
+ begin
115
+ @amqp_url = db_call(:get, "#{host_with_protocol}/amqp_url")["url"]
116
+ Minion.amqp_url = @amqp_url
117
+ rescue
118
+ @last_attempt = Time.now
119
+ end
122
120
  end
123
- Minion.amqp_url = url if !url.nil?
124
- @current_day = day_now
125
- end
121
+ !(@amqp_url.nil?)
122
+ end
123
+
124
+ def to_amqp(queue, payload)
125
+ if get_amqp_url
126
+ sig= signature(payload.to_json, @token_secret )
127
+ Minion.enqueue(queue, {:payload => content, :consumer_key => @token, :signature => sig,
128
+ :env => ENV['RACK_ENV'] || "?", :timestamp => Time.now})
129
+ end
126
130
  end
131
+
132
+ def recording_stats()
133
+ s = Time.now
134
+ yield if block_given?
135
+ record_stats((Time.now - s))
136
+ push_stats() if (rand(STATS_FREQ) == 1)
137
+ end
127
138
 
128
- def amqp_avg_set(value)
129
- #min and max can be the same target value if method is only used once.
130
- if value > @amqp_max
131
- @amqp_max = value
132
- end
133
- if value < @amqp_min
134
- @amqp_min = value
135
- end
139
+ def record_stats(value)
140
+ @tock += 1
141
+ @total_time += value
142
+ @amqp_max = value if value > @amqp_max
143
+ @amqp_min = value if value < @amqp_min
136
144
  end
137
-
145
+
138
146
  def push_stats()
139
- if (rand(300) == 1) #and @tock > 0 --> don't need to worry about this since tock is always incremented at least once before ever using as a divsor
140
- average = @total_time / @tock
141
- tstamp = Time.now
142
- Minion.enqueue("lw.stats", {:avg => average, :stamp => tstamp,
143
- :max => @amqp_max, :min => @amqp_min, :max => @amqp_max, :total => @total_time })
144
- @total_time = 0
145
- @tock = 0
146
- @amqp_max = 0
147
- @amqp_min = 500
148
- end
147
+ to_amqp("lw.stats", {:avg => (@total_time / @tock), :max => @amqp_max, :min => @amqp_min, :max => @amqp_max})
148
+ reset_stats
149
149
  end
150
150
 
151
+ def reset_stats()
152
+ @total_time = @tock = @amqp_max = 0
153
+ @amqp_min = MIN_AQMP
154
+ end
155
+
151
156
  def batch_log(entries)
152
- #db_call(:post, "#{host_with_protocol}/log", {:entries => $lr_queue.to_json})
153
- content = $lr_queue.to_json
154
- sig= signature(content, @token_secret )
155
- set_minion_url()
156
- s = Time.now
157
- Minion.enqueue("lw.logging", {:entries => content, :consumer_key => @token, :signature => sig })
158
- elapse = (Time.now - s)
159
- @total_time += elapse
160
- @tock += 1
161
- amqp_avg_set(elapse)
162
- push_stats()
157
+ recording_stats do
158
+ to_amqp("lw.logging", {:entries => entries.to_json})
159
+ end
163
160
  end
164
161
 
165
-
166
162
  private
167
163
  def db_call(method, uri, params = {})
168
164
  begin
data/logworm_amqp.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{logworm_amqp}
5
- s.version = "0.8.5"
5
+ s.version = "0.8.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Pomelo, LLC"]
9
- s.date = %q{2010-08-04}
9
+ s.date = %q{2010-08-06}
10
10
  s.description = %q{logworm logging tool}
11
11
  s.email = %q{schapira@pomelollc.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "README.md", "lib/base/config.rb", "lib/base/db.rb", "lib/base/query_builder.rb", "lib/logworm_amqp.rb"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logworm_amqp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 5
10
- version: 0.8.5
9
+ - 6
10
+ version: 0.8.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pomelo, LLC
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-04 00:00:00 -04:00
18
+ date: 2010-08-06 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency