kennel 1.125.0 → 1.127.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: 2464486b37bc4711843991d93789d4844d9c9aac33b40cf8b088ec4b249f39ab
4
- data.tar.gz: 794318abfb10fecca670f6a8d2ad22e6f117e8425d0dc964b76163a658593d16
3
+ metadata.gz: ec72f834db1c82d19ba21eabd482e5f46a540b0c9a3e0e51ecc20a80c192a6d7
4
+ data.tar.gz: c5b549fb934ce3e274d88149df509b4dcf16e1adc6be3271e94b3101dbee1ad7
5
5
  SHA512:
6
- metadata.gz: 97c3664e939d5776bf4dcc2a8fc72b647af0a8df0112035cadd6105e8117dd116097e85e60838050f96959df5ea0e17d7e00ffe89420712937a32190bcce70ca
7
- data.tar.gz: 4a1cf01f15ac6959c7cea683297fb41f3a74791a99b3a16c5391f76af48333d9a1b4ea9a9fc804750844feb75d5c02fae0caced96fc3b85723d128d1ad45e289
6
+ metadata.gz: e0bff1a22428c19da30025f79e8e7904675ea27d79eb2cfdf1a6cf0638a33efbdee44c10f898480b9e7d91d73296368e3bab58ce495282beb43cb13c975c9153
7
+ data.tar.gz: 445cf62d6e525c42808a42ba80e941829cab5c679ef74f71590799ec46e93f3d41ff8162bed775342510c042249a2acfaf10dea06507a2b5f7a7b0c8a450fb3c
@@ -230,7 +230,9 @@ module Kennel
230
230
 
231
231
  # Avoid diff from datadog presets sorting.
232
232
  presets = data[:template_variable_presets]
233
- invalid! "template_variable_presets must be sorted by name" if presets && presets != presets.sort_by { |p| p[:name] }
233
+ if presets && presets != presets.sort_by { |p| p[:name] }
234
+ invalid! :template_variable_presets_must_be_sorted, "template_variable_presets must be sorted by name"
235
+ end
234
236
  end
235
237
 
236
238
  def render_definitions(definitions)
@@ -214,26 +214,26 @@ module Kennel
214
214
  super
215
215
 
216
216
  if data[:name]&.start_with?(" ")
217
- invalid! "name cannot start with a space"
217
+ invalid! :name_must_not_start_with_space, "name cannot start with a space"
218
218
  end
219
219
 
220
220
  type = data.fetch(:type)
221
221
 
222
222
  # do not allow deprecated type that will be coverted by datadog and then produce a diff
223
223
  if type == "metric alert"
224
- invalid! "type 'metric alert' is deprecated, please set to a different type (e.g. 'query alert')"
224
+ invalid! :metric_alert_is_deprecated, "type 'metric alert' is deprecated, please set to a different type (e.g. 'query alert')"
225
225
  end
226
226
 
227
227
  # verify query includes critical value
228
228
  if query_value = data.fetch(:query)[/\s*[<>]=?\s*(\d+(\.\d+)?)\s*$/, 1]
229
229
  if Float(query_value) != Float(data.dig(:options, :thresholds, :critical))
230
- invalid! "critical and value used in query must match"
230
+ invalid! :critical_does_not_match_query, "critical and value used in query must match"
231
231
  end
232
232
  end
233
233
 
234
234
  # verify renotify interval is valid
235
235
  unless RENOTIFY_INTERVALS.include? data.dig(:options, :renotify_interval)
236
- invalid! "renotify_interval must be one of #{RENOTIFY_INTERVALS.join(", ")}"
236
+ invalid! :invalid_renotify_interval, "renotify_interval must be one of #{RENOTIFY_INTERVALS.join(", ")}"
237
237
  end
238
238
 
239
239
  if ["query alert", "service check"].include?(type) # TODO: most likely more types need this
@@ -243,15 +243,15 @@ module Kennel
243
243
  validate_using_links(data)
244
244
 
