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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 491e174273f8af94504a4e81d9a2ff7da5820aafe287ea9cb1e78df93d07f0f0
4
- data.tar.gz: bf918b4be464d408259e0f8204541a0619d1719670a9843a6e564cc4edc968d1
3
+ metadata.gz: 7b74c28c8a837145770672b8838930861f8c70355fe32132a234addfc6764f8c
4
+ data.tar.gz: 896986fa0d5db196515468a6d6b0d81d3cfdd160f65a9616de128f5dad7d1014
5
5
  SHA512:
6
- metadata.gz: 6ff9000e02764618a7e08c7349f315737778ff7afadf8ca303b7dda8db5648d2bd966412a255e7987ebd2416f8bfd264c3c2979bf143ed0d1f6fdd1a759fc85f
7
- data.tar.gz: daf144b7fc436cfb317c4cc298dbbd62d61d252b554261746ed00bcaf5279422bf1a4ab185d45c57974665bc38ebbbf61d0b8e28d8269225c011beb11a451d67
6
+ metadata.gz: ee5e20d4bc534fc6164ae2da424e59f71266ce6af567d3f55ba047c17eac987af57aec87d5888f0b4f4f4742b818d1ffe612309895689896f1b713428d0defce
7
+ data.tar.gz: dc1b244a0542b0dc304981450331bbd46b4f0c2961afb072196a000841bb5c32b4467ec2ba45c141570b4a10d37f66cda2a729dd14948515717314d0fe54268b
@@ -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"
@@ -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)
@@ -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
@@ -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
@@ -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
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
- # 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]
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) # 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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.56.0"
3
+ VERSION = "1.57.0"
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.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-10-03 00:00:00.000000000 Z
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