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
Gauges produce values of type float64 but custom resources can be of all kinds of types.
248
+
Kube-state-metrics performs implicity type conversions for a lot of type.
249
+
Supported types are:
250
+
251
+
* (u)int32/64, int, float32 and byte are cast to float64
252
+
* `nil` is generally mapped to `0.0` if NilIsZero is `true`. Otherwise it yields an error
253
+
* for bool `true` is mapped to `1.0` and `false` is mapped to `0.0`
254
+
* for string the following logic applies
255
+
* `"true"` and `"yes"` are mapped to `1.0` and `"false"` and `"no"` are mapped to `0.0` (all case insensitive)
256
+
* RFC3339 times are parsed to float timestamp
257
+
* finally the string is parsed to float using https://pkg.go.dev/strconv#ParseFloat which should support all common number formats. If that fails an error is yielded
258
+
259
+
##### Example for status conditions on Kubernetes Controllers
260
+
261
+
```yaml
262
+
kind: CustomResourceStateMetrics
263
+
spec:
264
+
resources:
265
+
- groupVersionKind:
266
+
group: myteam.io
267
+
kind: "Foo"
268
+
version: "v1"
269
+
labelsFromPath:
270
+
name:
271
+
- metadata
272
+
- name
273
+
namespace:
274
+
- metadata
275
+
- namespace
276
+
metrics:
277
+
- name: "foo_status"
278
+
help: "status condition "
279
+
each:
280
+
type: Gauge
281
+
gauge:
282
+
path: [status, conditions]
283
+
labelsFromPath:
284
+
type: ["type"]
285
+
valueFrom: ["status"]
286
+
```
287
+
288
+
This will work for kubernetes controller CRs which expose status conditions according to the kubernetes api (https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Condition):
> 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)
0 commit comments