consul-templaterb 1.13.1 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +4 -0
- data/lib/consul/async/consul_template.rb +6 -2
- data/lib/consul/async/version.rb +1 -1
- data/samples/haproxy_dns.cfg.erb +105 -0
- metadata +3 -3
- data/samples/criteo_choregraphies.html.erb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf5c69b8bbbe9ee35642288ce1e5535e2faa3d0
|
4
|
+
data.tar.gz: e40f21f3950ee6276e68022c9e1480f06098850b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e325f31bbc13002496602c82b1c58b661118443048ce43bf7cbd8520dce9afe024fdf5f6d3d43db6422521f3f80408d2cea94617d4f1ad91ca7fcd0ec3cfae8
|
7
|
+
data.tar.gz: 1d81cb3a0c852f95e501a3b6aec6a8db6c3baab3406f81389ed85830772906fea3bfb1e28b9efea1dfb0b88296b5ba98a3c0c2a35d7a8133d8953e6b440bc854
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## (UNRELEASED)
|
4
4
|
|
5
|
+
## 1.14.0 (May 6, 2019)
|
6
|
+
|
7
|
+
NEW FEATURES:
|
8
|
+
|
9
|
+
When `return nil` is performed in a template, consul-templaterb now considers the template is
|
10
|
+
not ready and thus do not start any process. It is useful if you want to start a process ONLY
|
11
|
+
when some conditions are met.
|
12
|
+
|
5
13
|
## 1.13.1 (April 12, 2019)
|
6
14
|
|
7
15
|
IMPROVEMENTS:
|
data/README.md
CHANGED
@@ -216,6 +216,10 @@ meaning that if 2 results of templates are modified at the same time, the signal
|
|
216
216
|
sent only once (it is helpful for instance if your app is using several configurations
|
217
217
|
files that must be consistent all together).
|
218
218
|
|
219
|
+
If any template does return nothing (aka use `return nil` in the code of a template),
|
220
|
+
consul-templaterb does consider that the template is not ready and will not launch the executable
|
221
|
+
nor write the file.
|
222
|
+
|
219
223
|
Signals can be customized per process. Two signals are supported with options `--sig-reload` and
|
220
224
|
`--sig-term`. When the option is added, the next `--exec` options to start a process will use the
|
221
225
|
given signal. By default, HUP will be sent to reload events (you can use NONE to avoid sending any
|
@@ -222,10 +222,14 @@ module Consul
|
|
222
222
|
end
|
223
223
|
to_cleanup << endpoint_key if (@iteration - endpt.seen_at) > 60
|
224
224
|
end
|
225
|
-
if not_ready.count.positive?
|
225
|
+
if not_ready.count.positive? || data.nil?
|
226
226
|
if @iteration - @last_debug_time > 1
|
227
227
|
@last_debug_time = @iteration
|
228
|
-
|
228
|
+
if data.nil?
|
229
|
+
::Consul::Async::Debug.print_info "Waiting for Template #{tpl_file_path} to not return nil, consider it not ready...\r"
|
230
|
+
else
|
231
|
+
::Consul::Async::Debug.print_info "Waiting for data from #{not_ready.count}/#{not_ready.count + ready} endpoints: #{not_ready[0..2]}...\r"
|
232
|
+
end
|
229
233
|
end
|
230
234
|
return [false, false, nil]
|
231
235
|
end
|
data/lib/consul/async/version.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
# HaProxy template with consul-templaterb adapted from
|
2
|
+
# https://github.com/haproxytech/haproxy/blob/master/blog/integration_with_consul/haproxy.conf.tmpl
|
3
|
+
#
|
4
|
+
# You might read this article:
|
5
|
+
# https://www.haproxy.com/blog/haproxy-and-consul-with-dns-for-service-discovery/
|
6
|
+
#
|
7
|
+
# This template is more powerful than initial implementation:
|
8
|
+
# * It discovers by itself the services (by default, all having http tag)
|
9
|
+
# * It allows having white/blacklists of services
|
10
|
+
# * It handles nicely services having http/non http tag
|
11
|
+
#
|
12
|
+
# Here is how to configure it with environment variables:
|
13
|
+
#
|
14
|
+
# This template can be configure the following way with environment variables
|
15
|
+
# Environment variables to filter services/instances
|
16
|
+
# SERVICES_TAG_FILTER: basic tag filter for service (default HTTP)
|
17
|
+
# EXCLUDE_SERVICES: comma-separated services regexps to exclude (default: lbl7.*,netsvc-probe.*,consul-probed.*)
|
18
|
+
# SERVICES_MATCHING: regexp to show only services matching the regexp, defaults to '.*'
|
19
|
+
#
|
20
|
+
# HaProxy specific:
|
21
|
+
# HAPROXY_DOMAIN_NAME the domain name to serve, eg: myservice => myservice.example.com
|
22
|
+
# CONSUL_DOMAIN_NAME_SUFFIX = suffix in consul configuration (default 'consul', so services are myservice.service.consul)
|
23
|
+
# HAPROXY_PREFIX_PATH = where you want HaProxy to reload config
|
24
|
+
# CONSUL_DNS_ADDR: Address of DNS resolver returning consul SRV records (defaults to 127.0.0.1:8600)
|
25
|
+
# PORT0: HaProxy port to use to serve (default: 8000)
|
26
|
+
# HAPROXY_STATS_BIND: bind stats on... (defaut: '127.0.0.1:1936', can use for instance '*:1936')
|
27
|
+
# HAPROXY_ADMIN_USER_PASSWORD: Password to access stats (defaults: none)
|
28
|
+
#
|
29
|
+
# USAGE examples:
|
30
|
+
#
|
31
|
+
# Reverse HTTP Proxy for services with tag http and starting with 'web'
|
32
|
+
# SERVICES_MATCHING='web.*' consul-templaterb samples/haproxy_dns.cfg.erb --sig-reload=HUP --exec 'haproxy -W -f samples/haproxy_dns.cfg'
|
33
|
+
|
34
|
+
<%
|
35
|
+
consul_domain_name = ENV['CONSUL_DOMAIN_NAME_SUFFIX'] || 'consul'
|
36
|
+
ha_proxy_data_prefix = ENV['HAPROXY_PREFIX_PATH'] || File.absolute_path('.')
|
37
|
+
ha_proxy_data_prefix += '/' unless ha_proxy_data_prefix.end_with? '/'
|
38
|
+
services_tag_filter = ENV['SERVICES_TAG_FILTER'] || 'http'
|
39
|
+
services_matching = Regexp.new(ENV['SERVICES_MATCHING'] || '.*')
|
40
|
+
|
41
|
+
# Services to hide
|
42
|
+
services_blacklist_raw = (ENV['EXCLUDE_SERVICES'] || 'lbl7.*,netsvc-probe.*,consul-probed.*').split(',')
|
43
|
+
services_blacklist = services_blacklist_raw.map { |v| Regexp.new(v) }
|
44
|
+
%>
|
45
|
+
global
|
46
|
+
# daemon
|
47
|
+
# debug
|
48
|
+
pidfile <%= ha_proxy_data_prefix %>haproxy.pid
|
49
|
+
stats socket <%= ha_proxy_data_prefix %>haproxy.sock level admin
|
50
|
+
# If you want to configure from KV, you might use:
|
51
|
+
# You might use instead: `kv("service/haproxy/maxconn").get_value_decoded() || 256`
|
52
|
+
maxconn 256
|
53
|
+
log 127.0.0.01:514 local0 info
|
54
|
+
server-state-file <%= ha_proxy_data_prefix %>haproxy.serverstates
|
55
|
+
description HAProxy / consul demo
|
56
|
+
|
57
|
+
resolvers consul
|
58
|
+
nameserver <%= consul_domain_name %> <%= ENV['CONSUL_DNS_ADDR'] || '127.0.0.1:8600' %>
|
59
|
+
accepted_payload_size 8192
|
60
|
+
|
61
|
+
defaults
|
62
|
+
log global
|
63
|
+
option httplog
|
64
|
+
option socket-stats
|
65
|
+
load-server-state-from-file global
|
66
|
+
default-server init-addr none inter 1s rise 2 fall 2
|
67
|
+
mode http
|
68
|
+
timeout client 30s
|
69
|
+
timeout connect 4s
|
70
|
+
timeout http-keep-alive 10s
|
71
|
+
timeout http-request 5s
|
72
|
+
timeout server 30s
|
73
|
+
|
74
|
+
frontend http-in
|
75
|
+
bind *:<%= ENV['PORT0'] || 8000 %>
|
76
|
+
maxconn 256
|
77
|
+
use_backend b_%[req.hdr(Host),lower,word(1,:)]
|
78
|
+
|
79
|
+
<%
|
80
|
+
services(tag: services_tag_filter).each do |service_name, tags|
|
81
|
+
if services_matching.match(service_name) && !services_blacklist.any? {|r| r.match(service_name)}
|
82
|
+
%>
|
83
|
+
backend b_<%= service_name %>.<%= ENV['HAPROXY_DOMAIN_NAME'] || 'example.com' %>
|
84
|
+
server-template <%= service_name %> 10 <%= services_tag_filter %>.<%= service_name %>.service.<%= consul_domain_name %> resolvers consul resolve-prefer ipv4 #check
|
85
|
+
<%
|
86
|
+
end
|
87
|
+
end
|
88
|
+
%>
|
89
|
+
|
90
|
+
frontend stats
|
91
|
+
bind <%= ENV['HAPROXY_STATS_BIND'] || '127.0.0.1:1936' %>
|
92
|
+
mode http
|
93
|
+
option forceclose
|
94
|
+
stats enable
|
95
|
+
stats uri /
|
96
|
+
stats show-legends
|
97
|
+
stats show-desc
|
98
|
+
stats show-node
|
99
|
+
stats refresh 60
|
100
|
+
<%
|
101
|
+
user_password = ENV['HAPROXY_ADMIN_USER_PASSWORD']
|
102
|
+
if user_password
|
103
|
+
%>
|
104
|
+
stats auth <%= user_password %>
|
105
|
+
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-templaterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SRE Core Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -204,10 +204,10 @@ files:
|
|
204
204
|
- samples/consul_template.xml.erb
|
205
205
|
- samples/consul_template_broken.txt.erb
|
206
206
|
- samples/criteo/haproxy.cfg.erb
|
207
|
-
- samples/criteo_choregraphies.html.erb
|
208
207
|
- samples/criteo_choregraphies.txt.erb
|
209
208
|
- samples/debug/compare_connect_services.txt.erb
|
210
209
|
- samples/ha_proxy.cfg.erb
|
210
|
+
- samples/haproxy_dns.cfg.erb
|
211
211
|
- samples/keys.html.erb
|
212
212
|
- samples/kv_yaml_to_json.json.erb
|
213
213
|
- samples/metrics.erb
|
@@ -1,99 +0,0 @@
|
|
1
|
-
<% require 'base64'
|
2
|
-
require 'json'
|
3
|
-
require 'date'
|
4
|
-
@current_time = Time.now.utc
|
5
|
-
%><%= render_file('common/header.html.erb', title: 'Choregraphies', refresh: 30) %>
|
6
|
-
<main class="container">
|
7
|
-
<div>
|
8
|
-
<h1>Show all choregraphie information</h1>
|
9
|
-
<div>This page only show choregraphie when at least one holder exists.</div>
|
10
|
-
<%
|
11
|
-
def display_holder(holder, value)
|
12
|
-
begin
|
13
|
-
holder_date = Time.parse(value)
|
14
|
-
status = 'success'
|
15
|
-
diff = (@current_time - holder_date).round(0)
|
16
|
-
status = 'warning' if diff > 3600
|
17
|
-
status = 'danger' if diff > 7200
|
18
|
-
diff_txt = "#{diff % 3600} seconds"
|
19
|
-
diff_txt = "#{(diff % 86400) / 3600} hours, #{diff_txt}" if diff > 3600
|
20
|
-
diff_txt = "#{diff / 86400} days, #{diff_txt}" if diff > 86400
|
21
|
-
rescue StandardError => e
|
22
|
-
status = 'info'
|
23
|
-
holder_date = "Cannot parse date: #{e}"
|
24
|
-
diff_txt = "Error Parsing date #{value}"
|
25
|
-
end
|
26
|
-
["<li class=\"list-group-item list-group-item-#{status}\">#{holder}: #{holder_date} : #{diff_txt} ago", status]
|
27
|
-
end
|
28
|
-
%>
|
29
|
-
|
30
|
-
<div id="accordion">
|
31
|
-
<% kv('choregraphie', recurse:true).each do |tuple| %>
|
32
|
-
<!-- <%= tuple['Key'] %> -->
|
33
|
-
<%
|
34
|
-
key = tuple['Key'].gsub('/', '-')
|
35
|
-
if tuple['Value'].nil?
|
36
|
-
json = []
|
37
|
-
holders = []
|
38
|
-
%>
|
39
|
-
<div class="alert alert-warning" role="alert">
|
40
|
-
Invalid Choregraphie data: <%= tuple %>
|
41
|
-
</div>
|
42
|
-
<%
|
43
|
-
else
|
44
|
-
json = JSON.parse(Base64.decode64(tuple['Value']))
|
45
|
-
begin
|
46
|
-
holders = json['holders']
|
47
|
-
rescue StandardError => e
|
48
|
-
%>
|
49
|
-
<h1>Failed to parse holders <%= e %> in <%= json %></h1>
|
50
|
-
<%
|
51
|
-
holders = []
|
52
|
-
end
|
53
|
-
end
|
54
|
-
%>
|
55
|
-
<% if holders.count > 0 %>
|
56
|
-
|
57
|
-
<div class="card">
|
58
|
-
<div class="card-header" id="heading-<%= key %>">
|
59
|
-
<span class="badge badge-pill badge-primary float-right"><%= holders.count%>/<%= json['concurrency'] %></span>
|
60
|
-
<h5 class="mb-0">
|
61
|
-
<a href="#<%= key %>" class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapse-<%= key %>" aria-expanded="true" aria-controls="collapse-<%= key %>">
|
62
|
-
<%= tuple['Key'] %>
|
63
|
-
</a>
|
64
|
-
</h5>
|
65
|
-
</div>
|
66
|
-
<%
|
67
|
-
text_result = ''
|
68
|
-
clazz = 'collapse'
|
69
|
-
holders.each_pair do |key,value|
|
70
|
-
if value.is_a?(Hash)
|
71
|
-
text_result+= "<li><u>#{key}:</u><ul class=\"list-group\">"
|
72
|
-
value.each_pair do |k, v|
|
73
|
-
res, status = display_holder(k, v)
|
74
|
-
clazz = 'collapse show' unless status == 'success'
|
75
|
-
text_result += res
|
76
|
-
end
|
77
|
-
text_result += '</ul></li>'
|
78
|
-
else
|
79
|
-
res, status = display_holder(key, value)
|
80
|
-
clazz = 'collapse show' unless status == 'success'
|
81
|
-
text_result << res
|
82
|
-
end
|
83
|
-
end
|
84
|
-
%>
|
85
|
-
<div id="collapse-<%= key %>" class="<%= clazz %>" aria-labelledby="heading-<%= key %>" data-parent="#accordion">
|
86
|
-
<div class="card-body">
|
87
|
-
<pre class="pre-scrollable"><code><%= JSON.pretty_generate(json) %></code></pre>
|
88
|
-
<ul class="list-group">
|
89
|
-
<%= text_result %>
|
90
|
-
</ul>
|
91
|
-
</div>
|
92
|
-
</div>
|
93
|
-
</div>
|
94
|
-
<% end %>
|
95
|
-
<% end %>
|
96
|
-
</div>
|
97
|
-
</div>
|
98
|
-
</main>
|
99
|
-
<%= render_file 'common/footer.html.erb' %>
|