consul-templaterb 1.15.1 → 1.15.2

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
  SHA1:
3
- metadata.gz: 8b78e19b82cfe21d36bd7985cfb3676bf6eb4adf
4
- data.tar.gz: 03fc0513a55921094d962be1f6ec9ae730058244
3
+ metadata.gz: 265b3062a39b78eaa45775583d748de5c349ac21
4
+ data.tar.gz: ad53bb875e0dabdf005c1081cd28b42c5e482bc5
5
5
  SHA512:
6
- metadata.gz: 9991598e1ca634be45e4239b5a279e37dce68413d293a64d68d7b028e103ff0a68895721e92c96adb742bdf623c2184b83fbd2852f44bffb0934fd198be562c2
7
- data.tar.gz: c4f9c73248c2c3fcfe170f5dd2a183585400a2ac2bf6f8ee4bdf57a9b5dfcd42d5059eba20af88fbf682706aced1d3fd284da1441f1f6b6d422669665ae63549
6
+ metadata.gz: a87af9eb230325e5d9f1f032e97e078c9ef2365e5ade766818eafd97dfdce9d537c1a2961a26aa50d8a0086ccc55ec20bbb7224dc5dd773486844dc4ceafcb11
7
+ data.tar.gz: d09545ef6d131b6324c198a9eca24fea15a10a58fbce25da44a97e68b31726a5372929cd606cba35d2c2674927c986c88ef2e54d9407ea7df44038d7f761f7d3
data/CHANGELOG.md CHANGED
@@ -2,7 +2,20 @@
2
2
 
3
3
  ## (UNRELEASED)
4
4
 
5
- ## 1.15.1 (May 14, 2019)
5
+ ## 1.15.2 (June 12, 2019)
6
+
7
+ IMPROVEMENTS
8
+
9
+ `samples/metrics.erb` can now output metrics with labels for services with any kind of
10
+ service/node meta. You can tune output of prometheus labels with the environment
11
+ variable `PROMETHEUS_EXPORTED_SERVICE_META` which contains the keys separated by
12
+ commas to extract from Service.Meta or Node.Meta.
13
+
14
+ Using `PROMETHEUS_EXPORTED_SERVICE_META='version,os'` would add prometheus labels
15
+ version="xx",os="linux" on instances having those metadata on service or nodes when
16
+ meta is available.
17
+
18
+ ## 1.15.1 (May 23, 2019)
6
19
 
7
20
  IMPROVEMENTS
8
21
 
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.15.1'.freeze
3
+ VERSION = '1.15.2'.freeze
4
4
  end
5
5
  end
@@ -7,6 +7,11 @@
7
7
  # And aggregates a list of Services, Services Instances/status
8
8
  # And nodes.
9
9
  require 'set'
10
+
11
+ # Services to hide
12
+ services_blacklist_raw = (ENV['EXCLUDE_SERVICES'] || '.*netsvc-probe.*,.*consul-probed.*').split(',')
13
+ services_blacklist = services_blacklist_raw.map { |v| Regexp.new(v) }
14
+
10
15
  num_services={}
11
16
  num_instances={}
12
17
  all_states = ['passing', 'warning', 'critical', 'total']
@@ -20,6 +25,7 @@
20
25
  'total' => 0
21
26
  }
22
27
  services(dc:dc).each do |service_name, tags|
28
+ next if services_blacklist.any? {|r| r.match(service_name)}
23
29
  distinct_services.add(service_name)
24
30
  num_services[dc]+=1
25
31
  service(service_name, dc:dc).each do |snode|
data/samples/metrics.erb CHANGED
@@ -5,7 +5,9 @@
5
5
  # INSTANCE_MUST_TAG: Second level of filtering (optional, default to SERVICES_TAG_FILTER)
6
6
  # INSTANCE_EXCLUDE_TAG: Exclude instances having the given tag
7
7
  # EXCLUDE_SERVICES: comma-separated services regexps to exclude (example: lbl7.*,netsvc-probe.*,consul-probed.*)
8
+ # PROMETHEUS_EXPORTED_SERVICE_META: comma-separated list of meta to export into metrics of service
8
9
  <%
10
+ service_metas_to_export = (ENV['PROMETHEUS_EXPORTED_SERVICE_META'] || 'version,os,criteo_flavor').split(',')
9
11
 
