kennel 1.75.1 → 1.77.0

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: 23af2ecfb9019df555f7fe3a3954f4d992208927744093ff1f8886afd571e457
4
- data.tar.gz: 6e2c902c47020e46b5fc0e647d8d63bbd7227657ce78303c673470be840ecbf9
3
+ metadata.gz: e6ac506da0670019c4f9bfeedda08ff728a0522b86a4e65356ef75b806ac1a33
4
+ data.tar.gz: e19bca2c80a775ba5a28a480b7b265246c0aa00699eec87147ef9d1b7725b603
5
5
  SHA512:
6
- metadata.gz: c2dfa7e9f54c83d3369b48b91896cb7dc7cfe75bb94d672d7de07bc7a6b8ea3f63ebe38788dddf5de90ead3b73f977c42f87497d61e7b23def6ae385d0a42213
7
- data.tar.gz: 9ebb18f6d9c54be18a783d8511e3128b9c59b5898f9f14a1be77c871dcdab837681bf04050ec97a1a2f675c84fda624469edaed0af9f5e0da11b60517ba93cea
6
+ metadata.gz: c29f4797475eb5f83eb7d3b5a35af710267eff90263764e0611f6d2bb52b75d3af34c3fdc7423e0945b2c0741c94bed3480152a17ef73b301877592d93c138c4
7
+ data.tar.gz: bbe104daf2fc7962fa95d94ce6b44b098ddd40461354717d99c0483f5672659a71ebaeaecaad32a28406161b8cd6ff726deefbf6986063b36e7eeb6e0edd60e5
data/Readme.md CHANGED
@@ -205,17 +205,18 @@ to unblock use the `validate: -> { false }` option.
205
205
 
206
206
  ### Linking with kennel_ids
207
207
 
208
- To link to existing monitors via their kennel_id
208
+ To link to existing monitors via their kennel_id `projects kennel_id` + `:` + `monitors kennel id`
209
209
 
210
210
  - Screens `uptime` widgets can use `monitor: {id: "foo:bar"}`
211
211
  - Screens `alert_graph` widgets can use `alert_id: "foo:bar"`
212
212
  - Monitors `composite` can use `query: -> { "%{foo:bar} || %{foo:baz}" }`
213
+ - Slos can use `monitor_ids: -> ["foo:bar"]`
213
214
 
214
215
  ### Debugging changes locally
215
216
 
216
217
  - rebase on updated `master` to not undo other changes
217
218
  - 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
219
+ - 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
220
 
220
221
  ### Reuse
221
222
 
@@ -257,7 +258,8 @@ Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a
257
258
 
258
259
  ### Grepping through all of datadog
259
260
 
260
- `TYPE=monitor rake kennel:dump`
261
+ `rake kennel:dump`
262
+ focus on a single type: `TYPE=monitors`
261
263
 
262
264
  ### Find all monitors with No-Data
263
265
 
@@ -15,8 +15,10 @@ module Kennel
15
15
  def initialize(token, git_sha)
16
16
  @token = token
17
17
  @git_sha = git_sha
18
- origin = ENV["PROJECT_REPOSITORY"] || Utils.capture_sh("git remote -v").split("\n").first
19
- @repo_part = origin[%r{github\.com[:/](.+?)(\.git|$)}, 1] || raise("no origin found")
18
+ @repo_part = ENV["GITHUB_REPOSITORY"] || begin
19
+ origin = ENV["PROJECT_REPOSITORY"] || Utils.capture_sh("git remote -v").split("\n").first
20
+ origin[%r{github\.com[:/](\S+?)(\.git|$)}, 1] || raise("no origin found in #{origin}")
21
+ end
20
22
  end
21
23
 
22
24
  def report(&block)
@@ -42,10 +42,15 @@ module Kennel
42
42
 
43
43
  case resource
44
44
  when "monitor"
45
- # flatten monitor options so they are all on the base
45
+ # flatten monitor options so they are all on the base which is how Monitor builds them
46
46
  data.merge!(data.delete(:options))
47
47
  data.merge!(data.delete(:thresholds) || {})
48
- [:notify_no_data, :notify_audit].each { |k| data.delete(k) if data[k] } # monitor uses true by default
48
+
49
+ # clean up values that are the default
50
+ data.delete(:notify_no_data) if data[:notify_no_data] # Monitor uses true by default
51
+ data.delete(:notify_audit) unless data[:notify_audit] # Monitor uses false by default
52
+
53
+ # keep all values that are settable
49
54
  data = data.slice(*model.instance_methods)
50
55
 
51
56
  # make query use critical method if it matches
@@ -61,6 +66,8 @@ module Kennel
61
66
  widgets&.each { |widget| dry_up_query!(widget) }
62
67
  end
63
68
 
69
+ data.delete(:tags) if data[:tags] == [] # do not create super + [] call
70
+
64
71
  # simplify template_variables to array of string when possible
65
72
  if vars = data[:template_variables]
66
73
  vars.map! { |v| v[:default] == "*" && v[:prefix] == v[:name] ? v[:name] : v }
@@ -18,6 +18,7 @@ module Kennel
18
18
  new_host_delay: 300,
