consul-templaterb 1.36.2 → 1.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/consul/async/consul_endpoint.rb +6 -0
- data/lib/consul/async/consul_template.rb +23 -50
- data/lib/consul/async/consul_template_engine.rb +3 -2
- data/lib/consul/async/consul_template_render.rb +3 -0
- data/lib/consul/async/debug.rb +2 -2
- data/lib/consul/async/json_endpoint.rb +7 -0
- data/lib/consul/async/process_handler.rb +3 -2
- data/lib/consul/async/vault_endpoint.rb +4 -4
- data/lib/consul/async/version.rb +1 -1
- data/samples/consul-ui/ringbuffer.rb +4 -3
- data/samples/consul-ui/timeline.json.erb +5 -2
- metadata +42 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75e9e4f71a0227c255c018398d3fa3b540811d296da2d3bf3a2e450b57d4a851
|
|
4
|
+
data.tar.gz: 20815dbb1c484c82c3adecfe7b3cf94c7128f1a82e8ccd889eb0d8bfb74be96b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53e301567b2adc4c8996d70ec705ab42139a95e490c0e1b51907fd30b95be595f702f48a28c7ba2e389c121153e90526880ba75c14a1d514dacfe5ba8f67d70c
|
|
7
|
+
data.tar.gz: 6c9ab309e5ece819a1eb8bb6ab18052749a96749eb04e25a0c1df6cd62a3b7d1848a72d5cfe88bee31e63a7b0738c8b5b5388019eaa89850bd4b6c467505be65
|
|
@@ -10,6 +10,7 @@ module Consul
|
|
|
10
10
|
attr_reader :base_url, :token, :retry_duration, :min_duration, :wait_duration, :max_retry_duration, :retry_on_non_diff,
|
|
11
11
|
:missing_index_retry_time_on_diff, :missing_index_retry_time_on_unchanged, :debug, :enable_gzip_compression,
|
|
12
12
|
:fail_fast_errors, :max_consecutive_errors_on_endpoint, :tls_cert_chain, :tls_private_key, :tls_verify_peer
|
|
13
|
+
|
|
13
14
|
def initialize(base_url: 'http://localhost:8500',
|
|
14
15
|
debug: { network: false },
|
|
15
16
|
token: nil,
|
|
@@ -88,6 +89,7 @@ module Consul
|
|
|
88
89
|
# It also keep statistics about result (x_consul_index, stats...)
|
|
89
90
|
class ConsulResult
|
|
90
91
|
attr_reader :data, :http, :x_consul_index, :last_update, :stats, :retry_in
|
|
92
|
+
|
|
91
93
|
def initialize(data, modified, http, x_consul_index, stats, retry_in, fake: false)
|
|
92
94
|
@data = data
|
|
93
95
|
@modified = modified
|
|
@@ -121,10 +123,12 @@ module Consul
|
|
|
121
123
|
next_retry + last_update
|
|
122
124
|
end
|
|
123
125
|
end
|
|
126
|
+
|
|
124
127
|
# Basic Encapsulation of HTTP response from Consul
|
|
125
128
|
# It supports empty responses to handle first call is an easy way
|
|
126
129
|
class HttpResponse
|
|
127
130
|
attr_reader :response_header, :response, :error
|
|
131
|
+
|
|
128
132
|
def initialize(http, override_nil_response = nil)
|
|
129
133
|
if http.nil?
|
|
130
134
|
@response_header = nil
|
|
@@ -137,11 +141,13 @@ module Consul
|
|
|
137
141
|
end
|
|
138
142
|
end
|
|
139
143
|
end
|
|
144
|
+
|
|
140
145
|
# This class represents a specific path in Consul HTTP API
|
|
141
146
|
# It also stores x_consul_index and keep track on updates of API
|
|
142
147
|
# So, it basically performs all the optimizations to keep updated with Consul internal state.
|
|
143
148
|
class ConsulEndpoint
|
|
144
149
|
attr_reader :conf, :path, :x_consul_index, :queue, :stats, :last_result, :enforce_json_200, :start_time, :default_value, :query_params
|
|
150
|
+
|
|
145
151
|
def initialize(conf, path, enforce_json_200 = true, query_params = {}, default_value = '[]', agent = nil)
|
|
146
152
|
@conf = conf.create(path, agent: agent)
|
|
147
153
|
@default_value = default_value
|
|
@@ -10,7 +10,9 @@ module Consul
|
|
|
10
10
|
# its rendering
|
|
11
11
|
class InvalidTemplateException < StandardError
|
|
12
12
|
attr_reader :cause
|
|
13
|
+
|
|
13
14
|
def initialize(cause)
|
|
15
|
+
super
|
|
14
16
|
@cause = cause
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -18,7 +20,9 @@ module Consul
|
|
|
18
20
|
# Exception thrown when the template is Invalid due to a Syntax Error
|
|
19
21
|
class SyntaxErrorInTemplate < InvalidTemplateException
|
|
20
22
|
attr_reader :cause
|
|
23
|
+
|
|
21
24
|
def initialize(cause)
|
|
25
|
+
super
|
|
22
26
|
@cause = cause
|
|
23
27
|
end
|
|
24
28
|
end
|
|
@@ -92,6 +96,7 @@ module Consul
|
|
|
92
96
|
# to template writters.
|
|
93
97
|
class EndPointsManager
|
|
94
98
|
attr_reader :consul_conf, :vault_conf, :running, :net_info, :start_time, :coordinate, :remote_resource, :templates
|
|
99
|
+
|
|
95
100
|
def initialize(consul_configuration, vault_configuration, templates, trim_mode = nil)
|
|
96
101
|
@running = true
|
|
97
102
|
@consul_conf = consul_configuration
|
|
@@ -132,7 +137,7 @@ module Consul
|
|
|
132
137
|
def service(name, dc: nil, passing: false, tag: nil, agent: nil)
|
|
133
138
|
raise 'You must specify a name for a service' if name.nil?
|
|
134
139
|
|
|
135
|
-
path =
|
|
140
|
+
path = "/v1/health/service/#{ERB::Util.url_encode(name.to_s)}"
|
|
136
141
|
query_params = {}
|
|
137
142
|
query_params[:dc] = dc if dc
|
|
138
143
|
query_params[:passing] = passing if passing
|
|
@@ -144,7 +149,7 @@ module Consul
|
|
|
144
149
|
def checks_for_service(name, dc: nil, passing: false, agent: nil)
|
|
145
150
|
raise 'You must specify a name for a service' if name.nil?
|
|
146
151
|
|
|
147
|
-
path =
|
|
152
|
+
path = "/v1/health/checks/#{ERB::Util.url_encode(name.to_s)}"
|
|
148
153
|
query_params = {}
|
|
149
154
|
query_params[:dc] = dc if dc
|
|
150
155
|
query_params[:passing] = passing if passing
|
|
@@ -155,7 +160,7 @@ module Consul
|
|
|
155
160
|
def checks_for_node(name, dc: nil, passing: false, agent: nil)
|
|
156
161
|
raise 'You must specify a name for a service' if name.nil?
|
|
157
162
|
|
|
158
|
-
path =
|
|
163
|
+
path = "/v1/health/node/#{ERB::Util.url_encode(name.to_s)}"
|
|
159
164
|
query_params = {}
|
|
160
165
|
query_params[:dc] = dc if dc
|
|
161
166
|
query_params[:passing] = passing if passing
|
|
@@ -184,7 +189,7 @@ module Consul
|
|
|
184
189
|
|
|
185
190
|
# https://www.consul.io/api/catalog.html#list-services-for-node
|
|
186
191
|
def node(name_or_id, dc: nil, agent: nil)
|
|
187
|
-
path =
|
|
192
|
+
path = "/v1/catalog/node/#{ERB::Util.url_encode(name_or_id.to_s)}"
|
|
188
193
|
query_params = {}
|
|
189
194
|
query_params[:dc] = dc if dc
|
|
190
195
|
create_if_missing(path, query_params, agent: agent) { ConsulTemplateNode.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}', agent)) }
|
|
@@ -247,7 +252,7 @@ module Consul
|
|
|
247
252
|
|
|
248
253
|
# https://www.consul.io/api/kv.html#read-key
|
|
249
254
|
def kv(name = nil, dc: nil, keys: nil, recurse: false, agent: nil)
|
|
250
|
-
path =
|
|
255
|
+
path = "/v1/kv/#{ERB::Util.url_encode(name.to_s)}"
|
|
251
256
|
query_params = {}
|
|
252
257
|
query_params[:dc] = dc if dc
|
|
253
258
|
query_params[:recurse] = recurse if recurse
|
|
@@ -301,10 +306,10 @@ module Consul
|
|
|
301
306
|
end
|
|
302
307
|
|
|
303
308
|
def find_line(e)
|
|
304
|
-
return e.message.dup[5
|
|
309
|
+
return e.message.dup[5..] if e.message.start_with? '(erb):'
|
|
305
310
|
|
|
306
311
|
e.backtrace.each do |line|
|
|
307
|
-
return line[5
|
|
312
|
+
return line[5..] if line.start_with? '(erb):'
|
|
308
313
|
end
|
|
309
314
|
nil
|
|
310
315
|
end
|
|
@@ -399,13 +404,13 @@ module Consul
|
|
|
399
404
|
max_consecutive_errors_on_endpoint: @max_consecutive_errors_on_endpoint,
|
|
400
405
|
agent: nil, endpoint_id: nil)
|
|
401
406
|
endpoint_id ||= begin
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
fqdn = path.dup
|
|
408
|
+
fqdn = "#{agent}#{fqdn}"
|
|
409
|
+
query_params.each_pair do |k, v|
|
|
410
|
+
fqdn += "&#{k}=#{v}"
|
|
411
|
+
end
|
|
412
|
+
fqdn
|
|
413
|
+
end
|
|
409
414
|
tpl = @endpoints[endpoint_id]
|
|
410
415
|
unless tpl
|
|
411
416
|
tpl = yield
|
|
@@ -437,6 +442,7 @@ module Consul
|
|
|
437
442
|
# Abstract class that stores information about a result
|
|
438
443
|
class ConsulTemplateAbstract
|
|
439
444
|
attr_reader :result, :endpoint, :seen_at
|
|
445
|
+
|
|
440
446
|
def initialize(consul_endpoint)
|
|
441
447
|
@endpoint = consul_endpoint
|
|
442
448
|
consul_endpoint.on_response do |res|
|
|
@@ -478,16 +484,10 @@ module Consul
|
|
|
478
484
|
|
|
479
485
|
# Concrete class of a result when the result is a JSON Object
|
|
480
486
|
class ConsulTemplateAbstractMap < ConsulTemplateAbstract
|
|
481
|
-
def initialize(consul_endpoint)
|
|
482
|
-
super(consul_endpoint)
|
|
483
|
-
end
|
|
484
487
|
end
|
|
485
488
|
|
|
486
489
|
# Concrete class of a result when the result is a JSON Array
|
|
487
490
|
class ConsulTemplateAbstractArray < ConsulTemplateAbstract
|
|
488
|
-
def initialize(consul_endpoint)
|
|
489
|
-
super(consul_endpoint)
|
|
490
|
-
end
|
|
491
491
|
end
|
|
492
492
|
|
|
493
493
|
# technically this class could be also an array, a simple string or any simple json object other than a hash.
|
|
@@ -500,6 +500,7 @@ module Consul
|
|
|
500
500
|
# basically a Hash.
|
|
501
501
|
class ServiceInstance < Hash
|
|
502
502
|
def initialize(obj)
|
|
503
|
+
super
|
|
503
504
|
merge!(obj)
|
|
504
505
|
end
|
|
505
506
|
|
|
@@ -578,17 +579,10 @@ module Consul
|
|
|
578
579
|
|
|
579
580
|
# Object returned by datacenters(), basically a JSON Array
|
|
580
581
|
class ConsulTemplateDatacenters < ConsulTemplateAbstractArray
|
|
581
|
-
def initialize(consul_endpoint)
|
|
582
|
-
super(consul_endpoint)
|
|
583
|
-
end
|
|
584
582
|
end
|
|
585
583
|
|
|
586
584
|
# Object returned by services() an abstract map of service_name, tags
|
|
587
585
|
class ConsulTemplateServices < ConsulTemplateAbstractMap
|
|
588
|
-
def initialize(consul_endpoint)
|
|
589
|
-
super(consul_endpoint)
|
|
590
|
-
end
|
|
591
|
-
|
|
592
586
|
def parse_result(res)
|
|
593
587
|
return res unless res.data == '{}' || endpoint.query_params[:tag]
|
|
594
588
|
|
|
@@ -610,31 +604,18 @@ module Consul
|
|
|
610
604
|
|
|
611
605
|
# Object returned by /v1/agent/self, a JSON Map
|
|
612
606
|
class ConsulAgentSelf < ConsulTemplateAbstractMap
|
|
613
|
-
def initialize(consul_endpoint)
|
|
614
|
-
super(consul_endpoint)
|
|
615
|
-
end
|
|
616
607
|
end
|
|
617
608
|
|
|
618
609
|
# Object returning metrics from Consul agent, a JSON Map
|
|
619
610
|
class ConsulAgentMetrics < ConsulTemplateAbstractMap
|
|
620
|
-
def initialize(consul_endpoint)
|
|
621
|
-
super(consul_endpoint)
|
|
622
|
-
end
|
|
623
611
|
end
|
|
624
612
|
|
|
625
613
|
# List of checks for agent
|
|
626
614
|
class ConsulTemplateChecks < ConsulTemplateAbstractArray
|
|
627
|
-
def initialize(consul_endpoint)
|
|
628
|
-
super(consul_endpoint)
|
|
629
|
-
end
|
|
630
615
|
end
|
|
631
616
|
|
|
632
617
|
# Get information about a single node
|
|
633
618
|
class ConsulTemplateNode < ConsulTemplateAbstractMap
|
|
634
|
-
def initialize(consul_endpoint)
|
|
635
|
-
super(consul_endpoint)
|
|
636
|
-
end
|
|
637
|
-
|
|
638
619
|
def exists?
|
|
639
620
|
!result_delegate.nil?
|
|
640
621
|
end
|
|
@@ -661,15 +642,13 @@ module Consul
|
|
|
661
642
|
|
|
662
643
|
# List of nodes of the whole cluster
|
|
663
644
|
class ConsulTemplateNodes < ConsulTemplateAbstractArray
|
|
664
|
-
def initialize(consul_endpoint)
|
|
665
|
-
super(consul_endpoint)
|
|
666
|
-
end
|
|
667
645
|
end
|
|
668
646
|
|
|
669
647
|
# The ServiceInstance has shortcuts (such as service_address method), but is
|
|
670
648
|
# basically a Hash.
|
|
671
649
|
class SerfMember < Hash
|
|
672
650
|
def initialize(obj)
|
|
651
|
+
super
|
|
673
652
|
merge!(obj)
|
|
674
653
|
end
|
|
675
654
|
|
|
@@ -686,10 +665,6 @@ module Consul
|
|
|
686
665
|
|
|
687
666
|
# List of serf members of the whole cluster
|
|
688
667
|
class ConsulTemplateMembers < ConsulTemplateAbstractArray
|
|
689
|
-
def initialize(consul_endpoint)
|
|
690
|
-
super(consul_endpoint)
|
|
691
|
-
end
|
|
692
|
-
|
|
693
668
|
def result_delegate
|
|
694
669
|
return @cached_result if @cached_json == result.json
|
|
695
670
|
|
|
@@ -708,6 +683,7 @@ module Consul
|
|
|
708
683
|
# Several helpers exist to handle nicely transformations
|
|
709
684
|
class ConsulTemplateKV < ConsulTemplateAbstractArray
|
|
710
685
|
attr_reader :root
|
|
686
|
+
|
|
711
687
|
def initialize(consul_endpoint, root)
|
|
712
688
|
@root = root
|
|
713
689
|
super(consul_endpoint)
|
|
@@ -762,9 +738,6 @@ module Consul
|
|
|
762
738
|
|
|
763
739
|
# Vault Secrets is a Map of secrets properly decoded
|
|
764
740
|
class ConsulTemplateVaultSecret < ConsulTemplateAbstractMap
|
|
765
|
-
def initialize(vault_endpoint)
|
|
766
|
-
super(vault_endpoint)
|
|
767
|
-
end
|
|
768
741
|
end
|
|
769
742
|
|
|
770
743
|
# Array of available secrets
|
|
@@ -11,8 +11,9 @@ module Consul
|
|
|
11
11
|
# The Engine keeps tracks of all templates, handle hot-reload of files if needed
|
|
12
12
|
# as well as ticking the clock to compute state of templates periodically.
|
|
13
13
|
class ConsulTemplateEngine
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
attr_accessor :hot_reload_failure, :template_frequency, :debug_memory
|
|
15
|
+
attr_reader :template_manager, :result, :templates
|
|
16
|
+
|
|
16
17
|
def initialize
|
|
17
18
|
@templates = []
|
|
18
19
|
@template_callbacks = []
|
|
@@ -7,6 +7,7 @@ module Consul
|
|
|
7
7
|
# .ready? will tell if rendering is full or partial
|
|
8
8
|
class ConsulTemplateRenderedResult
|
|
9
9
|
attr_reader :template_file, :output_file, :hot_reloaded, :ready, :modified, :last_result
|
|
10
|
+
|
|
10
11
|
def initialize(template_file, output_file, hot_reloaded, was_success, modified, last_result)
|
|
11
12
|
@template_file = template_file
|
|
12
13
|
@output_file = output_file
|
|
@@ -20,11 +21,13 @@ module Consul
|
|
|
20
21
|
@ready
|
|
21
22
|
end
|
|
22
23
|
end
|
|
24
|
+
|
|
23
25
|
# Object handling the whole rendering of a template
|
|
24
26
|
# It stores the input, the output and flags about last result being modified or simply readiness
|
|
25
27
|
# information about whether the template did receive all data to be fully rendered
|
|
26
28
|
class ConsulTemplateRender
|
|
27
29
|
attr_reader :template_file, :output_file, :template_file_ctime, :hot_reload_failure, :params
|
|
30
|
+
|
|
28
31
|
def initialize(template_manager, template_file, output_file, hot_reload_failure: 'die', params: {})
|
|
29
32
|
@hot_reload_failure = hot_reload_failure
|
|
30
33
|
@template_file = template_file
|
data/lib/consul/async/debug.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Consul
|
|
|
28
28
|
def self.print_info(msg)
|
|
29
29
|
return unless level > 1
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
$stderr.print "[INFO] #{msg}" if level > 1
|
|
32
32
|
warn '' if ENV['LOG_STREAM']
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ module Consul
|
|
|
39
39
|
def self.print_debug(msg)
|
|
40
40
|
return unless level > 2
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
$stderr.print "[DEBG] #{msg}"
|
|
43
43
|
warn '' if ENV['LOG_STREAM']
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -10,6 +10,7 @@ module Consul
|
|
|
10
10
|
attr_reader :url, :retry_duration, :min_duration, :retry_on_non_diff,
|
|
11
11
|
:debug, :enable_gzip_compression, :request_method, :json_body,
|
|
12
12
|
:headers, :tls_cert_chain, :tls_private_key, :tls_verify_peer
|
|
13
|
+
|
|
13
14
|
def initialize(url:,
|
|
14
15
|
debug: { network: false },
|
|
15
16
|
retry_duration: 10,
|
|
@@ -41,9 +42,11 @@ module Consul
|
|
|
41
42
|
self
|
|
42
43
|
end
|
|
43
44
|
end
|
|
45
|
+
|
|
44
46
|
# Result from call to a Remote JSON endpoint
|
|
45
47
|
class JSONResult
|
|
46
48
|
attr_reader :data, :http, :last_update, :stats, :retry_in
|
|
49
|
+
|
|
47
50
|
def initialize(data, modified, http, stats, retry_in, fake: false)
|
|
48
51
|
@data = data
|
|
49
52
|
@modified = modified
|
|
@@ -75,9 +78,11 @@ module Consul
|
|
|
75
78
|
next_retry + last_update
|
|
76
79
|
end
|
|
77
80
|
end
|
|
81
|
+
|
|
78
82
|
# Encapsulation of HTTP Response
|
|
79
83
|
class HttpResponse
|
|
80
84
|
attr_reader :response_header, :response, :error
|
|
85
|
+
|
|
81
86
|
def initialize(http, override_nil_response = nil)
|
|
82
87
|
if http.nil?
|
|
83
88
|
@response_header = nil
|
|
@@ -90,9 +95,11 @@ module Consul
|
|
|
90
95
|
end
|
|
91
96
|
end
|
|
92
97
|
end
|
|
98
|
+
|
|
93
99
|
# Endpoint (aka URL) of a remote API that might be called
|
|
94
100
|
class JSONEndpoint
|
|
95
101
|
attr_reader :conf, :url, :queue, :stats, :last_result, :enforce_json_200, :start_time, :default_value, :query_params
|
|
102
|
+
|
|
96
103
|
def initialize(conf, url, default_value, enforce_json_200: true, query_params: {}, default_value_on_error: false)
|
|
97
104
|
@conf = conf.create(url)
|
|
98
105
|
@default_value = default_value
|
|
@@ -7,8 +7,9 @@ module Consul
|
|
|
7
7
|
# Handle the full lifecycle of a process and allows to forward
|
|
8
8
|
# Posix signals to child process when needed.
|
|
9
9
|
class ProcessHandler
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
attr_accessor :reload_scheduled
|
|
11
|
+
attr_reader :command, :sig_reload, :sig_term, :pid, :exit_status, :last_signal_sent
|
|
12
|
+
|
|
12
13
|
def initialize(command, sig_reload: 'HUP', sig_term: 'TERM')
|
|
13
14
|
raise 'empty sig_term is not supported' unless sig_term
|
|
14
15
|
|
|
@@ -73,6 +73,7 @@ module Consul
|
|
|
73
73
|
fail_fast_errors: @fail_fast_errors)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
+
|
|
76
77
|
# Keep information about Vault result of a query
|
|
77
78
|
class VaultResult
|
|
78
79
|
attr_reader :data, :http, :stats, :retry_in
|
|
@@ -210,9 +211,8 @@ module Consul
|
|
|
210
211
|
def _get_errors(http)
|
|
211
212
|
return [http.error] if http.error
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
end
|
|
214
|
+
return http.json['errors'] if !http.json.nil? && http.json.key?('errors')
|
|
215
|
+
|
|
216
216
|
['unknown error']
|
|
217
217
|
end
|
|
218
218
|
|
|
@@ -250,7 +250,7 @@ module Consul
|
|
|
250
250
|
_handle_error(http_result) { connection = EventMachine::HttpRequest.new(conf.base_url, options) }
|
|
251
251
|
else
|
|
252
252
|
@consecutive_errors = 0
|
|
253
|
-
modified = @last_result.nil?
|
|
253
|
+
modified = @last_result.nil? || @last_result.data != http_result.response # Leaving it do to stats with this later
|
|
254
254
|
retry_in = get_lease_duration(http_result) * conf.lease_duration_factor
|
|
255
255
|
retry_in = [retry_in, conf.max_retry_duration].min
|
|
256
256
|
retry_in = [retry_in, conf.min_duration].max
|
data/lib/consul/async/version.rb
CHANGED
|
@@ -2,8 +2,8 @@ module ConsulTimeline
|
|
|
2
2
|
# Node of a ringbuffer
|
|
3
3
|
# This contains entries to next and previous elemens as well as the value
|
|
4
4
|
class RingBufferNode
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
attr_accessor :prev, :value, :next
|
|
6
|
+
|
|
7
7
|
def initialize(value, p_elem, n_elem)
|
|
8
8
|
@value = value
|
|
9
9
|
@prev = p_elem
|
|
@@ -30,6 +30,7 @@ module ConsulTimeline
|
|
|
30
30
|
"[prev=#{@prev.object_id}, next=#{@next.object_id}, value=#{@value}]"
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
|
+
|
|
33
34
|
# A ringbuffer that supports inserting out of order elements at the right place
|
|
34
35
|
# This is needed as Consul might notify us from changes in any order, so we
|
|
35
36
|
# might receive a notification t-2 AFTER t-1, at t.
|
|
@@ -112,5 +113,5 @@ if ARGV.count.positive? && ARGV[0] == 'debug'
|
|
|
112
113
|
arr = ringbuff.to_a
|
|
113
114
|
raise "OOPS wrong size := #{arr.count} instead of #{size}" unless arr.count == size
|
|
114
115
|
|
|
115
|
-
|
|
116
|
+
$stdout.puts JSON.generate(arr)
|
|
116
117
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<%
|
|
2
2
|
require 'json'
|
|
3
|
-
require 'ostruct'
|
|
4
3
|
require 'set'
|
|
5
4
|
services_blacklist_raw = (ENV['EXCLUDE_SERVICES'] || 'lbl7.*,netsvc-probe.*,consul-probed.*').split(',')
|
|
6
5
|
services_blacklist = services_blacklist_raw.map { |v| Regexp.new(v) } # Compute the health of a Service
|
|
@@ -69,8 +68,12 @@ old_state = if @previous_state
|
|
|
69
68
|
unless @events
|
|
70
69
|
load File.expand_path(File.join(File.dirname(template_info['source']), 'ringbuffer.rb'))
|
|
71
70
|
|
|
71
|
+
class Diff
|
|
72
|
+
attr_accessor :appeared, :disappeared, :stayed, :all
|
|
73
|
+
end
|
|
74
|
+
|
|
72
75
|
def diff(old, new_e)
|
|
73
|
-
diff =
|
|
76
|
+
diff = Diff.new
|
|
74
77
|
diff.appeared = new_e - old
|
|
75
78
|
diff.disappeared = old - new_e
|
|
76
79
|
diff.stayed = new_e & old
|
metadata
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: consul-templaterb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.37.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:
|
|
11
|
+
date: 2026-08-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: em-http-request
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: eventmachine
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: parallel
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '0'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: bundler
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rake
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
|
-
- - "
|
|
73
|
+
- - ">="
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '
|
|
75
|
+
version: '0'
|
|
76
76
|
type: :development
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
|
-
- - "
|
|
80
|
+
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '
|
|
82
|
+
version: '0'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: rspec
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - ">="
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
89
|
+
version: '0'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- - "
|
|
94
|
+
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
96
|
+
version: '0'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: rspec_junit_formatter
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
|
-
- - "
|
|
101
|
+
- - ">="
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: 0
|
|
103
|
+
version: '0'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
|
-
- - "
|
|
108
|
+
- - ">="
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: 0
|
|
110
|
+
version: '0'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: rubocop
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
114
114
|
requirements:
|
|
115
|
-
- - "
|
|
115
|
+
- - ">="
|
|
116
116
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: 0
|
|
117
|
+
version: '0'
|
|
118
118
|
type: :development
|
|
119
119
|
prerelease: false
|
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements:
|
|
122
|
-
- - "
|
|
122
|
+
- - ">="
|
|
123
123
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: 0
|
|
124
|
+
version: '0'
|
|
125
125
|
- !ruby/object:Gem::Dependency
|
|
126
126
|
name: rubocop-junit-formatter
|
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
|
128
128
|
requirements:
|
|
129
|
-
- -
|
|
129
|
+
- - ">="
|
|
130
130
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: 0
|
|
131
|
+
version: '0'
|
|
132
132
|
type: :development
|
|
133
133
|
prerelease: false
|
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
135
135
|
requirements:
|
|
136
|
-
- -
|
|
136
|
+
- - ">="
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
|
-
version: 0
|
|
138
|
+
version: '0'
|
|
139
139
|
- !ruby/object:Gem::Dependency
|
|
140
140
|
name: webmock
|
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
|
142
142
|
requirements:
|
|
143
|
-
- - "
|
|
143
|
+
- - ">="
|
|
144
144
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
145
|
+
version: '0'
|
|
146
146
|
type: :development
|
|
147
147
|
prerelease: false
|
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
|
150
|
-
- - "
|
|
150
|
+
- - ">="
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '
|
|
152
|
+
version: '0'
|
|
153
153
|
description: A ruby implementation of Consul Template with support of erb templating
|
|
154
154
|
with hi-performance on large clusters and advanced process management features.
|
|
155
155
|
email:
|
|
@@ -249,14 +249,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
249
249
|
requirements:
|
|
250
250
|
- - ">="
|
|
251
251
|
- !ruby/object:Gem::Version
|
|
252
|
-
version:
|
|
252
|
+
version: 3.3.0
|
|
253
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
requirements:
|
|
255
255
|
- - ">="
|
|
256
256
|
- !ruby/object:Gem::Version
|
|
257
257
|
version: '0'
|
|
258
258
|
requirements: []
|
|
259
|
-
rubygems_version: 3.
|
|
259
|
+
rubygems_version: 3.5.22
|
|
260
260
|
signing_key:
|
|
261
261
|
specification_version: 4
|
|
262
262
|
summary: Implementation of Consul template using Ruby and .erb templating language
|