consul-templaterb 1.21.4 → 1.21.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +4 -0
- data/INTERNALS.md +47 -0
- data/lib/consul/async/version.rb +1 -1
- data/samples/consul-ui/js/nodes.js +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fa40822c8a08d6cef1fff5fc846759ea9134d4b0faba09b2f0d986f3cf27f31
|
4
|
+
data.tar.gz: 25991106429db5b863c56f4ab136a99e2e58cfcd6529c84f5a6f15050d406184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d606bdb1129c6cc1bea6b62d824f0d5fdbc76620f228f1eb5eb3a89fb14d6b6b568b5189c4ca2e48189fa5a812cdccdc24b1d794ef7f3f724ff8b9af8ce5dd
|
7
|
+
data.tar.gz: 68550789a4a1d95a754329e57f41c24d1b2976c9f32d07f1414d40abc7f014208f4adc59043653b80e58abe567f87d6d31cdf3015e44a12bc8c6a9c584d025f8
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# How to contribute to Consul-Templaterb ?
|
2
2
|
|
3
|
+
## Architecxture Overview
|
4
|
+
|
5
|
+
Please read [INTERNALS.md](INTERNALS.md) to understand how it works.
|
6
|
+
|
3
7
|
## Samples
|
4
8
|
|
5
9
|
The [samples/](samples/) directory contains lots of useable templates that might help others using your new features.
|
data/INTERNALS.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# consul-templaterb Internal Architecture Overview
|
2
|
+
|
3
|
+
## Consul basics
|
4
|
+
|
5
|
+
`consul-templaterb` is a ruby library (or `GEM`) with a single binary that does render `.erb` files based on Consul exposed endpoints.
|
6
|
+
|
7
|
+
Consul is a kind of distributed K/V tree store that exposes most of his APIs using HTTP endpoints with a way to watch for changes based on an Index. Each part of the Consul Tree has its own Index reflecting the last id of transaction for this
|
8
|
+
part of the tree. It means that Consul has a kind of transaction ID for each subtree of the data.
|
9
|
+
|
10
|
+
Consul also exposes some specific endpoints to get some discovery specific endpoints (eg: `/v1/catalog/services` to get
|
11
|
+
the list of services registered in the cluster).
|
12
|
+
|
13
|
+
For each endpoint, `consul-templaterb` performs a watch by getting information about the last transaction on this endpoints, storing it locally and watching at Consul to get updates about the data within this endpoint.
|
14
|
+
|
15
|
+
## How it works
|
16
|
+
|
17
|
+
There is a loop in the engine, every second, all templates are rendered using the `ERB` template engine.
|
18
|
+
|
19
|
+
Each template is assigned to a `ConsulTemplateRender` object that keeps tracks of changes on disk of template (in order
|
20
|
+
to be able to hot-reload templates) as well as monitoring if the template is completely rendered, aka all data from
|
21
|
+
Consul is properly retrieved and consistent.
|
22
|
+
|
23
|
+
At each rendering, each template using a Consul Endpoint (for instance, calling `datacenters()`) does register itself
|
24
|
+
in `EndPointsManager`. If the endpoint is already registered, fetch the result if available and return the value, if not,
|
25
|
+
the endpoint is tagged as dirty. When the rendering of a template is completed, a check is performed to see if some endpoints used by the template are still marked as dirty. Being dirty means that some data from Consul is missing, so
|
26
|
+
that the result is not the definitive one. If no endpoint is dirty, then the result of template can be rendered on disk
|
27
|
+
and template is complete.
|
28
|
+
|
29
|
+
At startup, in order to converge faster, templates are rendered more quickly that every 1s to speed up startup time for first convergence, meaning that the delay between each rendering of template might be very fast, especially at startup (so, DO NOT USE Ruby I/O in templates unless you really know what you are doing)
|
30
|
+
|
31
|
+
### EndPointsManager
|
32
|
+
|
33
|
+
`EndPointsManager` is the object responsible of keeping track the endpoints (basically the I/O) of the whole library.
|
34
|
+
When a new Consul endpoint is added by a template, it is registered in that object. Each time a template is rendered,
|
35
|
+
all the endpoints are marked as used. When some endpoints are not used for a while (a few rendering loops), the
|
36
|
+
`EndPointsManager` will garbage collect those endpoints.
|
37
|
+
|
38
|
+
### ConsulTemplateEngine
|
39
|
+
|
40
|
+
When `consul-templaterb` starts, it creates an [ConsulTemplateEngine](lib/consul/async/consul_template_engine.rb) that
|
41
|
+
aggregates all options, template files and parameters. The engine then starts a loop running every second (this can be changed) that:
|
42
|
+
* perform a rendering of each of the `.erb` template files using a `ConsulTemplateRender` object
|
43
|
+
* when all template are rendered the first time, will start some program(s) if specified (the `--exec` parameters)
|
44
|
+
|
45
|
+
### ConsulTemplateRender
|
46
|
+
|
47
|
+
This object keeps track of template, its last state (rendered or not), and whether the file template needs to be reloaded (aka if file has been modified on filesystem).
|
data/lib/consul/async/version.rb
CHANGED
@@ -15,6 +15,10 @@ class ConsulNodesManager extends ConsulUIManager {
|
|
15
15
|
async initResource(data) {
|
16
16
|
this.mainSelector.initSelector(data["nodes"]);
|
17
17
|
}
|
18
|
+
|
19
|
+
async clean() {
|
20
|
+
this.mainSelector.initSelector({});
|
21
|
+
}
|
18
22
|
}
|
19
23
|
|
20
24
|
class NodeMainSelector extends MainSelector {
|
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.21.
|
4
|
+
version: 1.21.5
|
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-
|
11
|
+
date: 2019-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- CONTRIBUTING.md
|
173
173
|
- Dockerfile
|
174
174
|
- Gemfile
|
175
|
+
- INTERNALS.md
|
175
176
|
- LICENSE.txt
|
176
177
|
- README.md
|
177
178
|
- Rakefile
|