kennel 1.100.0 → 1.103.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kennel/id_map.rb +0 -4
- data/lib/kennel/syncer.rb +24 -3
- data/lib/kennel/tasks.rb +37 -6
- data/lib/kennel/version.rb +1 -1
- data/lib/kennel.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1325abc55c593c6537608b629a7a98de7ce05487bc3a066782bb1be1164268dd
|
4
|
+
data.tar.gz: 966282e916764aaaae5b6718a72d4070070d1ad3c2f6a43bbdf01c10e325d63c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fec764b934ecad2aa76a9282eb937ceef1774d19d50b56d1597846c04afd050dac9fcc51566618169929eb0da77c25d6eb3ac18c9993872229d5404b5d6e3127
|
7
|
+
data.tar.gz: 85201a83ceed329e4bf71b4392ec086c3d18714d5f76eda00dbe2fa6a7e05482523b91e40405241241666f9982eddb5c167bd6b3bd9448a56d39f30392ccadba
|
data/lib/kennel/id_map.rb
CHANGED
data/lib/kennel/syncer.rb
CHANGED
@@ -18,6 +18,7 @@ module Kennel
|
|
18
18
|
if noop?
|
19
19
|
Kennel.out.puts Utils.color(:green, "Nothing to do")
|
20
20
|
else
|
21
|
+
@warnings.each { |message| Kennel.out.puts Utils.color(:yellow, "Warning: #{message}") }
|
21
22
|
print_plan "Create", @create, :green
|
22
23
|
print_plan "Update", @update, :yellow
|
23
24
|
print_plan "Delete", @delete, :red
|
@@ -120,6 +121,7 @@ module Kennel
|
|
120
121
|
end
|
121
122
|
|
122
123
|
def calculate_diff
|
124
|
+
@warnings = []
|
123
125
|
@update = []
|
124
126
|
@delete = []
|
125
127
|
@id_map = IdMap.new
|
@@ -181,7 +183,11 @@ module Kennel
|
|
181
183
|
@expected.each do |e|
|
182
184
|
next unless id = e.id
|
183
185
|
resource = e.class.api_resource
|
184
|
-
|
186
|
+
if Kennel.strict_imports
|
187
|
+
raise "Unable to find existing #{resource} with id #{id}\nIf the #{resource} was deleted, remove the `id: -> { #{id} }` line."
|
188
|
+
else
|
189
|
+
@warnings << "#{resource} #{e.tracking_id} specifies id #{id}, but no such #{resource} exists. 'id' will be ignored. Remove the `id: -> { #{id} }` line."
|
190
|
+
end
|
185
191
|
end
|
186
192
|
end
|
187
193
|
|
@@ -254,13 +260,28 @@ module Kennel
|
|
254
260
|
end
|
255
261
|
|
256
262
|
def populate_id_map(expected, actual)
|
263
|
+
# mark everything as new
|
257
264
|
expected.each do |e|
|
258
|
-
@id_map.
|
265
|
+
@id_map.set(e.class.api_resource, e.tracking_id, IdMap::NEW)
|
266
|
+
if e.class.api_resource == "synthetics/tests"
|
267
|
+
@id_map.set(Kennel::Models::Monitor.api_resource, e.tracking_id, IdMap::NEW)
|
268
|
+
end
|
259
269
|
end
|
260
270
|
|
271
|
+
# override resources that exist with their id
|
272
|
+
project_prefix = @project_filter && "#{@project_filter}:"
|
261
273
|
actual.each do |a|
|
274
|
+
# ignore when not managed by kennel
|
262
275
|
next unless tracking_id = a.fetch(:tracking_id)
|
263
|
-
|
276
|
+
|
277
|
+
# ignore when deleted from the codebase
|
278
|
+
# (when running with project filter we cannot see the other resources in the codebase)
|
279
|
+
api_resource = a.fetch(:klass).api_resource
|
280
|
+
next if
|
281
|
+
!@id_map.get(api_resource, tracking_id) &&
|
282
|
+
(!project_prefix || tracking_id.start_with?(project_prefix))
|
283
|
+
|
284
|
+
@id_map.set(api_resource, tracking_id, a.fetch(:id))
|
264
285
|
if a[:klass].api_resource == "synthetics/tests"
|
265
286
|
@id_map.set(Kennel::Models::Monitor.api_resource, tracking_id, a.fetch(:monitor_id))
|
266
287
|
end
|
data/lib/kennel/tasks.rb
CHANGED
@@ -3,6 +3,7 @@ require "English"
|
|
3
3
|
require "kennel"
|
4
4
|
require "kennel/unmuted_alerts"
|
5
5
|
require "kennel/importer"
|
6
|
+
require "json"
|
6
7
|
|
7
8
|
module Kennel
|
8
9
|
module Tasks
|
@@ -75,6 +76,7 @@ namespace :kennel do
|
|
75
76
|
is_push = (ENV["TRAVIS_PULL_REQUEST"] == "false" || ENV["GITHUB_EVENT_NAME"] == "push")
|
76
77
|
task_name =
|
77
78
|
if on_default_branch && is_push
|
79
|
+
Kennel.strict_imports = false
|
78
80
|
"kennel:update_datadog"
|
79
81
|
else
|
80
82
|
"kennel:plan" # show plan in CI logs
|
@@ -89,7 +91,7 @@ namespace :kennel do
|
|
89
91
|
Kennel::UnmutedAlerts.print(Kennel.send(:api), tag)
|
90
92
|
end
|
91
93
|
|
92
|
-
desc "show monitors with no data by TAG, for example TAG=team:foo"
|
94
|
+
desc "show monitors with no data by TAG, for example TAG=team:foo [THRESHOLD_DAYS=7] [FORMAT=json]"
|
93
95
|
task nodata: :environment do
|
94
96
|
tag = ENV["TAG"] || Kennel::Tasks.abort("Call with TAG=foo:bar")
|
95
97
|
monitors = Kennel.send(:api).list("monitor", monitor_tags: tag, group_states: "no data")
|
@@ -97,16 +99,45 @@ namespace :kennel do
|
|
97
99
|
monitors.reject! { |m| m[:tags].include? "nodata:ignore" }
|
98
100
|
if monitors.any?
|
99
101
|
Kennel.err.puts <<~TEXT
|
100
|
-
|
101
|
-
To ignore monitors with nodata, tag the monitor with "nodata:ignore"
|
102
|
+
To ignore monitors with expected nodata, tag it with "nodata:ignore"
|
102
103
|
|
103
104
|
TEXT
|
104
105
|
end
|
105
106
|
|
107
|
+
now = Time.now
|
106
108
|
monitors.each do |m|
|
107
|
-
|
108
|
-
|
109
|
-
|
109
|
+
m[:days_in_no_data] =
|
110
|
+
if m[:overall_state_modified]
|
111
|
+
since = Date.parse(m[:overall_state_modified]).to_time
|
112
|
+
((now - since) / (24 * 60 * 60)).to_i
|
113
|
+
else
|
114
|
+
999
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
if threshold = ENV["THRESHOLD_DAYS"]
|
119
|
+
monitors.select! { |m| m[:days_in_no_data] > Integer(threshold) }
|
120
|
+
end
|
121
|
+
|
122
|
+
monitors.each { |m| m[:url] = Kennel::Utils.path_to_url("/monitors/#{m[:id]}") }
|
123
|
+
|
124
|
+
if ENV["FORMAT"] == "json"
|
125
|
+
report = monitors.map do |m|
|
126
|
+
match = m[:message].to_s.match(/-- Managed by kennel (\S+:\S+) in (\S+), /) || []
|
127
|
+
m.slice(:url, :name, :tags, :days_in_no_data).merge(
|
128
|
+
kennel_tracking_id: match[1],
|
129
|
+
kennel_source: match[2]
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
Kennel.out.puts JSON.pretty_generate(report)
|
134
|
+
else
|
135
|
+
monitors.each do |m|
|
136
|
+
Kennel.out.puts m[:name]
|
137
|
+
Kennel.out.puts Kennel::Utils.path_to_url("/monitors/#{m[:id]}")
|
138
|
+
Kennel.out.puts "No data since #{m[:days_in_no_data]}d"
|
139
|
+
Kennel.out.puts
|
140
|
+
end
|
110
141
|
end
|
111
142
|
end
|
112
143
|
|
data/lib/kennel/version.rb
CHANGED
data/lib/kennel.rb
CHANGED
@@ -42,9 +42,10 @@ module Kennel
|
|
42
42
|
|
43
43
|
@out = $stdout
|
44
44
|
@err = $stderr
|
45
|
+
@strict_imports = true
|
45
46
|
|
46
47
|
class << self
|
47
|
-
attr_accessor :out, :err
|
48
|
+
attr_accessor :out, :err, :strict_imports
|
48
49
|
|
49
50
|
def generate
|
50
51
|
store generated
|
@@ -70,7 +71,8 @@ module Kennel
|
|
70
71
|
path = "generated/#{part.tracking_id.tr("/", ":").sub(":", "/")}.json"
|
71
72
|
used << File.dirname(path) # only 1 level of sub folders, so this is safe
|
72
73
|
used << path
|
73
|
-
|
74
|
+
payload = part.as_json.merge(api_resource: part.class.api_resource)
|
75
|
+
write_file_if_necessary(path, JSON.pretty_generate(payload) << "\n")
|
74
76
|
end
|
75
77
|
|
76
78
|
# deleting all is slow, so only delete the extras
|
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.
|
4
|
+
version: 1.103.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: 2021-11-
|
11
|
+
date: 2021-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|