consul-templaterb 1.5.9 → 1.6.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: b8adb29eaa4b01d73d82d80cf9183f6761e06db0a3204a1a6959a41597b5475f
4
- data.tar.gz: 6ac7f61796835fb9663e9f6de39f8047a192e8e8f20b07b438a0865bd82ce8a0
3
+ metadata.gz: a08b64a111c5cf2ceeca1568dbd94d7c5e60bcc31b4cd72aa6277324d79a6bc5
4
+ data.tar.gz: da25a0959dce3230625c495c219f9617044481d362bd9b05e0949f908f6e73a8
5
5
  SHA512:
6
- metadata.gz: 05f0d978f9b90a5c855c6e7aee93719fef0104c530a0faa80a03232ab20e6c2945ecb9c769ab75e3f9f14f629489cfc10fa42e4fc7704b967e964fa32882bad4
7
- data.tar.gz: 35f472ccf9e47b07a0d1da65ab7259ab5ae49ea917418c0f9d2edae98cada88737fa294ca4bf38044a0e6d971ab4e6bf237e2c24d13da2cc2799f3927fc9465c
6
+ metadata.gz: 95771fbfe7302884d595d819e95aa408f09a1f63e3fe8d3ecb457d09541b07605d6eb32dcb00f4502f3340b8a4703fcbfbcc30a79ce7a71da4ac5f25c47bfab5
7
+ data.tar.gz: 1ccf48e196c9c50d59f7e432a8b29b06b097422b1771b7adfab29e2e722c97da8ef0a1119ea780ce72ebb3ade169d327096616bff5c85b452affd98c1cc67ac9
@@ -7,7 +7,7 @@ Metrics/AbcSize:
7
7
  Max: 80
8
8
 
9
9
  Metrics/BlockLength:
10
- Max: 135
10
+ Max: 140
11
11
 
12
12
  Metrics/BlockNesting:
13
13
  Max: 4
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## (UNRELEASED)
4
4
 
5
+ ## 1.6.0 (November 23, 2018)
6
+
7
+ BUG FIXES:
8
+
9
+ * Fixed rendering of favorites on Firefox in consul-ui
10
+
11
+ NEW FEATURES:
12
+
13
+ * Added the following helpers to help dealing with new Consul features and simplify writting templates in results
14
+ of `service()` calls:
15
+ * `status` to compute aggregated status of a service taking into account all checks
16
+ * `weights` to deal with weights added in Consul 1.2.3
17
+ * `current_weight` to deal with weight computed using the current status
18
+
5
19
  ## 1.5.9 (November 17, 2018)
6
20
 
7
21
  BUG FIXES:
@@ -114,9 +114,32 @@ Full example: [samples/consul_template.txt.erb](samples/consul_template.txt.erb)
114
114
  optional tag. If no tag is specified, will return all instances of service. By default, it will return all the
115
115
  services that are passing or not. An optional argument passing might be used to retrieve only passing instances.
116
116
 
117
+ ### Helpers
118
+
119
+ #### service_address
120
+
117
121
  This object also contains a Helper to get easily the correct Address by using `service_address` which returns
118
122
  the optional `['Service']['Address']` if found or `['Node']['Address']` otherwise.
119
123
 
124
+ #### status
125
+
126
+ Computing the status of an instance is non-trivial as it requires to parses all statuses of all checks and take
127
+ the worse of all thoses Status object. The `.status` attribute can be used as an alternative as it precomputes
128
+ this state in the same way consul does, it will then return the worse of all the statuses of all checks.
129
+ Returned value will be one of `passing`|`warning`|`critical`.
130
+
131
+ #### weights
132
+
133
+ `.weights` give the ability to deal with new `Weights` feature added in Consul 1.2.3.
134
+ It returns a Hash with `{"Passing": weight_when_service_is_passing, "Warning": weight_when_value_is_warning}`
135
+ to allow having weighted load balancing when statuses in Consul do change. It also deals nicely with versions
136
+ of Consul not yet supporting Weights.
137
+
138
+ #### current_weight
139
+
140
+ `.current_weight` computes automagically weight given the current status of service. It works the same way as
141
+ the DNS implementation of Consul.
142
+
120
143
  <details><summary>Examples</summary>
