kennel 1.78.1 → 1.78.2

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: d12735939d42da2f660773d9ca734a279fdc5c29b6619f6722b163f07f299236
4
- data.tar.gz: 14f40ae5314abc2ff5b58672ad096a9d1898b793c1dee490a45d9deefc67e513
3
+ metadata.gz: 404c565dc87a8ffd30f1c0293228cc5270bedd3c6e5eaae1d191ba6cdae60ce7
4
+ data.tar.gz: 274f807772d6077c625a503aeb3d98edeef795bf0d7c40845db56d7b2e2e2ff0
5
5
  SHA512:
6
- metadata.gz: b5340adfc8b564f648caa8f656b8b10fe9cd48177a6b15e21944adac24209344aeb81aa0bc5190e7a5997e8ebc0dc49af0304daf947abf99112dc8d56f6a9485
7
- data.tar.gz: 368fb6dffbc42be889f8692b876e867818cde5eefd04b982151efc7d9dc74a378a046f12a7764f448df5818ebca950e55f22e36d45822c68ed3e8a3442850162
6
+ metadata.gz: b165262ab6d8f6e8efadff786d3829a75e96d6893e4235eed961ef5203c66d0f250488e7911964a77c2862df0e196e08619582ce9cda51fed851141785a0a9c4
7
+ data.tar.gz: ab59bfdd4ca2d73526fb28126fd1f18765ce92703d7bad71c05d7f321f54fa39192db87ad4a7ae65c12441e38eb794264bceae8aad57be84e30a2c06ac65b3f5
@@ -178,7 +178,7 @@ module Kennel
178
178
  def validate_json(data)
179
179
  super
180
180
 
181
- validate_template_variables data, :widgets
181
+ validate_template_variables data
182
182
 
183
183
  # Avoid diff from datadog presets sorting.
184
184
  presets = data[:template_variable_presets]
@@ -209,7 +209,10 @@ module Kennel
209
209
  .map! { |w| %("#{w}.name") }
210
210
  used.uniq.each do |match, group|
211
211
  next if allowed.include?(group)
212
- invalid! "#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. Add more groupings or fix the #{match}"
212
+ invalid!(
213
+ "#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. " \
214
+ "Group the query by #{group.sub(".name", "").tr('"', "")} or change the #{match}"
215
+ )
213
216
  end
214
217
  end
215
218
  end
@@ -16,18 +16,22 @@ module Kennel
16
16
 
17
17
  # check for queries that do not use the variables and would be misleading
18
18
  # TODO: do the same check for apm_query and their group_by
19
- def validate_template_variables(data, key)
19
+ def validate_template_variables(data)
20
20
  variables = (data[:template_variables] || []).map { |v| "$#{v.fetch(:name)}" }
21
- queries = data[key].flat_map do |widget|
21
+ return if variables.empty?
22
+
23
+ queries = data[:widgets].flat_map do |widget|
22
24
  ([widget] + (widget.dig(:definition, :widgets) || [])).flat_map { |w| widget_queries(w) }
23
25
  end.compact
24
- bad = queries.grep_v(/(#{variables.map { |v| Regexp.escape(v) }.join("|")})\b/)
25
- if bad.any?
26
- invalid!(
27
- "queries #{bad.join(", ")} must use the template variables #{variables.join(", ")}\n" \
28
- "If that is not possible, add `validate: -> { false } # query foo in bar does not have baz tag`"
29
- )
30
- end
26
+
27
+ matches = variables.map { |v| Regexp.new "#{Regexp.escape(v)}\\b" }
28
+ queries.reject! { |q| matches.all? { |m| q.match? m } }
29
+ return if queries.empty?
30
+
31
+ invalid!(
32
+ "queries #{queries.join(", ")} must use the template variables #{variables.join(", ")}\n" \
33
+ "If that is not possible, add `validate: -> { false } # query foo in bar does not have baz tag`"
34
+ )
31
35
  end
32
36
 
33
37
  def widget_queries(widget)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.78.1"
3
+ VERSION = "1.78.2"
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.78.1
4
+ version: 1.78.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday