kennel 1.76.2 → 1.78.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f414fdeaa15b105fde4fa0cbcf70956246bcafafd31aa3d4a48dbed37e3a31ff
4
- data.tar.gz: b29014f8c562d772429a09ede70ad92d7ad892f4359628c66e24535cd50e4232
3
+ metadata.gz: 404c565dc87a8ffd30f1c0293228cc5270bedd3c6e5eaae1d191ba6cdae60ce7
4
+ data.tar.gz: 274f807772d6077c625a503aeb3d98edeef795bf0d7c40845db56d7b2e2e2ff0
5
5
  SHA512:
6
- metadata.gz: 2cb2504d598f41a5fb3f75431cadaf58749b4d8d381d8c87f89125c703c8122c916ceb3064e25332d2f8f0c8b9f0b69b28d76f1c71000d515e7e027e2df118da
7
- data.tar.gz: 75f379f50a897704e3bb488960920ce2e11e79249d32ad77b851d05ed6ed5c886ce060869c1bad6474b383fdb4ebcb8c117b051bf1e88b9fa590d96cede73284
6
+ metadata.gz: b165262ab6d8f6e8efadff786d3829a75e96d6893e4235eed961ef5203c66d0f250488e7911964a77c2862df0e196e08619582ce9cda51fed851141785a0a9c4
7
+ data.tar.gz: ab59bfdd4ca2d73526fb28126fd1f18765ce92703d7bad71c05d7f321f54fa39192db87ad4a7ae65c12441e38eb794264bceae8aad57be84e30a2c06ac65b3f5
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,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
 
@@ -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
@@ -178,7 +178,7 @@ module Kennel
178
178
  def validate_json(data)
179
179
  super
180
180
 
181
- validate_template_variables data, :widgets
181
+ validate_template_variables data
182
182
 
183
183
  # Avoid diff from datadog presets sorting.
184
184
  presets = data[:template_variable_presets]
@@ -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,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*#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!(
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
@@ -67,6 +67,7 @@ module Kennel
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
@@ -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, key)
19
+ def validate_template_variables(data)
20
20
  variables = (data[:template_variables] || []).map { |v| "$#{v.fetch(:name)}" }
21
- queries = data[key].flat_map do |widget|
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
- bad = queries.grep_v(/(#{variables.map { |v| Regexp.escape(v) }.join("|")})\b/)
25
- if bad.any?
26
- invalid!(
27
- "queries #{bad.join(", ")} must use the template variables #{variables.join(", ")}\n" \
28
- "If that is not possible, add `validate: -> { false } # query foo in bar does not have baz tag`"
29
- )
30
- end
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)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.76.2"
3
+ VERSION = "1.78.2"
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,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.76.2
4
+ version: 1.78.2
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-03 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday