kennel 1.88.1 → 1.89.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: 1091fcd44daba6435e7a9321610a27b8ac2510451cf97e8183d6ab744e080288
4
- data.tar.gz: f137076ec36e4018eaa1c1d60dd2da187f33bdb41fc3fe5c384be4787ddd9c77
3
+ metadata.gz: bdedd0f9bbcb9abf873cd2f9be0414700f77d2ea864e609db79773d1b3193e8e
4
+ data.tar.gz: 336875475665fac019c12daced64e474fb8e85e216e158d4328b62b287785e6a
5
5
  SHA512:
6
- metadata.gz: 52cd265a23705e8a8afca55f819c9fed1c2ae467e8de1cba5e696cd6191619458168fd649f26f5c00da33702e4002490e13f804335dad10e2204a96d16cf12a8
7
- data.tar.gz: d2cc461399929023573e22f55bc89699d952c9338f5e415cea9328af00d212b5e87fe2061837327ec88c4b60a2a277e1f272a511e85a9de0014142c51073f60e
6
+ metadata.gz: 0041e466ce433d82f9db8252829f8c64652815d7bf932ec93596d57af76dc13aaa9dfce963bbf82888e09d424937b597364954edc1cff14344143f0661e8e274
7
+ data.tar.gz: a286f227e597686085049ef0227b2e36b26d33ef41a7d96d13a535af73e1530254de6bf68ead11ebdd0c394d1562766a91a478c794ee17f35c288a7f102d46b7
data/Readme.md CHANGED
@@ -114,6 +114,7 @@ end
114
114
  - use [datadog monitor UI](https://app.datadoghq.com/monitors/manage) to find a monitor
115
115
  - get the `id` from the url
116
116
  - run `URL='https://app.datadoghq.com/monitors/123' bundle exec rake kennel:import` and copy the output
117
+ - import task also works with SLO alerts, e.g. `URL='https://app.datadoghq.com/slo/edit/123abc456def123/alerts/789' bundle exec rake kennel:import`
117
118
  - find or create a project in `projects/`
118
119
  - add the monitor to `parts: [` list, for example:
119
120
  ```Ruby
@@ -11,7 +11,7 @@ module Kennel
11
11
 
12
12
  def kennel_id
13
13
  name = self.class.name
14
- if name.start_with?("Kennel::")
14
+ if name.start_with?("Kennel::") # core objects would always generate the same id
15
15
  raise_with_location ArgumentError, "Set :kennel_id"
16
16
  end
17
17
  @kennel_id ||= Utils.snake_case name
@@ -129,9 +129,15 @@ module Kennel
129
129
  Utils.path_to_url "/monitors##{id}/edit"
130
130
  end
131
131
 
132
- # datadog uses / for show and # for edit as separator in it's links
133
132
  def self.parse_url(url)
134
- return unless id = url[/\/monitors[\/#](\d+)/, 1]
133
+ # datadog uses / for show and # for edit as separator in it's links
134
+ id = url[/\/monitors[\/#](\d+)/, 1]
135
+
136
+ # slo alert url
137
+ id ||= url[/\/slo\/edit\/[a-z\d]{10,}\/alerts\/(\d+)/, 1]
138
+
139
+ return unless id
140
+
135
141
  Integer(id)
136
142
  end
137
143
 
@@ -74,7 +74,11 @@ module Kennel
74
74
  end
75
75
 
76
76
  def tracking_id
77
- "#{project.kennel_id}:#{kennel_id}"
77
+ @tracking_id ||= begin
78
+ id = "#{project.kennel_id}:#{kennel_id}"
79
+ raise ValidationError, "#{id} kennel_id cannot include whitespace" if id.match?(/\s/) # <-> parse_tracking_id
80
+ id
81
+ end
78
82
  end
79
83
 
80
84
  def resolve_linked_tracking_ids!(*)
@@ -64,7 +64,7 @@ module Kennel
64
64
  end
65
65
 
66
66
  def self.parse_url(url)
67
- url[/\/slo(\?.*slo_id=|\/edit\/)([a-z\d]{10,})/, 2]
67
+ url[/\/slo(\?.*slo_id=|\/edit\/)([a-z\d]{10,})(&|$)/, 2]
68
68
  end
69
69
 
70
70
  def resolve_linked_tracking_ids!(id_map, **args)
data/lib/kennel/syncer.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  module Kennel
3
3
  class Syncer
4
4
  DELETE_ORDER = ["dashboard", "slo", "monitor"].freeze # dashboards references monitors + slos, slos reference monitors
5
+ LINE_UP = "\e[1A"
5
6
 
6
7
  def initialize(api, expected, project: nil)
7
8
  @api = api
@@ -37,23 +38,29 @@ module Kennel
37
38
 
38
39
  def update
39
40
  each_resolved @create do |_, e|
41
+ message = "#{e.class.api_resource} #{e.tracking_id}"
42
+ Kennel.out.puts "Creating #{message}"
40
43
  reply = @api.create e.class.api_resource, e.as_json
41
44
  reply[:klass] = e.class # store api resource class for later use
42
45
  id = reply.fetch(:id)
43
46
  populate_id_map [reply] # allow resolving ids we could previously no resolve
44
- Kennel.out.puts "Created #{e.class.api_resource} #{e.tracking_id} #{e.class.url(id)}"
47
+ Kennel.out.puts "#{LINE_UP}Created #{message} #{e.class.url(id)}"
45
48
  end
46
49
 
47
50
  each_resolved @update do |id, e|
51
+ message = "#{e.class.api_resource} #{e.tracking_id} #{e.class.url(id)}"
52
+ Kennel.out.puts "Updating #{message}"
48
53
  @api.update e.class.api_resource, id, e.as_json
49
- Kennel.out.puts "Updated #{e.class.api_resource} #{e.tracking_id} #{e.class.url(id)}"
54
+ Kennel.out.puts "#{LINE_UP}Updated #{message}"
50
55
  end
51
56
 
52
57
  @delete.each do |id, _, a|
53
58
  klass = a.fetch(:klass)
54
- @api.delete klass.api_resource, id
55
59
  tracking_id = klass.parse_tracking_id(a)
56
- Kennel.out.puts "Deleted #{klass.api_resource} #{tracking_id} #{id}"
60
+ message = "#{klass.api_resource} #{tracking_id} #{id}"
61
+ Kennel.out.puts "Deleting #{message}"
62
+ @api.delete klass.api_resource, id
63
+ Kennel.out.puts "#{LINE_UP}Deleted #{message}"
57
64
  end
58
65
  end
59
66
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.88.1"
3
+ VERSION = "1.89.0"
4
4
  end
data/template/Readme.md CHANGED
@@ -96,6 +96,7 @@ end
96
96
  - use [datadog monitor UI](https://app.datadoghq.com/monitors/manage) to find a monitor
97
97
  - get the `id` from the url
98
98
  - run `URL='https://app.datadoghq.com/monitors/123' bundle exec rake kennel:import` and copy the output
99
+ - import task also works with SLO alerts, e.g. `URL='https://app.datadoghq.com/slo/edit/123abc456def123/alerts/789' bundle exec rake kennel:import`
99
100
  - find or create a project in `projects/`
100
101
  - add the monitor to `parts: [` list, for example:
101
102
  ```Ruby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.88.1
4
+ version: 1.89.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser