kennel 1.111.1 → 1.113.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: a22d2d6a7199c2d5b565ad42834dc9634ec81fff3eaadf0bc1e31cff307c34fa
4
- data.tar.gz: 4ccfa084a8118408b8126fb125c24641741274225817d1fefb593ae69dd0f7b6
3
+ metadata.gz: b199d98b445f146f6e5ac3a2746d715c4286a75da4ddd9cf2268875e41a4f7f4
4
+ data.tar.gz: cc748229520b855819210413905525b962b7ea21ff13053258a011f59abaf001
5
5
  SHA512:
6
- metadata.gz: ad4d3c2ea98b94a4a178c95b34b4a30ba0bfb66a96ce07f2bbbef2e184abce14a4e509062fd73894f3204f6509ef1a53c05f64d0e2b97d4e8528372b25c667d1
7
- data.tar.gz: 0fd84a01af923c6b57b05ad6ad7f7577a30d695d98f1936e65e470ffb41b0b35cdbe5704b7d9526fa86291b230e2a5855ba028c04d6e51328b8f07baf0078357
6
+ metadata.gz: a26a733f32e1b0c167d950d4da1c8deb69717306e6428636e2b5ab03b450eb6db6f6797eb3a054a66083b91d351a6ca875703255cea2adec62f6022452d1e90c
7
+ data.tar.gz: cedb46594f03b8e2ebf89915f4bd8945f0378b51808e36460b5af8c7b44266e1661de771acb6febaffa2ca1226b88a533fccbea870e47e025b30677b7f91f5a4
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
@@ -8,6 +8,9 @@ module Kennel
8
8
  :deleted, :id, :created, :created_at, :creator, :org_id, :modified, :modified_at,
9
9
  :klass, :tracking_id # added by syncer.rb
10
10
  ].freeze
11
+ ALLOWED_KENNEL_ID_CHARS = "a-zA-Z_\\d.-"
12
+ ALLOWED_KENNEL_ID_FULL = "[#{ALLOWED_KENNEL_ID_CHARS}]+:[#{ALLOWED_KENNEL_ID_CHARS}]+"
13
+ ALLOWED_KENNEL_ID_REGEX = /\A#{ALLOWED_KENNEL_ID_FULL}\z/.freeze
11
14
 
12
15
  settings :id, :kennel_id
13
16
 
@@ -25,7 +28,7 @@ module Kennel
25
28
  end
26
29
 
27
30
  def parse_tracking_id(a)
28
- a[self::TRACKING_FIELD].to_s[/-- Managed by kennel (\S+:\S+)/, 1]
31
+ a[self::TRACKING_FIELD].to_s[/-- Managed by kennel (#{ALLOWED_KENNEL_ID_FULL})/, 1]
29
32
  end
30
33
 
31
34
  # TODO: combine with parse into a single method or a single regex
@@ -76,7 +79,9 @@ module Kennel
76
79
  def tracking_id
77
80
  @tracking_id ||= begin
78
81
  id = "#{project.kennel_id}:#{kennel_id}"
79
- raise ValidationError, "#{id} kennel_id cannot include whitespace" if id.match?(/\s/) # <-> parse_tracking_id
82
+ unless id.match?(ALLOWED_KENNEL_ID_REGEX) # <-> parse_tracking_id
83
+ raise ValidationError, "#{id} must match #{ALLOWED_KENNEL_ID_REGEX}"
84
+ end
80
85
  id
81
86
  end
82
87
  end
@@ -104,11 +109,8 @@ module Kennel
104
109
  private
105
110
 
106
111
  def resolve(value, type, id_map, force:)
107
- if tracking_id?(value)
108
- return resolve_link(value, type, id_map, force: force)
109
- end
110
-
111
- value
112
+ return value unless tracking_id?(value)
113
+ resolve_link(value, type, id_map, force: force)
112
114
  end
113
115
 
114
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)
data/lib/kennel/utils.rb CHANGED
@@ -149,7 +149,7 @@ module Kennel
149
149
  # TODO: use awesome-print or similar, but it has too many monkey-patches
150
150
  # https://github.com/amazing-print/amazing_print/issues/36
151
151
  def pretty_inspect(object)
152
- string = object.inspect
152
+ string = object.inspect.dup
153
153
  string.gsub!(/:([a-z_]+)=>/, "\\1: ")
154
154
  10.times do
155
155
  string.gsub!(/{(\S.*?\S)}/, "{ \\1 }") || break
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.111.1"
3
+ VERSION = "1.113.0"
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
@@ -127,6 +129,11 @@ 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
+ # somehow threading helps reduce this ~25%
135
+ Utils.parallel(parts, &:as_json)
136
+
130
137
  parts
131
138
  end
132
139
  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.111.1
4
+ version: 1.113.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-04-19 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.2.16
120
+ rubygems_version: 3.0.3
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Keep datadog monitors/dashboards/etc in version control, avoid chaotic management