245
245
  if type == "service check" && !data[:query].to_s.include?(".by(")
246
- invalid! "query must include a .by() at least .by(\"*\")"
246
+ invalid! :query_must_include_by, "query must include a .by() at least .by(\"*\")"
247
247
  end
248
248
 
249
249
  unless ALLOWED_PRIORITY_CLASSES.include?(priority.class)
250
- invalid! "priority needs to be an Integer"
250
+ invalid! :invalid_priority, "priority needs to be an Integer"
251
251
  end
252
252
 
253
253
  if data.dig(:options, :timeout_h)&.> 24
254
- invalid! "timeout_h must be <= 24"
254
+ invalid! :invalid_timeout_h, "timeout_h must be <= 24"
255
255
  end
256
256
  end
257
257
 
@@ -286,7 +286,7 @@ module Kennel
286
286
  forbidden = used - allowed
287
287
  return if forbidden.empty?
288
288
 
289
- invalid! <<~MSG.rstrip
289
+ invalid! :invalid_variable_used_in_message, <<~MSG.rstrip
290
290
  Used #{forbidden.join(", ")} in the message, but can only be used with #{allowed.join(", ")}.
291
291
  Group or filter the query by #{forbidden.map { |f| f.sub(".name", "") }.join(", ")} to use it.
292
292
  MSG
@@ -298,7 +298,7 @@ module Kennel
298
298
  ids = data[:query].tr("-", "_").scan(/\b\d+\b/)
299
299
  ids.reject! { |id| ALLOWED_UNLINKED.include?([tracking_id, id]) }
300
300
  if ids.any?
301
- invalid! <<~MSG.rstrip
301
+ invalid! :links_must_be_via_tracking_id, <<~MSG.rstrip
302
302
  Used #{ids} in the query, but should only use links in the form of %{<project id>:<monitor id>}
