consul-templaterb 1.28.0 → 1.31.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: c15ee78520048d7d091882b9d3b1d43b4cc5f5658cf39d782f06e1dc617d8cd9
4
- data.tar.gz: 6f77a9daab557420f2640a314a97f78af68e26fec91c1a66f3ee575d9bf150f8
3
+ metadata.gz: a0929b48d32c3a556bff69053efcb0f239ee7cc18b39907c71ae1309bebeabbb
4
+ data.tar.gz: f6a8130e754621e9603a11cbbbc0963c67ef043b5578c35944ed6a26f9e59d3e
5
5
  SHA512:
6
- metadata.gz: 8c2b374a9400061f3ffd673e418771bb5685ec3d13a631c3839660121d86575be1fbbd1cd99f7ee1a4ddedf850ec72fa984ca084575da587b7a239d2e4654b2e
7
- data.tar.gz: '0933c0a2f1f58c617c184679ab68c1e90d55f1d9ab796e45336ddbbf49ae2fd73cf1aafbfea6e921254a520c8be3e5f0f380cfbdacd694ba2de6c5f8e4f5a074'
6
+ metadata.gz: 643d665507cd9a633dffdc741f4d643a55a0c4acaefc7feb08396f95383f491dd8d1917f3264b49a04cc67d258efa8dee58a7bc50d7fe74b440fbad74877c36b
7
+ data.tar.gz: dfe3a05334f0d65216b5973ea9f5716c983ce6d428751243991d8708781d9b95ff19404fba886f83df711563b2c46a3850a06f391b7a26c2ec82a7987df046fa
@@ -1,6 +1,39 @@
1
1
  # CHANGELOG
2
2
 
