Skip to content

Commit

Permalink
Add basic test for nerve reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
joe committed Jul 25, 2016
1 parent 35704bb commit 85e8b2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
18 changes: 18 additions & 0 deletions example/nerve_services/serf_service1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"host": "1.2.3.4",
"port": 3000,
"reporter_type": "serf",
"check_interval": 2,
"zk_hosts": ["localhost:2181"],
"zk_path": "/nerve/services/your_http_service/services",
"weight": 2,
"checks": [
{
"type": "http",
"uri": "/health",
"timeout": 0.2,
"rise": 3,
"fall": 2
}
]
}
7 changes: 4 additions & 3 deletions lib/nerve/reporter/serf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def initialize(service)
# the name won't just be the name you gave but name_port. this allows a same
# service to be on multiple ports of a same machine.

# FIXME: support IPv6?
@data = "#{service['host']}:#{service['port']}"
@data = parse_data(get_service_data(service))
@config_file = File.join(@config_dir,"zzz_nerve_#{@name}.json")
File.unlink @config_file if File.exists? @config_file
end
Expand All @@ -34,7 +33,9 @@ def report_down

def update_data(new_data='')
@data = new_data if new_data
File.write(@config_file, JSON.generate({tags:{"smart:#{@name}"=>@data}}))
data = JSON.parse(@data)
tag = "#{data['host']}:#{data['port']}"
File.write(@config_file, JSON.generate({tags:{"smart:#{@name}" =>tag}}))
reload_serf
end

Expand Down
2 changes: 1 addition & 1 deletion spec/configuration_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(config_manager.config.keys()).to include('instance_id', 'services')
expect(config_manager.config['services'].keys()).to contain_exactly(
'your_http_service', 'your_tcp_service', 'rabbitmq_service',
'etcd_service1', 'zookeeper_service1'
'etcd_service1', 'serf_service1', 'zookeeper_service1'
)
end
end
Expand Down

0 comments on commit 85e8b2c

Please sign in to comment.