kennel 1.76.3 → 1.78.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +11 -1
- data/lib/kennel/api.rb +4 -1
- data/lib/kennel/models/dashboard.rb +1 -1
- data/lib/kennel/models/monitor.rb +14 -7
- data/lib/kennel/syncer.rb +4 -3
- data/lib/kennel/template_variables.rb +13 -9
- data/lib/kennel/version.rb +1 -1
- data/template/Readme.md +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1606ccb73f8c7b4e4a0ac2d6c4cf7473d320ece51d38bab7d7b574366086476d
|
4
|
+
data.tar.gz: 1ce0a1b1edd186c0acaf392ca5dd668419ccf891388e197cdbb40b611ec6cfc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39e476825364d1d6eca54cefab1173008894c02bcb749457c2c2b3d8a0995553b6bfbc44f281e61f9e031f316d1a8c06bf81f2bfaefea618258bf536bfcb555
|
7
|
+
data.tar.gz: 8588a48b7a5886b04d4ba9030e1cd6b27fc7ba3271150edab3447d7aae977e3b47100218b5c1ac2597d4176f969194c326a28434d825311b69710ec14bcb8ef5
|
data/Readme.md
CHANGED
@@ -83,7 +83,7 @@ end
|
|
83
83
|
- `gem install bundler && bundle install`
|
84
84
|
- `cp .env.example .env`
|
85
85
|
- open [Datadog API Settings](https://app.datadoghq.com/account/settings#api)
|
86
|
-
-
|
86
|
+
- create a `API Key` or get an existing one from an admin, then add it to `.env` as `DATADOG_API_KEY`
|
87
87
|
- find or create (check last page) your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=`
|
88
88
|
- change the `DATADOG_SUBDOMAIN=app` in `.env` to your companies subdomain if you have one
|
89
89
|
- verify it works by running `rake plan`, it might show some diff, but should not crash
|
@@ -198,6 +198,15 @@ end
|
|
198
198
|
end
|
199
199
|
```
|
200
200
|
|
201
|
+
### Updating existing resources with id
|
202
|
+
|
203
|
+
Setting `id` makes kennel take over a manually created datadog resource.
|
204
|
+
When manually creating to import, it is best to remove the `id` and delete the manually created resource.
|
205
|
+
|
206
|
+
When an `id` is set and the original resource is deleted, kennel will fail to update,
|
207
|
+
removing the `id` will cause kennel to create a new resource in datadog.
|
208
|
+
|
209
|
+
|
201
210
|
### Skipping validations
|
202
211
|
|
203
212
|
Some validations might be too strict for your usecase or just wrong, please [open an issue](https://github.com/grosser/kennel/issues) and
|
@@ -210,6 +219,7 @@ To link to existing monitors via their kennel_id `projects kennel_id` + `:` + `m
|
|
210
219
|
- Screens `uptime` widgets can use `monitor: {id: "foo:bar"}`
|
211
220
|
- Screens `alert_graph` widgets can use `alert_id: "foo:bar"`
|
212
221
|
- Monitors `composite` can use `query: -> { "%{foo:bar} || %{foo:baz}" }`
|
222
|
+
- Slos can use `monitor_ids: -> ["foo:bar"]`
|
213
223
|
|
214
224
|
### Debugging changes locally
|
215
225
|
|
data/lib/kennel/api.rb
CHANGED
@@ -42,8 +42,11 @@ module Kennel
|
|
42
42
|
request :put, "/api/v1/#{api_resource}/#{id}", body: attributes
|
43
43
|
end
|
44
44
|
|
45
|
+
# - force=true to not dead-lock on dependent monitors+slos
|
46
|
+
# external dependency on kennel managed resources is their problem, we don't block on it
|
47
|
+
# (?force=true did not work, force for dashboard is not documented but does not blow up)
|
45
48
|
def delete(api_resource, id)
|
46
|
-
request :delete, "/api/v1/#{api_resource}/#{id}", ignore_404: true
|
49
|
+
request :delete, "/api/v1/#{api_resource}/#{id}", params: { force: "true" }, ignore_404: true
|
47
50
|
end
|
48
51
|
|
49
52
|
private
|
@@ -192,7 +192,7 @@ module Kennel
|
|
192
192
|
end
|
193
193
|
|
194
194
|
if type == "query alert"
|
195
|
-
# verify interval is
|
195
|
+
# verify interval is valid
|
196
196
|
interval = data.fetch(:query)[/\(last_(\S+?)\)/, 1]
|
197
197
|
if interval && !QUERY_INTERVALS.include?(interval)
|
198
198
|
invalid! "query interval was #{interval}, but must be one of #{QUERY_INTERVALS.join(", ")}"
|
@@ -200,13 +200,20 @@ module Kennel
|
|
200
200
|
end
|
201
201
|
|
202
202
|
if ["query alert", "service check"].include?(type) # TODO: most likely more types need this
|
203
|
-
# verify is_match uses available variables
|
203
|
+
# verify is_match/is_exact_match uses available variables
|
204
204
|
message = data.fetch(:message)
|
205
|
-
used = message.scan(/{{\s
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
205
|
+
used = message.scan(/{{\s*([#^]is(?:_exact)?_match)\s*([^\s}]+)/)
|
206
|
+
if used.any?
|
207
|
+
allowed = data.fetch(:query)[/by\s*[({]([^})]+)[})]/, 1]
|
208
|
+
.to_s.gsub(/["']/, "").split(/\s*,\s*/)
|
209
|
+
.map! { |w| %("#{w}.name") }
|
210
|
+
used.uniq.each do |match, group|
|
211
|
+
next if allowed.include?(group)
|
212
|
+
invalid!(
|
213
|
+
"#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. " \
|
214
|
+
"Group the query by #{group.sub(".name", "").tr('"', "")} or change the #{match}"
|
215
|
+
)
|
216
|
+
end
|
210
217
|
end
|
211
218
|
end
|
212
219
|
end
|
data/lib/kennel/syncer.rb
CHANGED
@@ -38,7 +38,7 @@ module Kennel
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def update
|
41
|
-
changed = (@create + @update).map { |_, e| e }
|
41
|
+
changed = (@create + @update).map { |_, e| e }
|
42
42
|
|
43
43
|
@create.each do |_, e|
|
44
44
|
e.resolve_linked_tracking_ids!({}, force: true)
|
@@ -139,7 +139,8 @@ module Kennel
|
|
139
139
|
def ensure_all_ids_found
|
140
140
|
@expected.each do |e|
|
141
141
|
next unless id = e.id
|
142
|
-
|
142
|
+
resource = e.class.api_resource
|
143
|
+
raise "Unable to find existing #{resource} with id #{id}\nIf the #{resource} was deleted, remove the `id: -> { #{e.id} }` line."
|
143
144
|
end
|
144
145
|
end
|
145
146
|
|
@@ -188,7 +189,7 @@ module Kennel
|
|
188
189
|
end
|
189
190
|
|
190
191
|
# Do not add tracking-id when working with existing ids on a branch,
|
191
|
-
# so resource do not get deleted
|
192
|
+
# so resource do not get deleted from running an update on master (for example merge->CI).
|
192
193
|
# Also make sure the diff still makes sense, by kicking out the now noop-update.
|
193
194
|
#
|
194
195
|
# Note: ideally we'd never add tracking in the first place, but at that point we do not know the diff yet
|
@@ -16,18 +16,22 @@ module Kennel
|
|
16
16
|
|
17
17
|
# check for queries that do not use the variables and would be misleading
|
18
18
|
# TODO: do the same check for apm_query and their group_by
|
19
|
-
def validate_template_variables(data
|
19
|
+
def validate_template_variables(data)
|
20
20
|
variables = (data[:template_variables] || []).map { |v| "$#{v.fetch(:name)}" }
|
21
|
-
|
21
|
+
return if variables.empty?
|
22
|
+
|
23
|
+
queries = data[:widgets].flat_map do |widget|
|
22
24
|
([widget] + (widget.dig(:definition, :widgets) || [])).flat_map { |w| widget_queries(w) }
|
23
25
|
end.compact
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
|
27
|
+
matches = variables.map { |v| Regexp.new "#{Regexp.escape(v)}\\b" }
|
28
|
+
queries.reject! { |q| matches.all? { |m| q.match? m } }
|
29
|
+
return if queries.empty?
|
30
|
+
|
31
|
+
invalid!(
|
32
|
+
"queries #{queries.join(", ")} must use the template variables #{variables.join(", ")}\n" \
|
33
|
+
"If that is not possible, add `validate: -> { false } # query foo in bar does not have baz tag`"
|
34
|
+
)
|
31
35
|
end
|
32
36
|
|
33
37
|
def widget_queries(widget)
|
data/lib/kennel/version.rb
CHANGED
data/template/Readme.md
CHANGED
@@ -66,7 +66,7 @@ end
|
|
66
66
|
- `gem install bundler && bundle install`
|
67
67
|
- `cp .env.example .env`
|
68
68
|
- open [Datadog API Settings](https://app.datadoghq.com/account/settings#api)
|
69
|
-
-
|
69
|
+
- create a `API Key` or get an existing one from an admin, then add it to `.env` as `DATADOG_API_KEY`
|
70
70
|
- find or create (check last page) your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=`
|
71
71
|
- change the `DATADOG_SUBDOMAIN=app` in `.env` to your companies subdomain if you have one
|
72
72
|
- verify it works by running `rake plan`, it might show some diff, but should not crash
|
@@ -180,6 +180,15 @@ end
|
|
180
180
|
end
|
181
181
|
```
|
182
182
|
|
183
|
+
### Updating existing resources with id
|
184
|
+
|
185
|
+
Setting `id` makes kennel take over a manually created datadog resource.
|
186
|
+
When manually creating to import, it is best to remove the `id` and delete the manually created resource.
|
187
|
+
|
188
|
+
When an `id` is set and the original resource is deleted, kennel will fail to update,
|
189
|
+
removing the `id` will cause kennel to create a new resource in datadog.
|
190
|
+
|
191
|
+
|
183
192
|
### Skipping validations
|
184
193
|
|
185
194
|
Some validations might be too strict for your usecase or just wrong, please [open an issue](https://github.com/grosser/kennel/issues) and
|
@@ -192,6 +201,7 @@ To link to existing monitors via their kennel_id `projects kennel_id` + `:` + `m
|
|
192
201
|
- Screens `uptime` widgets can use `monitor: {id: "foo:bar"}`
|
193
202
|
- Screens `alert_graph` widgets can use `alert_id: "foo:bar"`
|
194
203
|
- Monitors `composite` can use `query: -> { "%{foo:bar} || %{foo:baz}" }`
|
204
|
+
- Slos can use `monitor_ids: -> ["foo:bar"]`
|
195
205
|
|
196
206
|
### Debugging changes locally
|
197
207
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kennel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.78.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09
|
11
|
+
date: 2020-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|