consul-templaterb 1.16.0 → 1.17.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: a89758ade44e162e917282e2f01c0ff0631261dc04705ccf5a284e66c0a8ec4c
4
- data.tar.gz: 158939ccb266b44496bb6240a5bf4da5c558ea6310abcc5e3fd2922eac9a102c
3
+ metadata.gz: f5db899f30382d8fe310ab54f5c8d7ca8c7f2a46a1dc0e1f66522d5eb6c5bf7c
4
+ data.tar.gz: 2b5a94664f2ab8409b1d1e763d8aca620138f11546a6c610e9baad711ad30988
5
5
  SHA512:
6
- metadata.gz: 72d8b16ea9f95a9bf742a417c2e6cf0bc984eeb66dd577407af5e699e37bb1ac9015bcd169ecb1a2ed5ed56d3a2aa0c8cde5224ed5f1cae822ea378a3c4a1faa
7
- data.tar.gz: 1306143770c8d18000db48572f66842bbdb74846ce92c08c3361d786c7ca16df215f961eba90493f55b67c5d05add9ff7fbc8448641e41d80573eb167d53220b
6
+ metadata.gz: 97c454b170b61ac2ec93a84aefbf006a6e90cfe0369caab1d321d1aa0e5761686036e693603a67ec051207b48665981c4e1d6c31a11d9c2ad403dfc0e7e966b5
7
+ data.tar.gz: 21fd3ad5e6c602a6bfc6b9edea7a85bf9415605869d5a9f13595bb23940a974d525a0b70c3c418be5959bdd4b1469a887b49d7a01797869e1e884a50801be043
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## (UNRELEASED)
4
4
 
5
+ ## 1.17.0 (July 15, 2019)
6
+
7
+ IMPROVEMENTS:
8
+
9
+ * when failing to write a file, describe the error with more context (file size...)
10
+
11
+ NEW FEATURES:
12
+
13
+ Added new coordinates endpoints:
14
+ * `coordinate.datacenters` list coordinates of datacenters (WAN)
15
+ * `coodinate.nodes` list coordinates of nodes (LAN)
16
+
5
17
  ## 1.16.0 (July 8, 2019)
6
18
 
7
19
  Added new helpers for `service()`
@@ -51,6 +51,26 @@ See [lib/consul/async/consul_template.rb:230](lib/consul/async/consul_template.r
51
51
  [lib/consul/async/consul_template.rb:260](lib/consul/async/consul_template.rb#L260) for up to date list of
52
52
  all those methods.
53
53
 
54
+ ## coordinate
55
+
56
+ The coordinate object allow to interact with the coordinates of DCs and nodes as explained in
57
+ [Network Coordinates](https://www.consul.io/docs/internals/coordinates.html).
58
+
59
+ ### coordinate.datacenters([dc: datacenter])
60
+
61
+ [List the Wan Coordinates](https://www.consul.io/api/coordinate.html#read-wan-coordinates) from local DC to
62
+ other DCs. If dc is set, it will perform the same operation but from another DC.
63
+
64
+ ### coordinate.nodes([dc: datacenter])
65
+
66
+ [Read all LAN nodes coordinates](https://www.consul.io/api/coordinate.html#read-lan-coordinates-for-all-nodes).
67
+ If If dc is set, it will perform the same operation but for another DC.
68
+
69
+ ### coordinate.rtt(nodeA, nodeB)
70
+
71
+ Computes the rtt between 2 nodes returned by `coordinate.nodes` or `coordinate.datacenters`. A re-implementation of Golang sample code
72
+ [Working with Coordinates](https://www.consul.io/docs/internals/coordinates.html#working-with-coordinates).
73
+
54
74
  ## datacenters()
55
75
 
56
76
  [Get the list of datacenters as string array](https://www.consul.io/api/catalog.html#list-datacenters).
@@ -21,8 +21,48 @@ module Consul
21
21
  end
22
22
  end
23
23
 
24
+ # Encapsulation of endpoints to get coordinates
25
+ class Coordinate
26
+ def initialize(endpoints_manager)
27
+ @endp_manager = endpoints_manager
28
+ end
29
+
30
+ # Return the coordinates of datacenters
31
+ def datacenters(dc: nil)
32
+ path = '/v1/coordinate/datacenters'
33
+ query_params = {}
34
+ query_params[:dc] = dc if dc
35
+ @endp_manager.create_if_missing(path, query_params) { ConsulTemplateNodes.new(ConsulEndpoint.new(@endp_manager.consul_conf, path, true, query_params, '[]')) }
36
+ end
37
+
38
+ # Returns the coordinates for all nodes of DC
39
+ def nodes(dc: nil)
40
+ path = '/v1/coordinate/nodes'
41
+ query_params = {}
42
+ query_params[:dc] = dc if dc
43
+ @endp_manager.create_if_missing(path, query_params) { ConsulTemplateNodes.new(ConsulEndpoint.new(@endp_manager.consul_conf, path, true, query_params, '[]')) }
44
+ end
45
+
46
+ # Computes the RTT between 2 nodes
47
+ def rtt(a, b)
48
+ # Calculate the Euclidean distance plus the heights.
49
+ a_vec = a['Vec']
50
+ b_vec = b['Vec']
51
+ sumsq = 0.0
52
+ a_vec.count.times do |i|
53
+ diff = a_vec[i] - b_vec[i]
54
+ sumsq += diff * diff
55
+ end
56
+ rtt = Math.sqrt(sumsq) + a['Height'] + b['Height']
57
+
58
+ adjusted = rtt + a['Adjustment'] + b['Adjustment']
59
+ rtt = adjusted if adjusted.positive?
60
+ rtt
61
+ end
62
+ end
63
+
24
64
  class EndPointsManager
25
- attr_reader :consul_conf, :vault_conf, :net_info, :start_time
65
+ attr_reader :consul_conf, :vault_conf, :net_info, :start_time, :coordinate
26
66
  def initialize(consul_configuration, vault_configuration, trim_mode = nil)
27
67
  @consul_conf = consul_configuration
28
68
  @vault_conf = vault_configuration
@@ -48,6 +88,7 @@ module Consul
48
88
  },
49
89
  params: {}
50
90
  }
91
+ @coordinate = Coordinate.new(self)
51
92
 
52
93
  # Setup token renewal
53
94
  vault_setup_token_renew unless @vault_conf.token.nil? || !@vault_conf.token_renew
@@ -246,10 +287,14 @@ module Consul
246
287
  "netinfo=#{@net_info} aka "\
247
288
  "#{Utilities.bytes_to_h((net_info[:network_bytes] / (Time.now.utc - @start_time)).round(1))}/s ...\r"
248
289
  tmp_file = "#{file}.tmp"
249
- File.open(tmp_file, 'w') do |f|
250
- f.write data
290
+ begin
291
+ File.open(tmp_file, 'w') do |f|
292
+ f.write data
293
+ end
294
+ File.rename(tmp_file, file)
295
+ rescue StandardError => e
296
+ ::Consul::Async::Debug.puts_error "Failed writting #{Utilities.bytes_to_h data.bytesize} bytes to #{file}: #{e.class}, message: #{e.inspect}"
251
297
  end
252
- File.rename(tmp_file, file)
253
298
  end
254
299
  [true, data != last_result, data]
255
300
  end
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.16.0'.freeze
3
+ VERSION = '1.17.0'.freeze
4
4
  end
5
5
  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.16.0
4
+ version: 1.17.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-07-08 00:00:00.000000000 Z
11
+ date: 2019-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request