121
144
  <div class="samples">
122
145
 
@@ -129,7 +152,7 @@ the optional `['Service']['Address']` if found or `['Node']['Address']` otherwis
129
152
  <% service(service_name, tag:'http').sort {|a,b| a['Node']['Node'] <=> b['Node']['Node'] }.each do |snode|
130
153
  %> * <%= service_name %> -> <%=
131
154
  snode['Node']['Node'] %>:<%= snode['Service']['Port'] %> <%=
132
- snode['Service']['Tags'] %> status: <%
155
+ snode['Service']['Tags'] %> status: <%= snode.status %> Current Weight: <%= snode.current_weight %> Checks: <%
133
156
  snode['Checks'].each do |c| %> <%= c['Status']
134
157
  %><% end if snode['Checks'] %>
135
158
  <% end
@@ -51,6 +51,7 @@ options = {
51
51
  max_retry_duration: 600, # On consecutive errors, delay will increase, max value
52
52
  missing_index_retry_time_on_diff: 15, # On endpoints without X-Consul-Index => next request
53
53
  missing_index_retry_time_on_unchanged: 60, # Endpoints with X-Consul index and no diff
54
+ enable_gzip_compression: true,
54
55
  paths: {
55
56
  '/v1/catalog/services': {
56
57
  min_duration: 30, # Since services change a lot, refresh services every 30 seconds
@@ -88,6 +89,10 @@ optparse = OptionParser.new do |opts|
88
89
  exit 0
89
90
  end
90
91
 
92
+ opts.on('-g', '--no-gzip-compression', 'Disable GZIP compression in HTTP requests') do
93
+ options[:consul][:enable_gzip_compression] = false
94
+ end
95
+
91
96
  opts.on('-c', '--consul-addr=<address>', String, 'Address of Consul, eg: http://localhost:8500') do |consul_url|
92
97
  options[:consul][:base_url] = consul_url
93
98
  end
@@ -7,7 +7,7 @@ module Consul
7
7
  module Async
8
8
  class ConsulConfiguration
9
9
  attr_reader :base_url, :token, :retry_duration, :min_duration, :wait_duration, :max_retry_duration, :retry_on_non_diff,
10
- :missing_index_retry_time_on_diff, :missing_index_retry_time_on_unchanged, :debug
10
+ :missing_index_retry_time_on_diff, :missing_index_retry_time_on_unchanged, :debug, :enable_gzip_compression
11
11
  def initialize(base_url: 'http://localhost:8500',
12
12
  debug: { network: false },
13
13
  token: nil,
@@ -18,10 +18,12 @@ module Consul
18
18
  max_retry_duration: 600,
19
19
  missing_index_retry_time_on_diff: 15,
20
20
  missing_index_retry_time_on_unchanged: 60,
21
+ enable_gzip_compression: true,
21
22
  paths: {})
22
23
  @base_url = base_url
23
24
  @token = token
24
25
  @debug = debug
26
+ @enable_gzip_compression = enable_gzip_compression
25
27
  @retry_duration = retry_duration
26
28
  @min_duration = min_duration
27
29
  @wait_duration = wait_duration
@@ -54,6 +56,7 @@ module Consul
54
56
  max_retry_duration: ch(path, :max_retry_duration),
55
57
  missing_index_retry_time_on_diff: ch(path, :missing_index_retry_time_on_diff),
56
58
  missing_index_retry_time_on_unchanged: ch(path, :missing_index_retry_time_on_unchanged),
59
+ enable_gzip_compression: enable_gzip_compression,
57
60
  paths: @paths)
58
61
  end
59
62
  end
@@ -171,6 +174,7 @@ module Consul
171
174
  keepalive: true,
172
175
  callback: method(:on_response)
173
176
  }
177
+ res[:head]['accept-encoding'] = 'identity' unless conf.enable_gzip_compression
174
178
  @query_params.each_pair do |k, v|
175
179
  res[:query][k] = v
176
180
  end
@@ -310,6 +310,33 @@ module Consul
310
310
  val = self['Node']['Address'] unless !val.nil? && val != ''
311
311
  val
312
312
  end
313
+
314
+ # Return the global state of a Service, will return passing|warning|critical
315
+ def status
316
+ ret = 'passing'
317
+ checks = self['Checks']
318
+ return ret unless checks
319
+ checks.each do |chk|
320
+ st = chk['Status']
321
+ if st == 'critical'
322
+ ret = st
323
+ elsif st == 'warning' && ret == 'passing'
324
+ ret = st
325
+ end
326
+ end
327
+ ret
328
+ end
329
+
330
+ # Return Consul weights even if Consul version < 1.2.3 with same semantics
331
+ def weights
332
+ self['Service']['Weights'] || { 'Passing' => 1, 'Warning' => 1 }
333
+ end
334
+
335
+ # Return the weights applied on instance according to current status
336
+ def current_weight
337
+ current_status = status
338
+ weights[current_status.capitalize] || 0
339
+ end
313
340
  end
314
341
 
315
342
  class ConsulTemplateService < ConsulTemplateAbstractMap
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.5.9'.freeze
3
+ VERSION = '1.6.0'.freeze
4
4
  end
5
5
  end
@@ -12,20 +12,7 @@
12
12
 
13
13
  # Services to hide
14
14
  services_blacklist = (ENV['EXCLUDE_SERVICES'] || 'consul-agent-http,mesos-slave,mesos-agent-watcher,mesos-exporter-slave').split(',')
15
- # Compute the health of a Service
16
- def compute_state(snode)
17
- states = ['passing', []]
18
- snode['Checks'].each do |chk|
19
- st = chk['Status']
20
- states[1] << st
21
- if st == 'critical'
22
- states[0] = st
23
- elsif st == 'warning' && states[0] == 'passing'
24
- states[0] = st
25
- end
26
- end
27
- states
28
- end
15
+
29
16
  def compute_attributes(snode)
30
17
  w = 100
31
18
  snode['Service']['Tags'].each do |tag|
@@ -33,9 +20,9 @@
33
20
  w = match[1].to_i if match
34
21
  end
35
22
  attributes = ""
36
- states = compute_state(snode)
37
- attributes = "#{attributes} disabled" if states[0] == 'critical'
38
- if states[0] == 'warning'
23
+ node_status = snode.status
24
+ attributes = "#{attributes} disabled" if node_status == 'critical'
25
+ if node_status == 'warning'
39
26
  w = w / 8
40
27
  end
41
28
  attributes = "#{attributes} weight #{w}" if w.positive?
@@ -13,19 +13,6 @@
13
13
  # Services to hide
14
14
  services_blacklist = (ENV['EXCLUDE_SERVICES'] || 'consul-agent-http,mesos-slave,mesos-agent-watcher,mesos-exporter-slave').split(',')
15
15
  # Compute the health of a Service
16
- def compute_state(snode)
17
- states = ['passing', []]
18
- snode['Checks'].each do |chk|
19
- st = chk['Status']
20
- states[1] << st
21
- if st == 'critical'
22
- states[0] = st
23
- elsif st == 'warning' && states[0] == 'passing'
24
- states[0] = st
25
- end
26
- end
27
- states
28
- end
29
16
  def compute_attributes(snode)
30
17
  w = 100
31
18
  snode['Service']['Tags'].each do |tag|
@@ -33,9 +20,9 @@
33
20
  w = match[1].to_i if match
34
21
  end
35
22
  attributes = ""
36
- states = compute_state(snode)
37
- attributes = "#{attributes} disabled" if states[0] == 'critical'
38
- if states[0] == 'warning'
23
+ node_status = snode.status
24
+ attributes = "#{attributes} disabled" if node_status == 'critical'
25
+ if node_status == 'warning'
39
26
  w = w / 8
40
27
  end
41
28
  attributes = "#{attributes} weight #{w}" if w.positive?
@@ -20,26 +20,17 @@
20
20
 
21
21
  # Services to hide
22
22
  services_blacklist = (ENV['EXCLUDE_SERVICES'] || 'consul-agent-http,mesos-slave,mesos-agent-watcher,mesos-exporter-slave').split(',')
23
- # Compute the health of a Service
24
- def compute_state(node)
25
- states = ['passing', []]
26
- node['Checks'].each do |chk|
27
- st = chk['Status']
28
- states[1] << st
29
- states[0] = st if st == 'critical' || (st == 'warning' && states[0] == 'passing')
30
- end
31
- states
32
- end
23
+
33
24
  def compute_attributes(node)
34
- w = 100
25
+ w = node.currrent_weight
35
26
  node['Service']['Tags'].each do |tag|
36
27
  match = /^weight-([1-9][0-9])*$/.match(tag)
37
28
  w = match[1].to_i if match
38
29
  end
39
30
  attributes = ""
40
- states = compute_state(node)
41
- attributes = "#{attributes} disabled" if states[0] == 'critical'
42
- if states[0] == 'warning'
31
+ node_status = snode.status
32
+ attributes = "#{attributes} disabled" if node_status == 'critical'
33
+ if node_status == 'warning'
43
34
  w = w / 8
44
35
  end
45
36
  attributes = "#{attributes} weight #{w}" if w.positive?
@@ -18,30 +18,17 @@
18
18
 
19
19
  # Services to hide
20
20
  services_blacklist = (ENV['EXCLUDE_SERVICES'] || 'consul-agent-http,mesos-slave,mesos-agent-watcher,mesos-exporter-slave').split(',')
21
- # Compute the health of a Service
22
- def compute_state(node)
23
- states = ['passing', []]
24
- node['Checks'].each do |chk|
25
- st = chk['Status']
26
- states[1] << st
27
- if st == 'critical'
28
- states[0] = st
29
- elsif st == 'warning' && states[0] == 'passing'
30
- states[0] = st
31
- end
32
- end
33
- states
34
- end
35
- def compute_attributes(node)
21
+
22
+ def compute_attributes(snode)
36
23
  w = 100
37
- node['Service']['Tags'].each do |tag|
24
+ snode['Service']['Tags'].each do |tag|
38
25
  match = /^weight-([1-9][0-9])*$/.match(tag)
39
26
  w = match[1].to_i if match
40
27
  end
41
28
  attributes = ""
42
- states = compute_state(node)
43
- attributes = "#{attributes} disabled" if states[0] == 'critical'
44
- if states[0] == 'warning'
29
+ node_status = snode.status
30
+ attributes = "#{attributes} disabled" if node_status == 'critical'
31
+ if node_status == 'warning'
45
32
  w = w / 8
46
33
  end
47
34
  attributes = "#{attributes} weight #{w}" if w.positive?
@@ -13,20 +13,6 @@
13
13
 
14
14
  # Services to hide
15
15
  services_blacklist = (ENV['EXCLUDE_SERVICES'] || '').split(',')
16
- # Compute the health of a Service
17
- def compute_state(snode)
18
- states = ['passing', []]
19
- snode['Checks'].each do |chk|
20
- st = chk['Status']
21
- states[1] << st
22
- if st == 'critical'
23
- states[0] = st
24
- elsif st == 'warning' && states[0] == 'passing'
25
- states[0] = st
26
- end
27
- end
28
- states
29
- end
30
16
  backends = {}
31
17
  service_count = 0
32
18
  services(tag: service_tag_filter).each do |service_name, tags|
@@ -38,7 +24,7 @@
38
24
  'critical' => 0,
39
25
  }
40
26
  service(service_name).each do |snode|
41
- state = compute_state(snode)[0]
27
+ state = node.status
42
28
  res[state] += 1
43
29
  end
44
30
  backends[service_name] = {
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.5.9
4
+ version: 1.6.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: 2018-11-16 00:00:00.000000000 Z
11
+ date: 2018-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  version: '0'
228
228
  requirements: []
229
229
  rubyforge_project:
230
- rubygems_version: 2.7.8
230
+ rubygems_version: 2.7.7
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: Implementation of Consul template using Ruby and .erb templating language