diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index c28b04b0f..431fd0f1b 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -337,7 +337,8 @@ Supported types are: * `nil` is generally mapped to `0.0` if NilIsZero is `true`, otherwise it will throw an error * for bool `true` is mapped to `1.0` and `false` is mapped to `0.0` * for string the following logic applies - * `"true"` and `"yes"` are mapped to `1.0`, `"false"`, `"no"` and `"unknown"` are mapped to `0.0` (all case-insensitive) + * `"true"` and `"yes"` are mapped to `1.0`, `"false"` and `"no"` are mapped to `0.0` (all case-insensitive) + * `"unknown"` is mapped to `-1.0` (all case-insensitive) * RFC3339 times are parsed to float timestamp * Quantities like "250m" or "512Gi" are parsed to float using * Percentages ending with a "%" are parsed to float diff --git a/pkg/customresourcestate/registry_factory.go b/pkg/customresourcestate/registry_factory.go index 39c261bd2..26639e81a 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -727,7 +727,7 @@ func toFloat64(value interface{}, nilIsZero bool) (float64, error) { } return 0, nil case string: - // The string contains a boolean as a string + // The string is a boolean or `"unknown"` according to https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Condition normalized := strings.ToLower(value.(string)) if normalized == "true" || normalized == "yes" { return 1, nil @@ -736,7 +736,7 @@ func toFloat64(value interface{}, nilIsZero bool) (float64, error) { return 0, nil } if normalized == "unknown" { - return 0, nil + return -1, nil } // The string contains a RFC3339 timestamp if t, e := time.Parse(time.RFC3339, value.(string)); e == nil {