kennel 1.56.0 → 1.57.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kennel.rb +2 -1
- data/lib/kennel/api.rb +4 -2
- data/lib/kennel/importer.rb +3 -1
- data/lib/kennel/models/dashboard.rb +12 -0
- data/lib/kennel/models/monitor.rb +0 -2
- data/lib/kennel/models/record.rb +1 -1
- data/lib/kennel/models/slo.rb +71 -0
- data/lib/kennel/syncer.rb +19 -19
- data/lib/kennel/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b74c28c8a837145770672b8838930861f8c70355fe32132a234addfc6764f8c
|
4
|
+
data.tar.gz: 896986fa0d5db196515468a6d6b0d81d3cfdd160f65a9616de128f5dad7d1014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee5e20d4bc534fc6164ae2da424e59f71266ce6af567d3f55ba047c17eac987af57aec87d5888f0b4f4f4742b818d1ffe612309895689896f1b713428d0defce
|
7
|
+
data.tar.gz: dc1b244a0542b0dc304981450331bbd46b4f0c2961afb072196a000841bb5c32b4467ec2ba45c141570b4a10d37f66cda2a729dd14948515717314d0fe54268b
|
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
|
@@ -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
|
@@ -101,8 +101,6 @@ module Kennel
|
|
101
101
|
@as_json = data
|
102
102
|
end
|
103
103
|
|
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
104
|
def resolve_linked_tracking_ids(id_map)
|
107
105
|
if as_json[:type] == "composite"
|
108
106
|
as_json[:query] = as_json[:query].gsub(/%\{(.*?)\}/) do
|
data/lib/kennel/models/record.rb
CHANGED
@@ -5,7 +5,7 @@ module Kennel
|
|
5
5
|
LOCK = "\u{1F512}"
|
6
6
|
READONLY_ATTRIBUTES = [
|
7
7
|
:deleted, :matching_downtimes, :id, :created, :created_at, :creator, :org_id, :modified,
|
8
|
-
:overall_state_modified, :overall_state, :api_resource
|
8
|
+
:modified_at, :overall_state_modified, :overall_state, :api_resource
|
9
9
|
].freeze
|
10
10
|
REQUEST_DEFAULTS = {
|
11
11
|
style: { width: "normal", palette: "dog_classic", type: "solid" },
|
@@ -0,0 +1,71 @@
|
|
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
|
+
API_LIST_INCOMPLETE = false
|
7
|
+
DEFAULTS = {
|
8
|
+
description: nil,
|
9
|
+
query: nil,
|
10
|
+
monitor_ids: []
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
settings :id, :type, :description, :thresholds, :query, :tags, :monitor_ids, :monitor_tags, :kennel_id, :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
|
+
)
|
22
|
+
|
23
|
+
def as_json
|
24
|
+
return @as_json if @as_json
|
25
|
+
data = {
|
26
|
+
name: "#{name}#{LOCK}",
|
27
|
+
description: description,
|
28
|
+
thresholds: thresholds,
|
29
|
+
monitor_ids: monitor_ids,
|
30
|
+
tags: tags,
|
31
|
+
type: type
|
32
|
+
}
|
33
|
+
|
34
|
+
data[:query] = query if query
|
35
|
+
data[:id] = id if id
|
36
|
+
|
37
|
+
@as_json = data
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.api_resource
|
41
|
+
"slo"
|
42
|
+
end
|
43
|
+
|
44
|
+
def url(id)
|
45
|
+
Utils.path_to_url "/slo?slo_id=#{id}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def resolve_linked_tracking_ids(id_map)
|
49
|
+
as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
|
50
|
+
id.is_a?(String) ? resolve_link(id, id_map, force: true) : id
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.normalize(expected, actual)
|
55
|
+
super
|
56
|
+
|
57
|
+
# remove readonly values
|
58
|
+
actual[:thresholds]&.each do |threshold|
|
59
|
+
threshold.delete(:warning_display)
|
60
|
+
threshold.delete(:target_display)
|
61
|
+
end
|
62
|
+
|
63
|
+
# tags come in a semi-random order and order is never updated
|
64
|
+
expected[:tags]&.sort!
|
65
|
+
actual[:tags].sort!
|
66
|
+
|
67
|
+
ignore_default(expected, actual, DEFAULTS)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
[nil, a]
|
81
|
-
end
|
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]
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
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]
|
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) #
|
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/version.rb
CHANGED
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.57.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: 2019-
|
11
|
+
date: 2019-11-12 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
|