trd-rails-collector 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. data/lib/trd-rails-collector.rb +26 -8
  2. metadata +4 -4
@@ -38,7 +38,7 @@ module TreasureData
38
38
  require 'yaml'
39
39
  sample = <<EOF
40
40
  defaults: &defaults
41
- apikey: "78fbbc1ff83088ab72e2b68c980c4c75786bee6e"
41
+ apikey: "YOUR_API_KEY"
42
42
  database: myapp
43
43
  table: access
44
44
 
@@ -76,9 +76,10 @@ EOF
76
76
  config.middleware.use TreasureData::Rack
77
77
  end
78
78
 
79
- SIZE_LIMIT = 1024*1024 # 1MB
80
- TIME_LIMIT = 5 # 1min TODO
81
- SLEEP_TIME = 10 # 10sec TODO
79
+ SIZE_LIMIT = 1024*1024 # bytes
80
+ TIME_LIMIT = 60 # sec
81
+ SLEEP_TIME = 10 # sec
82
+ RETRY_LIMIT = 8
82
83
 
83
84
  API_HOST = 'api.treasure-data.com'
84
85
  API_PORT = 80
@@ -138,6 +139,7 @@ EOF
138
139
 
139
140
  def upload_main
140
141
  tuple = nil
142
+ error_count = 0
141
143
 
142
144
  until @finish
143
145
  @map.synchronize do
@@ -160,9 +162,20 @@ EOF
160
162
 
161
163
  begin
162
164
  code, body = upload(*tuple)
165
+ if code[0] != ?2
166
+ raise "import failed: #{body}"
167
+ end
163
168
  rescue
164
- # TODO retry
165
- $stderr.puts $!
169
+ if error_count < RETRY_LIMIT
170
+ # TODO wait before retry
171
+ sleep (2 ** error_count)
172
+ tuple = nil
173
+ error_count += 1
174
+ RAILS_DEFAULT_LOGGER.error "Failed to upload log to Treasure Data, retrying: #{$!}"
175
+ else
176
+ RAILS_DEFAULT_LOGGER.error "Failed to upload log to Treasure Data, trashed: #{$!}"
177
+ $stderr.puts "Failed to upload log to Treasure Data, trashed: #{$!}"
178
+ end
166
179
  end
167
180
  end
168
181
 
@@ -189,9 +202,9 @@ EOF
189
202
  header['Date'] = Time.now.rfc2822
190
203
  header['Content-Length'] = data.size.to_s
191
204
 
192
- url = "/v2/import/#{e @db}/#{e @table}/msgpack.gz"
205
+ url = "/v3/table/import/#{e @db}/#{e @table}/msgpack.gz"
193
206
 
194
- RAILS_DEFAULT_LOGGER.debug "Uploading compressed logs #{data.size} bytes to #{url}"
207
+ RAILS_DEFAULT_LOGGER.info "Uploading compressed logs (#{data.size} bytes) to Treasure Data"
195
208
  request = Net::HTTP::Put.new(url, header)
196
209
  request.body = data
197
210
 
@@ -225,6 +238,9 @@ EOF
225
238
  # Rails 3
226
239
  'action_dispatch.request.path_parameters',
227
240
 
241
+ # Rails 2
242
+ 'action_controller.request.path_parameters',
243
+
228
244
  # Rack default
229
245
  'rack.routing_args',
230
246
  ]
@@ -262,6 +278,7 @@ EOF
262
278
  # time parameter is required
263
279
  m['time'] = Time.now.to_i
264
280
 
281
+ #puts m.to_json
265
282
  TreasureData.emit(m)
266
283
 
267
284
  #File.open('out.log', "a") {|f|
@@ -269,6 +286,7 @@ EOF
269
286
  #}
270
287
 
271
288
  #File.open('envlog.txt', "a") {|f|
289
+ # require 'pp'
272
290
  # f.write env.pretty_inspect
273
291
  #}
274
292
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trd-rails-collector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sadayuki Furuhashi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-25 00:00:00 +09:00
18
+ date: 2011-06-27 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency