kennel 1.69.0 → 1.72.1

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: daadbdb69c86de7a0dcdec2bc1eeaedd4b0c2221e2059d241db57e717a8876b6
4
- data.tar.gz: 1d93147d3d88468564c6c9fcfd0a1fa3926df23d44961b876273e24ac642c851
3
+ metadata.gz: 9dec3dd3c3595176bc3340b7fcfd0227cca53a09ab56db9911da90546f8cc125
4
+ data.tar.gz: '019ee1e8e9c7e37d3218f77790ab5cc5ef08504fd0a603ee710a4623e36f72fa'
5
5
  SHA512:
6
- metadata.gz: 7737e951ba0e6f34bdec5c4c000e64852acfcc1939d19385a7a92d9b88821c5d6efe0f29f1d8a292692c3ae8b85bd248af0f05ed3e591595da5d2ee41382fd37
7
- data.tar.gz: 62989fb72a5bc60f052449ecf4d380f59f7e945a8d1857e7f3e789549d8625eac8ffd51c2a946b4f0367cd2d439b2ecb02eb99f79cb42202bb020dadf8a6b612
6
+ metadata.gz: a49dda9dcff0d0a8d330a68f2c9a6e69fb20624067bc24b9fae57c3e7f9cfe94ea9f3cb412acc456a4743ca5b61643a7494e5599833d296e92893372ee39be9a
7
+ data.tar.gz: 11a86599302eb683e8b7f37df641af3d0965ac52ace5ee00375d2a3644cc35e0b4844c31f1cdd71a98a9eec5e91002a7b20d23a611dd51ce902de5c93df462cf
data/Readme.md CHANGED
@@ -23,7 +23,7 @@ Manage datadog monitors/dashboards/slos as code
23
23
  ```
24
24
  - add a basic projects and teams so others can copy-paste to get started
25
25
  - setup travis build for your repo
26
- - uncomment `.travis.yml` section for automated github PR feedback and datadog updates on merge
26
+ - uncomment `.travis.yml` section for automated PR planing and datadog updates on merge
27
27
  - follow `Setup` in your repos Readme.md
28
28
  <!-- NOT IN -->
29
29
 
@@ -72,7 +72,7 @@ end
72
72
  ### Updating an existing monitor
73
73
  - use [datadog monitor UI](https://app.datadoghq.com/monitors/manage) to find a monitor
74
74
  - get the `id` from the url
75
- - run `RESOURCE=monitor ID=12345 bundle exec rake kennel:import` and copy the output
75
+ - run `URL='https://app.datadoghq.com/monitors/123' bundle exec rake kennel:import` and copy the output
76
76
  - find or create a project in `projects/`
77
77
  - add the monitor to `parts: [` list, for example:
78
78
  ```Ruby
@@ -118,7 +118,7 @@ end
118
118
  ### Updating an existing dashboard
119
119
  - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to find a dashboard
120
120
  - get the `id` from the url
121
- - run `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import` and copy the output
121
+ - run `URL='https://app.datadoghq.com/dashboard/bet-foo-bar' bundle exec rake kennel:import` and copy the output
122
122
  - find or create a project in `projects/`
123
123
  - add a dashboard to `parts: [` list, for example:
124
124
  ```Ruby
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # Not used in here, but in our templated repo ... so keeping it around for now.
2
3
  module Kennel
3
4
  class GithubReporter
4
5
  MAX_COMMENT_SIZE = 65536
@@ -16,12 +16,13 @@ module Kennel
16
16
  TIMESERIES_DEFAULTS = { show_legend: false, legend_size: "0" }.freeze
17
17
  SUPPORTED_DEFINITION_OPTIONS = [:events, :markers, :precision].freeze
18
18
 
19
- settings :title, :description, :definitions, :widgets, :layout_type
19
+ settings :title, :description, :definitions, :widgets, :layout_type, :template_variable_presets
20
20
 
21
21
  defaults(
22
22
  description: -> { "" },
23
23
  definitions: -> { [] },
24
24
  widgets: -> { [] },
25
+ template_variable_presets: -> { [] },
25
26
  id: -> { nil }
26
27
  )
27
28
 
@@ -102,6 +103,7 @@ module Kennel
102
103
  title: "#{title}#{LOCK}",
103
104
  description: description,
104
105
  template_variables: render_template_variables,
106
+ template_variable_presets: template_variable_presets,
105
107
  widgets: all_widgets
106
108
  }
107
109
 
@@ -116,6 +118,10 @@ module Kennel
116
118
  Utils.path_to_url "/dashboard/#{id}"
117
119
  end
118
120
 
121
+ def self.parse_url(url)
122
+ url[/\/dashboard\/([a-z\d-]+)/, 1]
123
+ end
124
+
119
125
  def resolve_linked_tracking_ids(id_map)
120
126
  widgets = as_json[:widgets].flat_map { |w| [w, *w.dig(:definition, :widgets) || []] }
121
127
  widgets.each do |widget|
@@ -163,6 +169,10 @@ module Kennel
163
169
  super
164
170
 
165
171
  validate_template_variables data, :widgets
172
+
173
+ # Avoid diff from datadog presets sorting.
174
+ presets = data[:template_variable_presets]
175
+ invalid! "template_variable_presets must be sorted by name" if presets != presets.sort_by { |p| p[:name] }
166
176
  end
167
177
 
168
178
  def render_definitions
@@ -120,6 +120,12 @@ module Kennel
120
120
  Utils.path_to_url "/monitors##{id}/edit"
121
121
  end
122
122
 
123
+ # datadog uses both / and # as separator in it's links
124
+ def self.parse_url(url)
125
+ return unless id = url[/\/monitors[\/#](\d+)/, 1]
126
+ Integer(id)
127
+ end
128
+
123
129
  def self.normalize(expected, actual)
124
130
  super
125
131
  options = actual.fetch(:options)
@@ -196,7 +202,7 @@ module Kennel
196
202
  # verify is_match uses available variables
197
203
  message = data.fetch(:message)
198
204
  used = message.scan(/{{\s*#is_match\s*"([a-zA-Z\d_.-]+).name"/).flatten.uniq
199
- allowed = data.fetch(:query)[/by\s*{([^\}]+)}/, 1].to_s.split(/\s*,\s*/)
205
+ allowed = data.fetch(:query)[/by\s*[\({]([^\}\)]+)[}\)]/, 1].to_s.gsub(/["']/, "").split(/\s*,\s*/)
200
206
  unsupported = used - allowed
201
207
  if unsupported.any?
202
208
  invalid! "is_match used with #{unsupported}, but metric is only grouped by #{allowed}"
@@ -11,6 +11,14 @@ module Kennel
11
11
  settings :id, :kennel_id
12
12
 
13
13
  class << self
14
+ def parse_any_url(url)
15
+ subclasses.detect do |s|
16
+ if id = s.parse_url(url)
17
+ break s.api_resource, id
18
+ end
19
+ end
20
+ end
21
+
14
22
  private
15
23
 
16
24
  def normalize(_expected, actual)
@@ -62,6 +62,10 @@ module Kennel
62
62
  Utils.path_to_url "/slo?slo_id=#{id}"
63
63
  end
64
64
 
65
+ def self.parse_url(url)
66
+ url[/\/slo\?slo_id=([a-z\d]+)/, 1]
67
+ end
68
+
65
69
  def resolve_linked_tracking_ids(id_map)
66
70
  as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
67
71
  id.is_a?(String) ? resolve_link(id, :monitor, id_map) : id
@@ -228,7 +228,7 @@ module Kennel
228
228
  json = e.as_json
229
229
  field = tracking_field(json)
230
230
  value = json[field]
231
- json[field] = value.dup.sub!(/\n-- Managed by kennel .*/, "") || raise("did not find tracking id in #{value}")
231
+ json[field] = value.dup.sub!(/\n?-- Managed by kennel .*/, "") || raise("did not find tracking id in #{value}")
232
232
  end
233
233
 
234
234
  def tracking_id(a)
@@ -68,7 +68,7 @@ namespace :kennel do
68
68
  Kennel.update
69
69
  end
70
70
 
71
- desc "update if this is a push to the default branch, otherwise plan (report to github with GITHUB_TOKEN)"
71
+ desc "update if this is a push to the default branch, otherwise plan"
72
72
  task :travis do
73
73
  on_default_branch = (ENV["TRAVIS_BRANCH"] == (ENV["DEFAULT_BRANCH"] || "master"))
74
74
  is_push = (ENV["TRAVIS_PULL_REQUEST"] == "false")
@@ -79,9 +79,7 @@ namespace :kennel do
79
79
  "kennel:plan" # show plan in travis logs
80
80
  end
81
81
 
82
- Kennel::GithubReporter.report(ENV["GITHUB_TOKEN"]) do
83
- Rake::Task[task_name].invoke
84
- end
82
+ Rake::Task[task_name].invoke
85
83
  end
86
84
 
87
85
  desc "show unmuted alerts filtered by TAG, for example TAG=team:foo"
@@ -111,12 +109,18 @@ namespace :kennel do
111
109
  end
112
110
  end
113
111
 
114
- desc "Convert existing resources to copy-pastable definitions to import existing resources RESOURCE=[dashboard,monitor,slo] ID=1234"
112
+ desc "Convert existing resources to copy-pasteable definitions to import existing resources (call with URL= or call with RESOURCE= and ID=)"
115
113
  task import: :environment do
116
- resource = ENV["RESOURCE"] || Kennel::Tasks.abort("Call with RESOURCE=dashboard or monitor or slo")
117
- id = ENV["ID"] || Kennel::Tasks.abort("Call with ID=1234")
118
- id = Integer(id) if id =~ /^\d+$/ # dashboards can have alphanumeric ids
119
- puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
114
+ if (id = ENV["ID"]) && (resource = ENV["RESOURCE"])
115
+ id = Integer(id) if id =~ /^\d+$/ # dashboards can have alphanumeric ids
116
+ elsif (url = ENV["URL"])
117
+ resource, id = Kennel::Models::Record.parse_any_url(url) || Kennel::Tasks.abort("Unable to parse url")
118
+ else
119
+ possible_resources = Kennel::Models::Record.subclasses.map(&:api_resource)
120
+ Kennel::Tasks.abort("Call with URL= or call with RESOURCE=#{possible_resources.join(" or ")} and ID=")
121
+ end
122
+
123
+ Kennel.out.puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
120
124
  end
121
125
 
122
126
  desc "Dump ALL of datadog config as raw json ... useful for grep/search TYPE=slo|monitor|dashboard"
@@ -19,6 +19,7 @@ module Kennel
19
19
  .gsub(/::/, "_") # Foo::Bar -> foo_bar
20
20
  .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # FOOBar -> foo_bar
21
21
  .gsub(/([a-z\d])([A-Z])/, '\1_\2') # fooBar -> foo_bar
22
+ .tr("-", "_") # foo-bar -> foo_bar
22
23
  .downcase
23
24
  end
24
25
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.69.0"
3
+ VERSION = "1.72.1"
4
4
  end
@@ -54,7 +54,7 @@ end
54
54
  ### Updating an existing monitor
55
55
  - use [datadog monitor UI](https://app.datadoghq.com/monitors/manage) to find a monitor
56
56
  - get the `id` from the url
57
- - run `RESOURCE=monitor ID=12345 bundle exec rake kennel:import` and copy the output
57
+ - run `URL='https://app.datadoghq.com/monitors/123' bundle exec rake kennel:import` and copy the output
58
58
  - find or create a project in `projects/`
59
59
  - add the monitor to `parts: [` list, for example:
60
60
  ```Ruby
@@ -100,7 +100,7 @@ end
100
100
  ### Updating an existing dashboard
101
101
  - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to find a dashboard
102
102
  - get the `id` from the url
103
- - run `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import` and copy the output
103
+ - run `URL='https://app.datadoghq.com/dashboard/bet-foo-bar' bundle exec rake kennel:import` and copy the output
104
104
  - find or create a project in `projects/`
105
105
  - add a dashboard to `parts: [` list, for example:
106
106
  ```Ruby
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.69.0
4
+ version: 1.72.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday