fluent-output-router 0.9.2 → 0.9.3

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 (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/fluent/plugin/out_router.rb +31 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDY1YjVmZWE4MjE5YWEzNjZhYzlkMWU3MjM4N2E2MTk0N2M4MjAyMQ==
4
+ MWRhOGYwN2Y4MjUwNjYyYjViNDA2ZjA2NzMzZDk0NWRmZWI2NTFiNQ==
5
5
  data.tar.gz: !binary |-
6
- NTQxMWZjZjI4YzBiMmU0ZGEwYmMyNTIxY2M4NzA2MTM3NDk2YTVkYw==
6
+ MTg0ZjM5NmY2MDcxOGMwMzdjOWU4NDlkMDk4ZjM5MGQyNDM0NGY3Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODZjY2ZhNDQyYWY4MjU2ODlkMWY0ZDFlOGQ0ODQ2ZTUxYjY0ZjU1ZTk2MDM5
10
- NmY5OGE2MTgyYWRiM2U0Yzk2ODFkNTczZWU1YjBlM2YxN2JjOGRkMDk0MjFi
11
- ZTA5OWVmYmM3OTI3YTZlY2Y5YWE0MTY5YjQ1ZGY0ZTNiYzU0NGM=
9
+ NjcyNWZlY2EyMmFjZjJlODNhZDgxNzRhYjIxOTU0ZWQ3MWYzMTcwMGZlMTU0
10
+ ZTk4Y2ZlMGMxODRmMTliODYyZmQxMzI0ODA3YjZmYTBhOWY4YmUyMWExMTA1
11
+ ZjE3ZTllNzQ5M2Y2MTY2YThjM2U5Y2RlNjBhNjdmZWQzOGY1YmE=
12
12
  data.tar.gz: !binary |-
13
- NjM0ZjMxMGI0Mzc1ZDI5YjA0Y2E2NzNiNGY2NGYyYzY2MWU0YTY5OGMyMGFj
14
- OTQ3MzZhMWM3YjhiNTRmZjQ3NjhhM2E2ZjM0MDNhYjI0ZjQ2ZDQ5YWQ5ODgx
15
- NDA5Zjk5ZTkwODQxYjIyYzlkNDljNDQxYzZhYzQ2Mzk4YTA2ZDQ=
13
+ NGI0OGU0NTYwODNlNjljOTA4NTYxMTZjMmJhNmY3N2Y5MzIzZDcxNzBiZmU5
14
+ ZTUwZDJmMjk5N2Q1OTc2NDdmMmI1MWRhN2I0MGUzM2FiY2RmZDE5MmEyN2M0
15
+ NjFjNmJjNjc4OGQwYzY1MDdiZDlkMTZhOWJkYTRmZDkzZTUxNzM=
@@ -17,12 +17,13 @@
17
17
  require 'erb'
18
18
  require 'rubygems'
19
19
  require 'json'
20
+ require 'thread'
20
21
 
21
22
  module Fluent
22
23
  class RouterOutput < Fluent::Output
23
24
 
24
25
  Fluent::Plugin.register_output('router', self)
25
- MIN_REAPER_INTERVAL = 5 #sec
26
+ MIN_REAPER_INTERVAL = 15 #sec
26
27
  ROUTER_STATE_FILE = "router_state.json"
27
28
 
28
29
  def initialize
@@ -30,6 +31,7 @@ module Fluent
30
31
  @outputs = {}
31
32
  @last_used_time = {}
32
33
  @last_reaper_run = Time.now
34
+ @semaphore = Mutex.new
33
35
  end
34
36
 
35
37
  def configure(conf)
@@ -71,18 +73,25 @@ module Fluent
71
73
 
72
74
  private
73
75
 
76
+ # start_output is synchroned with a mutex
77
+ # to avoid any concurrency problems if the input plugin is multithreaded
78
+ # for example: the scribe input plugin is multitreaded by default
74
79
  def start_output(key)
75
- log "Starting a new output of type " + @output_config['type'] +
76
- " for key #{key}"
77
- @outputs[key] = Fluent::Plugin.new_output @output_config['type']
78
- @last_used_time[key] = Time.now
79
- config = @output_config.clone
80
- template! config, :key => key
81
- out = @outputs[key]
82
- out.configure config
83
- out.start
84
- @state_serializer.store(@outputs.keys)
85
- out
80
+ @semaphore.synchronize do
81
+ unless @outputs[key]
82
+ log "Starting a new output of type " + @output_config['type'] +
83
+ " for key #{key}"
84
+ @outputs[key] = Fluent::Plugin.new_output @output_config['type']
85
+ @last_used_time[key] = Time.now
86
+ config = @output_config.clone
87
+ template! config, :key => key
88
+ out = @outputs[key]
89
+ out.configure config
90
+ out.start
91
+ @state_serializer.store(@outputs.keys)
92
+ end
93
+ @outputs[key]
94
+ end
86
95
  end
87
96
 
88
97
  def stop_output(key)
@@ -99,7 +108,6 @@ module Fluent
99
108
  conf.elements.each { |e| mark_used e }
100
109
  end
101
110
 
102
- # MUTABLE. WHICH ALSO MEANS IT IS TERRIBLE.
103
111
  def template!(conf, keys)
104
112
  conf.each do |k,v|
105
113
  case v
@@ -120,13 +128,18 @@ module Fluent
120
128
 
121
129
  # This is the reaper that is used to avoids resource leaks
122
130
  # It will stop any active output plugin that does not get any input
131
+ # The code in run_reaper is synchroned with a mutex
132
+ # to avoid any concurrency problems if the input plugin is multithreaded
133
+ # for example: the scribe input plugin is multitreaded by default
123
134
  def run_reaper(now)
124
135
  if now - @last_reaper_run > MIN_REAPER_INTERVAL then
125
- @last_used_time.each {|key, stored_time|
126
- if now - stored_time > @inactivity_timeout then
127
- stop_output(key)
128
- end }
129
- @last_reaper_run = now
136
+ @last_reaper_run = now
137
+ @semaphore.synchronize do
138
+ @last_used_time.each {|key, stored_time|
139
+ if now - stored_time > @inactivity_timeout then
140
+ stop_output(key)
141
+ end }
142
+ end
130
143
  end
131
144
  end
132
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-output-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Almroth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-19 00:00:00.000000000 Z
12
+ date: 2013-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd