kennel 1.52.0 → 1.55.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: 7d34d639d4d27f3953211bc4f94f36d559b5ada87d3f289219bf611c8183805d
4
- data.tar.gz: c531670c166981073648ae9e12f1ca6c47f27a5642a4b8abf0fc5890134bcead
3
+ metadata.gz: 6e23afaba22ded8b1fb654a9552ed135247cb3a9a5c5610090bfa9096123ffb4
4
+ data.tar.gz: 7e4096a43a6fcd52f519131c2238879f2eb551d90c5883a9d5e1e8996f90075c
5
5
  SHA512:
6
- metadata.gz: 5e4f308f0076d4cc5f290c5041fc37a57a64986fb1d0ec586bf448b9293880fd42e67b6d6de60607369f2918efc7aeb87177fd7a27a1749ca272fdb2c5519d0f
7
- data.tar.gz: e1852e1d4c0cceb841f73559ae248357ce5d1fdfe81e3d8a0a348374d2f1e6819befbc9fcdec0caae00cc72808430f91fd10d46b7dd88fe57b721faf55e1d882
6
+ metadata.gz: bb7d4a1e6f48f645e220169bcabac5ae8fed56f01033a63be6ea855e5308e62ec3d31a4c9326823d99e973d85056f1151a1924ae33ced07b620224b1e716eb8b
7
+ data.tar.gz: 7bb59bc7ca8bd3b024903c61bdc11c4f816d9fca0fc666cae36dcdb6258d660608ba6cfe16ccbf1877957c54eb9e9feda437055d44fe4f5a3e0abe701623680d
data/Readme.md CHANGED
@@ -42,19 +42,23 @@ Keep datadog monitors/dashboards/etc in version control, avoid chaotic managemen
42
42
  - `gem install bundler && bundle install`
43
43
  - `cp .env.example .env`
44
44
  - open [Datadog API Settings](https://app.datadoghq.com/account/settings#api)
45
- - find or create your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=` (will be on the last page if new)
46
45
  - copy any `API Key` and add it to `.env` as `DATADOG_API_KEY`
46
+ - find or create (check last page) your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=`
47
+ - change the `DATADOG_SUBDOMAIN=app` in `.env` to your companies subdomain if you have one
47
48
  -->
48
49
 
49
50
  ### Adding a team
50
51
 
52
+ - `mention` is used for all team monitors via `super()`
53
+ - `renotify_interval` is used for all team monitors (defaults to `0` / off)
54
+ - `tags` is used for all team monitors/dashboards (defaults to `team:<team-name>`)
55
+
51
56
  ```Ruby
52
57
  # teams/my_team.rb
53
58
  module Teams
54
59
  class MyTeam < Kennel::Models::Team
55
60
  defaults(
56
- slack: -> { "my-alerts" },
57
- email: -> { "my-team@example.com" }
61
+ mention: -> { "@slack-my-team" }
58
62
  )
59
63
  end
60
64
  end
@@ -62,13 +66,14 @@ end
62
66
 
63
67
  ### Adding a new monitor
64
68
  - use [datadog monitor UI](https://app.datadoghq.com/monitors#create/metric) to create a monitor
65
- - get the `id` from the url
66
- - `RESOURCE=monitor ID=12345 bundle exec rake kennel:import`
67
69
  - see below
68
70
 
69
71
  ### Updating an existing monitor
72
+ - use [datadog monitor UI](https://app.datadoghq.com/monitors#create/metric) to find a monitor
73
+ - get the `id` from the url
74
+ - run `RESOURCE=monitor ID=12345 bundle exec rake kennel:import` and copy the output
70
75
  - find or create a project in `projects/`
71
- - add a monitor to `parts: [` list
76
+ - add the monitor to `parts: [` list, for example:
72
77
  ```Ruby
73
78
  # projects/my_project.rb
74
79
  class MyProject < Kennel::Models::Project
@@ -83,7 +88,8 @@ end
83
88
  kennel_id: -> { "load-too-high" }, # make up a unique name
84
89
  name: -> { "Foobar Load too high" }, # nice descriptive name that will show up in alerts and emails
85
90
  message: -> {
86
- # Explain what behavior to expect and how to fix the cause. Use #{super()} to add team notifications.
91
+ # Explain what behavior to expect and how to fix the cause
92
+ # Use #{super()} to add team notifications.
87
93
  <<~TEXT
88
94
  Foobar will be slow and that could cause Barfoo to go down.
89
95
  Add capacity or debug why it is suddenly slow.
@@ -98,21 +104,22 @@ end
98
104
  )
99
105
  end
100
106
  ```
101
- - `bundle exec rake plan` update to existing should be shown (not Create / Delete)
102
- - alternatively: `bundle exec rake generate` to only update the generated `json` files
107
+ - run `PROJECT=my_project bundle exec rake plan`, an Update to the existing monitor should be shown (not Create / Delete)
108
+ - alternatively: `bundle exec rake generate` to only locally update the generated `json` files
103
109
  - review changes then `git commit`
104
110
  - make a PR ... get reviewed ... merge
105
111
  - datadog is updated by travis
106
112
 
107
113
  ### Adding a new dashboard
108
114
  - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to create a dashboard
109
- - get the `id` from the url
110
- - `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import`
111
115
  - see below
112
116
 
113
117
  ### Updating an existing dashboard
118
+ - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to find a dashboard
119
+ - get the `id` from the url
120
+ - run `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import` and copy the output
114
121
  - find or create a project in `projects/`
115
- - add a dashboard to `parts: [` list
122
+ - add a dashboard to `parts: [` list, for example:
116
123
  ```Ruby
117
124
  class MyProject < Kennel::Models::Project
118
125
  defaults(
@@ -172,6 +179,10 @@ To link to existing monitors via their kennel_id
172
179
 
173
180
  Run `rake kennel:alerts TAG=service:my-service` to see all un-muted alerts for a given datadog monitor tag.
174
181
 
182
+ ### Validating mentions work
183
+
184
+ `rake kennel:validate_mentions` should run as part of CI
185
+
175
186
  ## Examples
176
187
 
177
188
  ### Reusable monitors/dashes/etc
@@ -196,7 +207,7 @@ Reuse it in multiple projects.
196
207
  ```Ruby
197
208
  class Database < Kennel::Models::Project
198
209
  defaults(
199
- team: -> { Kennel::Models::Team.new(slack: -> { 'foo' }, kennel_id: -> { 'foo' }) },
210
+ team: -> { Kennel::Models::Team.new(mention: -> { '@slack-foo' }, kennel_id: -> { 'foo' }) },
200
211
  parts: -> { [Monitors::LoadTooHigh.new(self, critical: -> { 13 })] }
201
212
  )
202
213
  end
@@ -15,7 +15,7 @@ module Kennel
15
15
  evaluation_delay: nil,
16
16
  new_host_delay: 300,
17
17
  timeout_h: 0,
18
- renotify_interval: 120,
18
+ renotify_interval: 0,
19
19
  no_data_timeframe: nil # this works out ok since if notify_no_data is on, it would never be nil
20
20
  }.freeze
21
21
  DEFAULT_ESCALATION_MESSAGE = ["", nil].freeze
@@ -27,9 +27,9 @@ module Kennel
27
27
  )
28
28
 
29
29
  defaults(
30
- message: -> { "\n\n@slack-#{project.slack}" },
30
+ message: -> { "\n\n#{project.mention}" },
31
31
  escalation_message: -> { DEFAULT_ESCALATION_MESSAGE.first },
32
- renotify_interval: -> { MONITOR_OPTION_DEFAULTS.fetch(:renotify_interval) },
32
+ renotify_interval: -> { project.team.renotify_interval },
33
33
  warning: -> { nil },
34
34
  ok: -> { nil },
35
35
  id: -> { nil },
@@ -2,10 +2,10 @@
2
2
  module Kennel
3
3
  module Models
4
4
  class Project < Base
5
- settings :team, :parts, :tags, :slack
5
+ settings :team, :parts, :tags, :mention
6
6
  defaults(
7
7
  tags: -> { ["service:#{kennel_id}"] + team.tags },
8
- slack: -> { team.slack }
8
+ mention: -> { team.mention }
9
9
  )
10
10
 
11
11
  def self.file_location
@@ -2,19 +2,11 @@
2
2
  module Kennel
3
3
  module Models
4
4
  class Team < Base
5
- settings :slack, :email, :tags, :kennel_id
5
+ settings :mention, :tags, :renotify_interval, :kennel_id
6
6
  defaults(
7
- tags: -> { ["team:#{kennel_id.sub(/^teams_/, "")}"] }
7
+ tags: -> { ["team:#{kennel_id.sub(/^teams_/, "")}"] },
8
+ renotify_interval: -> { 0 }
8
9
  )
9
-
10
- def initialize(*)
11
- super
12
- invalid! "remove leading # from slack" if slack.to_s.start_with?("#")
13
- end
14
-
15
- def tracking_id
16
- kennel_id
17
- end
18
10
  end
19
11
  end
20
12
  end
data/lib/kennel/tasks.rb CHANGED
@@ -12,6 +12,36 @@ namespace :kennel do
12
12
  abort "Error during diffing" unless $CHILD_STATUS.success?
13
13
  end
14
14
 
15
+ # ideally do this on every run, but it's slow (~1.5s) and brittle (might not find all + might find false-positives)
16
+ # https://help.datadoghq.com/hc/en-us/requests/254114 for automatic validation
17
+ desc "Verify that all used monitor mentions are valid"
18
+ task validate_mentions: :environment do
19
+ known = Kennel.send(:api)
20
+ .send(:request, :get, "/monitor/notifications")
21
+ .fetch(:handles)
22
+ .values
23
+ .flatten(1)
24
+ .map { |v| v.fetch(:value) }
25
+
26
+ known += ENV["KNOWN"].to_s.split(",")
27
+
28
+ bad = []
29
+ Dir["generated/**/*.json"].each do |f|
30
+ next unless message = JSON.parse(File.read(f))["message"]
31
+ used = message.scan(/\s(@[^\s{,'"]+)/).flatten(1)
32
+ .grep(/^@.*@|^@.*-/) # ignore @here etc handles ... datadog uses @foo@bar.com for emails and @foo-bar for integrations
33
+ (used - known).each { |v| bad << [f, v] }
34
+ end
35
+
36
+ if bad.any?
37
+ subdomain = ENV["DATADOG_SUBDOMAIN"]
38
+ url = (subdomain ? "https://zendesk.datadoghq.com" : "") + "/account/settings"
39
+ puts "Invalid mentions found, either ignore them by adding to `KNOWN` env var or add them via #{url}"
40
+ bad.each { |f, v| puts "Invalid mention #{v} in monitor message of #{f}" }
41
+ abort
42
+ end
43
+ end
44
+
15
45
  desc "generate local definitions"
16
46
  task generate: :environment do
17
47
  Kennel.generate
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.52.0"
3
+ VERSION = "1.55.1"
4
4
  end
data/template/Readme.md CHANGED
@@ -25,18 +25,22 @@ Keep datadog monitors/dashboards/etc in version control, avoid chaotic managemen
25
25
  - `gem install bundler && bundle install`
26
26
  - `cp .env.example .env`
27
27
  - open [Datadog API Settings](https://app.datadoghq.com/account/settings#api)
28
- - find or create your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=` (will be on the last page if new)
29
28
  - copy any `API Key` and add it to `.env` as `DATADOG_API_KEY`
29
+ - find or create (check last page) your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=`
30
+ - change the `DATADOG_SUBDOMAIN=app` in `.env` to your companies subdomain if you have one
30
31
 
31
32
  ### Adding a team
32
33
 
34
+ - `mention` is used for all team monitors via `super()`
35
+ - `renotify_interval` is used for all team monitors (defaults to `0` / off)
36
+ - `tags` is used for all team monitors/dashboards (defaults to `team:<team-name>`)
37
+
33
38
  ```Ruby
34
39
  # teams/my_team.rb
35
40
  module Teams
36
41
  class MyTeam < Kennel::Models::Team
37
42
  defaults(
38
- slack: -> { "my-alerts" },
39
- email: -> { "my-team@example.com" }
43
+ mention: -> { "@slack-my-team" }
40
44
  )
41
45
  end
42
46
  end
@@ -44,13 +48,14 @@ end
44
48
 
45
49
  ### Adding a new monitor
46
50
  - use [datadog monitor UI](https://app.datadoghq.com/monitors#create/metric) to create a monitor
47
- - get the `id` from the url
48
- - `RESOURCE=monitor ID=12345 bundle exec rake kennel:import`
49
51
  - see below
50
52
 
51
53
  ### Updating an existing monitor
54
+ - use [datadog monitor UI](https://app.datadoghq.com/monitors#create/metric) to find a monitor
55
+ - get the `id` from the url
56
+ - run `RESOURCE=monitor ID=12345 bundle exec rake kennel:import` and copy the output
52
57
  - find or create a project in `projects/`
53
- - add a monitor to `parts: [` list
58
+ - add the monitor to `parts: [` list, for example:
54
59
  ```Ruby
55
60
  # projects/my_project.rb
56
61
  class MyProject < Kennel::Models::Project
@@ -65,7 +70,8 @@ end
65
70
  kennel_id: -> { "load-too-high" }, # make up a unique name
66
71
  name: -> { "Foobar Load too high" }, # nice descriptive name that will show up in alerts and emails
67
72
  message: -> {
68
- # Explain what behavior to expect and how to fix the cause. Use #{super()} to add team notifications.
73
+ # Explain what behavior to expect and how to fix the cause
74
+ # Use #{super()} to add team notifications.
69
75
  <<~TEXT
70
76
  Foobar will be slow and that could cause Barfoo to go down.
71
77
  Add capacity or debug why it is suddenly slow.
@@ -80,21 +86,22 @@ end
80
86
  )
81
87
  end
82
88
  ```
83
- - `bundle exec rake plan` update to existing should be shown (not Create / Delete)
84
- - alternatively: `bundle exec rake generate` to only update the generated `json` files
89
+ - run `PROJECT=my_project bundle exec rake plan`, an Update to the existing monitor should be shown (not Create / Delete)
90
+ - alternatively: `bundle exec rake generate` to only locally update the generated `json` files
85
91
  - review changes then `git commit`
86
92
  - make a PR ... get reviewed ... merge
87
93
  - datadog is updated by travis
88
94
 
89
95
  ### Adding a new dashboard
90
96
  - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to create a dashboard
91
- - get the `id` from the url
92
- - `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import`
93
97
  - see below
94
98
 
95
99
  ### Updating an existing dashboard
100
+ - go to [datadog dashboard UI](https://app.datadoghq.com/dashboard/lists) and click on _New Dashboard_ to find a dashboard
101
+ - get the `id` from the url
102
+ - run `RESOURCE=dashboard ID=abc-def-ghi bundle exec rake kennel:import` and copy the output
96
103
  - find or create a project in `projects/`
97
- - add a dashboard to `parts: [` list
104
+ - add a dashboard to `parts: [` list, for example:
98
105
  ```Ruby
99
106
  class MyProject < Kennel::Models::Project
100
107
  defaults(
@@ -142,6 +149,7 @@ To link to existing monitors via their kennel_id
142
149
 
143
150
  - Screens `uptime` widgets can use `monitor: {id: "foo:bar"}`
144
151
  - Screens `alert_graph` widgets can use `alert_id: "foo:bar"`
152
+ - Monitors `composite` can use `query: -> { "%{foo:bar} || %{foo:baz}" }`
145
153
 
146
154
  ### Debugging changes locally
147
155
 
@@ -177,7 +185,7 @@ Reuse it in multiple projects.
177
185
  ```Ruby
178
186
  class Database < Kennel::Models::Project
179
187
  defaults(
180
- team: -> { Kennel::Models::Team.new(slack: -> { 'foo' }, kennel_id: -> { 'foo' }) },
188
+ team: -> { Kennel::Models::Team.new(mention: -> { '@slack-foo' }, kennel_id: -> { 'foo' }) },
181
189
  parts: -> { [Monitors::LoadTooHigh.new(self, critical: -> { 13 })] }
182
190
  )
183
191
  end
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.52.0
4
+ version: 1.55.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: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2019-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday