td-logger 0.3.11 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -0
- data/VERSION +1 -1
- data/lib/td/logger/td_logger.rb +60 -41
- data/lib/td/logger/version.rb +1 -1
- metadata +12 -12
data/ChangeLog
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
|
2
|
+
== 2012-03-31 version 0.3.12
|
3
|
+
|
4
|
+
* TreasureDataLogger#close shows a error message if upload failed
|
5
|
+
instead of raising errors
|
6
|
+
* TreasureDataLogger#close deletes uploaded queue entry
|
7
|
+
* Changed increment storategy of flush_interval from += 10 to ** 2
|
8
|
+
|
9
|
+
|
2
10
|
== 2012-03-12 version 0.3.11
|
3
11
|
|
4
12
|
* Added TD.event.post_with_time(action, record, time) method
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.12
|
data/lib/td/logger/td_logger.rb
CHANGED
@@ -9,7 +9,7 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
9
9
|
obj = allocate
|
10
10
|
obj.instance_eval { initialize(*args, &block) }
|
11
11
|
dc = DelegateClass(obj.class).new(obj)
|
12
|
-
ObjectSpace.define_finalizer(
|
12
|
+
ObjectSpace.define_finalizer(obj, finalizer(obj))
|
13
13
|
dc
|
14
14
|
end
|
15
15
|
|
@@ -66,7 +66,7 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
66
66
|
@chunk_limit = 8*1024*1024
|
67
67
|
@queue_limit = 50
|
68
68
|
|
69
|
-
@flush_interval =
|
69
|
+
@flush_interval = 2
|
70
70
|
@max_flush_interval = 300
|
71
71
|
@retry_wait = 1.0
|
72
72
|
@retry_limit = 12
|
@@ -91,12 +91,24 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
91
91
|
}
|
92
92
|
@upload_thread.join if @upload_thread
|
93
93
|
|
94
|
-
@
|
95
|
-
|
96
|
-
|
94
|
+
@queue.reject! {|db,table,data|
|
95
|
+
begin
|
96
|
+
upload(db, table, data)
|
97
|
+
true
|
98
|
+
rescue
|
99
|
+
@logger.error "Failed to upload event logs to Treasure Data, trashed: #{$!}"
|
100
|
+
false
|
101
|
+
end
|
97
102
|
}
|
98
|
-
@
|
99
|
-
|
103
|
+
@map.reject! {|(db,table),buffer|
|
104
|
+
data = buffer.flush!
|
105
|
+
begin
|
106
|
+
upload(db, table, data)
|
107
|
+
true
|
108
|
+
rescue
|
109
|
+
@logger.error "Failed to upload event logs to Treasure Data, trashed: #{$!}"
|
110
|
+
false
|
111
|
+
end
|
100
112
|
}
|
101
113
|
end
|
102
114
|
end
|
@@ -118,18 +130,13 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
118
130
|
now = Time.now.to_i
|
119
131
|
|
120
132
|
if @next_time <= now || (@flush_now && @error_count == 0)
|
121
|
-
|
122
|
-
begin
|
123
|
-
flushed = try_flush
|
124
|
-
ensure
|
125
|
-
@mutex.lock
|
126
|
-
end
|
133
|
+
flushed = try_flush
|
127
134
|
@flush_now = false
|
128
135
|
end
|
129
136
|
|
130
137
|
if @error_count == 0
|
131
138
|
if flushed && @flush_interval < @max_flush_interval
|
132
|
-
@flush_interval = [@flush_interval
|
139
|
+
@flush_interval = [@flush_interval ** 2, @max_flush_interval].min
|
133
140
|
end
|
134
141
|
next_wait = @flush_interval
|
135
142
|
else
|
@@ -173,7 +180,6 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
173
180
|
|
174
181
|
def append(data)
|
175
182
|
@gz << data
|
176
|
-
map = MessagePack.unpack(data)
|
177
183
|
end
|
178
184
|
|
179
185
|
def size
|
@@ -249,6 +255,7 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
249
255
|
buffer.append(data)
|
250
256
|
|
251
257
|
if buffer.size > @chunk_limit
|
258
|
+
# flush this buffer
|
252
259
|
data = buffer.flush!
|
253
260
|
@queue << [db, table, data]
|
254
261
|
@map.delete(key)
|
@@ -264,43 +271,55 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
264
271
|
true
|
265
272
|
end
|
266
273
|
|
274
|
+
# assume @mutex is locked
|
267
275
|
def try_flush
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
276
|
+
# force flush small buffers if queue is empty
|
277
|
+
if @queue.empty?
|
278
|
+
@map.reject! {|(db,table),buffer|
|
279
|
+
data = buffer.flush!
|
280
|
+
@queue << [db, table, data]
|
281
|
+
}
|
282
|
+
end
|
283
|
+
|
284
|
+
if @queue.empty?
|
285
|
+
return false
|
275
286
|
end
|
276
287
|
|
277
288
|
flushed = false
|
278
289
|
|
279
|
-
|
280
|
-
|
290
|
+
@mutex.unlock
|
291
|
+
begin
|
292
|
+
until @queue.empty?
|
293
|
+
db, table, data = @queue.first
|
281
294
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
@error_count = 0
|
286
|
-
flushed = true
|
287
|
-
rescue
|
288
|
-
if @error_count < @retry_limit
|
289
|
-
@logger.error "Failed to upload event logs to Treasure Data, retrying: #{$!}"
|
290
|
-
@error_count += 1
|
291
|
-
else
|
292
|
-
@logger.error "Failed to upload event logs to Treasure Data, trashed: #{$!}"
|
293
|
-
$!.backtrace.each {|bt|
|
294
|
-
@logger.info bt
|
295
|
-
}
|
295
|
+
begin
|
296
|
+
upload(db, table, data)
|
297
|
+
@queue.shift
|
296
298
|
@error_count = 0
|
297
|
-
|
299
|
+
flushed = true
|
300
|
+
|
301
|
+
rescue
|
302
|
+
if @error_count < @retry_limit
|
303
|
+
@logger.error "Failed to upload event logs to Treasure Data, retrying: #{$!}"
|
304
|
+
@error_count += 1
|
305
|
+
else
|
306
|
+
@logger.error "Failed to upload event logs to Treasure Data, trashed: #{$!}"
|
307
|
+
$!.backtrace.each {|bt|
|
308
|
+
@logger.info bt
|
309
|
+
}
|
310
|
+
@error_count = 0
|
311
|
+
@queue.clear
|
312
|
+
end
|
313
|
+
return nil
|
314
|
+
|
298
315
|
end
|
299
|
-
return
|
300
316
|
end
|
317
|
+
|
318
|
+
ensure
|
319
|
+
@mutex.lock
|
301
320
|
end
|
302
321
|
|
303
|
-
flushed
|
322
|
+
return flushed
|
304
323
|
end
|
305
324
|
|
306
325
|
def upload(db, table, data)
|
data/lib/td/logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
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-
|
12
|
+
date: 2012-05-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70152935365260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70152935365260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: td-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70152935363700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.4
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70152935363700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fluent-logger
|
38
|
-
requirement: &
|
38
|
+
requirement: &70152935337300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.4.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70152935337300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70152935327220 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70152935327220
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70152935313920 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 2.7.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70152935313920
|
69
69
|
description: Treasure Data logging library for Rails
|
70
70
|
email:
|
71
71
|
executables: []
|