kennel 1.113.2 → 1.114.1

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: adf4f9d7bbb7ca7762d12c2dfc2f77faf2ad22dd5ea0179130ac793d56d66b06
4
- data.tar.gz: 6346728be4090edba0d00b8830517ac8e9ca3df4c16255638520b4133fcaff14
3
+ metadata.gz: 248d75d411fad53dd8011982ec16d2104547991ec35480bf9d085feaed419285
4
+ data.tar.gz: fe11bc68ac149ff7ef989c8bd2b2b497eb465f6f0eccc66d5fbf304de9801666
5
5
  SHA512:
6
- metadata.gz: 7fc4b90e41dcaafa071fe13b2a7324f9fa0d2ea5d5041d75e6d8e2afbd5b8ab85106ed715964b717282beefe4fa6aeb442ff7721fde5d727343aba1702b85e39
7
- data.tar.gz: 948288a0179b596477b7034ee03341d34ff1d8fd0f3be5f53a9fdb6a8c9a3892d10e50aa1b2aab843f77e1449066c0192e178cd3cb5b0083d6f9f4a0dddfe248
6
+ metadata.gz: d9888da18e41995160fb03516fc02037cb07f43acae46b298941952ec053df4b2ca62ea918a5b1b17664c76d926bb702b6e28a375af1f3047451e2463f88226c
7
+ data.tar.gz: 92917f89e251d9345f1cf580ebb0206b1206882abe036d1e44284835c025ca61822e261d35a120fe7194303ede139e3c56db48b878fdb137f8d176cc4796441f
data/Readme.md CHANGED
@@ -72,6 +72,95 @@ end
72
72
  - `parts/` monitors/dashboards/etc that are used by multiple projects
73
73
  - `generated/` projects as json, to show current state and proposed changes in PRs
74
74
 
75
+ ## About the models
76
+
77
+ Kennel provides several classes which act as models for different purposes:
78
+
79
+ * `Kennel::Models::Dashboard`, `Kennel::Models::Monitor`, `Kennel::Models::Slo`, `Kennel::Models::SyntheticTest`;
80
+ these models represent the various Datadog objects
81
+ * `Kennel::Models::Project`; a container for a collection of Datadog objects
82
+ * `Kennel::Models::Team`; provides defaults and values (e.g. tags, mentions) for the other models.
83
+
84
+ After loading all the `*.rb` files under `projects/`, Kennel's starting point
85
+ is to find all the subclasses of `Kennel::Models::Project`, and for each one,
86
+ create an instance of that subclass (via `.new`) and then call `#parts` on that
87
+ instance. `parts` should return a collection of the Datadog-objects (Dashboard / Monitor / etc).
88
+
89
+ ### Model Settings
90
+
91
+ Each of the models defines various settings; for example, a Monitor has `name`, `message`,
92
+ `type`, `query`, `tags`, and many more.
93
+
94
+ When defining a subclass of a model, one can use `defaults` to provide default values for
95
+ those settings:
96
+
97
+ ```Ruby
98
+ class MyMonitor < Kennel::Models::Monitor
99
+ defaults(
100
+ name: "Error rate",
101
+ type: "query alert",
102
+ critical: 5.0,
103
+ query: -> {
104
+ "some datadog metric expression > #{critical}"
105
+ },
106
+ # ...
107
+ )
108
+ end
109
+ ```
110
+
111
+ This is equivalent to defining instance methods of those names, which return those values:
112
+
113
+ ```Ruby
114
+ class MyMonitor < Kennel::Models::Monitor
115
+ def name
116
+ "Error rate"
117
+ end
118
+
119
+ def type
120
+ "query alert"
121
+ end
122
+
123
+ def critical
124
+ 5.0
125
+ end
126
+
127
+ def query
128
+ "some datadog metric expression > #{critical}"
129
+ end
130
+ end
131
+ ```
132
+
133
+ except that `defaults` will complain if you try to use a setting name which doesn't
134
+ exist. Note also that you can use either plain values (`critical: 5.0`), or procs
135
+ (`query: -> { ... }`). Using a plain value is equivalent to using a proc which returns
136
+ that same value; use whichever suits you best.
137
+
138
+ When you _instantiate_ a model class, you can pass settings in the constructor, after
139
+ the project:
140
+
141
+ ```Ruby
142
+ project = Kennel::Models::Project.new
143
+ my_monitor = MyMonitor.new(
144
+ project,
145
+ critical: 10.0,
146
+ message: -> {
147
+ <<~MESSAGE
148
+ Something bad is happening and you should be worried.
149
+
150
+ #{super()}
151
+ MESSAGE
152
+ },
153
+ )
154
+ ```
155
+
156
+ This works just like `defaults` (it checks the setting names, and it accepts
157
+ either plain values or procs), but it applies just to this instance of the class,
158
+ rather than to the class as a whole (i.e. it defines singleton methods, rather
159
+ than instance methods).
160
+
161
+ Most of the examples in this Readme use the proc syntax (`critical: -> { 5.0 }`) but
162
+ for simple constants you may prefer to use the plain syntax (`critical: 5.0`).
163
+
75
164
  ## Workflows
76
165
  <!-- ONLY IN template/Readme.md
77
166
 
@@ -211,6 +211,10 @@ module Kennel
211
211
  def validate_json(data)
212
212
  super
213
213
 
214
+ if data[:name]&.start_with?(" ")
215
+ invalid! "name cannot start with a space"
216
+ end
217
+
214
218
  type = data.fetch(:type)
215
219
 
216
220
  # do not allow deprecated type that will be coverted by datadog and then produce a diff
@@ -241,6 +245,10 @@ module Kennel
241
245
  unless ALLOWED_PRIORITY_CLASSES.include?(priority.class)
242
246
  invalid! "priority needs to be an Integer"
243
247
  end
248
+
249
+ if data.dig(:options, :timeout_h)&.> 24
250
+ invalid! "timeout_h must be <= 24"
251
+ end
244
252
  end
245
253
 
246
254
  # verify is_match/is_exact_match and {{foo.name}} uses available variables
@@ -11,6 +11,8 @@ module Kennel
11
11
  def self.file_location
12
12
  @file_location ||= begin
13
13
  method_in_file = instance_methods(false).first
14
+ return if method_in_file.nil?
15
+
14
16
  instance_method(method_in_file).source_location.first.sub("#{Bundler.root}/", "")
15
17
  end
16
18
  end
@@ -3,6 +3,20 @@ module Kennel
3
3
  module SettingsAsMethods
4
4
  SETTING_OVERRIDABLE_METHODS = [].freeze
5
5
 
6
+ AS_PROCS = ->(options) do
7
+ # Fragile; depends on the fact that in both locations where AS_PROCS is
8
+ # used, we're 2 frames away from the user code.
9
+ file, line, = caller(2..2).first.split(":", 3)
10
+
11
+ options.transform_values do |v|
12
+ if v.class == Proc
13
+ v
14
+ else
15
+ eval "-> { v }", nil, file, line.to_i
16
+ end
17
+ end
18
+ end
19
+
6
20
  def self.included(base)
7
21
  base.extend ClassMethods
8
22
  base.instance_variable_set(:@settings, [])
@@ -31,7 +45,7 @@ module Kennel
31
45
  end
32
46
 
33
47
  def defaults(options)
34
- options.each do |name, block|
48
+ AS_PROCS.call(options).each do |name, block|
35
49
  validate_setting_exist name
36
50
  define_method name, &block
37
51
  end
@@ -58,12 +72,7 @@ module Kennel
58
72
  raise ArgumentError, "Expected #{self.class.name}.new options to be a Hash, got a #{options.class}"
59
73
  end
60
74
 
61
- options.each do |k, v|
62
- next if v.class == Proc
63
- raise ArgumentError, "Expected #{self.class.name}.new option :#{k} to be Proc, for example `#{k}: -> { 12 }`"
64
- end
65
-
66
- options.each do |name, block|
75
+ AS_PROCS.call(options).each do |name, block|
67
76
  self.class.send :validate_setting_exist, name
68
77
  define_singleton_method name, &block
69
78
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.113.2"
3
+ VERSION = "1.114.1"
4
4
  end
data/template/Readme.md CHANGED
@@ -56,6 +56,95 @@ end
56
56
  - `parts/` monitors/dashboards/etc that are used by multiple projects
57
57
  - `generated/` projects as json, to show current state and proposed changes in PRs
58
58
 
59
+ ## About the models
60
+
61
+ Kennel provides several classes which act as models for different purposes:
62
+
63
+ * `Kennel::Models::Dashboard`, `Kennel::Models::Monitor`, `Kennel::Models::Slo`, `Kennel::Models::SyntheticTest`;
64
+ these models represent the various Datadog objects
65
+ * `Kennel::Models::Project`; a container for a collection of Datadog objects
66
+ * `Kennel::Models::Team`; provides defaults and values (e.g. tags, mentions) for the other models.
67
+
68
+ After loading all the `*.rb` files under `projects/`, Kennel's starting point
69
+ is to find all the subclasses of `Kennel::Models::Project`, and for each one,
70
+ create an instance of that subclass (via `.new`) and then call `#parts` on that
71
+ instance. `parts` should return a collection of the Datadog-objects (Dashboard / Monitor / etc).
72
+
73
+ ### Model Settings
74
+
75
+ Each of the models defines various settings; for example, a Monitor has `name`, `message`,
76
+ `type`, `query`, `tags`, and many more.
77
+
78
+ When defining a subclass of a model, one can use `defaults` to provide default values for
79
+ those settings:
80
+
81
+ ```Ruby
82
+ class MyMonitor < Kennel::Models::Monitor
83
+ defaults(
84
+ name: "Error rate",
85
+ type: "query alert",
86
+ critical: 5.0,
87
+ query: -> {
88
+ "some datadog metric expression > #{critical}"
89
+ },
90
+ # ...
91
+ )
92
+ end
93
+ ```
94
+
95
+ This is equivalent to defining instance methods of those names, which return those values:
96
+
97
+ ```Ruby
98
+ class MyMonitor < Kennel::Models::Monitor
99
+ def name
100
+ "Error rate"
101
+ end
102
+
103
+ def type
104
+ "query alert"
105
+ end
106
+
107
+ def critical
108
+ 5.0
109
+ end
110
+
111
+ def query
112
+ "some datadog metric expression > #{critical}"
113
+ end
114
+ end
115
+ ```
116
+
117
+ except that `defaults` will complain if you try to use a setting name which doesn't
118
+ exist. Note also that you can use either plain values (`critical: 5.0`), or procs
119
+ (`query: -> { ... }`). Using a plain value is equivalent to using a proc which returns
120
+ that same value; use whichever suits you best.
121
+
122
+ When you _instantiate_ a model class, you can pass settings in the constructor, after
123
+ the project:
124
+
125
+ ```Ruby
126
+ project = Kennel::Models::Project.new
127
+ my_monitor = MyMonitor.new(
128
+ project,
129
+ critical: 10.0,
130
+ message: -> {
131
+ <<~MESSAGE
132
+ Something bad is happening and you should be worried.
133
+
134
+ #{super()}
135
+ MESSAGE
136
+ },
137
+ )
138
+ ```
139
+
140
+ This works just like `defaults` (it checks the setting names, and it accepts
141
+ either plain values or procs), but it applies just to this instance of the class,
142
+ rather than to the class as a whole (i.e. it defines singleton methods, rather
143
+ than instance methods).
144
+
145
+ Most of the examples in this Readme use the proc syntax (`critical: -> { 5.0 }`) but
146
+ for simple constants you may prefer to use the plain syntax (`critical: 5.0`).
147
+
59
148
  ## Workflows
60
149
 
61
150
  ### Setup
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.113.2
4
+ version: 1.114.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2022-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday