kennel 1.63.0 → 1.66.2

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: 7b8b30272574c9e7ad071340fefe2a6f020d2d00e499343cfa416322c1af91ea
4
- data.tar.gz: b70c3cbfa377a9bbf023d3ada61c156519410c082702a8cd4693b95132198654
3
+ metadata.gz: 5d5c7df715aecb3223069ef066f070a0b78dd699c46feae0052e90facc2ef0f5
4
+ data.tar.gz: d88d4f7b8ff2ec7458490fd79cf269bc319abf589c17ace29a4d368a29626b2d
5
5
  SHA512:
6
- metadata.gz: d9b8457368d955fc88a30608d746381d2bcbecac9997c6f9bbf650f4d7ec3487950b414a0876d7d72e3f349144ef221d1117942f9042e25e03fdc5f53e351ece
7
- data.tar.gz: 57ce23d124ec7a8f2a6d2ff85e1adb9cd5725c19e80ba53130545924d265b6d8bedf89044f7c5e89ee49d0f060c365131b6ef7c912fe29b060dd39f6533f9eab
6
+ metadata.gz: f7a603b340355a6be34c57d7843729dbdf9d27f910d94511ab4dc6c5a71c32a477160ebfe188fc03675bc28261dc9beb82f27faaceb4be355aceba343bbf5c54
7
+ data.tar.gz: e320fdfb09fc4f2400cdcad2f16297e6715dbb9094959e8fd50784bc7b1a4b880e65de806caaaa1b3e016ce90a4d8217e1c3e174b757cf6d83895273e5652b80
data/Readme.md CHANGED
@@ -184,6 +184,14 @@ Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a
184
184
 
185
185
  `rake kennel:validate_mentions` should run as part of CI
186
186
 
187
+ ### Grepping through all of datadog
188
+
189
+ `TYPE=monitor rake kennel:dump`
190
+
191
+ ### Find all monitors with No-Data
192
+
193
+ `rake kennel:nodata TAG=team:foo`
194
+
187
195
  ## Examples
188
196
 
189
197
  ### Reusable monitors/dashes/etc
@@ -220,10 +228,10 @@ end
220
228
  ```Bash
221
229
  rake play
222
230
  cd template
223
- rake kennel:plan
231
+ rake plan
224
232
  ```
225
233
 
226
- Then make changes to play around, do not commit changes and make sure to revert with a `rake kennel:update` after deleting everything.
234
+ Then make changes to play around, do not commit changes and make sure to revert with a `rake kennel:update_datadog` after deleting everything.
227
235
 
228
236
  To make changes via the UI, make a new free datadog account and use it's credentaisl instead.
229
237
 
@@ -43,12 +43,12 @@ module Kennel
43
43
  end
44
44
 
45
45
  def delete(api_resource, id)
46
- request :delete, "/api/v1/#{api_resource}/#{id}"
46
+ request :delete, "/api/v1/#{api_resource}/#{id}", ignore_404: true
47
47
  end
48
48
 
49
49
  private
50
50
 
51
- def request(method, path, body: nil, params: {})
51
+ def request(method, path, body: nil, params: {}, ignore_404: false)
52
52
  params = params.merge(application_key: @app_key, api_key: @api_key)
53
53
  query = Faraday::FlatParamsEncoder.encode(params)
54
54
  response = nil
@@ -66,7 +66,7 @@ module Kennel
66
66
  Kennel.err.puts "Retrying on server error #{response.status} for #{path}"
67
67
  end
68
68
 
69
- unless response.success?
69
+ if !response.success? && (response.status != 404 || !ignore_404)
70
70
  message = +"Error #{response.status} during #{method.upcase} #{path}\n"
71
71
  message << "request:\n#{JSON.pretty_generate(body)}\nresponse:\n" if body
72
72
  message << response.body
@@ -7,13 +7,13 @@ module Kennel
7
7
  class << self
8
8
  def report(token, &block)
9
9
  return yield unless token
10
- new(token).report(&block)
10
+ new(token, Utils.capture_sh("git rev-parse HEAD").strip).report(&block)
11
11
  end
12
12
  end
13
13
 
14
- def initialize(token)
14
+ def initialize(token, git_sha)
15
15
  @token = token
16
- @git_sha = Utils.capture_sh("git rev-parse HEAD").strip
16
+ @git_sha = git_sha
17
17
  origin = ENV["PROJECT_REPOSITORY"] || Utils.capture_sh("git remote -v").split("\n").first
18
18
  @repo_part = origin[%r{github\.com[:/](.+?)(\.git|$)}, 1] || raise("no origin found")
19
19
  end
@@ -27,8 +27,6 @@ module Kennel
27
27
  comment "```\n#{output || "Error"}\n```"
28
28
  end
29
29
 
30
- private
31
-
32
30
  # https://developer.github.com/v3/repos/comments/#create-a-commit-comment
33
31
  def comment(body)
34
32
  # truncate to maximum allowed comment size for github to avoid 422
@@ -39,6 +37,8 @@ module Kennel
39
37
  post "commits/#{@git_sha}/comments", body: body
40
38
  end
41
39
 
40
+ private
41
+
42
42
  def post(path, data)
43
43
  url = "https://api.github.com/repos/#{@repo_part}/#{path}"
44
44
  response = Faraday.post(url, data.to_json, authorization: "token #{@token}")
@@ -5,7 +5,8 @@ module Kennel
5
5
  include OptionalValidations
6
6
 
7
7
  RENOTIFY_INTERVALS = [0, 10, 20, 30, 40, 50, 60, 90, 120, 180, 240, 300, 360, 720, 1440].freeze # minutes
8
- QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "1d"].freeze
8
+ # 2d and 1w are valid timeframes for anomaly monitors
9
+ QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "1d", "2d", "1w"].freeze
9
10
  OPTIONAL_SERVICE_CHECK_THRESHOLDS = [:ok, :warning].freeze
10
11
  READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [
11
12
  :multi, :matching_downtimes, :overall_state_modified, :overall_state, :restricted_roles
@@ -132,7 +133,7 @@ module Kennel
132
133
 
133
134
  case actual[:type]
134
135
  when "event alert"
135
- # setting 0 results in thresholds not getting returned from the api
136
+ # setting nothing results in thresholds not getting returned from the api
136
137
  options[:thresholds] ||= { critical: 0 }
137
138
 
138
139
  when "service check"
@@ -42,7 +42,10 @@ module Kennel
42
42
 
43
43
  self.class.send(:normalize, expected, actual)
44
44
 
45
- HashDiff.diff(actual, expected, use_lcs: false)
45
+ # strict: ignore Integer vs Float
46
+ # similarity: show diff when not 100% similar
47
+ # use_lcs: saner output
48
+ Hashdiff.diff(actual, expected, use_lcs: false, strict: false, similarity: 1)
46
49
  end
47
50
 
48
51
  def tracking_id
@@ -3,6 +3,7 @@ module Kennel
3
3
  class Syncer
4
4
  CACHE_FILE = "tmp/cache/details" # keep in sync with .travis.yml caching
5
5
  TRACKING_FIELDS = [:message, :description].freeze
6
+ DELETE_ORDER = ["dashboard", "slo", "monitor"].freeze # dashboards references monitors + slos, slos reference monitors
6
7
 
7
8
  def initialize(api, expected, project: nil)
8
9
  @api = api
@@ -98,6 +99,8 @@ module Kennel
98
99
  ensure_all_ids_found
99
100
  @create = @expected.map { |e| [nil, e] }
100
101
  end
102
+
103
+ @delete.sort_by! { |_, _, a| DELETE_ORDER.index a.fetch(:api_resource) }
101
104
  end
102
105
 
103
106
  # Make diff work even though we cannot mass-fetch definitions
@@ -111,14 +111,21 @@ namespace :kennel do
111
111
  end
112
112
  end
113
113
 
114
- desc "Convert existing resources to copy-pastable definitions to import existing resources RESOURCE=dash ID=1234"
114
+ desc "Convert existing resources to copy-pastable definitions to import existing resources RESOURCE=[dashboard,monitor,slo] ID=1234"
115
115
  task import: :environment do
116
- resource = ENV["RESOURCE"] || Kennel::Tasks.abort("Call with RESOURCE=dash") # TODO: add others
116
+ resource = ENV["RESOURCE"] || Kennel::Tasks.abort("Call with RESOURCE=dashboard or monitor or slo")
117
117
  id = ENV["ID"] || Kennel::Tasks.abort("Call with ID=1234")
118
118
  id = Integer(id) if id =~ /^\d+$/ # dashboards can have alphanumeric ids
119
119
  puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
120
120
  end
121
121
 
122
+ desc "Dump ALL of datadog config as raw json ... useful for grep/search TYPE=slo|monitor|dashboard"
123
+ task dump: :environment do
124
+ Kennel.send(:api).list(ENV.fetch("TYPE")).each do |r|
125
+ Kennel.out.puts JSON.pretty_generate(r)
126
+ end
127
+ end
128
+
122
129
  task :environment do
123
130
  require "kennel"
124
131
  gem "dotenv"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.63.0"
3
+ VERSION = "1.66.2"
4
4
  end
@@ -166,6 +166,14 @@ Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a
166
166
 
167
167
  `rake kennel:validate_mentions` should run as part of CI
168
168
 
169
+ ### Grepping through all of datadog
170
+
171
+ `TYPE=monitor rake kennel:dump`
172
+
173
+ ### Find all monitors with No-Data
174
+
175
+ `rake kennel:nodata TAG=team:foo`
176
+
169
177
  ## Examples
170
178
 
171
179
  ### Reusable monitors/dashes/etc
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.63.0
4
+ version: 1.66.2
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-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.9
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.9
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: net-http-persistent-retry
43
43
  requirement: !ruby/object:Gem::Requirement