kennel 1.113.3 → 1.114.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: 1820e573733a40ccb56114ecc6c94f8d7732feb10d556f3bf1107c9d21fab7f0
4
- data.tar.gz: ed5230938e75e643c71b719f6ec4e3e317e9e94d9fb1a2848bbbe881eea56f4e
3
+ metadata.gz: b1266c924cd004d26036f81424b92ca52cf0720f041a6cc1ee0a7d1533b19f93
4
+ data.tar.gz: 250117caacd886189bde046f5a8166746a8cd6b87c7330fc106954cf4c7fae20
5
5
  SHA512:
6
- metadata.gz: beb8e6d2a60fd3c8ebe26cdd14ca70d89b9a107ee0a831cea52601464b7c13afe058f25eaee76add474e728f404d4c56216eea24e5ce4c5a5b58897da1e43af0
7
- data.tar.gz: 8000438dd34c1e22334283f2e3892379cc08fadeb6085d74ecd41a3b32fdc0aacb28b9a2019d6bdad7a48bcea94084200f69d8c814054fe928aedf16b06b7ea2
6
+ metadata.gz: aba95188ef4c6c2b7e974f53ba60ad3aac21b29dcb353bc6b05790374ba0a0c4113c0dd316e1e84975723a8d4d4e117102c13d18e18ddf7050fa97931b506af8
7
+ data.tar.gz: 15903c3da36d10fd42220431da69ac76c7c95d1407771e2f7c5c6bb0dfe132c2054e32131ba12b149eb41c52ebfb17f3004bdc78aab6a54c7f28600515a08632
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
 
@@ -3,6 +3,16 @@ module Kennel
3
3
  module SettingsAsMethods
4
4
  SETTING_OVERRIDABLE_METHODS = [].freeze
5
5
 
6
+ AS_PROCS = ->(options) do
7
+ options.transform_values do |v|
8
+ if v.class == Proc
9
+ v
10
+ else
11
+ -> { v }
12
+ end
13
+ end
14
+ end
15
+
6
16
  def self.included(base)
7
17
  base.extend ClassMethods
8
18
  base.instance_variable_set(:@settings, [])
@@ -31,7 +41,7 @@ module Kennel
31
41
  end
32
42
 
33
43
  def defaults(options)
34
- options.each do |name, block|
44
+ AS_PROCS.call(options).each do |name, block|
35
45
  validate_setting_exist name
36
46
  define_method name, &block
37
47
  end
@@ -58,12 +68,7 @@ module Kennel
58
68
  raise ArgumentError, "Expected #{self.class.name}.new options to be a Hash, got a #{options.class}"
59
69
  end
60
70
 
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|
71
+ AS_PROCS.call(options).each do |name, block|
67
72
  self.class.send :validate_setting_exist, name
68
73
  define_singleton_method name, &block
69
74
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.113.3"
3
+ VERSION = "1.114.0"
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.3
4
+ version: 1.114.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: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2022-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday