kennel 1.61.5 → 1.65.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +14 -5
- data/lib/kennel/api.rb +3 -3
- data/lib/kennel/file_cache.rb +6 -5
- data/lib/kennel/github_reporter.rb +5 -5
- data/lib/kennel/models/base.rb +1 -1
- data/lib/kennel/models/monitor.rb +3 -3
- data/lib/kennel/models/slo.rb +13 -4
- data/lib/kennel/tasks.rb +7 -0
- data/lib/kennel/version.rb +1 -1
- data/template/Readme.md +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f80b8b4232aa41c2b405d35ebb4377a6292e6278ab9261fb2ee36a13e9577e2
|
4
|
+
data.tar.gz: 9e677dee555faaab7b3be0cc58d341f5b36a4cf078a30dc79bf7f5210d9f01b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a99873dc872ff3c0af64d4ef4bfa04b3822e75a25dc1b4a08c62b4382476f5b68d5d8a80e621e301d7f8ca470c9d899afb68ebb37d28043bc4820b298d9d8cb1
|
7
|
+
data.tar.gz: 3b1ae467dd9845b826a0c0b5bd03f2352e07c80108404c5d7ff818cf6e207de60a1378627b222f5c93e6d585d3eb44c51f56fb7ab21e92c44f4394c94e60bbdb
|
data/Readme.md
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
![](template/github/cage.jpg?raw=true)
|
4
4
|
|
5
|
-
|
5
|
+
Manage datadog monitors/dashboards/slos as code
|
6
6
|
|
7
|
-
- Documented, reusable,
|
7
|
+
- Documented, reusable, and searchable
|
8
8
|
- Changes are PR reviewed and auditable
|
9
|
-
-
|
9
|
+
- Updating shows diff before applying
|
10
|
+
- Automated import of existing monitors/dashboards/slos
|
10
11
|
|
11
12
|
![](template/github/screen.png?raw=true)
|
12
13
|
<!-- NOT IN template/Readme.md -->
|
@@ -183,6 +184,14 @@ Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a
|
|
183
184
|
|
184
185
|
`rake kennel:validate_mentions` should run as part of CI
|
185
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
|
+
|
186
195
|
## Examples
|
187
196
|
|
188
197
|
### Reusable monitors/dashes/etc
|
@@ -219,10 +228,10 @@ end
|
|
219
228
|
```Bash
|
220
229
|
rake play
|
221
230
|
cd template
|
222
|
-
rake
|
231
|
+
rake plan
|
223
232
|
```
|
224
233
|
|
225
|
-
Then make changes to play around, do not commit changes and make sure to revert with a `rake kennel:
|
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.
|
226
235
|
|
227
236
|
To make changes via the UI, make a new free datadog account and use it's credentaisl instead.
|
228
237
|
|
data/lib/kennel/api.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/kennel/file_cache.rb
CHANGED
@@ -32,11 +32,12 @@ module Kennel
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def load_data
|
35
|
-
@data =
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
@data =
|
36
|
+
begin
|
37
|
+
Marshal.load(File.read(@file)) # rubocop:disable Security/MarshalLoad
|
38
|
+
rescue StandardError
|
39
|
+
{}
|
40
|
+
end
|
40
41
|
end
|
41
42
|
|
42
43
|
def persist
|
@@ -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 =
|
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}")
|
data/lib/kennel/models/base.rb
CHANGED
@@ -8,7 +8,7 @@ module Kennel
|
|
8
8
|
QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "1d"].freeze
|
9
9
|
OPTIONAL_SERVICE_CHECK_THRESHOLDS = [:ok, :warning].freeze
|
10
10
|
READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [
|
11
|
-
:multi, :matching_downtimes, :overall_state_modified, :overall_state
|
11
|
+
:multi, :matching_downtimes, :overall_state_modified, :overall_state, :restricted_roles
|
12
12
|
]
|
13
13
|
|
14
14
|
# defaults that datadog uses when options are not sent, so safe to leave out if our values match their defaults
|
@@ -35,7 +35,7 @@ module Kennel
|
|
35
35
|
ok: -> { nil },
|
36
36
|
id: -> { nil },
|
37
37
|
notify_no_data: -> { true },
|
38
|
-
no_data_timeframe: -> {
|
38
|
+
no_data_timeframe: -> { 60 },
|
39
39
|
notify_audit: -> { true },
|
40
40
|
new_host_delay: -> { MONITOR_OPTION_DEFAULTS.fetch(:new_host_delay) },
|
41
41
|
tags: -> { @project.tags },
|
@@ -57,7 +57,7 @@ module Kennel
|
|
57
57
|
options: {
|
58
58
|
timeout_h: timeout_h,
|
59
59
|
notify_no_data: notify_no_data,
|
60
|
-
no_data_timeframe: no_data_timeframe,
|
60
|
+
no_data_timeframe: notify_no_data ? no_data_timeframe : nil,
|
61
61
|
notify_audit: notify_audit,
|
62
62
|
require_full_window: require_full_window,
|
63
63
|
new_host_delay: new_host_delay,
|
data/lib/kennel/models/slo.rb
CHANGED
@@ -6,11 +6,12 @@ module Kennel
|
|
6
6
|
DEFAULTS = {
|
7
7
|
description: nil,
|
8
8
|
query: nil,
|
9
|
+
groups: nil,
|
9
10
|
monitor_ids: [],
|
10
11
|
thresholds: []
|
11
12
|
}.freeze
|
12
13
|
|
13
|
-
settings :type, :description, :thresholds, :query, :tags, :monitor_ids, :monitor_tags, :name
|
14
|
+
settings :type, :description, :thresholds, :query, :tags, :monitor_ids, :monitor_tags, :name, :groups
|
14
15
|
|
15
16
|
defaults(
|
16
17
|
id: -> { nil },
|
@@ -18,7 +19,8 @@ module Kennel
|
|
18
19
|
query: -> { DEFAULTS.fetch(:query) },
|
19
20
|
description: -> { DEFAULTS.fetch(:description) },
|
20
21
|
monitor_ids: -> { DEFAULTS.fetch(:monitor_ids) },
|
21
|
-
thresholds: -> { DEFAULTS.fetch(:thresholds) }
|
22
|
+
thresholds: -> { DEFAULTS.fetch(:thresholds) },
|
23
|
+
groups: -> { DEFAULTS.fetch(:groups) }
|
22
24
|
)
|
23
25
|
|
24
26
|
def initialize(*)
|
@@ -39,8 +41,15 @@ module Kennel
|
|
39
41
|
type: type
|
40
42
|
}
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
if v = query
|
45
|
+
data[:query] = v
|
46
|
+
end
|
47
|
+
if v = id
|
48
|
+
data[:id] = v
|
49
|
+
end
|
50
|
+
if v = groups
|
51
|
+
data[:groups] = v
|
52
|
+
end
|
44
53
|
|
45
54
|
@as_json = data
|
46
55
|
end
|
data/lib/kennel/tasks.rb
CHANGED
@@ -119,6 +119,13 @@ namespace :kennel do
|
|
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"
|
data/lib/kennel/version.rb
CHANGED
data/template/Readme.md
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
![](github/cage.jpg?raw=true)
|
4
4
|
|
5
|
-
|
5
|
+
Manage datadog monitors/dashboards/slos as code
|
6
6
|
|
7
|
-
- Documented, reusable,
|
7
|
+
- Documented, reusable, and searchable
|
8
8
|
- Changes are PR reviewed and auditable
|
9
|
-
-
|
9
|
+
- Updating shows diff before applying
|
10
|
+
- Automated import of existing monitors/dashboards/slos
|
10
11
|
|
11
12
|
![](github/screen.png?raw=true)
|
12
13
|
|
@@ -165,6 +166,14 @@ Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a
|
|
165
166
|
|
166
167
|
`rake kennel:validate_mentions` should run as part of CI
|
167
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
|
+
|
168
177
|
## Examples
|
169
178
|
|
170
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.
|
4
|
+
version: 1.65.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: 2020-
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|