kennel 1.16.2 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 617e550ae31d28ef32f0e46948246f78156fddde356a0c42bd6dfcacf63eac8d
4
- data.tar.gz: d7e3b335b847c8bfe3d9a1cf2a4d967160539137ebe64704a5d71c7b5ac2ccda
3
+ metadata.gz: d354b23d7d94b5204db458729029fea0b9d2cce10689059b7818cfb42da4101b
4
+ data.tar.gz: 0c364c6db65fdf0d1fe462bc91930b6fbfeafc05f7ab152fe3d4584796fd1d57
5
5
  SHA512:
6
- metadata.gz: 723d7464968287acb6157a59f3cebc30322c17c92dfad47a9e1a49c63a4c5ab3a490b1a13bc179591c30c424b57ac28410526c493bc80ca34b5084ec8f3b65ba
7
- data.tar.gz: 62cf68ab5ef460ece823a3ac014542692afabb8980c84f584af1b5de73230508039ab634bfcfa480f1608b6a7b9039734de5ef98b337e82a596540d82092d3b5
6
+ metadata.gz: 21149b9899661a927d688f5db2b71702cecf6ced3998b40d7ed03917487bcaa63c11fe581004959840c319f3b5fc228a7b8ae59f3639bdb67ee77b1d14ff5f12
7
+ data.tar.gz: 9e7e174417f5a884acf06f45a03dee86fc23fe95d41cd2df993ca1e4e20fa7e72eaffc754becc0f4452ea2d3a75037dd9d43eb11ea722ed7788d62a06d17a1c3
data/Readme.md CHANGED
@@ -15,7 +15,7 @@ Keep datadog monitors/dashboards/etc in version control, avoid chaotic managemen
15
15
 
16
16
  - create a new private `kennel` repo for your organization (do not fork this repo)
17
17
  - use the template folder as starting point:
18
- ```
18
+ ```Bash
19
19
  git clone git@github.com:your-org/kennel.git
20
20
  git clone git@github.com:grosser/kennel.git seed
