kennel 1.112.1 → 1.113.2

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: 4afd2070d0b8c2097b1e67b0ad6b1f72928058370066d463da37f4b3340d903a
4
- data.tar.gz: b11721c83b65f8af2749faef9a967691fafe235e85214fa15163b4341b00d928
3
+ metadata.gz: adf4f9d7bbb7ca7762d12c2dfc2f77faf2ad22dd5ea0179130ac793d56d66b06
4
+ data.tar.gz: 6346728be4090edba0d00b8830517ac8e9ca3df4c16255638520b4133fcaff14
5
5
  SHA512:
6
- metadata.gz: 8d75553fdb2b17fc63e4cac6f7b56290d25756848109b4bc015125e1369cfbb624c270d46f108f502c2dca6c55de64bc2d63c606d8b259f3f97fe7bba7b7700f
7
- data.tar.gz: f63b3f9d0a4d273f189ae55d50e4e477bf7a7ca4a88474a97771592ede2080b6a4ab3aa815a76def48951d43b092db5eb880dd64acce0de69bcb51aa1c1d0e32
6
+ metadata.gz: 7fc4b90e41dcaafa071fe13b2a7324f9fa0d2ea5d5041d75e6d8e2afbd5b8ab85106ed715964b717282beefe4fa6aeb442ff7721fde5d727343aba1702b85e39
7
+ data.tar.gz: 948288a0179b596477b7034ee03341d34ff1d8fd0f3be5f53a9fdb6a8c9a3892d10e50aa1b2aab843f77e1449066c0192e178cd3cb5b0083d6f9f4a0dddfe248
data/Readme.md CHANGED
@@ -307,7 +307,8 @@ https://foo.datadog.com/monitor/123
307
307
  ## Development
308
308
 
309
309
  ### Benchmarking
310
- Setting `FORCE_GET_CACHE=true` will cache all get requests, which makes benchmarking improvements more reliable.
310
+ - Setting `FORCE_GET_CACHE=true` will cache all get requests, which makes benchmarking improvements more reliable.
311
+ - Setting `STORE=false` will make `rake plan` not update the files on disk and save a bit of time
311
312
 
312
313
  ### Integration testing
313
314
  ```Bash
@@ -131,12 +131,15 @@ module Kennel
131
131
  as_json[:query] = as_json[:query].gsub(/%{(.*?)}/) do
132
132
  resolve($1, type, id_map, **args) || $&
133
133
  end
134
+ else # do nothing
134
135
  end
135
136
  end
136
137
 
137
138
  def validate_update!(_actuals, diffs)
138
- if bad_diff = diffs.find { |diff| diff[1] == "type" }
139
- invalid! "Datadog does not allow update of #{bad_diff[1]} (#{bad_diff[2].inspect} -> #{bad_diff[3].inspect})"
139
+ # ensure type does not change, but not if it's metric->query which is supported and used by importer.rb
140
+ _, path, from, to = diffs.detect { |_, path, _, _| path == "type" }
141
+ if path && !(from == "metric alert" && to == "query alert")
142
+ invalid! "Datadog does not allow update of #{path} (#{from.inspect} -> #{to.inspect})"
140
143
  end
141
144
  end
142
145
 
@@ -145,7 +148,7 @@ module Kennel
145
148
  end
146
149
 
147
150
  def self.url(id)
148
- Utils.path_to_url "/monitors##{id}/edit"
151
+ Utils.path_to_url "/monitors/#{id}/edit"
149
152
  end
150
153
 
151
154
  def self.parse_url(url)
@@ -109,11 +109,8 @@ module Kennel
109
109
  private
110
110
 
111
111
  def resolve(value, type, id_map, force:)
112
- if tracking_id?(value)
113
- return resolve_link(value, type, id_map, force: force)
114
- end
115
-
116
- value
112
+ return value unless tracking_id?(value)
113
+ resolve_link(value, type, id_map, force: force)
117
114
  end
118
115
 
119
116
  def tracking_id?(id)
@@ -68,8 +68,8 @@ module Kennel
68
68
  end
69
69
 
70
70
  def resolve_linked_tracking_ids!(id_map, **args)
71
- return unless as_json[:monitor_ids] # ignore_default can remove it
72
- as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
71
+ return unless ids = as_json[:monitor_ids] # ignore_default can remove it
72
+ as_json[:monitor_ids] = ids.map do |id|
73
73
  resolve(id, :monitor, id_map, **args) || id
74
74
  end
75
75
  end
data/lib/kennel/syncer.rb CHANGED
@@ -7,7 +7,7 @@ module Kennel
7
7
  def initialize(api, expected, project_filter: nil)
8
8
  @api = api
9
9
  @project_filter = project_filter
10
- @expected = expected
10
+ @expected = Set.new expected # need set to speed up deletion
11
11
  calculate_diff
12
12
  validate_plan
13
13
  prevent_irreversible_partial_updates
@@ -110,9 +110,10 @@ module Kennel
110
110
 
111
111
  @expected.each(&:add_tracking_id) # avoid diff with actual
112
112
 
113
+ lookup_map = matching_expected_lookup_map
113
114
  items = actual.map do |a|
114
- e = matching_expected(a)
115
- if e && @expected.delete(e)
115
+ e = matching_expected(a, lookup_map)
116
+ if e && @expected.delete?(e)
116
117
  [e, a]
117
118
  else
118
119
  [nil, a]
@@ -127,7 +128,7 @@ module Kennel
127
128
  items.each do |e, a|
128
129
  id = a.fetch(:id)
129
130
  if e
130
- diff = e.diff(a)
131
+ diff = e.diff(a) # slow ...
131
132
  @update << [id, e, a, diff] if diff.any?
132
133
  elsif a.fetch(:tracking_id) # was previously managed
133
134
  @delete << [id, nil, a]
@@ -166,9 +167,9 @@ module Kennel
166
167
  end
167
168
  end
168
169
 
169
- def matching_expected(a)
170
- # index list by all the thing we look up by: tracking id and actual id
171
- @lookup_map ||= @expected.each_with_object({}) do |e, all|
170
+ # index list by all the thing we look up by: tracking id and actual id
171
+ def matching_expected_lookup_map
172
+ @expected.each_with_object({}) do |e, all|
172
173
  keys = [e.tracking_id]
173
174
  keys << "#{e.class.api_resource}:#{e.id}" if e.id
174
175
  keys.compact.each do |key|
@@ -176,9 +177,11 @@ module Kennel
176
177
  all[key] = e
177
178
  end
178
179
  end
180
+ end
179
181
 
182
+ def matching_expected(a, map)
180
183
  klass = a.fetch(:klass)
181
- @lookup_map["#{klass.api_resource}:#{a.fetch(:id)}"] || @lookup_map[a.fetch(:tracking_id)]
184
+ map["#{klass.api_resource}:#{a.fetch(:id)}"] || map[a.fetch(:tracking_id)]
182
185
  end
183
186
 
184
187
  def print_plan(step, list, color)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.112.1"
3
+ VERSION = "1.113.2"
4
4
  end
data/lib/kennel.rb CHANGED
@@ -47,7 +47,9 @@ module Kennel
47
47
  attr_accessor :out, :err, :strict_imports
48
48
 
49
49
  def generate
50
- store generated
50
+ out = generated
51
+ store out if ENV["STORE"] != "false" # quicker when debugging
52
+ out
51
53
  end
52
54
 
53
55
  def plan
@@ -106,7 +108,7 @@ module Kennel
106
108
  known = []
107
109
  filter = project_filter
108
110
 
109
- parts = Models::Project.recursive_subclasses.flat_map do |project_class|
111
+ parts = Utils.parallel(Models::Project.recursive_subclasses) do |project_class|
110
112
  project = project_class.new
111
113
  kennel_id = project.kennel_id
112
114
  if filter
@@ -114,7 +116,7 @@ module Kennel
114
116
  next [] unless filter.include?(kennel_id)
115
117
  end
116
118
  project.validated_parts
117
- end
119
+ end.flatten(1)
118
120
 
119
121
  if filter && parts.empty?
120
122
  raise "#{filter.join(", ")} does not match any projects, try any of these:\n#{known.uniq.sort.join("\n")}"
@@ -127,6 +129,10 @@ module Kennel
127
129
  use a different `kennel_id` when defining multiple projects/monitors/dashboards to avoid this conflict
128
130
  ERROR
129
131
  end
132
+
133
+ # trigger json caching here so it counts into generating
134
+ Utils.parallel(parts, &:as_json)
135
+
130
136
  parts
131
137
  end
132
138
  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.112.1
4
+ version: 1.113.2
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-05-05 00:00:00.000000000 Z
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday