You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pkg/customresourcestate implement info and stateSet metric type and refactor configuration file
* Adds detection of booleans in string format to getNum.
* Refactors configuration file to allow definition of different metric types
having different configuration variables.
* Refactor order of types and funcs in pkg/customersourcestate.
* Allows info and stateSet metrics to iterate over arrays.
* Adds `nilIsZero` config variable to gauge to indicate non-existing values to tread as 0 value instead of returning an error.
* Skip adding a label instead of setting value to `<nil>`.
* Replace namespace and subsystem by metricsNamePrefix
* Adjust docs for customresourcestate metrics to align with new configuration file
The configuration supports three kind of metrics from the [OpenMetrics specification](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md).
173
+
174
+
The metric type is specified by the `type` field and its specific configuration at the types specific struct.
175
+
176
+
#### Gauge
177
+
178
+
> Gauges are current measurements, such as bytes of memory currently used or the number of items in a queue. For gauges the absolute value is what is of interest to a user. [[0]](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#gauge)
179
+
180
+
Example:
181
+
182
+
```yaml
183
+
kind: CustomResourceStateMetrics
184
+
spec:
185
+
resources:
186
+
- groupVersionKind:
187
+
group: myteam.io
188
+
kind: "Foo"
189
+
version: "v1"
190
+
metrics:
191
+
- name: "uptime"
192
+
help: "Foo uptime"
193
+
each:
194
+
type: Gauge
195
+
gauge:
196
+
path: [status, uptime]
197
+
```
198
+
199
+
Produces the metric:
200
+
201
+
```prometheus
202
+
kube_myteam_io_v1_Foo_uptime 43.21
203
+
```
204
+
205
+
#### StateSet
206
+
207
+
> StateSets represent a series of related boolean values, also called a bitset. If ENUMs need to be encoded this MAY be done via StateSet. [[1]](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#stateset)
208
+
209
+
```yaml
210
+
kind: CustomResourceStateMetrics
211
+
spec:
212
+
resources:
213
+
- groupVersionKind:
214
+
group: myteam.io
215
+
kind: "Foo"
216
+
version: "v1"
217
+
metrics:
218
+
- name: "status_phase"
219
+
help: "Foo status_phase"
220
+
each:
221
+
type: StateSet
222
+
stateSet:
223
+
labelName: phase
224
+
path: [status, phase]
225
+
list: [Pending, Bar, Baz]
226
+
```
227
+
228
+
Metrics of type `SateSet` will generate a metric for each value defined in `list` for each resource.
229
+
The value will be 1, if the value matches the one in list.
> Info metrics are used to expose textual information which SHOULD NOT change during process lifetime. Common examples are an application's version, revision control commit, and the version of a compiler. [[2]](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#info)
242
+
243
+
Metrics of type `Info` will always have a value of 1.
244
+
245
+
```yaml
246
+
kind: CustomResourceStateMetrics
247
+
spec:
248
+
resources:
249
+
- groupVersionKind:
250
+
group: myteam.io
251
+
kind: "Foo"
252
+
version: "v1"
253
+
metrics:
254
+
- name: "version"
255
+
help: "Foo version"
256
+
each:
257
+
type: Info
258
+
info:
259
+
labelsFromPath:
260
+
version: [spec, version]
261
+
```
262
+
263
+
Produces the metric:
264
+
265
+
```prometheus
266
+
kube_myteam_io_v1_Foo_version{version="v1.2.3"} 1
267
+
```
268
+
163
269
### Naming
164
270
165
271
The default metric names are prefixed to avoid collisions with other metrics.
166
-
By default, a namespace of `kube` and a subsystem based on your custom resource's group+version+kind is used.
167
-
You can override these with the namespace and subsystem fields.
272
+
By default, a metric prefix of `kube_` and concatenated by your custom resource's group+version+kind is used.
273
+
You can override this with the `metricNamePrefix` field.
168
274
169
275
```yaml
170
276
kind: CustomResourceStateMetrics
171
277
spec:
172
278
resources:
173
279
- groupVersionKind: ...
174
-
namespace: myteam
175
-
subsystem: foos
280
+
metricNamePrefix: myteam_foos
176
281
metrics:
177
282
- name: uptime
178
283
...
@@ -183,7 +288,18 @@ Produces:
183
288
myteam_foos_uptime 43.21
184
289
```
185
290
186
-
To omit namespace and/or subsystem altogether, set them to `_`.
291
+
To omit namespace and/or subsystem altogether, set them to the empty string:
0 commit comments