kennel 1.26.1 → 1.27.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: b53e1cf9ac40c2103047f10ba9c8abccbff06fcc21bff9af67e15ea3966193bf
4
- data.tar.gz: 52726d8b021ffb2100ad9689d17a129523171e2ca5951a3a2248139f703e4391
3
+ metadata.gz: 0e5b0226f92f89c176e7591b3f3f1dc5fbccce47c540f28110d5860416b33e17
4
+ data.tar.gz: 1cdc34e2b90c0e99381d275747742661bc0828a649701f4490673e788d47341b
5
5
  SHA512:
6
- metadata.gz: e98d4ce043700352cad069feb58217b889a4cf4bca1f12396f20a9cdc812af92eb64871458814775e3bd2f6929e7cf0a7d3150262a0211502937332e587f9b96
7
- data.tar.gz: 146d9e9d4cf7b1d0c10d5707f83a2670f5f5d6deb5188c62c0c4e514be68ce950c0981fca2b0225a9fef56e280b3a6168bd07d0120f6aeedb829bfb520dc98fe
6
+ metadata.gz: 0af7a3063ed49c51634c0fec06e1b6749bc8aa30857f2c2135376c80799a10856ae44acc27fc91ddf21500f1e4069396cdcc886365291c789a35f459236cc0ac
7
+ data.tar.gz: 249d02adb861130b88ea1ad17e26f5b19ca95fb729c3b3af4ae7f473a5b6e65198faa57431670e54079289aa0f6497eab1917b1fdbbba996bed568bc25b8df01
@@ -33,13 +33,18 @@ module Kennel
33
33
  params = params.merge(application_key: @app_key, api_key: @api_key)
34
34
  query = Faraday::FlatParamsEncoder.encode(params)
35
35
  response = nil
36
+ tries = 2
36
37
 
37
- 2.times do |i|
38
- response = @client.send(method, "#{path}?#{query}") do |request|
39
- request.body = JSON.generate(body) if body
40
- request.headers["Content-type"] = "application/json"
38
+ tries.times do |i|
39
+ response = Utils.retry Faraday::ConnectionFailed, times: 2 do
40
+ @client.send(method, "#{path}?#{query}") do |request|
41
+ request.body = JSON.generate(body) if body
42
+ request.headers["Content-type"] = "application/json"
43
+ end
41
44
  end
42
- break if i == 1 || method != :get || response.status < 500
45
+
46
+ break if i == tries - 1 || method != :get || response.status < 500
47
+ Kennel.err.puts "Retrying on server error #{response.status} for #{path}"
43
48
  end
44
49
 
45
50
  unless response.success?
@@ -70,6 +70,8 @@ module Kennel
70
70
  private
71
71
 
72
72
  def validate_json(data)
73
+ super
74
+
73
75
  # check for bad variables
74
76
  # TODO: do the same check for apm_query and their group_by
75
77
  variables = (data[:template_variables] || []).map { |v| "$#{v.fetch(:name)}" }
@@ -151,6 +151,8 @@ module Kennel
151
151
  end
152
152
 
153
153
  def validate_json(data)
154
+ super
155
+
154
156
  type = data.fetch(:type)
155
157
 
156
158
  # do not allow deprecated type that will be coverted by datadog and then produce a diff
@@ -100,6 +100,8 @@ module Kennel
100
100
  private
101
101
 
102
102
  def validate_json(data)
103
+ super
104
+
103
105
  # check for fields that are unsettable
104
106
  data[:widgets].each do |w|
105
107
  COPIED_WIDGET_VALUES.each do |ignored|
@@ -5,5 +5,22 @@ module Kennel
5
5
  base.settings :validate
6
6
  base.defaults(validate: -> { true })
7
7
  end
8
+
9
+ # https://stackoverflow.com/questions/20235206/ruby-get-all-keys-in-a-hash-including-sub-keys/53876255#53876255
10
+ def self.all_keys(items)
11
+ case items
12
+ when Hash then items.keys + items.values.flat_map { |v| all_keys(v) }
13
+ when Array then items.flat_map { |i| all_keys(i) }
14
+ else []
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def validate_json(data)
21
+ bad = OptionalValidations.all_keys(data).grep_v(Symbol)
22
+ return if bad.empty?
23
+ invalid! "only use Symbols to avoid permanent diffs (#{bad.map(&:inspect).join(", ")})"
24
+ end
8
25
  end
9
26
  end
@@ -114,6 +114,15 @@ module Kennel
114
114
  def natural_order(name)
115
115
  name.split(/(\d+)/).each_with_index.map { |x, i| i.odd? ? x.to_i : x }
116
116
  end
117
+
118
+ def retry(*errors, times:)
119
+ yield
120
+ rescue *errors => e
121
+ times -= 1
122
+ raise if times < 0
123
+ Kennel.err.puts "Error #{e}, #{times} retries left"
124
+ retry
125
+ end
117
126
  end
118
127
  end
119
128
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.26.1"
3
+ VERSION = "1.27.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.26.1
4
+ version: 1.27.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: 2018-12-14 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday