kennel 2.21.1 → 2.22.1

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: 9487ffad47b72d1a4e4781239ef3fbd500f806e5d63590c03326d7c6b689529e
4
- data.tar.gz: ec5258bd90e47766deb06f71ab8041b3009f6242279a7d9d9bdede0d36da67ec
3
+ metadata.gz: 21600f7f1ed4c550d106f75619a29a57cf2c6631c95a04b332f2d1a808fc94be
4
+ data.tar.gz: e366f291cf986a51e7841a70641854fe3090ed39b8616b4acc6b80fc030dcf33
5
5
  SHA512:
6
- metadata.gz: 2a02de737a11b72651a05c4fbf5bd6e8180cffb95f9d398696e70ee8c8a8c0217e264892582f842a22c9c73ab1f559035c23e1e8da0f74c14680bcf9757c0c63
7
- data.tar.gz: 7a2ad8b0f2561a624d410453c601da3c39184625c0565ba5d78a51689bcde28a5a623e3791ee316f7cc3d4141f0d5482735f643ad46c60364f7122ae8e2e5adf
6
+ metadata.gz: cb9953eb8430131345f3b21ef6cec57ece7248114439a2d5c6bbe22ca522b72350077ff927f8521f51a97695827f8dc1b91cf1809b0c0e05d7dab486643465c7
7
+ data.tar.gz: dca2a03ad0132035f34d331daf622ed41c281e993037212b8d7894fbdcdd6442dcc7fe62bc2ca9f125ef816027f70d94422a1e06bda60e42743309e8a787958c
data/lib/kennel/api.rb CHANGED
@@ -55,6 +55,8 @@ module Kennel
55
55
  end
56
56
 
57
57
  def update(api_resource, id, attributes)
58
+ restore_widget_ids(id, attributes) if api_resource == "dashboard"
59
+
58
60
  response = request :put, "/api/v1/#{api_resource}/#{id}", body: attributes
59
61
  response[:id] = response.delete(:public_id) if api_resource == "synthetics/tests"
60
62
  self.class.with_tracking(api_resource, response)
@@ -86,6 +88,33 @@ module Kennel
86
88
 
87
89
  private
88
90
 
91
+ # keep widget ids stable so stored dashboard urls that point at a widget do not break on every update
92
+ # widget ids are dropped when diffing since they change on every update, but that also changes them in datadog
93
+ # and breaks stored urls that point at a specific widget, so restore the previous ids by matching widget titles
94
+ def restore_widget_ids(id, attributes)
95
+ return unless (widgets = attributes[:widgets])
96
+ return unless (current = show("dashboard", id, {}, ignore_404: true))
97
+
98
+ ids = {}
99
+ each_widget_with_key(current[:widgets]) { |key, widget| ids[key] = widget[:id] }
100
+ each_widget_with_key(widgets) do |key, widget|
101
+ next unless (id = ids[key])
102
+ widget[:id] ||= id # do not set nil, that breaks updates
103
+ end
104
+ end
105
+
106
+ # yield each widget with a key built from its (optional) group title and its own title
107
+ def each_widget_with_key(widgets, prefix: nil, &block)
108
+ widgets.each do |widget|
109
+ title = widget.dig(:definition, :title)
110
+ key = [prefix, title].compact.join("-")
111
+ yield key, widget
112
+ if (nested = widget.dig(:definition, :widgets))
113
+ each_widget_with_key(nested, prefix: title, &block)
114
+ end
115
+ end
116
+ end
117
+
89
118
  def with_pagination(enabled, params)
90
119
  return yield params unless enabled
91
120
  raise ArgumentError if params[:limit] || params[:offset]
@@ -352,6 +352,10 @@ module Kennel
352
352
  if data.dig(:options, :timeout_h)&.> 24
353
353
  invalid! :invalid_timeout_h, "timeout_h must be <= 24"
354
354
  end
355
+
356
+ if type == "composite" && data.dig(:options, :new_group_delay)
357
+ invalid! :composite_new_group_delay, "new_group_delay is not supported for composite monitors"
358
+ end
355
359
  end
356
360
 
357
361
  # verify is_match/is_exact_match and {{foo.name}} uses available variables
@@ -48,7 +48,9 @@ module Kennel
48
48
  threshold =
49
49
  thresholds.detect { |t| t[:timeframe] == p } ||
50
50
  raise(ArgumentError, "#{tracking_id} unable to find threshold with timeframe #{p}")
51
- data[:warning_threshold] = threshold[:warning]
51
+ if (value = threshold[:warning]) # only set if needed to avoid permanent diff
52
+ data[:warning_threshold] = value
53
+ end
52
54
  data[:target_threshold] = threshold[:target]
53
55
  end
54
56
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "2.21.1"
3
+ VERSION = "2.22.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.21.1
4
+ version: 2.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser