consul-templaterb 1.28.2 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b99b274e76706dd09a6da62555cc79c462d5072237825fb10fea80ef3d3e558
4
- data.tar.gz: 68e4a32addfb0decb19e8dbda17dfc99665c6e19da03d789cddf61196c051c7a
3
+ metadata.gz: 802bc9946fe5828724eff84a9564b5ec8313a5f6d795f1abb1c0dcafca94a268
4
+ data.tar.gz: fa0acac3ecf2d94000eb909d0001294552931e34c44ee8492d51081bd23806f0
5
5
  SHA512:
6
- metadata.gz: c1385863a2b51bb12c4b900c869a82048acecec0abe9e6875e151cf39151e5f0ff983b130549191d236315c22ff45e61810c515397d75fe2847dc28e70044499
7
- data.tar.gz: 9a6acde596746461c64b99145f13952e4e4cfc4ea009b9e31f65afab96f5e7ecf93f5764ad7d0e5fd98e5b37419bc5b60c169abf6aefdc5bb2cbbd55f1495c30
6
+ metadata.gz: 801abf727fd2f3c5db209244c5d7da533e27ff3985ac82c1c234e86f8bf70ce5f6a99bb608ca01d1d07b814d019b2f19010a7a8cbd6d7a4b5531b2345c50c280
7
+ data.tar.gz: 7ec7df66f3bfc071ba4fa8e6414006e9551e6ac34503c45a725b628f9891602185cae8ba69fecde220dbde25ab2dd8576c30e2158d96c303c7bb79ea7124984c
@@ -1,6 +1,40 @@
1
1
  # CHANGELOG
2
2
 
