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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0622cc6a3d8c7a66e692373a5cbd88ceafc6fa6d705524492a06c5e2c67e4204
4
- data.tar.gz: d1c057023a8c6d0f093b752ec8cc64c9a8fa185e49d5251b44eeeb87f2441377
3
+ metadata.gz: 305e0eb2205f87e8f993c0a6d19936f8ab2b2bdffa20316cc54dd241932cdad0
4
+ data.tar.gz: aea7a8fe0cbb8981e777bf83cdcfdf07489581c0621140f299aa9ec4a3447ac3
5
5
  SHA512:
6
- metadata.gz: fcfb2a52f2cbbe918d77bebfc2fc19334ad892691a538bd14dc043b52bbf71bcebb11793704798069a7779d20cf67cb096c88347c1f14d35e4a16b691ad3f99a
7
- data.tar.gz: d21f845c889de0d9bcfc8e54fefa141e1abfaa3a50bd2556294e468c191d15eaa48cbf054c6f1b1c4f0a7d43b8d5df780f0e3e567b9002826bb6dffa5f1550b7
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.tag(api_resource, reply)
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.tag(api_resource, response)
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.tag(api_resource, r) }
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.tag(api_resource, response)
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.tag(api_resource, response)
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
@@ -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
- *TITLES, :id, :kennel_id, :type, :tags, :query, :sli_specification,
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
- title_field = TITLES.detect { |f| data[f] }
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, "") # avoid double lock icon
30
+ title.tr!(Kennel::Models::Record::LOCK, "")
37
31
 
38
32
  # calculate or reuse kennel_id
39
33
  data[:kennel_id] =
@@ -34,7 +34,8 @@ module Kennel
34
34
  },
35
35
  time: {},
36
36
  title_align: "left",
37
- title_size: "16"
37
+ title_size: "16",
38
+ show_legend: true
38
39
  },
39
40
  "note" => {
40
41
  show_tick: false,
@@ -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) if a.fetch(:tracking_id) }.compact
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.158.0"
3
+ VERSION = "1.160.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.158.0
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-03-28 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs