kennel 2.22.2 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kennel/api.rb +3 -2
- data/lib/kennel/importer.rb +1 -1
- data/lib/kennel/models/monitor.rb +3 -1
- data/lib/kennel/models/project.rb +1 -1
- data/lib/kennel/models/slo.rb +7 -0
- data/lib/kennel/parts_serializer.rb +21 -7
- data/lib/kennel/template_variables.rb +15 -1
- data/lib/kennel/version.rb +1 -1
- data/lib/kennel.rb +8 -3
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7aa1a80ee02f8f528d79075c83293405c2cd1974534211bef8be52c2ec8c7a33
|
|
4
|
+
data.tar.gz: 869cdbdd20bbdc9d73562a675c37e86aae1c4343a0e008f2874545442b47396e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b279ef955d3f281245173826eb8d57a255dd1abae803f99ce8baf72edc4f622d613d3ec32c81f984a26f8be8e59b6b9cbfe6f2522ce94ff4ab72f5f7ec5ea907
|
|
7
|
+
data.tar.gz: f3dd35dc1ca45cf2fa3f7b14127da6febae75255488f66f3cf1b3a56873a7845848647322d2694d4c11126cb0ff685afa8b2bcafbc9a04fa142cf29eb438da34
|
data/lib/kennel/api.rb
CHANGED
|
@@ -103,10 +103,11 @@ module Kennel
|
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
# yield each widget with a key built from its
|
|
106
|
+
# yield each widget with a key built from its group optional title/position and its own title/position
|
|
107
107
|
def each_widget_with_key(widgets, prefix: nil, &block)
|
|
108
|
-
widgets.
|
|
108
|
+
widgets.each_with_index do |widget, i|
|
|
109
109
|
title = widget.dig(:definition, :title)
|
|
110
|
+
title = i.to_s if title.to_s.empty?
|
|
110
111
|
key = [prefix, title].compact.join("-")
|
|
111
112
|
yield key, widget
|
|
112
113
|
if (nested = widget.dig(:definition, :widgets))
|
data/lib/kennel/importer.rb
CHANGED
|
@@ -161,7 +161,7 @@ module Kennel
|
|
|
161
161
|
|
|
162
162
|
sort_hash(hash).map do |k, v|
|
|
163
163
|
pretty_value =
|
|
164
|
-
if v.is_a?(Hash) || (v.is_a?(Array) && !v.all?
|
|
164
|
+
if v.is_a?(Hash) || (v.is_a?(Array) && !v.all?(String))
|
|
165
165
|
# update answer here when changing https://stackoverflow.com/questions/8842546/best-way-to-pretty-print-a-hash
|
|
166
166
|
# (exclude last indent gsub)
|
|
167
167
|
pretty = JSON.pretty_generate(v)
|
|
@@ -377,7 +377,9 @@ module Kennel
|
|
|
377
377
|
return unless (match = data.fetch(:query).match(/(?:{([^}]*)}\s*)?by\s*[({]([^})]+)[})]/))
|
|
378
378
|
|
|
379
379
|
allowed =
|
|
380
|
-
match[1].to_s.split(/\s*,\s*/)
|
|
380
|
+
match[1].to_s.split(/\s*,\s*/)
|
|
381
|
+
.reject { |k| k.start_with?("!") } # {!a:b} does not pin a value, so a.name is not available
|
|
382
|
+
.map { |k| k.split(":", 2)[-2] } + # {a:b} -> a TODO: does not work for service check
|
|
381
383
|
match[2].to_s.gsub(/["']/, "").split(/\s*,\s*/) # by {a} -> a
|
|
382
384
|
|
|
383
385
|
return if allowed.include?("*")
|
|
@@ -32,7 +32,7 @@ module Kennel
|
|
|
32
32
|
|
|
33
33
|
def validated_parts
|
|
34
34
|
all = filter_parts(parts)
|
|
35
|
-
unless all.is_a?(Array) && all.all?
|
|
35
|
+
unless all.is_a?(Array) && all.all?(Record)
|
|
36
36
|
raise "Project #{kennel_id} #parts must return an array of Records"
|
|
37
37
|
end
|
|
38
38
|
|
data/lib/kennel/models/slo.rb
CHANGED
|
@@ -79,6 +79,13 @@ module Kennel
|
|
|
79
79
|
url[/[?&]slo_id=([a-z\d]{10,})/, 1] || url[/\/slo\/([a-z\d]{10,})(:?\/edit)?(\?|$)/, 1]
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
# datadog rejects changing the type in place, so force a re-create
|
|
83
|
+
def allowed_update_error(actual)
|
|
84
|
+
actual_type = actual[:type]
|
|
85
|
+
return if actual_type == type
|
|
86
|
+
"cannot update type from #{actual_type} to #{type}"
|
|
87
|
+
end
|
|
88
|
+
|
|
82
89
|
def resolve_linked_tracking_ids!(id_map, **args)
|
|
83
90
|
return unless (ids = as_json[:monitor_ids]) # ignore_default can remove it
|
|
84
91
|
as_json[:monitor_ids] = ids.map do |id|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
require "etc"
|
|
3
|
+
require "parallel"
|
|
2
4
|
|
|
3
5
|
module Kennel
|
|
4
6
|
class PartsSerializer
|
|
@@ -29,20 +31,32 @@ module Kennel
|
|
|
29
31
|
attr_reader :filter
|
|
30
32
|
|
|
31
33
|
def write_changed(parts)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
paths_used = []
|
|
35
|
+
to_generate = []
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
parts.each do |part|
|
|
36
38
|
path = path_for_tracking_id(part.tracking_id)
|
|
37
39
|
|
|
38
40
|
# match paths returned from existing_files_and_folders
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
paths_used << File.dirname(path) # we have 1 level of sub folders, so this is enough
|
|
42
|
+
paths_used << path
|
|
41
43
|
|
|
42
44
|
content = part.as_json.merge(api_resource: part.class.api_resource)
|
|
43
|
-
|
|
45
|
+
to_generate << [path, content]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
paths_changed = generate_and_write(to_generate)
|
|
49
|
+
|
|
50
|
+
[paths_used, paths_changed]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# JSON.pretty_generate is CPU-bound and threads are limited by the GVL, so we fork
|
|
54
|
+
def generate_and_write(to_generate)
|
|
55
|
+
chunks = to_generate.each_slice(100) # processing 1-by-1 would be slow
|
|
56
|
+
|
|
57
|
+
Parallel.flat_map(chunks, exit!: true) do |chunk|
|
|
58
|
+
chunk.filter_map { |path, content| path if write_file_if_necessary(path, content) }
|
|
44
59
|
end
|
|
45
|
-
[used, changed]
|
|
46
60
|
end
|
|
47
61
|
|
|
48
62
|
def existing_files_and_folders
|
|
@@ -38,8 +38,22 @@ module Kennel
|
|
|
38
38
|
|
|
39
39
|
def widget_queries(widget)
|
|
40
40
|
requests = widget.dig(:definition, :requests) || []
|
|
41
|
-
return requests
|
|
41
|
+
return hostmap_queries(requests) if requests.is_a?(Hash) # hostmap widgets have hash requests
|
|
42
42
|
requests.flat_map { |r| r[:q] || r[:queries]&.map { |q| q[:query] } } # old format with q: or queries: [{query:}]
|
|
43
43
|
end
|
|
44
|
+
|
|
45
|
+
# hostmap requests nest queries at varying depth, for example
|
|
46
|
+
# { fill: { q: "..." } } or { fill: { queries: [{ search: { query: "..." } }] }, request_type: "hosts" }
|
|
47
|
+
def hostmap_queries(node)
|
|
48
|
+
case node
|
|
49
|
+
when Hash
|
|
50
|
+
query = node[:q] || node[:query]
|
|
51
|
+
[*query, *hostmap_queries(node.except(:q, :query).values)]
|
|
52
|
+
when Array
|
|
53
|
+
node.flat_map { |v| hostmap_queries(v) }
|
|
54
|
+
else
|
|
55
|
+
[] # scalar leaves like request_type: "hosts"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
44
58
|
end
|
|
45
59
|
end
|
data/lib/kennel/version.rb
CHANGED
data/lib/kennel.rb
CHANGED
|
@@ -43,9 +43,14 @@ module Teams
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
module Kennel
|
|
46
|
-
UnresolvableIdError
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
class UnresolvableIdError < StandardError
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class DisallowedUpdateError < StandardError
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class GenerationAbortedError < StandardError
|
|
53
|
+
end
|
|
49
54
|
|
|
50
55
|
class << self
|
|
51
56
|
attr_accessor :in, :out, :err
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kennel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.24.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Grosser
|
|
@@ -65,6 +65,20 @@ dependencies:
|
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '1.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: parallel
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '2.3'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '2.3'
|
|
68
82
|
- !ruby/object:Gem::Dependency
|
|
69
83
|
name: zeitwerk
|
|
70
84
|
requirement: !ruby/object:Gem::Requirement
|