kennel 2.24.0 → 2.25.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: 7aa1a80ee02f8f528d79075c83293405c2cd1974534211bef8be52c2ec8c7a33
4
- data.tar.gz: 869cdbdd20bbdc9d73562a675c37e86aae1c4343a0e008f2874545442b47396e
3
+ metadata.gz: 64e8bc3c825a3c4cd9f5428560dbae6066b67c7d7cbfb6158a31edd3f0b267f2
4
+ data.tar.gz: a22b60eda435282639659125f298f5ef7f4a2a87b8aae4b5eee99c054544a2b4
5
5
  SHA512:
6
- metadata.gz: b279ef955d3f281245173826eb8d57a255dd1abae803f99ce8baf72edc4f622d613d3ec32c81f984a26f8be8e59b6b9cbfe6f2522ce94ff4ab72f5f7ec5ea907
7
- data.tar.gz: f3dd35dc1ca45cf2fa3f7b14127da6febae75255488f66f3cf1b3a56873a7845848647322d2694d4c11126cb0ff685afa8b2bcafbc9a04fa142cf29eb438da34
6
+ metadata.gz: 4f337fdb7be03d4416132005f3a5398ee40fe44d8c963e445c4b94f5f54a54de775365b1b8d0c77b186578b47673cf88dba3cfb5ea52430a3f2fb9d71fc1525e
7
+ data.tar.gz: e9923de8fbdc157d4e89cfc30b62a2ad24ea56aab5e7e6de898512482cffad0554810c0c7494589453f70040a55c1b764fb865940d05d20af2385985b7ed40c2
data/lib/kennel/api.rb CHANGED
@@ -88,30 +88,51 @@ module Kennel
88
88
 
89
89
  private
90
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
91
+ # keep widget + tab ids stable so stored dashboard urls that point at a widget or tab do not break on every update
92
+ # ids are dropped when diffing since storing them would be ugly, so restore the previous ids by matching widget titles
94
93
  def restore_widget_ids(id, attributes)
95
94
  return unless (widgets = attributes[:widgets])
96
95
  return unless (current = show("dashboard", id, {}, ignore_404: true))
97
96
 
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])
97
+ # backfill widget ids
98
+ widget_title_to_id = {}
99
+ each_widget_with_title(current[:widgets]) { |title, widget| widget_title_to_id[title] = widget[:id] }
100
+ each_widget_with_title(widgets) do |title, widget|
101
+ next unless (id = widget_title_to_id[title])
102
102
  widget[:id] ||= id # do not set nil, that breaks updates
103
103
  end
104
+
105
+ return unless (tabs = attributes[:tabs])
106
+
107
+ # backfill tag ids ... first by name, then just whatever we got left
108
+ # not setting nils so we get the proper `{"errors":["Required parameter 'id' is missing"]}` error
109
+ tab_name_to_id = {}
110
+ current[:tabs]&.each do |tab|
111
+ tab_name_to_id[tab[:name]] = tab[:id] # collect old tab names
112
+ end
113
+ tabs.each do |tab|
114
+ next if tab[:id]
115
+ next unless (id = tab_name_to_id.delete(tab[:name])) # reused moved tabs so links keep working
116
+ tab[:id] = id
117
+ end
118
+ tabs.each do |tab|
119
+ next if tab[:id]
120
+ next unless (id = tab_name_to_id.delete(tab_name_to_id.keys.first)) # reuse renamed tabs so links keep working
121
+ tab[:id] ||= id
122
+ end
104
123
  end
105
124
 
106
- # yield each widget with a key built from its group optional title/position and its own title/position
107
- def each_widget_with_key(widgets, prefix: nil, &block)
108
- widgets.each_with_index do |widget, i|
125
+ # yield each widget with a key built from its group optional title and its own title
126
+ # untitled widgets (e.g. images) are keyed by their definition, since positions change when widgets are
127
+ # reordered in the UI and would lose their id since the same id ends up being used twice
128
+ def each_widget_with_title(widgets, prefix: nil, &block)
129
+ widgets.each do |widget|
109
130
  title = widget.dig(:definition, :title)
110
- title = i.to_s if title.to_s.empty?
111
- key = [prefix, title].compact.join("-")
131
+ title = (widget[:definition] || {}).except(:id).to_s if title.to_s.empty?
132
+ key = prefix ? [prefix, title] : [title]
112
133
  yield key, widget
113
134
  if (nested = widget.dig(:definition, :widgets))
114
- each_widget_with_key(nested, prefix: title, &block)
135
+ each_widget_with_title(nested, prefix: title, &block)
115
136
  end
116
137
  end
117
138
  end
@@ -77,7 +77,7 @@ module Kennel
77
77
 
78
78
  settings(
79
79
  :title, :description, :definitions, :widgets, :layout_type, :template_variable_presets, :reflow_type,
80
- :tags
80
+ :tags, :tabs, :default_timeframe
81
81
  )
82
82
 
83
83
  defaults(
@@ -86,7 +86,9 @@ module Kennel
86
86
  widgets: -> { [] },
87
87
  template_variable_presets: -> { DEFAULTS.fetch(:template_variable_presets) },
88
88
  reflow_type: -> { layout_type == "ordered" ? "auto" : nil },
89
- tags: -> { project.tags }
89
+ tags: -> { project.tags },
90
+ tabs: -> { nil },
91
+ default_timeframe: -> { nil }
90
92
  )
91
93
 
92
94
  class << self
@@ -100,6 +102,8 @@ module Kennel
100
102
  ignore_default expected, actual, DEFAULTS
101
103
  ignore_default expected, actual, reflow_type: "auto" if expected[:layout_type] == "ordered"
102
104
 
105
+ dry_up_dashboard_tabs(actual)
106
+
103
107
  widgets_pairs(expected, actual).each do |pair|
104
108
  pair.each { |w| sort_conditional_formats w }
105
109
  ignore_widget_defaults(*pair)
@@ -110,6 +114,11 @@ module Kennel
110
114
 
111
115
  private
112
116
 
117
+ def dry_up_dashboard_tabs(dashboard)
118
+ return unless (tabs = dashboard[:tabs])
119
+ tabs.each { |t| t.delete :id } # we never want to update that, see api.rb
120
+ end
121
+
113
122
  # conditional_formats ordering is randomly changed by datadog, compare a stable ordering
114
123
  def sort_conditional_formats(widget)
115
124
  if (formats = widget&.dig(:definition, :conditional_formats))
@@ -163,6 +172,14 @@ module Kennel
163
172
  tags: tags.grep(TAG_PREFIX)
164
173
  )
165
174
 
175
+ if (value = tabs)
176
+ json[:tabs] = value
177
+ end
178
+
179
+ if (value = default_timeframe)
180
+ json[:default_timeframe] = value
181
+ end
182
+
166
183
  json[:reflow_type] = reflow_type if reflow_type # setting nil breaks create with "ordered"
167
184
 
168
185
  json
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "2.24.0"
3
+ VERSION = "2.25.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.24.0
4
+ version: 2.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -151,7 +151,7 @@ require_paths:
151
151
  - lib
152
152
  required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - ">="
154
+ - - "~>"
155
155
  - !ruby/object:Gem::Version
156
156
  version: 4.0.0
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 4.0.3
163
+ rubygems_version: 4.0.20
164
164
  specification_version: 4
165
165
  summary: Keep datadog monitors/dashboards/etc in version control, avoid chaotic management
166
166
  via UI