3
- ## (UNRELEASED)
3
+ ## 1.32.0 (Jan 27, 2021)
4
+
5
+ IMPROVEMENTS:
6
+
7
+ * Use Ruby 2.7.2 in Travis build
8
+ * [VAULT] Do not handle missing secret as a blocking exception ([#73](https://github.com/criteo/consul-templaterb/pull/73))
9
+
10
+ ## 1.31.1 (Jan 25, 2021)
11
+
12
+ IMPROVEMENTS:
13
+
14
+ * Use Node.Meta.fqdn to display node names in timeline if set
15
+
16
+ ## 1.31.0 (Jan 18, 2021)
17
+
18
+ IMPROVEMENTS:
19
+
20
+ * Do not apply penalty on unmodified services not changing much (Will improve streaming performance)
21
+
22
+ ## 1.30.0 (Dec 18, 2020)
23
+
24
+ IMPROVEMENTS:
25
+
26
+ * Allow customization to sort nodes in service view in Consul-UI ([#71](https://github.com/criteo/consul-templaterb/pull/71))
27
+
28
+ NEW FEATURES:
29
+
30
+ * Auto-detection of rate-limit on Consul Side (introduced in Consul 1.6.2+), this feature
31
+ will work only Consul 1.9+ (see [Consul #7527](https://github.com/hashicorp/consul/issues/7527)).
32
+
33
+ ## 1.29.0 (Oct 6, 2020)
34
+
35
+ IMPROVEMENTS:
36
+
37
+ * When no template has been specified, stop early with an error message
4
38
 
5
39
  ## 1.28.2 (Oct 5, 2020)
6
40
 
@@ -375,6 +375,11 @@ ARGV.each do |tpl|
375
375
  consul_engine.add_template(tpl, dest)
376
376
  end
377
377
 
378
+ if consul_engine.templates.count.zero?
379
+ puts 'You must specify at least one template as arg or using -t'
380
+ exit 255
381
+ end
382
+
378
383
  template_manager = Consul::Async::EndPointsManager.new(consul_conf, vault_conf, consul_engine.templates, options[:erb][:trim_mode])
379
384
 
380
385
  Signal.trap('USR1', 'IGNORE') unless Gem.win_platform?
@@ -225,9 +225,34 @@ module Consul
225
225
  retry_in / 2 + Consul::Async::Utilities.random.rand(retry_in)
226
226
  end
227
227
 
228
+ # rubocop:disable Style/ClassVars
229
+ def _last_429
230
+ @@_last_429 ||= { count: 0 }
231
+ end
232
+ # rubocop:enable Style/ClassVars
233
+
228
234
  def _handle_error(http, consul_index)
229
235
  retry_in = _compute_retry_in([600, conf.retry_duration + 2**@consecutive_errors].min)
230
- ::Consul::Async::Debug.puts_error "[#{path}] X-Consul-Index:#{consul_index} - #{http.error} - Retry in #{retry_in}s #{stats.body_bytes_human}"
236
+ if http.response_header.status == 429
237
+ _last_429
238
+ retry_in = 60 + Consul::Async::Utilities.random.rand(180) if retry_in < 60
239
+ _last_429[:time] = Time.now.utc
240
+ _last_429[:count] += 1
241
+ if (_last_429[:count] % 10) == 1
242
+ if _last_429[:count] == 1
243
+ ::Consul::Async::Debug.puts_error "Rate limiting detected on Consul side (HTTP 429)!\n\n" \
244
+ "******************************* CONFIGURATION ISSUE DETECTED *******************************\n" \
245
+ "* Too many simultaneous connections for Consul agent #{conf.base_url}\n" \
246
+ "* You should tune 'limits.http_max_conns_per_client' to a higher value.\n" \
247
+ "* This program will behave badly until you change this.\n" \
248
+ "* See https://www.consul.io/docs/agent/options.html#http_max_conns_per_client for more info\n" \
249
+ "********************************************************************************************\n\n"
250
+ end
251
+ ::Consul::Async::Debug.puts_error "[#{path}] Too many conns to #{conf.base_url}, errors=#{_last_429[:count]} - Retry in #{retry_in}s #{stats.body_bytes_human}"
252
+ end
253
+ else
254
+ ::Consul::Async::Debug.puts_error "[#{path}] X-Consul-Index:#{consul_index} - #{http.error} - Retry in #{retry_in}s #{stats.body_bytes_human}"
255
+ end
231
256
  @consecutive_errors += 1
232
257
  http_result = HttpResponse.new(http)
233
258
  EventMachine.add_timer(retry_in) do
@@ -272,11 +297,12 @@ module Consul
272
297
  end
273
298
  new_content = http_result.response.freeze
274
299
  modified = @last_result.fake? || @last_result.data != new_content
275
- if n_consul_index == consul_index || n_consul_index.nil?
300
+ if n_consul_index.nil?
276
301
  retry_in = modified ? conf.missing_index_retry_time_on_diff : conf.missing_index_retry_time_on_unchanged
277
302
  n_consul_index = consul_index
278
303
  else
279
304
  retry_in = modified ? conf.min_duration : conf.retry_on_non_diff
305
+ retry_in = 0.1 if retry_in < (Time.now - @last_result.last_update)
280
306
  end
281
307
  retry_in = _compute_retry_in(retry_in)
282
308
  retry_in = 0.1 if retry_in < 0.1
@@ -245,7 +245,7 @@ module Consul
245
245
  http = connection.send(http_method.downcase, build_request) # Under the hood: c.send('get', {stuff}) === c.get({stuff})
246
246
  http.callback do
247
247
  http_result = VaultHttpResponse.new(http.dup.freeze, default_value)
248
- if enforce_json_200 && http.response_header.status != 200
248
+ if enforce_json_200 && ![200, 404].include?(http.response_header.status)
249
249
  _handle_error(http_result) { connection = EventMachine::HttpRequest.new(conf.base_url, options) }
250
250
  else
251
251
  @consecutive_errors = 0
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.28.2'.freeze
3
+ VERSION = '1.32.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ SORT_CONSUL_SERVICE_NODES = -> (nodes) { nodes.sort {|a,b| a['Node']['Node'] <=> b['Node']['Node'] } }
@@ -94,3 +94,9 @@ This app supports the following environment variables:
94
94
  * `EXCLUDE_SERVICES`: comma-separated services to exclude (default: lbl7.*,netsvc-probe.*,consul-probed.*)
95
95
  * `CONSUL_TIMELINE_BUFFER`: number of entries to keep in the timeline. 1000 by default.
96
96
  * `CONSUL_TIMELINE_BLACKLIST`: regexp of services to hide from timeline
97
+
98
+ ### Preferences
99
+
100
+ Some templates allows you to override some behavior through `.preferences.rb` file.
101
+ In order to do that, rename `.preferences.rb.samples` file to `.preferences.rb`
102
+ and update lambda defined inside to match targeted behavior.
@@ -6,6 +6,19 @@
6
6
  # INSTANCE_EXCLUDE_TAG: Exclude instances having the given tag (default: canary)
7
7
  # EXCLUDE_SERVICES: comma-separated services regexps to exclude (default: lbl7.*,netsvc-probe.*,consul-probed.*)
8
8
 
9
+ unless @sort_consul_service_nodes
10
+ begin
11
+ target_dir = File.split(File.expand_path(template_info['source']))[0]
12
+ target = File.join(target_dir, '.preferences.rb')
13
+ load "#{target}"
14
+ STDERR.puts "Using #{target} file."
15
+ @sort_consul_service_nodes = SORT_CONSUL_SERVICE_NODES
16
+ rescue LoadError
17
+ STDERR.puts 'Couldn\'t find .preferences.rb file ; default configuration will be used.'
18
+ @sort_consul_service_nodes = -> (nodes) { nodes.sort {|a,b| a['Node']['Node'] <=> b['Node']['Node'] } }
19
+ end
20
+ end
21
+
9
22
  service_tag_filter = ENV['SERVICES_TAG_FILTER'] || nil
10
23
  instance_must_tag = ENV['INSTANCE_MUST_TAG'] || service_tag_filter
11
24
  instance_exclude_tag = ENV['INSTANCE_EXCLUDE_TAG']
@@ -20,7 +33,7 @@
20
33
  if !services_blacklist.any? {|r| r.match(service_name)} && (instance_must_tag.nil? || tags.include?(instance_must_tag))
21
34
  tags_per_service[service_name] = tags.sort
22
35
  the_backends = []
23
- service(service_name).sort {|a,b| a['Node']['Node'] <=> b['Node']['Node'] }.each do |snode|
36
+ @sort_consul_service_nodes.call(service(service_name)).each do |snode|
24
37
  tags_of_instance = snode['Service']['Tags'].sort
25
38
  if (instance_must_tag.nil? || tags_of_instance.include?(instance_must_tag)) && !tags_of_instance.include?(instance_exclude_tag)
26
39
  the_backends << snode if snode['Service']['Port']
@@ -434,7 +434,7 @@ class ServiceTimeline {
434
434
  }
435
435
  var text = e.instance;
436
436
  if (e.instance_info && e.instance_info.node) {
437
- text = e.instance_info.node;
437
+ text = e.instance_info.fqdn;
438
438
  if (e.instance_info.port > 0) {
439
439
  text += ":" + e.instance_info.port
440
440
  }
@@ -41,10 +41,12 @@ cur_state = services.map do |service_name, _tags|
41
41
  mindex = chk['ModifyIndex'] || 0
42
42
  mod_index = mindex if mod_index < mindex
43
43
  end
44
- ["#{instance['Node']['Node']}:#{instance['Service']['ID']}",
44
+ node_name = instance['Node']['Node']
45
+ ["#{node_name}:#{instance['Service']['ID']}",
45
46
  {
46
47
  'address' => instance.service_address,
47
- 'node' => instance['Node']['Node'],
48
+ 'node' => node_name,
49
+ 'fqdn' => instance.node_meta['fqdn'] || node_name,
48
50
  'port' => instance['Service']['Port'],
49
51
  'idx' => mod_index || cur_index,
50
52
  'status' => instance.status,
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.28.2
4
+ version: 1.32.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: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -181,6 +181,7 @@ files:
181
181
  - samples/all_services_multi_agents.txt.erb
182
182
  - samples/all_templates.erb
183
183
  - samples/checks_in_warning_or_critical_state.yaml.erb
184
+ - samples/consul-ui/.preferences.rb.samples
184
185
  - samples/consul-ui/README.md
185
186
  - samples/consul-ui/common/footer.html.erb
186
187
  - samples/consul-ui/common/header.html.erb