checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA256:
3
- metadata.gz: 491e174273f8af94504a4e81d9a2ff7da5820aafe287ea9cb1e78df93d07f0f0
4
- data.tar.gz: bf918b4be464d408259e0f8204541a0619d1719670a9843a6e564cc4edc968d1
3
+ metadata.gz: ef549d9d676c1901f184a65c88313dd7ad3146390f1801ae530b4028d280e60e
4
+ data.tar.gz: 0ff01feab2d2da87bc51b6f5bfb5ff8a2a947a950214b627ca09c81ca89ea347
5
5
SHA512:
6
- metadata.gz: 6ff9000e02764618a7e08c7349f315737778ff7afadf8ca303b7dda8db5648d2bd966412a255e7987ebd2416f8bfd264c3c2979bf143ed0d1f6fdd1a759fc85f
7
- data.tar.gz: daf144b7fc436cfb317c4cc298dbbd62d61d252b554261746ed00bcaf5279422bf1a4ab185d45c57974665bc38ebbbf61d0b8e28d8269225c011beb11a451d67
6
+ metadata.gz: 1ba3c81e8c16f0fe11bc91b29bc40f9086cba82c5fa18cda2f0f00500c0b7a3a85d3bddf405f3081b718711040c3891d81008a364668af6c98eb343da05e7515
7
+ data.tar.gz: dd8c7dbed5e32a3c8e690fd42e6db8252bfd30727398b933d9013d9d7ce4a3da5f997d8c8ade339aac4969eecf5f22c8b520b813bc17a489a6ddb126ff8f9588
data/lib/kennel.rb CHANGED
@@ -20,8 +20,9 @@ require "kennel/models/base"
20
20
require "kennel/models/record"
21
21
22
22
# records
23
- require "kennel/models/monitor"
24
23
require "kennel/models/dashboard"
24
+ require "kennel/models/monitor"
25
+ require "kennel/models/slo"
25
26
26
27
# settings
27
28
require "kennel/models/project"
data/lib/kennel/api.rb CHANGED
@@ -8,7 +8,8 @@ module Kennel
8
8
end
9
9
10
10
def show(api_resource, id, params = {})
11
- request :get, "/api/v1/#{api_resource}/#{id}", params: params
11
+ reply = request :get, "/api/v1/#{api_resource}/#{id}", params: params
12
+ api_resource == "slo" ? reply[:data] : reply
12
13
end
13
14
14
15
def list(api_resource, params = {})
@@ -16,7 +17,8 @@ module Kennel
16
17
end
17
18
18
19
def create(api_resource, attributes)
19
- request :post, "/api/v1/#{api_resource}", body: attributes
20
+ reply = request :post, "/api/v1/#{api_resource}", body: attributes
21
+ api_resource == "slo" ? reply[:data].first : reply
20
22
end
21
23
22
24
def update(api_resource, id, attributes)
data/lib/kennel/importer.rb CHANGED
@@ -107,7 +107,9 @@ module Kennel
107
107
108
108
"\n#{pretty}\n "
109
109
elsif k == :message
110
- "\n <<~TEXT\n#{v.each_line.map { |l| l.strip.empty? ? "\n" : " #{l}" }.join}\n TEXT\n "
110
+ "\n <<~TEXT\n#{v.each_line.map { |l| l.strip.empty? ? "\n" : " #{l}" }.join}\n \#{super()}\n TEXT\n "
111
+ elsif k == :tags
112
+ " super() + #{v.inspect} "
111
113
else
112
114
" #{v.inspect} "
113
115
end
data/lib/kennel/models/dashboard.rb CHANGED
@@ -15,7 +15,7 @@ module Kennel
15
15
}.freeze
16
16
SUPPORTED_DEFINITION_OPTIONS = [:events, :markers, :precision].freeze
17
17
18
- settings :id, :title, :description, :definitions, :widgets, :kennel_id, :layout_type
18
+ settings :title, :description, :definitions, :widgets, :layout_type
19
19
20
20
defaults(
21
21
description: -> { "" },
@@ -33,6 +33,14 @@ module Kennel
33
33
super
34
34
35
35
base_pairs(expected, actual).each do |pair|
36
+ # datadog always adds 2 to slo widget height
37
+ # need to check fir layout since some monitors have height/width in their definition
38
+ pair.dig(1, :widgets)&.each do |widget|
39
+ if widget.dig(:definition, :type) == "slo" && widget.dig(:layout, :height)
40
+ widget[:layout][:height] -= 2
41
+ end
42
+ end
43
+
36
44
# conditional_formats ordering is randomly changed by datadog, compare a stable ordering
37
45
pair.each do |b|
38
46
b[:widgets]&.each do |w|
@@ -100,6 +108,10 @@ module Kennel
100
108
if (id = definition[:alert_id]) && tracking_id?(id)
101
109
definition[:alert_id] = resolve_link(id, id_map, force: false).to_s
102
110
end
111
+ when "slo"
112
+ if (id = definition[:slo_id]) && tracking_id?(id)
113
+ definition[:slo_id] = resolve_link(id, id_map, force: false).to_s
114
+ end
103
115
end
104
116
end
105
117
end
data/lib/kennel/models/monitor.rb CHANGED
@@ -4,11 +4,12 @@ module Kennel
4
4
class Monitor < Record
5
5
include OptionalValidations
6
6
7
- API_LIST_INCOMPLETE = false
8
7
RENOTIFY_INTERVALS = [0, 10, 20, 30, 40, 50, 60, 90, 120, 180, 240, 300, 360, 720, 1440].freeze # minutes
9
8
QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "1d"].freeze
10
9
OPTIONAL_SERVICE_CHECK_THRESHOLDS = [:ok, :warning].freeze
11
- READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [:multi]
10
+ READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [
11
+ :multi, :matching_downtimes, :overall_state_modified, :overall_state
12
+ ]
12
13
13
14
# defaults that datadog uses when options are not sent, so safe to leave out if our values match their defaults
14
15
MONITOR_OPTION_DEFAULTS = {
@@ -21,8 +22,8 @@ module Kennel
21
22
DEFAULT_ESCALATION_MESSAGE = ["", nil].freeze
22
23
23
24
settings(
24
- :query, :name, :message, :escalation_message, :critical, :kennel_id, :type, :renotify_interval, :warning, :timeout_h, :evaluation_delay,
25
- :ok, :id, :no_data_timeframe, :notify_no_data, :notify_audit, :tags, :critical_recovery, :warning_recovery, :require_full_window,
25
+ :query, :name, :message, :escalation_message, :critical, :type, :renotify_interval, :warning, :timeout_h, :evaluation_delay,
26
+ :ok, :no_data_timeframe, :notify_no_data, :notify_audit, :tags, :critical_recovery, :warning_recovery, :require_full_window,
26
27
:threshold_windows, :new_host_delay
27
28
)
28
29
@@ -101,8 +102,6 @@ module Kennel
101
102
@as_json = data
102
103
end
103
104
104
- # resolve composite monitors ... only works when referenced monitors already exist
105
- # since leaving names or bad ids in the query breaks the monitor update
106
105
def resolve_linked_tracking_ids(id_map)
107
106
if as_json[:type] == "composite"
108
107
as_json[:query] = as_json[:query].gsub(/%\{(.*?)\}/) do
data/lib/kennel/models/record.rb CHANGED
@@ -4,18 +4,20 @@ module Kennel
4
4
class Record < Base
5
5
LOCK = "\u{1F512}"
6
6
READONLY_ATTRIBUTES = [
7
- :deleted, :matching_downtimes, :id, :created, :created_at, :creator, :org_id, :modified,
7
+ :deleted, :id, :created, :created_at, :creator, :org_id, :modified, :modified_at, :api_resource
8
- :overall_state_modified, :overall_state, :api_resource
9
8
].freeze
10
9
REQUEST_DEFAULTS = {
11
10
style: { width: "normal", palette: "dog_classic", type: "solid" },
12
11
conditional_formats: [],
13
12
aggregator: "avg"
14
13
}.freeze
14
+ API_LIST_INCOMPLETE = false
15
15
16
16
class ValidationError < RuntimeError
17
17
end
18
18
19
+ settings :id, :kennel_id
20
+
19
21
class << self
20
22
private
21
23
@@ -56,6 +58,7 @@ module Kennel
56
58
attr_reader :project
57
59
58
60
def initialize(project, *args)
61
+ raise ArgumentError, "First argument must be a project, not #{project.class}" unless project.is_a?(Project)
59
62
@project = project
60
63
super(*args)
61
64
end
data/lib/kennel/models/slo.rb ADDED
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+ module Kennel
3
+ module Models
4
+ class Slo < Record
5
+ READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [:type_id, :monitor_tags]
6
+ DEFAULTS = {
7
+ description: nil,
8
+ query: nil,
9
+ monitor_ids: [],
10
+ thresholds: []
11
+ }.freeze
12
+
13
+ settings :type, :description, :thresholds, :query, :tags, :monitor_ids, :monitor_tags, :name
14
+
15
+ defaults(
16
+ id: -> { nil },
17
+ tags: -> { @project.tags },
18
+ query: -> { DEFAULTS.fetch(:query) },
19
+ description: -> { DEFAULTS.fetch(:description) },
20
+ monitor_ids: -> { DEFAULTS.fetch(:monitor_ids) },
21
+ thresholds: -> { DEFAULTS.fetch(:thresholds) }
22
+ )
23
+
24
+ def initialize(*)
25
+ super
26
+ if thresholds.any? { |t| t[:warning] && t[:warning].to_f <= t[:critical].to_f }
27
+ raise ValidationError, "Threshold warning must be greater-than critical value"
28
+ end
29
+ end
30
+
31
+ def as_json
32
+ return @as_json if @as_json
33
+ data = {
34
+ name: "#{name}#{LOCK}",
35
+ description: description,
36
+ thresholds: thresholds,
37
+ monitor_ids: monitor_ids,
38
+ tags: tags,
39
+ type: type
40
+ }
41
+
42
+ data[:query] = query if query
43
+ data[:id] = id if id
44
+
45
+ @as_json = data
46
+ end
47
+
48
+ def self.api_resource
49
+ "slo"
50
+ end
51
+
52
+ def url(id)
53
+ Utils.path_to_url "/slo?slo_id=#{id}"
54
+ end
55
+
56
+ def resolve_linked_tracking_ids(id_map)
57
+ as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
58
+ id.is_a?(String) ? resolve_link(id, id_map, force: false) || 1 : id
59
+ end
60
+ end
61
+
62
+ def self.normalize(expected, actual)
63
+ super
64
+
65
+ # remove readonly values
66
+ actual[:thresholds]&.each do |threshold|
67
+ threshold.delete(:warning_display)
68
+ threshold.delete(:target_display)
69
+ end
70
+
71
+ # tags come in a semi-random order and order is never updated
72
+ expected[:tags]&.sort!
73
+ actual[:tags].sort!
74
+
75
+ ignore_default(expected, actual, DEFAULTS)
76
+ end
77
+ end
78
+ end
79
+ end
data/lib/kennel/syncer.rb CHANGED
@@ -71,28 +71,28 @@ module Kennel
71
71
Progress.progress "Diffing" do
72
72
filter_by_project! actual
73
73
74
- details_cache do |cache|
75
- items = actual.map do |a|
76
- e = matching_expected(a)
77
- if e && @expected.delete(e)
78
- [e, a]
79
- else
74
+ items = actual.map do |a|
75
+ e = matching_expected(a)
76
+ if e && @expected.delete(e)
77
+ [e, a]
78
+ else
79
+ [nil, a]
80
- [nil, a]
81
- end
82
80
end
81
+ end
83
82
83
+ details_cache do |cache|
84
84
# fill details of things we need to compare (only do this part in parallel for safety & balancing)
85
85
Utils.parallel(items.select { |e, _| e && e.class::API_LIST_INCOMPLETE }) { |_, a| fill_details(a, cache) }
86
+ end
86
87
87
- # pick out things to update or delete
88
- items.each do |e, a|
89
- id = a.fetch(:id)
90
- if e
91
- diff = e.diff(a)
92
- @update << [id, e, a, diff] if diff.any?
93
- elsif tracking_id(a) # was previously managed
94
- @delete << [id, nil, a]
88
+ # pick out things to update or delete
89
+ items.each do |e, a|
90
+ id = a.fetch(:id)
91
+ if e
92
+ diff = e.diff(a)
93
+ @update << [id, e, a, diff] if diff.any?
94
+ elsif tracking_id(a) # was previously managed
95
+ @delete << [id, nil, a]
95
- end
96
96
end
97
97
end
98
98
@@ -113,7 +113,7 @@ module Kennel
113
113
114
114
# dashes are nested, others are not
115
115
def unnest(api_resource, result)
116
- result[api_resource.to_sym] || result
116
+ result[api_resource.to_sym] || result[:data] || result
117
117
end
118
118
119
119
def details_cache(&block)
@@ -124,7 +124,7 @@ module Kennel
124
124
def download_definitions
125
125
Utils.parallel(Models::Record.subclasses.map(&:api_resource)) do |api_resource|
126
126
results = @api.list(api_resource, with_downtimes: false) # lookup monitors without adding unnecessary downtime information
127
- results = results[results.keys.first] if results.is_a?(Hash) # dashes/screens are nested in {dash: {}}
127
+ results = results[results.keys.first] if results.is_a?(Hash) # dashboards are nested in {dashboards: []}
128
128
results.each { |c| c[:api_resource] = api_resource } # store api resource for later diffing
129
129
end.flatten(1)
130
130
end
data/lib/kennel/tasks.rb CHANGED
@@ -4,12 +4,23 @@ require "kennel"
4
4
require "kennel/unmuted_alerts"
5
5
require "kennel/importer"
6
6
7
+ module Kennel
8
+ module Tasks
9
+ class << self
10
+ def abort(message = nil)
11
+ Kennel.err.puts message if message
12
+ raise SystemExit, message
13
+ end
14
+ end
15
+ end
16
+ end
17
+
7
18
namespace :kennel do
8
19
desc "Ensure there are no uncommited changes that would be hidden from PR reviewers"
9
20
task no_diff: :generate do
10
21
result = `git status --porcelain`.strip
11
- abort "Diff found:\n#{result}\nrun `rake generate` and commit the diff to fix" unless result == ""
12
- abort "Error during diffing" unless $CHILD_STATUS.success?
22
+ Kennel::Tasks.abort "Diff found:\n#{result}\nrun `rake generate` and commit the diff to fix" unless result == ""
23
+ Kennel::Tasks.abort "Error during diffing" unless $CHILD_STATUS.success?
13
24
end
14
25
15
26
# ideally do this on every run, but it's slow (~1.5s) and brittle (might not find all + might find false-positives)
@@ -38,7 +49,7 @@ namespace :kennel do
38
49
url = (subdomain ? "https://zendesk.datadoghq.com" : "") + "/account/settings"
39
50
puts "Invalid mentions found, either ignore them by adding to `KNOWN` env var or add them via #{url}"
40
51
bad.each { |f, v| puts "Invalid mention #{v} in monitor message of #{f}" }
41
- abort
52
+ Kennel::Tasks.abort
42
53
end
43
54
end
44
55
@@ -76,16 +87,16 @@ namespace :kennel do
76
87
77
88
desc "show unmuted alerts filtered by TAG, for example TAG=team:foo"
78
89
task alerts: :environment do
79
- tag = ENV["TAG"] || abort("Call with TAG=foo:bar")
90
+ tag = ENV["TAG"] || Kennel::Tasks.abort("Call with TAG=foo:bar")
80
91
Kennel::UnmutedAlerts.print(Kennel.send(:api), tag)
81
92
end
82
93
83
94
desc "show monitors with no data by TAG, for example TAG=team:foo"
84
95
task nodata: :environment do
85
- tag = ENV["TAG"] || abort("Call with TAG=foo:bar")
96
+ tag = ENV["TAG"] || Kennel::Tasks.abort("Call with TAG=foo:bar")
86
97
monitors = Kennel.send(:api).list("monitor", monitor_tags: tag, group_states: "no data")
87
98
monitors.select! { |m| m[:overall_state] == "No Data" }
88
- monitors.reject! { |m| m[:tags].include? ["nodata:ignore"] }
99
+ monitors.reject! { |m| m[:tags].include? "nodata:ignore" }
89
100
if monitors.any?
90
101
Kennel.err.puts <<~TEXT
91
102
This is a useful task to find monitors that have mis-spelled metrics or never received data at any time.
@@ -103,8 +114,8 @@ namespace :kennel do
103
114
104
115
desc "Convert existing resources to copy-pastable definitions to import existing resources RESOURCE=dash ID=1234"
105
116
task import: :environment do
106
- resource = ENV["RESOURCE"] || abort("Call with RESOURCE=dash") # TODO: add others
107
- id = ENV["ID"] || abort("Call with ID=1234")
117
+ resource = ENV["RESOURCE"] || Kennel::Tasks.abort("Call with RESOURCE=dash") # TODO: add others
118
+ id = ENV["ID"] || Kennel::Tasks.abort("Call with ID=1234")
108
119
id = Integer(id) if id =~ /^\d+#x2F; # dashboards can have alphanumeric ids
109
120
puts Kennel::Importer.new(Kennel.send(:api)).import(resource, id)
110
121
end
data/lib/kennel/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
# frozen_string_literal: true
2
2
module Kennel
3
- VERSION = "1.56.0"
3
+ VERSION = "1.58.1"
4
4
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.56.0
4
+ version: 1.58.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-10-03 00:00:00.000000000 Z
11
+ date: 2019-11-25 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: faraday
@@ -69,6 +69,7 @@ files:
69
69
- lib/kennel/models/monitor.rb
70
70
- lib/kennel/models/project.rb
71
71
- lib/kennel/models/record.rb
72
+ - lib/kennel/models/slo.rb
72
73
- lib/kennel/models/team.rb
73
74
- lib/kennel/optional_validations.rb
74
75
- lib/kennel/progress.rb