consul-templaterb 1.29.0 → 1.32.1

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: 76c96f61a1890c149604e52ed7d68bd239fe6b8df3bdf12b21fc5aacc07d985b
4
- data.tar.gz: 7053673ba6ee2775cdc80a04fd2c8b2d8956b41f58108eac1617599d604072bd
3
+ metadata.gz: 4c45366cab4f4e92c620ccd80d1263afd031b3b26163630e7969d1dd68c7136e
4
+ data.tar.gz: 89c565116147e7e9ae610dad3bbfb378f0ccdfaaf0ccf1f7738f257264ee7517
5
5
  SHA512:
6
- metadata.gz: 75c8c5f6b55d8246942f0e86a7d2041d54822b980379c49e06b51f2d806f316dc8f35674751eb6610b50ec465140ac8412133765378aa60d47057557dbd694a8
7
- data.tar.gz: 24366dc573380c88460224829282e80ed8e39f3312daf885cd28c8d5e3028c87d0239b4b0fdc8920820e101c58e5e47121ab181ff1fae6cbf769b4152c2e20c2
6
+ metadata.gz: 322c5a2ba771c67090b06a87dcf01d9977846d665423bc5dbeda38188343d94f94b78c35fa7ebdac7936e2180eab91dc60f4c66cdf9fcd660605133ca6eca07e
7
+ data.tar.gz: a08fa814f2b7b9ec2ca5e6a5ee7a18fcfbbd74602cafa6cc9ae24f1ca664621f746824dab7664fcac29f270590c7a7c8939b993c92013174eaf2c94f1117a517
@@ -1,6 +1,41 @@
1
1
  # CHANGELOG
2
2
 
3
- ## (UNRELEASED)
3
+ ## 1.31.1 (Jan 28, 2021)
4
+
5
+ IMPROVEMENTS:
6
+
7
+ * Switched to Github Actions (build)
8
+ * No functional changes in GEM - Test release only
9
+
10
+ ## 1.32.0 (Jan 27, 2021)
11
+
12
+ IMPROVEMENTS:
13
+
14
+ * Use Ruby 2.7.2 in Travis build
15
+ * [VAULT] Do not handle missing secret as a blocking exception ([#73](https://github.com/criteo/consul-templaterb/pull/73))
16
+
17
+ ## 1.31.1 (Jan 25, 2021)
18
+
19
+ IMPROVEMENTS:
20
+
21
+ * Use Node.Meta.fqdn to display node names in timeline if set
22
+
23
+ ## 1.31.0 (Jan 18, 2021)
24
+
25
+ IMPROVEMENTS:
26
+
27
+ * Do not apply penalty on unmodified services not changing much (Will improve streaming performance)
28
+
29
+ ## 1.30.0 (Dec 18, 2020)
30
+
31
+ IMPROVEMENTS:
32
+
33
+ * Allow customization to sort nodes in service view in Consul-UI ([#71](https://github.com/criteo/consul-templaterb/pull/71))
34
+
35
+ NEW FEATURES:
36
+
37
+ * Auto-detection of rate-limit on Consul Side (introduced in Consul 1.6.2+), this feature
38
+ will work only Consul 1.9+ (see [Consul #7527](https://github.com/hashicorp/consul/issues/7527)).
4
39
 
5
40
  ## 1.29.0 (Oct 6, 2020)
6
41
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # consul-templaterb
2
2
 
3
- [![Build Status](https://api.travis-ci.org/criteo/consul-templaterb.svg?branch=master)](https://travis-ci.org/criteo/consul-templaterb)
3
+ [![Build Status](https://github.com/criteo/consul-templaterb/workflows/Ruby/badge.svg?branch=master)](https://github.com/criteo/consul-templaterb/actions?query=branch%3Amaster)
4
4
  [![Gem Version](https://badge.fury.io/rb/consul-templaterb.svg)](http://github.com/criteo/consul-templaterb/releases)
5
5
  [![GEM Downloads](https://ruby-gem-downloads-badge.herokuapp.com/consul-templaterb?type=total&metric=true)](https://rubygems.org/gems/consul-templaterb)
6
6
  [![License](https://img.shields.io/badge/license-ApacheV2-yellowgreen.svg)](#license)
@@ -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.29.0'.freeze
3
+ VERSION = '1.32.1'.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.29.0
4
+ version: 1.32.1
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-06 00:00:00.000000000 Z
11
+ date: 2021-01-28 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
@@ -255,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
256
  - !ruby/object:Gem::Version
256
257
  version: '0'
257
258
  requirements: []
258
- rubygems_version: 3.0.8
259
+ rubygems_version: 3.1.4
259
260
  signing_key:
260
261
  specification_version: 4
261
262
  summary: Implementation of Consul template using Ruby and .erb templating language