303
303
  If that is not possible, add `validate_using_links: ->(*){} # linked monitors are not in kennel
304
304
  MSG
@@ -211,8 +211,8 @@ module Kennel
211
211
  end
212
212
  end
213
213
 
214
- def invalid!(message)
215
- unfiltered_validation_errors << ValidationMessage.new(message)
214
+ def invalid!(tag, message)
215
+ unfiltered_validation_errors << ValidationMessage.new(tag || OptionalValidations::UNIGNORABLE, message)
216
216
  end
217
217
 
218
218
  def raise_with_location(error, message)
@@ -85,7 +85,7 @@ module Kennel
85
85
  super
86
86
 
87
87
  if data[:thresholds].any? { |t| t[:warning] && t[:warning].to_f <= t[:critical].to_f }
88
- invalid! "Threshold warning must be greater-than critical value"
88
+ invalid! :warning_must_be_gt_critical, "Threshold warning must be greater-than critical value"
89
89
  end
90
90
  end
91
91
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
3
  module OptionalValidations
4
- ValidationMessage = Struct.new(:text)
4
+ ValidationMessage = Struct.new(:tag, :text)
5
+
6
+ UNIGNORABLE = :unignorable
5
7
 
6
8
  def self.included(base)
7
- base.settings :validate
8
- base.defaults(validate: -> { true })
9
+ base.settings :ignored_errors
10
+ base.defaults(ignored_errors: -> { [] })
9
11
  end
10
12
 
11
13
  def self.valid?(parts)
@@ -15,14 +17,26 @@ module Kennel
15
17
 
16
18
  return true if parts_with_errors.empty?
17
19
 
20
+ example_tag = nil
21
+
18
22
  Kennel.err.puts
19
23
  parts_with_errors.sort_by(&:safe_tracking_id).each do |part|
20
24
  part.filtered_validation_errors.each do |err|
21
- Kennel.err.puts "#{part.safe_tracking_id} #{err.text}"
25
+ Kennel.err.puts "#{part.safe_tracking_id} [#{err.tag.inspect}] #{err.text.gsub("\n", " ")}"
26
+ example_tag = err.tag unless err.tag == :unignorable
22
27
  end
23
28
  end
24
29
  Kennel.err.puts
25
30
 
31
+ Kennel.err.puts <<~MESSAGE if example_tag
32
+ If a particular error cannot be fixed, it can be marked as ignored via `ignored_errors`, e.g.:
33
+ Kennel::Models::Monitor.new(
34
+ ...,
35
+ ignored_errors: [#{example_tag.inspect}]
36
+ )
37
+
38
+ MESSAGE
39
+
26
40
  false
27
41
  end
28
42
 
@@ -32,6 +46,7 @@ module Kennel
32
46
  bad = Kennel::Utils.all_keys(data).grep_v(Symbol).sort.uniq
33
47
  return if bad.empty?
34
48
  invalid!(
49
+ :hash_keys_must_be_symbols,
35
50
  "Only use Symbols as hash keys to avoid permanent diffs when updating.\n" \
36
51
  "Change these keys to be symbols (usually 'foo' => 1 --> 'foo': 1)\n" \
37
52
  "#{bad.map(&:inspect).join("\n")}"
@@ -39,39 +54,30 @@ module Kennel
39
54
  end
40
55
 
41
56
  def filter_validation_errors
42
- if validate
43
- unfiltered_validation_errors
44
- elsif unfiltered_validation_errors.empty?
45
- msg = "`validate` is set to false, but there are no validation errors to suppress. Remove `validate: false`"
46
-
47
- mode = ENV.fetch("UNNECESSARY_VALIDATE_FALSE") do
48
- if ENV.key?("PROJECT") || ENV.key?("TRACKING_ID")
49
- "fail"
50
- else
51
- nil
52
- end
53
- end
54
-
55
- if mode == "fail"
56
- [ValidationMessage.new(msg)]
57
- else
58
- Kennel.out.puts "#{safe_tracking_id} #{msg}" if mode == "show"
57
+ if unfiltered_validation_errors.empty?
58
+ if ignored_errors.empty?
59
59
  []
60
+ else
61
+ [ValidationMessage.new(UNIGNORABLE, "`ignored_errors` is non-empty, but there are no errors to ignore. Remove `ignored_errors`")]
60
62
  end
61
63
  else
62
- mode = ENV.fetch("SUPPRESSED_ERRORS", "ignore")
63
-
64
- if mode == "fail"
65
- unfiltered_validation_errors
66
- else
67
- if mode == "show"
68
- unfiltered_validation_errors.each do |err|
69
- Kennel.out.puts "#{safe_tracking_id} `validate: false` suppressing error: #{err.text.gsub("\n", " ")}"
64
+ to_report =
65
+ if ENV["NO_IGNORED_ERRORS"]
66
+ # Turn off all suppressions, to see what errors are actually being suppressed
67
+ unfiltered_validation_errors
68
+ else
69
+ unfiltered_validation_errors.reject do |err|
70
+ err.tag != UNIGNORABLE && ignored_errors.include?(err.tag)
70
71
  end
71
72
  end
72
73
 
73
- []
74
+ unused_ignores = ignored_errors - unfiltered_validation_errors.map(&:tag)
75
+
76
+ unless unused_ignores.empty?
77
+ to_report << ValidationMessage.new(UNIGNORABLE, "Unused ignores #{unused_ignores.map(&:inspect).sort.uniq.join(" ")}. Remove these from `ignored_errors`")
74
78
  end
79
+
80
+ to_report
75
81
  end
76
82
  end
77
83
  end
@@ -29,8 +29,8 @@ module Kennel
29
29
  return if queries.empty?
30
30
 
31
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`"
32
+ :queries_must_use_template_variables,
33
+ "queries #{queries.join(", ")} must use the template variables #{variables.join(", ")}"
34
34
  )
35
35
  end
36
36
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.125.0"
3
+ VERSION = "1.127.0"
4
4
  end
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.125.0
4
+ version: 1.127.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: 2022-11-30 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs