kennel 1.158.0 → 1.160.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 +4 -4
- data/lib/kennel/api.rb +5 -5
- data/lib/kennel/importer.rb +4 -10
- data/lib/kennel/models/dashboard.rb +2 -1
- data/lib/kennel/models/record.rb +1 -0
- data/lib/kennel/syncer.rb +31 -1
- data/lib/kennel/version.rb +1 -1
- 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: 305e0eb2205f87e8f993c0a6d19936f8ab2b2bdffa20316cc54dd241932cdad0
|
4
|
+
data.tar.gz: aea7a8fe0cbb8981e777bf83cdcfdf07489581c0621140f299aa9ec4a3447ac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19ebc04a7b038919f635a33fc9e8f9e94500c62d9e8c68f6a51df9d66d4d8bc9e4b0036cd48b04f1215cfaa23d28321982ac28f90b26fd091cbac6da671b1f22
|
7
|
+
data.tar.gz: cddea78b6c4050cfbb3b7de37346ea91022a00f72f3da62368870878c8630a2024988b894bb102be81e05f80002c0e9ffcf2ce1ae434673eca43fc342c902f44
|
data/lib/kennel/api.rb
CHANGED
@@ -7,7 +7,7 @@ module Kennel
|
|
7
7
|
|
8
8
|
RateLimitParams = Data.define(:limit, :period, :remaining, :reset, :name)
|
9
9
|
|
10
|
-
def self.
|
10
|
+
def self.with_tracking(api_resource, reply)
|
11
11
|
klass = Models::Record.api_resource_map[api_resource]
|
12
12
|
return reply unless klass # do not blow up on unknown models
|
13
13
|
|
@@ -28,7 +28,7 @@ module Kennel
|
|
28
28
|
response = request :get, "/api/v1/#{api_resource}/#{id}", params: params
|
29
29
|
response = response.fetch(:data) if api_resource == "slo"
|
30
30
|
response[:id] = response.delete(:public_id) if api_resource == "synthetics/tests"
|
31
|
-
self.class.
|
31
|
+
self.class.with_tracking(api_resource, response)
|
32
32
|
end
|
33
33
|
|
34
34
|
def list(api_resource, params = {})
|
@@ -44,7 +44,7 @@ module Kennel
|
|
44
44
|
# ignore monitor synthetics create and that inherit the kennel_id, we do not directly manage them
|
45
45
|
response.reject! { |m| m[:type] == "synthetics alert" } if api_resource == "monitor"
|
46
46
|
|
47
|
-
response.map { |r| self.class.
|
47
|
+
response.map { |r| self.class.with_tracking(api_resource, r) }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -52,13 +52,13 @@ module Kennel
|
|
52
52
|
response = request :post, "/api/v1/#{api_resource}", body: attributes
|
53
53
|
response = response.fetch(:data).first if api_resource == "slo"
|
54
54
|
response[:id] = response.delete(:public_id) if api_resource == "synthetics/tests"
|
55
|
-
self.class.
|
55
|
+
self.class.with_tracking(api_resource, response)
|
56
56
|
end
|
57
57
|
|
58
58
|
def update(api_resource, id, attributes)
|
59
59
|
response = request :put, "/api/v1/#{api_resource}/#{id}", body: attributes
|
60
60
|
response[:id] = response.delete(:public_id) if api_resource == "synthetics/tests"
|
61
|
-
self.class.
|
61
|
+
self.class.with_tracking(api_resource, response)
|
62
62
|
end
|
63
63
|
|
64
64
|
# - force=true to not dead-lock on dependent monitors+slos
|
data/lib/kennel/importer.rb
CHANGED
@@ -2,12 +2,9 @@
|
|
2
2
|
|
3
3
|
module Kennel
|
4
4
|
class Importer
|
5
|
-
# title will have the lock symbol we need to remove when re-importing
|
6
|
-
TITLES = [:name, :title].freeze
|
7
|
-
|
8
5
|
# bring important fields to the top
|
9
6
|
SORT_ORDER = [
|
10
|
-
*
|
7
|
+
*Kennel::Models::Record::TITLE_FIELDS, :id, :kennel_id, :type, :tags, :query, :sli_specification,
|
11
8
|
*Models::Record.subclasses.flat_map { |k| k::TRACKING_FIELDS },
|
12
9
|
:template_variables
|
13
10
|
].freeze
|
@@ -17,10 +14,6 @@ module Kennel
|
|
17
14
|
end
|
18
15
|
|
19
16
|
def import(resource, id)
|
20
|
-
if ["screen", "dash"].include?(resource)
|
21
|
-
raise ArgumentError, "resource 'screen' and 'dash' are deprecated, use 'dashboard'"
|
22
|
-
end
|
23
|
-
|
24
17
|
model =
|
25
18
|
Kennel::Models::Record.subclasses.detect { |c| c.api_resource == resource } ||
|
26
19
|
raise(ArgumentError, "#{resource} is not supported")
|
@@ -31,9 +24,10 @@ module Kennel
|
|
31
24
|
model.normalize({}, data) # removes id
|
32
25
|
data[:id] = id
|
33
26
|
|
34
|
-
|
27
|
+
# title will have the lock symbol we need to remove when re-importing
|
28
|
+
title_field = Kennel::Models::Record::TITLE_FIELDS.detect { |f| data[f] }
|
35
29
|
title = data.fetch(title_field)
|
36
|
-
title.tr!(Kennel::Models::Record::LOCK, "")
|
30
|
+
title.tr!(Kennel::Models::Record::LOCK, "")
|
37
31
|
|
38
32
|
# calculate or reuse kennel_id
|
39
33
|
data[:kennel_id] =
|
data/lib/kennel/models/record.rb
CHANGED
@@ -26,6 +26,7 @@ module Kennel
|
|
26
26
|
:deleted, :id, :created, :created_at, :creator, :org_id, :modified, :modified_at,
|
27
27
|
:klass, :tracking_id # added by syncer.rb
|
28
28
|
].freeze
|
29
|
+
TITLE_FIELDS = [:name, :title].freeze # possible fields that could have the title
|
29
30
|
ALLOWED_KENNEL_ID_CHARS = "a-zA-Z_\\d.-"
|
30
31
|
ALLOWED_KENNEL_ID_SEGMENT = /[#{ALLOWED_KENNEL_ID_CHARS}]+/
|
31
32
|
ALLOWED_KENNEL_ID_FULL = "#{ALLOWED_KENNEL_ID_SEGMENT}:#{ALLOWED_KENNEL_ID_SEGMENT}".freeze
|
data/lib/kennel/syncer.rb
CHANGED
@@ -89,6 +89,10 @@ module Kennel
|
|
89
89
|
|
90
90
|
# see which expected match the actual
|
91
91
|
matching, unmatched_expected, unmatched_actual = MatchedExpected.partition(expected, actual)
|
92
|
+
unmatched_actual.select! { |a| a.fetch(:tracking_id) } # ignore items that were never managed by kennel
|
93
|
+
|
94
|
+
convert_replace_into_update!(matching, unmatched_actual, unmatched_expected)
|
95
|
+
|
92
96
|
validate_expected_id_not_missing unmatched_expected
|
93
97
|
fill_details! matching # need details to diff later
|
94
98
|
|
@@ -105,7 +109,7 @@ module Kennel
|
|
105
109
|
end.compact
|
106
110
|
|
107
111
|
# delete previously managed
|
108
|
-
deletes = unmatched_actual.map { |a| Types::PlannedDelete.new(a)
|
112
|
+
deletes = unmatched_actual.map { |a| Types::PlannedDelete.new(a) }
|
109
113
|
|
110
114
|
# unmatched expected need to be created
|
111
115
|
unmatched_expected.each(&:add_tracking_id)
|
@@ -119,6 +123,32 @@ module Kennel
|
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
126
|
+
# if there is a new item that has the same name or title as an "to be deleted" item,
|
127
|
+
# update it instead to avoid old urls from becoming invalid
|
128
|
+
# - careful with unmatched_actual being huge since it has all api resources
|
129
|
+
# - don't do it when a monitor type is changing since that would block the update
|
130
|
+
def convert_replace_into_update!(matching, unmatched_actual, unmatched_expected)
|
131
|
+
unmatched_expected.reject! do |e|
|
132
|
+
e_field, e_value = Kennel::Models::Record::TITLE_FIELDS.detect do |field|
|
133
|
+
next unless (value = e.as_json[field])
|
134
|
+
break [field, value]
|
135
|
+
end
|
136
|
+
raise unless e_field # uncovered: should never happen ...
|
137
|
+
e_monitor_type = e.as_json[:type]
|
138
|
+
|
139
|
+
actual = unmatched_actual.detect do |a|
|
140
|
+
a[:klass] == e.class && a[e_field] == e_value && a[:type] == e_monitor_type
|
141
|
+
end
|
142
|
+
next false unless actual # keep in unmatched
|
143
|
+
|
144
|
+
# add as update and remove from unmatched
|
145
|
+
unmatched_actual.delete(actual)
|
146
|
+
actual[:tracking_id] = e.tracking_id
|
147
|
+
matching << [e, actual]
|
148
|
+
true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
122
152
|
# fill details of things we need to compare
|
123
153
|
def fill_details!(details_needed)
|
124
154
|
details_needed = details_needed.map { |e, a| a if e && e.class.api_resource == "dashboard" }.compact
|
data/lib/kennel/version.rb
CHANGED
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.160.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: 2025-
|
11
|
+
date: 2025-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diff-lcs
|