3
- ## (UNRELEASED)
3
+ ## 1.31.0 (Jan 18, 2021)
4
+
5
+ IMPROVEMENTS:
6
+
7
+ * Do not apply penalty on unmodified services not changing much (Will improve streaming performance)
8
+
9
+ ## 1.30.0 (Dec 18, 2020)
10
+
11
+ IMPROVEMENTS:
12
+
13
+ * Allow customization to sort nodes in service view in Consul-UI ([#71](https://github.com/criteo/consul-templaterb/pull/71))
14
+
15
+ NEW FEATURES:
16
+
17
+ * Auto-detection of rate-limit on Consul Side (introduced in Consul 1.6.2+), this feature
18
+ will work only Consul 1.9+ (see [Consul #7527](https://github.com/hashicorp/consul/issues/7527)).
19
+
20
+ ## 1.29.0 (Oct 6, 2020)
21
+
22
+ IMPROVEMENTS:
23
+
24
+ * When no template has been specified, stop early with an error message
25
+
26
+ ## 1.28.2 (Oct 5, 2020)
27
+
28
+ NEW FEATURES:
29
+
30
+ * Added new decorator to compute node names in consul-ui ([#70](https://github.com/criteo/consul-templaterb/pull/70))
31
+
32
+ ## 1.28.1 (Sept 30, 2020)
33
+
34
+ IMPROVEMENTS:
35
+
36
+ * Reduced size of GEM from 400k o 100k by removing not needed files
4
37
 
5
38
  ## 1.28.0 (Sept 25, 2020)
6
39
 
@@ -10,7 +43,7 @@ NEW FEATURES:
10
43
  to a process executed. This avoids for instance reloading too much a HAProxy configuration
11
44
  without having to play with `-w` as described in [#69](https://github.com/criteo/consul-templaterb/issues/69)
12
45
 
13
- BUGFIX:
46
+ BUG FIXES:
14
47
 
15
48
  * Removed warnings at runtime with Ruby 2.7+
16
49
  * Minor JS fix in Consul-UI (Added missing unused parameter to function `serviceTitleGenerator`)
@@ -25,7 +58,7 @@ IMPROVEMENTS:
25
58
 
26
59
  BUGIX:
27
60
 
28
- * Fix collision in JSON queries when using payload in requests #68
61
+ * Fix collision in JSON queries when using payload in requests [#68](https://github.com/criteo/consul-templaterb/pull/68)
29
62
 
30
63
  ## 1.27.0 (June 5, 2020)
31
64
 
@@ -38,15 +71,15 @@ NEW FEATURES:
38
71
 
39
72
  ## 1.26.3 (April 15, 2020)
40
73
 
41
- BUGFIX:
74
+ BUG FIXES:
42
75
 
43
76
  * Removed all Criteo specific decorators from Consul-UI
44
77
 
45
78
  ## 1.26.2 (April 15, 2020)
46
79
 
47
- BUGFIX:
80
+ BUG FIXES:
48
81
 
49
- * Fixed broken Dockerfile (was missing the new `decorator.js.erb` file). Fixes #61 (Thanks to @ simongareste)
82
+ * Fixed broken Dockerfile (was missing the new `decorator.js.erb` file). Fixes #61 (Thanks to [@simongareste](https://github.com/simongareste))
50
83
 
51
84
  NEW FEATURES:
52
85
 
@@ -54,7 +87,7 @@ NEW FEATURES:
54
87
 
55
88
  ## 1.26.1 (March 27, 2020)
56
89
 
57
- BUGFIX:
90
+ BUG FIXES:
58
91
 
59
92
  * Using `agent: http://vault_or_consul_agent:port>` was not properly taken into account in some endpoints
60
93
 
@@ -72,7 +105,7 @@ NEW FEATURES:
72
105
 
73
106
  ## 1.25.2 (February 29, 2020)
74
107
 
75
- BUGFIX:
108
+ BUG FIXES:
76
109
 
77
110
  * Update rake to 12.3.3 to fix [CVE-2020-8130](https://github.com/advisories/GHSA-jppv-gw3r-w3q8)
78
111
 
@@ -91,7 +124,7 @@ NEW FEATURES:
91
124
 
92
125
  ## 1.24.1 (February 19, 2020)
93
126
 
94
- BUGFIX:
127
+ BUG FIXES:
95
128
 
96
129
  * Properly set service meta in node meta decorator
97
130
 
@@ -108,7 +141,7 @@ NEW FEATURES:
108
141
  * Implementation of #59 - implementation of `--retry` and `--vault-retry` new flags
109
142
  Those flags work in a similar way as in consul-template: stop program after X failures
110
143
  of consul or vault endpoints
111
- * Added --fail-fast that stop the programs immediately if vault or consul are not available
144
+ * Added `--fail-fast` that stop the programs immediately if vault or consul are not available
112
145
  at startup (also works with `--once`)
113
146
 
114
147
  ## 1.22.0 (January 17, 2020)
@@ -119,7 +152,7 @@ NEW FEATURES:
119
152
 
120
153
  ## 1.21.8 (January 2, 2020)
121
154
 
122
- BUGFIX:
155
+ BUG FIXES:
123
156
 
124
157
  * Escape properly metadata containing double quotes in prometheus exporter
125
158
 
@@ -133,13 +166,13 @@ IMPROVEMENTS:
133
166
 
134
167
  IMPROVEMENTS:
135
168
 
136
- * Added node_meta_info for serviceInstanceDecorator and serviceMetaDecorator
169
+ * Added `node_meta_info` for `serviceInstanceDecorator` and `serviceMetaDecorator` in Consul-UI
137
170
 
138
171
  ## 1.21.5 (December 6, 2019)
139
172
 
140
173
  NEW FEATURES:
141
174
 
142
- * Added clean() method in nodes.js to allow nexw behaviors
175
+ * Added `clean()` method in nodes.js to allow new behaviors
143
176
 
144
177
  ## 1.21.4 (November 28, 2019)
145
178
 
@@ -170,7 +203,7 @@ IMPROVEMENTS:
170
203
  ## 1.21.0 (November 21, 2019)
171
204
 
172
205
  * added function `templates` to list all templates being rendered
173
- * added support for JS decorators in consul-ui (thanks to @Thib17)
206
+ * added support for JS decorators in consul-ui (thanks to [@Thib17](https://github.com/Thib17))
174
207
 
175
208
  ## 1.20.0 (October 16, 2019)
176
209
 
@@ -189,7 +222,7 @@ NEW FEATURES:
189
222
 
190
223
  * Added new function `checks_for_node`
191
224
 
192
- BUGFIXs:
225
+ BUG FIXES:
193
226
 
194
227
  * Avoid try publishing several times Gem on rubygems.org
195
228
 
@@ -211,13 +244,13 @@ IMPROVEMENTS:
211
244
 
212
245
  ## 1.18.3 (September 2, 2019)
213
246
 
214
- BUGFIX:
247
+ BUG FIXES:
215
248
 
216
249
  * When vault receives at timeout, correctly reschedule it
217
250
 
218
251
  ## 1.18.2 (August 28, 2019)
219
252
 
220
- BUGFIX:
253
+ BUG FIXES:
221
254
 
222
255
  * In Consul UI, showing data from KV with markup was not properly handled
223
256
 
@@ -233,7 +266,7 @@ Support any request method for remote_resource.as_json (#41)
233
266
 
234
267
  ## 1.18.1 (July 27, 2019)
235
268
 
236
- BUGFIX:
269
+ BUG FIXES:
237
270
 
238
271
  Fixed wrong lazy initialization in `remote_resource.as_json` that
239
272
  cause too many connections to be opened.
@@ -242,13 +275,13 @@ cause too many connections to be opened.
242
275
 
243
276
  NEW FEATURES:
244
277
 
245
- * Support for `remote_resource` provided by @kamaradclimber
278
+ * Support for `remote_resource` provided by [@kamaradclimber](https://github.com/kamaradclimber)
246
279
  * Added support for `remote_resource.as_json` to fetch JSON remote resource from a web server
247
280
  * Added `samples/list_ruby_versions_from_rubygems.txt.erb` to demonstrate usage
248
281
 
249
282
  ## 1.17.3 (July 18, 2019)
250
283
 
251
- BUGFIX:
284
+ BUG FIXES:
252
285
 
253
286
  * Added gem parallel as a dependency to allow `samples/prometheus_consul_coordinates.erb`
254
287
  to work properly
@@ -373,7 +406,7 @@ NEW FEATURES:
373
406
 
374
407
  ## 1.10.1 (February 28, 2019)
375
408
 
376
- BUGFIX:
409
+ BUG FIXES:
377
410
 
378
411
  * Ensure that timeline sort properly events when healthchecks are removed (eg: maintenance)
379
412
 
@@ -396,7 +429,7 @@ IMPROVEMENTS:
396
429
 
397
430
  ## 1.9.8 (January 16, 2019)
398
431
 
399
- BUGFIX:
432
+ BUG FIXES:
400
433
 
401
434
  * When default value was the same as real value, endpoints were always marked as
402
435
  dirty, thus rendering of templates did never succeed.
@@ -412,7 +445,7 @@ IMPROVEMENTS:
412
445
 
413
446
  ## 1.9.6 (January 15, 2019)
414
447
 
415
- BUGFIX:
448
+ BUG FIXES:
416
449
 
417
450
  * Keep connections open properly as it increase timeouts on Consul servers on
418
451
  very large templates
@@ -423,7 +456,7 @@ IMPROVEMENTS:
423
456
 
424
457
  ## 1.9.5 (January 14, 2019)
425
458
 
426
- BUGFIX:
459
+ BUG FIXES:
427
460
 
428
461
  * Ensure to always re-open Connection to Consul agent in case of network error
429
462
 
@@ -473,11 +506,11 @@ IMPROVEMENTS:
473
506
 
474
507
  OPTIMIZATIONS:
475
508
 
476
- * Better network issue because of X-Consul-Index parsing bug
509
+ * Better network usage because of X-Consul-Index parsing bug
477
510
 
478
- NEW FEATURES:
511
+ BUG FIXES:
479
512
 
480
- * value.endpoint.x_consul_index now works as expected
513
+ * `value.endpoint.x_consul_index` now works as expected
481
514
 
482
515
  IMPROVEMENTS:
483
516
 
@@ -517,7 +550,7 @@ NEW FEATURES:
517
550
 
518
551
  ## 1.8.1 (December 12, 2018)
519
552
 
520
- BUGFIX:
553
+ BUG FIXES:
521
554
 
522
555
  * Properly fill `template_info` strtucture when hot reload is performed so templates using
523
556
  `template_info()` new function can behave nicely.
@@ -626,8 +659,8 @@ IMPROVEMENTS:
626
659
  * [Prometheus template](samples/metrics.erb) to export easily Consul
627
660
  informations about nodes, datacenters and all services states
628
661
  * Code style cleanup + travis now enforces Rubocop
629
- * Remove criteo references in spec files thanks to @pierrecdn
630
- * Bitrate display more consistent thanks to @pierrecdn
662
+ * Remove criteo references in spec files thanks to [@pierrecdn](https://github.com/pierrecdn)
663
+ * Bitrate display more consistent thanks to [@pierrecdn](https://github.com/pierrecdn)
631
664
 
632
665
  ## 1.5.3 (September 24, 2018)
633
666
 
@@ -388,7 +388,7 @@ name or its ID. If DC is specified, will lookup for given node in another datace
388
388
 
389
389
  [Find all the checks](https://www.consul.io/api/health.html#list-checks-for-service) of a given service.
390
390
 
391
- ## def checks_in_state(check_state, dc: nil, [agent: consul_agent_address])
391
+ ## checks_in_state(check_state, dc: nil, [agent: consul_agent_address])
392
392
 
393
393
  [Find all the checks in a given state](https://www.consul.io/api-docs/health#list-checks-in-state) in the whole cluster.
394
394
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.28.0'.freeze
3
+ VERSION = '1.31.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']
@@ -36,6 +36,13 @@ function usefullLinksGenerator(instance, serviceName, node_meta_info) {
36
36
  return top;
37
37
  }
38
38
 
39
+ /**
40
+ * createNodeDisplayElement resolves and displays the node name.
41
+ */
42
+ function createNodeDisplayElement(nodeName, nodemeta) {
43
+ return document.createTextNode(nodeName);
44
+ }
45
+
39
46
  /**
40
47
  * serviceInstanceDecorator is called to decorate an instance.
41
48
  */
@@ -71,7 +71,7 @@ class NodeMainSelector extends MainSelector {
71
71
  content.setAttribute('class', 'instance-content');
72
72
  var contentHead = document.createElement('div');
73
73
  contentHead.setAttribute('class', 'instance-content-header');
74
- contentHead.appendChild(nodeNameGenator(node['Node']['Name'], node['Node']['Address']));
74
+ contentHead.appendChild(nodeNameGenator(node['Node']));
75
75
  contentHead.appendChild(nodeAddressGenator(node['Node']['Address']));
76
76
  contentHead.appendChild(nodeMetaGenerator(node['Node']['Meta']));
77
77
  content.appendChild(contentHead);
@@ -304,8 +304,8 @@ class ServiceMainSelector extends MainSelector {
304
304
  element.setAttribute("class", "list-group-item service-instance");
305
305
  var state = nodeState(instance.checks);
306
306
  element.appendChild(weightsGenerator(instance.weights, state));
307
- element.appendChild(serviceTitleGenerator(instance, serviceName));
308
307
  var node_info = this.nodes[instance.name];
308
+ element.appendChild(serviceTitleGenerator(instance, serviceName, node_info));
309
309
  if (node_info != null) {
310
310
  node_info = node_info.meta;
311
311
  element.appendChild(nodeMetaGenerator(node_info, instance.sMeta));
@@ -63,7 +63,7 @@ function nodeState(checks) {
63
63
 
64
64
  supported_protocols = ['https', 'http', 'sftp', 'ftp', 'ssh', 'telnet']
65
65
 
66
- function serviceTitleGenerator(instance, serviceName) {
66
+ function serviceTitleGenerator(instance, serviceName, node_info) {
67
67
  var protocol = null;
68
68
  for (i in supported_protocols) {
69
69
  var protoc = supported_protocols[i]
@@ -86,7 +86,10 @@ function serviceTitleGenerator(instance, serviceName) {
86
86
  instanceLink.setAttribute('target', '_blank');
87
87
  }
88
88
 
89
- instanceLink.appendChild(document.createTextNode(instance.name + appendPort));
89
+ var nodemeta = (node_info != null) ? node_info.meta : null;
90
+ instanceLink.appendChild(createNodeDisplayElement(instance.name, nodemeta));
91
+ instanceLink.appendChild(document.createTextNode(appendPort));
92
+
90
93
  const nodeInfo = document.createElement('a');
91
94
  nodeInfo.appendChild(document.createTextNode('\u24D8'));
92
95
  nodeInfo.setAttribute('title', 'Click to see details of Node: ' + instance.name +
@@ -103,7 +106,7 @@ function serviceTitleGenerator(instance, serviceName) {
103
106
  return htmlTitle;
104
107
  }
105
108
 
106
- function nodeNameGenator(nodename, nodeaddr) {
109
+ function nodeNameGenator(node) {
107
110
  var protocol = 'ssh://'
108
111
 
109
112
  var htmlTitle = document.createElement('h5');
@@ -111,10 +114,10 @@ function nodeNameGenator(nodename, nodeaddr) {
111
114
  var instanceLink = document.createElement('a');
112
115
  instanceLink.setAttribute('class', 'instance-name');
113
116
  if (protocol != null) {
114
- instanceLink.setAttribute('href', protocol + nodeaddr);
117
+ instanceLink.setAttribute('href', protocol + node['Address']);
115
118
  instanceLink.setAttribute('target', '_blank');
116
119
  }
117
- instanceLink.appendChild(document.createTextNode(nodename));
120
+ instanceLink.appendChild(createNodeDisplayElement(node['Name'], node['Meta']));
118
121
  htmlTitle.appendChild(instanceLink);
119
122
 
120
123
  return htmlTitle;