21
21
  mv seed/teamplate/* kennel/
@@ -47,7 +47,7 @@ Keep datadog monitors/dashboards/etc in version control, avoid chaotic managemen
47
47
 
48
48
  ### Adding a team
49
49
 
50
- ```ruby
50
+ ```Ruby
51
51
  # teams/my_team.rb
52
52
  module Teams
53
53
  class MyTeam < Kennel::Models::Team
@@ -145,6 +145,14 @@ end
145
145
  end
146
146
  ```
147
147
 
148
+ ### Importing an existing resources
149
+
150
+ ```Bash
151
+ RESOURCE=dash ID=12345 rake kennel:import
152
+ ```
153
+
154
+ Put returned definition into a project of your choice.
155
+
148
156
  ### Adding a new screenboard
149
157
  - similar to `dash.rb`
150
158
  - add to `parts:` list
@@ -164,7 +172,7 @@ end
164
172
 
165
173
  ### Skipping validations
166
174
 
167
- Some validations might be too strict for your usecase or just wrong, please open an issue and
175
+ Some validations might be too strict for your usecase or just wrong, please [open an issue](https://github.com/grosser/kennel/issues) and
168
176
  to unblock use the `validate: -> { false }` option.
169
177
 
170
178
  ### Debugging locally
@@ -208,7 +216,7 @@ end
208
216
 
209
217
  ### Integration testing
210
218
 
211
- ```
219
+ ```Bash
212
220
  rake play
213
221
  cd template
214
222
  rake kennel:plan
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kennel
4
+ class Importer
5
+ SORT_ORDER = [:title, :id, :description, :template_variables].freeze
6
+
7
+ # TODO: make model diff normalization reusable
8
+ IGNORED = Models::Base::READONLY_ATTRIBUTES - [:id] + [:created_by, :read_only]
9
+
10
+ def initialize(api)
11
+ @api = api
12
+ end
13
+
14
+ def import(resource, id)
15
+ data = @api.show(resource, id)
16
+ case resource
17
+ when "dash"
18
+ data = data[:dash]
19
+ IGNORED.each { |k| data.delete(k) }
20
+ <<~RUBY
21
+ Kennel::Models::Dash.new(
22
+ self,
23
+ #{pretty_print(data).lstrip}
24
+ )
25
+ RUBY
26
+ else
27
+ raise ArgumentError, "#{resource} is not supported"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def pretty_print(hash)
34
+ list = hash.sort_by { |k, _| SORT_ORDER.index(k) || 999 }
35
+ list.map do |k, v|
36
+ case v
37
+ when Hash, Array
38
+ pretty = JSON.pretty_generate(v)
39
+ .gsub(/(^\s*)"(.*?)":/, "\\1\\2:") # "foo": 1 -> foo: 1
40
+ .gsub(/^/, " ") # indent
41
+ " #{k}: -> {\n#{pretty}\n }"
42
+ else
43
+ " #{k}: -> { #{v.inspect} }"
44
+ end
45
+ end.join(",\n")
46
+ end
47
+ end
48
+ end
@@ -34,7 +34,7 @@ module Kennel
34
34
  id: id,
35
35
  title: "#{title}#{LOCK}",
36
36
  description: description,
37
- read_only: false,
37
+ read_only: false, # TODO: delete it instead
38
38
  template_variables: render_template_variables,
39
39
  graphs: render_graphs
40
40
  }
@@ -102,6 +102,7 @@ module Kennel
102
102
  graph
103
103
  end + graphs
104
104
 
105
+ # TODO: solve this via ignore-defaults
105
106
  all.each do |g|
106
107
  g[:definition][:autoscale] = true unless g[:definition].key?(:autoscale)
107
108
  end
@@ -2,6 +2,7 @@
2
2
  require "English"
3
3
  require "kennel"
4
4
  require "kennel/unmuted_alerts"
5
+ require "kennel/importer"
5
6
 
6
7
  namespace :kennel do
7
8
  desc "Ensure there are no uncommited changes that would be hidden from PR reviewers"
@@ -49,6 +50,13 @@ namespace :kennel do
49
50
  Kennel::UnmutedAlerts.print(Kennel.send(:api), tag)
50
51
  end
51
52
 
53
+ desc "Covert existing resources to copy-pastable definitions to import existing resources RESOURCE=dash ID=1234"
54
+ task import: :environment do
55
+ resource = ENV["RESOURCE"] || abort("Call with RESOURCE=dash") # TODO: add others
56
+ id = Integer(ENV["ID"] || abort("Call with ID=1234"))
57
+ puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
58
+ end
59
+
52
60
  task :environment do
53
61
  require "kennel"
54
62
  gem "dotenv"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.16.2"
3
+ VERSION = "1.17.0"
4
4
  end
@@ -29,7 +29,7 @@ Keep datadog monitors/dashboards/etc in version control, avoid chaotic managemen
29
29
 
30
30
  ### Adding a team
31
31
 
32
- ```ruby
32
+ ```Ruby
33
33
  # teams/my_team.rb
34
34
  module Teams
35
35
  class MyTeam < Kennel::Models::Team
@@ -127,6 +127,14 @@ end
127
127
  end
128
128
  ```
129
129
 
130
+ ### Importing an existing resources
131
+
132
+ ```Bash
133
+ RESOURCE=dash ID=12345 rake kennel:import
134
+ ```
135
+
136
+ Put returned definition into a project of your choice.
137
+
130
138
  ### Adding a new screenboard
131
139
  - similar to `dash.rb`
132
140
  - add to `parts:` list
@@ -146,7 +154,7 @@ end
146
154
 
147
155
  ### Skipping validations
148
156
 
149
- Some validations might be too strict for your usecase or just wrong, please open an issue and
157
+ Some validations might be too strict for your usecase or just wrong, please [open an issue](https://github.com/grosser/kennel/issues) and
150
158
  to unblock use the `validate: -> { false }` option.
151
159
 
152
160
  ### Debugging locally
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.16.2
4
+ version: 1.17.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: 2018-10-09 00:00:00.000000000 Z
11
+ date: 2018-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -49,6 +49,7 @@ files:
49
49
  - lib/kennel/api.rb
50
50
  - lib/kennel/file_cache.rb
51
51
  - lib/kennel/github_reporter.rb
52
+ - lib/kennel/importer.rb
52
53
  - lib/kennel/models/base.rb
53
54
  - lib/kennel/models/dash.rb
54
55
  - lib/kennel/models/monitor.rb