Skip to content

Commit

Permalink
Change counter parameters to follow other plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
repeatedly committed Mar 30, 2018
1 parent bc997ac commit 056a344
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
12 changes: 4 additions & 8 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ def before_run
end

if counter = config[:counter_server]
@counter_endpoint = counter.endpoint
@counter_scope = counter.scope
@counter_path = counter.path
run_counter_server
run_counter_server(counter)
end

socket_manager_path = ServerEngine::SocketManager::Server.generate_path
Expand Down Expand Up @@ -135,11 +132,10 @@ def stop_rpc_server
@rpc_server.shutdown
end

def run_counter_server
host, port = @counter_endpoint.split(':')
def run_counter_server(counter_conf)
@counter = Fluent::Counter::Server.new(
@counter_scope,
{ host: host, port: port, log: $log, path: @counter_path }
counter_conf.scope,
{host: counter_conf.bind, port: counter_conf.port, log: $log, path: counter_conf.backup_path}
)
@counter.start
end
Expand Down
14 changes: 9 additions & 5 deletions lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ class SystemConfig
desc 'scope name of counter server'
config_param :scope, :string

desc 'endpoint of counter server'
config_param :endpoint, :string # host:port
desc 'the port of counter server to listen to'
config_param :port, :integer, default: nil
desc 'the bind address of counter server to listen to'
config_param :bind, :string, default: nil

desc 'backup file path of counter values'
config_param :path, :string
config_param :backup_path, :string
end

config_section :counter_client, multi: false do
desc 'endpoint of counter client'
config_param :endpoint, :string # host:port
desc 'the port of counter server'
config_param :port, :integer, default: nil
desc 'the IP address or hostname of counter server'
config_param :host, :string
end

def self.create(conf)
Expand Down
17 changes: 13 additions & 4 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ def test_system_config
time_format %Y
</log>
<counter_server>
endpoint 127.0.0.1:4321
bind 127.0.0.1
port 4321
scope server1
path /tmp/backup
backup_path /tmp/backup
</counter_server>
<counter_client>
host 127.0.0.1
port 4321
</counter_client>
</system>
EOC
conf = Fluent::Config.parse(conf_data, "(test)", "(test_dir)", true)
Expand All @@ -157,9 +162,13 @@ def test_system_config
assert_equal :json, sys_conf.log.format
assert_equal '%Y', sys_conf.log.time_format
counter_server = sys_conf.counter_server
assert_equal '127.0.0.1:4321', counter_server.endpoint
assert_equal '127.0.0.1', counter_server.bind
assert_equal 4321, counter_server.port
assert_equal 'server1', counter_server.scope
assert_equal '/tmp/backup', counter_server.path
assert_equal '/tmp/backup', counter_server.backup_path
counter_client = sys_conf.counter_client
assert_equal '127.0.0.1', counter_client.host
assert_equal 4321, counter_client.port
end

def test_main_process_signal_handlers
Expand Down

0 comments on commit 056a344

Please sign in to comment.