19
19
  timeout_h: 0,
20
20
  renotify_interval: 0,
21
+ notify_audit: false,
21
22
  no_data_timeframe: nil, # this works out ok since if notify_no_data is on, it would never be nil
22
23
  groupby_simple_monitor: false
23
24
  }.freeze
@@ -36,9 +37,9 @@ module Kennel
36
37
  warning: -> { nil },
37
38
  ok: -> { nil },
38
39
  id: -> { nil },
39
- notify_no_data: -> { true },
40
+ notify_no_data: -> { true }, # datadog sets this to false by default, but true is the safer
40
41
  no_data_timeframe: -> { 60 },
41
- notify_audit: -> { true },
42
+ notify_audit: -> { MONITOR_OPTION_DEFAULTS.fetch(:notify_audit) },
42
43
  new_host_delay: -> { MONITOR_OPTION_DEFAULTS.fetch(:new_host_delay) },
43
44
  tags: -> { @project.tags },
44
45
  timeout_h: -> { MONITOR_OPTION_DEFAULTS.fetch(:timeout_h) },
@@ -191,7 +192,7 @@ module Kennel
191
192
  end
192
193
 
193
194
  if type == "query alert"
194
- # verify interval is valud
195
+ # verify interval is valid
195
196
  interval = data.fetch(:query)[/\(last_(\S+?)\)/, 1]
196
197
  if interval && !QUERY_INTERVALS.include?(interval)
197
198
  invalid! "query interval was #{interval}, but must be one of #{QUERY_INTERVALS.join(", ")}"
@@ -199,13 +200,17 @@ module Kennel
199
200
  end
200
201
 
201
202
  if ["query alert", "service check"].include?(type) # TODO: most likely more types need this
202
- # verify is_match uses available variables
203
+ # verify is_match/is_exact_match uses available variables
203
204
  message = data.fetch(:message)
204
- used = message.scan(/{{\s*#is_match\s*"([a-zA-Z\d_.-]+).name"/).flatten.uniq
205
- allowed = data.fetch(:query)[/by\s*[({]([^})]+)[})]/, 1].to_s.gsub(/["']/, "").split(/\s*,\s*/)
206
- unsupported = used - allowed
207
- if unsupported.any?
208
- 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
209
214
  end
210
215
  end
211
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)
@@ -188,7 +188,7 @@ module Kennel
188
188
  end
189
189
 
190
190
  # 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.
191
+ # so resource do not get deleted from running an update on master (for example merge->CI).
192
192
  # Also make sure the diff still makes sense, by kicking out the now noop-update.
193
193
  #
194
194
  # Note: ideally we'd never add tracking in the first place, but at that point we do not know the diff yet
@@ -124,10 +124,18 @@ namespace :kennel do
124
124
  Kennel.out.puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
125
125
  end
126
126
 
127
- desc "Dump ALL of datadog config as raw json ... useful for grep/search TYPE=slo|monitor|dashboard"
127
+ desc "Dump ALL of datadog config as raw json ... useful for grep/search [TYPE=slo|monitor|dashboard]"
128
128
  task dump: :environment do
129
- Kennel.send(:api).list(ENV.fetch("TYPE")).each do |r|
130
- Kennel.out.puts JSON.pretty_generate(r)
129
+ resources =
130
+ if type = ENV["TYPE"]
131
+ [type]
132
+ else
133
+ Kennel::Models::Record.subclasses.map(&:api_resource)
134
+ end
135
+ resources.each do |resource|
136
+ Kennel.send(:api).list(resource).each do |r|
137
+ Kennel.out.puts JSON.pretty_generate(r)
138
+ end
131
139
  end
132
140
  end
133
141
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.75.1"
3
+ VERSION = "1.77.0"
4
4
  end
@@ -187,17 +187,18 @@ to unblock use the `validate: -> { false }` option.
187
187
 
188
188
  ### Linking with kennel_ids
189
189
 
190
- To link to existing monitors via their kennel_id
190
+ To link to existing monitors via their kennel_id `projects kennel_id` + `:` + `monitors kennel id`
191
191
 
192
192
  - Screens `uptime` widgets can use `monitor: {id: "foo:bar"}`
193
193
  - Screens `alert_graph` widgets can use `alert_id: "foo:bar"`
194
194
  - Monitors `composite` can use `query: -> { "%{foo:bar} || %{foo:baz}" }`
195
+ - Slos can use `monitor_ids: -> ["foo:bar"]`
195
196
 
196
197
  ### Debugging changes locally
197
198
 
198
199
  - rebase on updated `master` to not undo other changes
199
200
  - 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
201
+ - 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
202
 
202
203
  ### Reuse
203
204
 
@@ -239,7 +240,8 @@ Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a
239
240
 
240
241
  ### Grepping through all of datadog
241
242
 
242
- `TYPE=monitor rake kennel:dump`
243
+ `rake kennel:dump`
244
+ focus on a single type: `TYPE=monitors`
243
245
 
244
246
  ### Find all monitors with No-Data
245
247
 
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.75.1
4
+ version: 1.77.0
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-07-23 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday