kennel 1.58.3 → 1.60.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: d6eb8595b53bd765cb23745ba69474537f573d5359eec2d381e21bfba4d906c6
4
- data.tar.gz: 57868385f03594a028c6140389be0f92b5899ec6953cd0d4a7f504122da2301d
3
+ metadata.gz: f6b4a0efd1cc9562ad3fe039254ba48b197a392556105b3d56f66985105a8806
4
+ data.tar.gz: 8277eccfa9f48eec9ee8fe6dcf516fd4ad1e36c5760ec850dc4d60d71714ddcd
5
5
  SHA512:
6
- metadata.gz: 72304befa0ab9ad0a0ac92b0112d3a37f2b0176f7940d6167eb761be8aadec2de30c12942ad6b495dd39da35a2d47153b769e2d2b7be41f3f71635c7a1afeee2
7
- data.tar.gz: f927605bda707be196eeb7ff18987f4fd6737d2ba6c619e331b8c12832079051663445477ff57ffe2bfd79ca5bf38851b79c379f90d136eba22d448252f1517f
6
+ metadata.gz: 405531a24f9f801592c687f4f2a2ca448785b8907e549eafde3d7ea02935db63aa010d955d0f0d86d50f75ae1f42344fcf5c7904500e5e6d049ba9cbb1b6483a
7
+ data.tar.gz: 6c1d454d24dd9b0fc313e0a208a52c2a8efc77258171aefc4df8a115beca66d681925095a4f4ac544792452d7e2e5c09557350a72f467cc38fcbfbceb699350d
data/lib/kennel.rb CHANGED
@@ -29,6 +29,10 @@ require "kennel/models/project"
29
29
  require "kennel/models/team"
30
30
 
31
31
  module Kennel
32
+ MISSING_ID = 1
33
+ class ValidationError < RuntimeError
34
+ end
35
+
32
36
  @out = $stdout
33
37
  @err = $stderr
34
38
 
@@ -68,7 +72,7 @@ module Kennel
68
72
  Progress.progress "Generating" do
69
73
  load_all
70
74
  parts = Models::Project.recursive_subclasses.flat_map do |project_class|
71
- project_class.new.parts
75
+ project_class.new.validated_parts
72
76
  end
73
77
  parts.map(&:tracking_id).group_by { |id| id }.select do |id, same|
74
78
  raise "#{id} is defined #{same.size} times" if same.size != 1
data/lib/kennel/api.rb CHANGED
@@ -13,7 +13,24 @@ module Kennel
13
13
  end
14
14
 
15
15
  def list(api_resource, params = {})
16
- request :get, "/api/v1/#{api_resource}", params: params
16
+ if api_resource == "slo"
17
+ raise ArgumentError if params[:limit] || params[:offset]
18
+ limit = 1000
19
+ offset = 0
20
+ all = []
21
+
22
+ loop do
23
+ result = request :get, "/api/v1/#{api_resource}", params: params.merge(limit: limit, offset: offset)
24
+ data = result.fetch(:data)
25
+ all.concat data
26
+ break all if data.size < limit
27
+ offset += limit
28
+ end
29
+ else
30
+ result = request :get, "/api/v1/#{api_resource}", params: params
31
+ result = result.fetch(:dashboards) if api_resource == "dashboard"
32
+ result
33
+ end
17
34
  end
18
35
 
19
36
  def create(api_resource, attributes)
@@ -101,16 +101,16 @@ module Kennel
101
101
  when "uptime"
102
102
  if ids = definition[:monitor_ids]
103
103
  definition[:monitor_ids] = ids.map do |id|
104
- tracking_id?(id) ? resolve_link(id, id_map, force: false) : id
104
+ tracking_id?(id) ? resolve_link(id, id_map) : id
105
105
  end
106
106
  end
107
107
  when "alert_graph"
108
108
  if (id = definition[:alert_id]) && tracking_id?(id)
109
- definition[:alert_id] = resolve_link(id, id_map, force: false).to_s
109
+ definition[:alert_id] = resolve_link(id, id_map).to_s
110
110
  end
111
111
  when "slo"
112
112
  if (id = definition[:slo_id]) && tracking_id?(id)
113
- definition[:slo_id] = resolve_link(id, id_map, force: false).to_s
113
+ definition[:slo_id] = resolve_link(id, id_map).to_s
114
114
  end
115
115
  end
116
116
  end
@@ -105,6 +105,7 @@ module Kennel
105
105
  def resolve_linked_tracking_ids(id_map)
106
106
  if as_json[:type] == "composite"
107
107
  as_json[:query] = as_json[:query].gsub(/%\{(.*?)\}/) do
108
+ # need force here since it validates the id exists
108
109
  resolve_link($1, id_map, force: true)
109
110
  end
110
111
  end
@@ -14,6 +14,18 @@ module Kennel
14
14
  instance_method(method_in_file).source_location.first.sub("#{Bundler.root}/", "")
15
15
  end
16
16
  end
17
+
18
+ def validated_parts
19
+ all = parts
20
+ validate_parts(all)
21
+ all
22
+ end
23
+
24
+ private
25
+
26
+ # hook for users to add custom validations via `prepend`
27
+ def validate_parts(parts)
28
+ end
17
29
  end
18
30
  end
19
31
  end
@@ -13,9 +13,6 @@ module Kennel
13
13
  }.freeze
14
14
  API_LIST_INCOMPLETE = false
15
15
 
16
- class ValidationError < RuntimeError
17
- end
18
-
19
16
  settings :id, :kennel_id
20
17
 
21
18
  class << self
@@ -81,10 +78,19 @@ module Kennel
81
78
 
82
79
  private
83
80
 
84
- def resolve_link(id, id_map, force:)
85
- id_map[id] || begin
86
- message = "Unable to find #{id} in existing monitors (they need to be created first to link them)"
87
- force ? invalid!(message) : Kennel.err.puts(message)
81
+ def resolve_link(id, id_map, force: false)
82
+ found = id_map[id]
83
+ return found if found && found != :new
84
+
85
+ if found == :new
86
+ if force
87
+ invalid! "Monitor #{id} will be created in the current run and can only be used after that"
88
+ else
89
+ Kennel.err.puts "Monitor #{id} will be created in the current run, the next run will link it properly"
90
+ Kennel::MISSING_ID
91
+ end
92
+ else
93
+ invalid! "Unable to find monitor #{id} (does not exist and is not being created by the current run)"
88
94
  end
89
95
  end
90
96
 
@@ -35,7 +35,7 @@ module Kennel
35
35
  description: description,
36
36
  thresholds: thresholds,
37
37
  monitor_ids: monitor_ids,
38
- tags: tags,
38
+ tags: tags.uniq,
39
39
  type: type
40
40
  }
41
41
 
@@ -55,7 +55,7 @@ module Kennel
55
55
 
56
56
  def resolve_linked_tracking_ids(id_map)
57
57
  as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
58
- id.is_a?(String) ? resolve_link(id, id_map, force: false) || 1 : id
58
+ id.is_a?(String) ? resolve_link(id, id_map) : id
59
59
  end
60
60
  end
61
61
 
data/lib/kennel/syncer.rb CHANGED
@@ -38,7 +38,6 @@ module Kennel
38
38
  def update
39
39
  @create.each do |_, e|
40
40
  reply = @api.create e.class.api_resource, e.as_json
41
- reply = unnest(e.class.api_resource, reply)
42
41
  Kennel.out.puts "Created #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(reply.fetch(:id))}"
43
42
  end
44
43
 
@@ -101,21 +100,16 @@ module Kennel
101
100
  end
102
101
  end
103
102
 
104
- # Hack to get diff to work until we can mass-fetch definitions
103
+ # Make diff work even though we cannot mass-fetch definitions
105
104
  def fill_details(a, cache)
106
105
  resource = a.fetch(:api_resource)
107
106
  args = [resource, a.fetch(:id)]
108
107
  full = cache.fetch(args, a[:modified] || a.fetch(:modified_at)) do
109
- unnest(resource, @api.show(*args))
108
+ @api.show(*args)
110
109
  end
111
110
  a.merge!(full)
112
111
  end
113
112
 
114
- # dashes are nested, others are not
115
- def unnest(api_resource, result)
116
- result[api_resource.to_sym] || result[:data] || result
117
- end
118
-
119
113
  def details_cache(&block)
120
114
  cache = FileCache.new CACHE_FILE, Kennel::VERSION
121
115
  cache.open(&block)
@@ -195,6 +189,7 @@ module Kennel
195
189
 
196
190
  def resolve_linked_tracking_ids(actual)
197
191
  map = actual.each_with_object({}) { |a, lookup| lookup[tracking_id(a)] = a.fetch(:id) }
192
+ @expected.each { |e| map[e.tracking_id] ||= :new }
198
193
  @expected.each { |e| e.resolve_linked_tracking_ids(map) }
199
194
  end
200
195
 
data/lib/kennel/tasks.rb CHANGED
@@ -18,7 +18,7 @@ end
18
18
  namespace :kennel do
19
19
  desc "Ensure there are no uncommited changes that would be hidden from PR reviewers"
20
20
  task no_diff: :generate do
21
- result = `git status --porcelain`.strip
21
+ result = `git status --porcelain generated/`.strip
22
22
  Kennel::Tasks.abort "Diff found:\n#{result}\nrun `rake generate` and commit the diff to fix" unless result == ""
23
23
  Kennel::Tasks.abort "Error during diffing" unless $CHILD_STATUS.success?
24
24
  end
@@ -45,8 +45,7 @@ namespace :kennel do
45
45
  end
46
46
 
47
47
  if bad.any?
48
- subdomain = ENV["DATADOG_SUBDOMAIN"]
49
- url = (subdomain ? "https://zendesk.datadoghq.com" : "") + "/account/settings"
48
+ url = Kennel::Utils.path_to_url "/account/settings"
50
49
  puts "Invalid mentions found, either ignore them by adding to `KNOWN` env var or add them via #{url}"
51
50
  bad.each { |f, v| puts "Invalid mention #{v} in monitor message of #{f}" }
52
51
  Kennel::Tasks.abort
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.58.3"
3
+ VERSION = "1.60.0"
4
4
  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.58.3
4
+ version: 1.60.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: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday