kennel 1.76.1 → 1.78.1

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: 950dfe31db52b682fe8158995404f60035aeee8be018884db0a9f8bb33900ce3
4
- data.tar.gz: 17300f8517cdc04eee3f8a037e77e6f9b3a15f1646b09e2a1f2250a6e565fa85
3
+ metadata.gz: d12735939d42da2f660773d9ca734a279fdc5c29b6619f6722b163f07f299236
4
+ data.tar.gz: 14f40ae5314abc2ff5b58672ad096a9d1898b793c1dee490a45d9deefc67e513
5
5
  SHA512:
6
- metadata.gz: 1356476dbc82439b5fb79f6041e3bf3fdb43b1696fb21da903fb25f9e43c6c33d4cdfb25e30042029f5751744bd0a8da43e8f330d62a3bd033f3cddb07a0ccb2
7
- data.tar.gz: e6a7666696af4c04938f79d824442a4315efaf591d8a57be32ae065b528ce09a4fe65aad02650cce5ee422526a57713e3c8f887097964eb3c2e4f3bf9b042f94
6
+ metadata.gz: b5340adfc8b564f648caa8f656b8b10fe9cd48177a6b15e21944adac24209344aeb81aa0bc5190e7a5997e8ebc0dc49af0304daf947abf99112dc8d56f6a9485
7
+ data.tar.gz: 368fb6dffbc42be889f8692b876e867818cde5eefd04b982151efc7d9dc74a378a046f12a7764f448df5818ebca950e55f22e36d45822c68ed3e8a3442850162
data/Readme.md CHANGED
@@ -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,12 +219,13 @@ 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
 
216
226
  - rebase on updated `master` to not undo other changes
217
227
  - figure out project name by converting the class name to snake-case
218
- - run `PROJECT=foo bundle exec rake kennel:update_datadog` to test changes for a single project
228
+ - run `PROJECT=foo bundle exec rake kennel:update_datadog` to test changes for a single project (monitors: remove mentions while debugging to avoid alert spam)
219
229
 
220
230
  ### Reuse
221
231
 
@@ -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 valud
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,17 @@ 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*#is_match\s*"([a-zA-Z\d_.-]+).name"/).flatten.uniq
206
- allowed = data.fetch(:query)[/by\s*[({]([^})]+)[})]/, 1].to_s.gsub(/["']/, "").split(/\s*,\s*/)
207
- unsupported = used - allowed
208
- if unsupported.any?
209
- invalid! "is_match used with #{unsupported}, but metric is only grouped by #{allowed}"
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! "#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. Add more groupings or fix the #{match}"
213
+ end
210
214
  end
211
215
  end
212
216
  end
@@ -63,10 +63,11 @@ module Kennel
63
63
  end
64
64
 
65
65
  def self.parse_url(url)
66
- url[/\/slo\?slo_id=([a-z\d]+)/, 1]
66
+ url[/\/slo\?.*slo_id=([a-z\d]+)/, 1]
67
67
  end
68
68
 
69
69
  def resolve_linked_tracking_ids!(id_map, **args)
70
+ return unless as_json[:monitor_ids] # ignore_default can remove it
70
71
  as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
71
72
  id.is_a?(String) ? resolve_link(id, :monitor, id_map, **args) : id
72
73
  end
@@ -38,7 +38,7 @@ module Kennel
38
38
  end
39
39
 
40
40
  def update
41
- changed = (@create + @update).map { |_, e| e } unless @create.empty?
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
- raise "Unable to find existing #{e.class.api_resource} with id #{id}"
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 fr:om merges to master.
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.76.1"
3
+ VERSION = "1.78.1"
4
4
  end
@@ -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,12 +201,13 @@ 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
 
198
208
  - rebase on updated `master` to not undo other changes
199
209
  - figure out project name by converting the class name to snake-case
200
- - run `PROJECT=foo bundle exec rake kennel:update_datadog` to test changes for a single project
210
+ - run `PROJECT=foo bundle exec rake kennel:update_datadog` to test changes for a single project (monitors: remove mentions while debugging to avoid alert spam)
201
211
 
202
212
  ### Reuse
203
213
 
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.76.1
4
+ version: 1.78.1
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-08-26 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday