kennel 1.121.1 → 1.122.0

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: c3eb87db53998806797dc41a7a73bacc01e1134655c7165c0498e30d7344e8fb
4
- data.tar.gz: 5ce8b48a088fdae20fc4b49211ca229f3f8e028f654eaa489b49ebf6de980646
3
+ metadata.gz: 43b746ea91f86217a6fc43383a3368ccd654c89936c44003088054380be8c36d
4
+ data.tar.gz: 5fcd75471c8d0152236d032b023b4769975251047bc276f00219df3b1e60964d
5
5
  SHA512:
6
- metadata.gz: a22b79c15a1e7c29947011de54e58fbc5a3c71d988bf2a65e046304d6c890e0472405b548c06144b6f1f9f9fe2a6a91ed1a0608e59dcd925fe73b7023f9f91fd
7
- data.tar.gz: a3afc60d010f1364a46439d4f649d770cb1a76bb720856c9beada4cd89f4ab932b9aa1dfa8470feb97de969a0230752f94ec3a92f4e5a00275fa18fecdb46651
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
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.1"
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.1
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