10
12
  service_tag_filter = ENV['SERVICES_TAG_FILTER'] || nil
11
13
  instance_must_tag = ENV['INSTANCE_MUST_TAG'] || service_tag_filter
@@ -16,24 +18,42 @@
16
18
  services_blacklist = services_blacklist_raw.map { |v| Regexp.new(v) }
17
19
 
18
20
  backends = {}
21
+ all_stats = {}
19
22
  service_count = 0
23
+
20
24
  services(tag: service_tag_filter).each do |service_name, tags|
21
25
  if !services_blacklist.any? {|r| r.match(service_name)} && (instance_must_tag.nil? || tags.include?(instance_must_tag))
22
26
  service_count += 1
23
- res = {
24
- 'passing' => 0,
25
- 'warning' => 0,
26
- 'critical' => 0,
27
- }
28
27
  srv = service(service_name)
28
+ all_stats[service_name] = srv.endpoint.stats
29
29
  srv.each do |snode|
30
+ key = "#{snode['Service']['Service']}"
31
+ metas = {}
32
+ service_metas_to_export.each do |k|
33
+ meta = nil
34
+ meta = snode['Service']['Meta'][k] if snode['Service']['Meta']
35
+ meta = snode['Node']['Meta'][k] if !meta && snode['Node']['Meta']
36
+ if meta
37
+ key += "::#{k}=#{meta}"
38
+ metas[k] = meta
39
+ end
40
+ end
41
+ back = backends[key]
42
+ if back.nil?
43
+ back = {
44
+ metas: metas,
45
+ service_name: service_name,
46
+ state: {
47
+ 'passing' => 0,
48
+ 'warning' => 0,
49
+ 'critical' => 0,
50
+ }
51
+ }
52
+ backends[key] = back
53
+ end
30
54
  state = snode.status
31
- res[state] += 1
55
+ back[:state][state] += 1
32
56
  end
33
- backends[service_name] = {
34
- state: res,
35
- stats: srv.endpoint.stats,
36
- }
37
57
  end
38
58
  end
39
59
  %>
@@ -73,21 +93,29 @@ end
73
93
  <%
74
94
  json_backends = {}
75
95
  now = Time.now.utc
76
- backends.each_pair do |service_name, service_info|
96
+ backends.each_pair do |k, service_info|
97
+ service_name = service_info[:service_name]
98
+ meta_string = ""
99
+ service_info[:metas].each_pair do |k,v|
100
+ meta_string+=",#{k}=\"#{v}\""
101
+ end
77
102
  service_info[:state].each_pair do |state_name, state_count|
78
- %>consul_service_count{service="<%= service_name %>",state="<%= state_name %>"} <%= state_count %>
103
+ %>consul_service_count{service="<%= service_name %>",state="<%= state_name %>"<%= meta_string %>} <%= state_count %>
79
104
  <%
80
105
  end
81
- current_stats = service_info[:stats]
106
+ end
107
+
108
+ # Global statistics
109
+ all_stats.each_pair do |service_name, current_stats|
82
110
  %>consul_service_stats_requests_total{service="<%= service_name %>",type="success"} <%= current_stats.successes %>
83
111
  <%
84
112
  if current_stats.errors > 0
85
113
  %>consul_service_stats_requests_total{service="<%= service_name %>",type="errors"} <%= current_stats.errors %>
86
114
  <%
87
115
  end
88
- %>consul_service_stats_requests_bytes{service="<%= service_name %>"} <%= service_info[:stats].body_bytes %>
89
- consul_service_stats_requests_bytes_per_sec{service="<%= service_name %>"} <%= service_info[:stats].bytes_per_sec(now) %>
90
- consul_service_changes_total{service="<%= service_name %>"} <%= service_info[:stats].changes %>
116
+ %>consul_service_stats_requests_bytes{service="<%= service_name %>"} <%= current_stats.body_bytes %>
117
+ consul_service_stats_requests_bytes_per_sec{service="<%= service_name %>"} <%= current_stats.bytes_per_sec(now) %>
118
+ consul_service_changes_total{service="<%= service_name %>"} <%= current_stats.changes %>
91
119
 
92
120
  <%
93
121
  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.15.1
4
+ version: 1.15.2
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-05-23 00:00:00.000000000 Z
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request