kennel 1.51.0 → 1.52.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: cf65db42c0f1dbd43a7f2a6d0910a018565db65e431cea3c39b88d796b1ccce0
4
- data.tar.gz: 1d0db8fca3e1f1b9d4085ae1e783b2b6f28a0ae3682ba9b2b743612b1b71b5dc
3
+ metadata.gz: 7d34d639d4d27f3953211bc4f94f36d559b5ada87d3f289219bf611c8183805d
4
+ data.tar.gz: c531670c166981073648ae9e12f1ca6c47f27a5642a4b8abf0fc5890134bcead
5
5
  SHA512:
6
- metadata.gz: a774657cac63f4080d9767453ccf5e9c301aaaf2cae15486e26f87e54c851dc9246421cb6aa16f585a7311748dc6031ed6a65124c1cf01d19669ca1604ff78ab
7
- data.tar.gz: a922269b47847376d1287e42a06aed1fe4fdbab3c0a8f550f9983fe1d2823314c186e3f809dbb2ea607446d67fd6f168d28e113dd8f0d33428ead5979deae804
6
+ metadata.gz: 5e4f308f0076d4cc5f290c5041fc37a57a64986fb1d0ec586bf448b9293880fd42e67b6d6de60607369f2918efc7aeb87177fd7a27a1749ca272fdb2c5519d0f
7
+ data.tar.gz: e1852e1d4c0cceb841f73559ae248357ce5d1fdfe81e3d8a0a348374d2f1e6819befbc9fcdec0caae00cc72808430f91fd10d46b7dd88fe57b721faf55e1d882
data/Readme.md CHANGED
@@ -160,6 +160,7 @@ To link to existing monitors via their kennel_id
160
160
 
161
161
  - Screens `uptime` widgets can use `monitor: {id: "foo:bar"}`
162
162
  - Screens `alert_graph` widgets can use `alert_id: "foo:bar"`
163
+ - Monitors `composite` can use `query: -> { "%{foo:bar} || %{foo:baz}" }`
163
164
 
164
165
  ### Debugging changes locally
165
166
 
@@ -53,6 +53,9 @@ module Kennel
53
53
  if query && critical
54
54
  query.sub!(/([><=]) (#{Regexp.escape(critical.to_f.to_s)}|#{Regexp.escape(critical.to_i.to_s)})$/, "\\1 \#{critical}")
55
55
  end
56
+ elsif resource == "dashboard"
57
+ widgets = data[:widgets]&.flat_map { |widget| widget.dig(:definition, :widgets) || [widget] }
58
+ widgets&.each { |widget| dry_up_query!(widget) }
56
59
  end
57
60
 
58
61
  # simplify template_variables to array of string when possible
@@ -71,6 +74,20 @@ module Kennel
71
74
 
72
75
  private
73
76
 
77
+ # reduce duplication in imports by using dry `q: :metadata` when possible
78
+ def dry_up_query!(widget)
79
+ (widget.dig(:definition, :requests) || []).each do |request|
80
+ next unless request.is_a?(Hash)
81
+ next unless metadata = request[:metadata]
82
+ next unless query = request[:q]&.dup
83
+ metadata.each do |m|
84
+ next unless exp = m[:expression]
85
+ query.sub!(exp, "")
86
+ end
87
+ request[:q] = :metadata if query.delete(", ") == ""
88
+ end
89
+ end
90
+
74
91
  def pretty_print(hash)
75
92
  sort_widgets hash
76
93
 
@@ -84,6 +101,7 @@ module Kennel
84
101
  .gsub(/(^\s*)"([a-zA-Z][a-zA-Z\d_]*)":/, "\\1\\2:") # "foo": 1 -> foo: 1
85
102
  .gsub(/: \[\n\s+\]/, ": []") # empty arrays on a single line
86
103
  .gsub(/^/, " ") # indent
104
+ .gsub('q: "metadata"', "q: :metadata") # bring symbols back
87
105
 
88
106
  "\n#{pretty}\n "
89
107
  elsif k == :message
@@ -148,6 +148,13 @@ module Kennel
148
148
 
149
149
  private
150
150
 
151
+ def resolve_link(id, id_map, force:)
152
+ id_map[id] || begin
153
+ message = "Unable to find #{id} in existing monitors (they need to be created first to link them)"
154
+ force ? invalid!(message) : Kennel.err.puts(message)
155
+ end
156
+ end
157
+
151
158
  # let users know which project/resource failed when something happens during diffing where the backtrace is hidden
152
159
  def invalid!(message)
153
160
  raise ValidationError, "#{tracking_id} #{message}"
@@ -101,11 +101,13 @@ module Kennel
101
101
  case definition[:type]
102
102
  when "uptime"
103
103
  if ids = definition[:monitor_ids]
104
- definition[:monitor_ids] = ids.map { |id| resolve_link(id, id_map) }
104
+ definition[:monitor_ids] = ids.map do |id|
105
+ tracking_id?(id) ? resolve_link(id, id_map, force: false) : id
106
+ end
105
107
  end
106
108
  when "alert_graph"
107
- if id = definition[:alert_id]
108
- definition[:alert_id] = resolve_link(id, id_map).to_s
109
+ if (id = definition[:alert_id]) && tracking_id?(id)
110
+ definition[:alert_id] = resolve_link(id, id_map, force: false).to_s
109
111
  end
110
112
  end
111
113
  end
@@ -113,6 +115,10 @@ module Kennel
113
115
 
114
116
  private
115
117
 
118
+ def tracking_id?(id)
119
+ id.is_a?(String) && !id.match?(/\A\d+\z/)
120
+ end
121
+
116
122
  # creates queries from metadata to avoid having to keep q and expression in sync
117
123
  #
118
124
  # {q: :metadata, metadata: [{expression: "sum:bar", alias_name: "foo"}, ...], }
@@ -127,16 +133,6 @@ module Kennel
127
133
  end
128
134
  end
129
135
 
130
- def resolve_link(id, id_map)
131
- return id unless tracking_id?(id)
132
- id_map[id] ||
133
- Kennel.err.puts("Unable to find #{id} in existing monitors (they need to be created first to link them)")
134
- end
135
-
136
- def tracking_id?(id)
137
- id.is_a?(String) && !id.match?(/\A\d+\z/)
138
- end
139
-
140
136
  def validate_json(data)
141
137
  super
142
138
 
@@ -108,6 +108,16 @@ module Kennel
108
108
  @as_json = data
109
109
  end
110
110
 
111
+ # resolve composite monitors ... only works when referenced monitors already exist
112
+ # since leaving names or bad ids in the query breaks the monitor update
113
+ def resolve_linked_tracking_ids(id_map)
114
+ if as_json[:type] == "composite"
115
+ as_json[:query] = as_json[:query].gsub(/%\{(.*?)\}/) do
116
+ resolve_link($1, id_map, force: true)
117
+ end
118
+ end
119
+ end
120
+
111
121
  def self.api_resource
112
122
  "monitor"
113
123
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.51.0"
3
+ VERSION = "1.52.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.51.0
4
+ version: 1.52.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-08-23 00:00:00.000000000 Z
11
+ date: 2019-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday