kennel 1.121.0 → 1.122.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: bb8230c7d3bd7abc24f4c0a1b18de96b7ef892d2f54bdc2ccc010d9ba10a80c6
4
- data.tar.gz: b2793e6ac6a79cdb809f77f749b5210501e48bfefb5baa38c2f16ed7043c75ed
3
+ metadata.gz: 43b746ea91f86217a6fc43383a3368ccd654c89936c44003088054380be8c36d
4
+ data.tar.gz: 5fcd75471c8d0152236d032b023b4769975251047bc276f00219df3b1e60964d
5
5
  SHA512:
6
- metadata.gz: 24d20844e2b74bee9f13c2daf5a80d4a366e7251b826b61e1dd4d5172918cf5fc5b5d694bc7604c7f64d3543150a2f1a8d1884c5c6f462e48b52b74a51267c5f
7
- data.tar.gz: 1c52708d519c711b55aa62cb9016ec7124b52634526343ee4140422223e90da351aadd466238bff5e07031dac8b14312cafecde3917e7308193d2c3af9119aeb
6
+ metadata.gz: e9ce639cdd5748f689eeb352da8ea9c14a2a4243350368574b8b3c1b52534dbf470ca3e969ad96ecd685d8df93d368e7e4d5f5c98da2af7e5cc843ccbc8053ce
7
+ data.tar.gz: 7039072c9129311145694b53823cab5c11263e972ae8f6c586e0b86063a8ab9d375c2ecd1069bd2812f626ce631f2940fe55ca9a018033b435df63bcbef1d355
data/Readme.md CHANGED
@@ -406,6 +406,14 @@ https://foo.datadog.com/monitor/123
406
406
  ### Find all monitors with No-Data
407
407
  `rake kennel:nodata TAG=team:foo`
408
408
 
409
+ ### Finding the tracking id of a resource
410
+
411
+ When trying to link resources together, this avoids having to go through datadog UI.
412
+
413
+ ```Bash
414
+ rake kennel:tracking_id ID=123 RESOURCE=monitor
415
+ ```
416
+
409
417
  <!-- NOT IN template/Readme.md -->
410
418
 
411
419
  ## Development
@@ -24,7 +24,7 @@ module Kennel
24
24
  end
25
25
 
26
26
  def report(&block)
27
- output = Utils.strip_shell_control(Utils.tee_output(&block).strip)
27
+ output = Utils.tee_output(&block).strip
28
28
  rescue StandardError
29
29
  output = "Error:\n#{$ERROR_INFO.message}"
30
30
  raise
@@ -60,6 +60,8 @@ module Kennel
60
60
  data[:critical] = data[:critical].to_i if data[:type] == "event alert"
61
61
 
62
62
  data[:type] = "query alert" if data[:type] == "metric alert"
63
+
64
+ link_composite_monitors(data)
63
65
  when "dashboard"
64
66
  widgets = data[:widgets]&.flat_map { |widget| widget.dig(:definition, :widgets) || [widget] }
65
67
  widgets&.each do |widget|
@@ -91,6 +93,18 @@ module Kennel
91
93
 
92
94
  private
93
95
 
96
+ def link_composite_monitors(data)
97
+ if data[:type] == "composite"
98
+ data[:query].gsub!(/\d+/) do |id|
99
+ object = Kennel.send(:api).show("monitor", id)
100
+ tracking_id = Kennel::Models::Monitor.parse_tracking_id(object)
101
+ tracking_id ? "%{#{tracking_id}}" : id
102
+ rescue StandardError # monitor not found
103
+ id # keep the id
104
+ end
105
+ end
106
+ end
107
+
94
108
  # reduce duplication in imports by using dry `q: :metadata` when possible
95
109
  def dry_up_widget_metadata!(widget)
96
110
  (widget.dig(:definition, :requests) || []).each do |request|
@@ -4,7 +4,9 @@ require "benchmark"
4
4
  module Kennel
5
5
  class Progress
6
6
  # print what we are doing and a spinner until it is done ... then show how long it took
7
- def self.progress(name)
7
+ def self.progress(name, interval: 0.2, &block)
8
+ return progress_no_tty(name, &block) unless Kennel.err.tty?
9
+
8
10
  Kennel.err.print "#{name} ... "
9
11
 
10
12
  stop = false
@@ -16,15 +18,20 @@ module Kennel
16
18
  loop do
17
19
  break if stop
18
20
  Kennel.err.print animation[count % animation.size]
19
- sleep 0.2
21
+ sleep interval
20
22
  Kennel.err.print "\b"
21
23
  count += 1
22
24
  end
23
25
  end
24
26
 
25
- time = Benchmark.realtime { result = yield }
27
+ time = Benchmark.realtime { result = block.call }
26
28
 
27
29
  stop = true
30
+ begin
31
+ spinner.run # wake thread, so it stops itself
32
+ rescue ThreadError
33
+ # thread was already dead, but we can't check with .alive? since it's a race condition
34
+ end
28
35
  spinner.join
29
36
  Kennel.err.print "#{time.round(2)}s\n"
30
37
 
@@ -32,5 +39,17 @@ module Kennel
32
39
  ensure
33
40
  stop = true # make thread stop without killing it
34
41
  end
42
+
43
+ class << self
44
+ private
45
+
46
+ def progress_no_tty(name)
47
+ Kennel.err.puts "#{name} ..."
48
+ result = nil
49
+ time = Benchmark.realtime { result = yield }
50
+ Kennel.err.puts "#{name} ... #{time.round(2)}s"
51
+ result
52
+ end
53
+ end
35
54
  end
36
55
  end
@@ -8,17 +8,15 @@ module Kennel
8
8
 
9
9
  private
10
10
 
11
+ # load_all's purpose is to "require" all the .rb files under './projects',
12
+ # while allowing them to resolve reference to ./teams and ./parts via autoload
11
13
  def load_all
12
- # load_all's purpose is to "require" all the .rb files under './projects',
13
- # also with reference to ./teams and ./parts. What happens if you call it
14
- # more than once?
15
- #
16
- # For a reason yet to be investigated, Zeitwerk rejects second and subsequent calls.
17
- # But even if we skip over the Zeitwerk part, the nature of 'require' is
18
- # somewhat one-way: we're not providing any mechanism to *un*load things.
19
- # As long as the contents of `./projects`, `./teams` and `./parts` doesn't
20
- # change between calls, then simply by no-op'ing subsequent calls to `load_all`
21
- # we can have `load_all` appear to be idempotent.
14
+ # Zeitwerk rejects second and subsequent calls.
15
+ # Even if we skip over the Zeitwerk part, the nature of 'require' is
16
+ # one-way: ruby does not provide a mechanism to *un*require things.
17
+ return if defined?(@@load_all) && @@load_all
18
+ @@load_all = true
19
+
22
20
  loader = Zeitwerk::Loader.new
23
21
  Dir.exist?("teams") && loader.push_dir("teams", namespace: Teams)
24
22
  Dir.exist?("parts") && loader.push_dir("parts")
data/lib/kennel/syncer.rb CHANGED
@@ -42,7 +42,7 @@ module Kennel
42
42
 
43
43
  def confirm
44
44
  return false if noop?
45
- return true if ENV["CI"] || !STDIN.tty?
45
+ return true if ENV["CI"] || !STDIN.tty? || !Kennel.err.tty?
46
46
  Utils.ask("Execute Plan ?")
47
47
  end
48
48
 
data/lib/kennel/tasks.rb CHANGED
@@ -233,6 +233,17 @@ namespace :kennel do
233
233
  end
234
234
  end
235
235
 
236
+ desc "Resolve given id to kennel tracking-id RESOURCE= ID="
237
+ task tracking_id: "kennel:environment" do
238
+ resource = ENV.fetch("RESOURCE")
239
+ id = ENV.fetch("ID")
240
+ klass =
241
+ Kennel::Models::Record.subclasses.detect { |s| s.api_resource == resource } ||
242
+ raise("resource #{resource} not know")
243
+ object = Kennel.send(:api).show(resource, id)
244
+ Kennel.out.puts klass.parse_tracking_id(object)
245
+ end
246
+
236
247
  task :environment do
237
248
  Kennel::Tasks.load_environment
238
249
  end
data/lib/kennel/utils.rb CHANGED
@@ -42,7 +42,7 @@ module Kennel
42
42
  end
43
43
 
44
44
  def ask(question)
45
- Kennel.err.printf color(:red, "#{question} - press 'y' to continue: ")
45
+ Kennel.err.printf color(:red, "#{question} - press 'y' to continue: ", force: true)
46
46
  begin
47
47
  STDIN.gets.chomp == "y"
48
48
  rescue Interrupt # do not show a backtrace if user decides to Ctrl+C here
@@ -51,12 +51,10 @@ module Kennel
51
51
  end
52
52
  end
53
53
 
54
- def color(color, text)
55
- "\e[#{COLORS.fetch(color)}m#{text}\e[0m"
56
- end
54
+ def color(color, text, force: false)
55
+ return text unless force || Kennel.out.tty?
57
56
 
58
- def strip_shell_control(text)
59
- text.gsub(/\e\[\d+m(.*?)\e\[0m/, "\\1").gsub(/.#{Regexp.escape("\b")}/, "")
57
+ "\e[#{COLORS.fetch(color)}m#{text}\e[0m"
60
58
  end
61
59
 
62
60
  def capture_stdout
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.121.0"
3
+ VERSION = "1.122.0"
4
4
  end
data/template/Readme.md CHANGED
@@ -388,3 +388,11 @@ https://foo.datadog.com/monitor/123
388
388
  ### Find all monitors with No-Data
389
389
  `rake kennel:nodata TAG=team:foo`
390
390
 
391
+ ### Finding the tracking id of a resource
392
+
393
+ When trying to link resources together, this avoids having to go through datadog UI.
394
+
395
+ ```Bash
396
+ rake kennel:tracking_id ID=123 RESOURCE=monitor
397
+ ```
398
+
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.121.0
4
+ version: 1.122.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-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs