samples/ha_proxy.cfg.erb in consul-templaterb-1.5.9 vs samples/ha_proxy.cfg.erb in consul-templaterb-1.6.0
- old
+ new
@@ -16,33 +16,20 @@
instance_must_tag = ENV['INSTANCE_MUST_TAG'] || service_tag_filter
instance_exclude_tag = ENV['INSTANCE_EXCLUDE_TAG'] || 'canary'
# Services to hide
services_blacklist = (ENV['EXCLUDE_SERVICES'] || 'consul-agent-http,mesos-slave,mesos-agent-watcher,mesos-exporter-slave').split(',')
- # Compute the health of a Service
- def compute_state(node)
- states = ['passing', []]
- node['Checks'].each do |chk|
- st = chk['Status']
- states[1] << st
- if st == 'critical'
- states[0] = st
- elsif st == 'warning' && states[0] == 'passing'
- states[0] = st
- end
- end
- states
- end
- def compute_attributes(node)
+
+ def compute_attributes(snode)
w = 100
- node['Service']['Tags'].each do |tag|
+ snode['Service']['Tags'].each do |tag|
match = /^weight-([1-9][0-9])*$/.match(tag)
w = match[1].to_i if match
end
attributes = ""
- states = compute_state(node)
- attributes = "#{attributes} disabled" if states[0] == 'critical'
- if states[0] == 'warning'
+ node_status = snode.status
+ attributes = "#{attributes} disabled" if node_status == 'critical'
+ if node_status == 'warning'
w = w / 8
end
attributes = "#{attributes} weight #{w}" if w.positive?
end
backends = {}
\ No newline at end of file