diff --git a/docs/metrics/extend/customresourcestate-metrics.md b/docs/metrics/extend/customresourcestate-metrics.md index 9330478b8e..c28b04b0f8 100644 --- a/docs/metrics/extend/customresourcestate-metrics.md +++ b/docs/metrics/extend/customresourcestate-metrics.md @@ -337,7 +337,7 @@ 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` and `"false"` and `"no"` are mapped to `0.0` (all case-insensitive) + * `"true"` and `"yes"` are mapped to `1.0`, `"false"`, `"no"` and `"unknown"` are mapped to `0.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 e4413d4dc2..5d2f22b068 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -131,9 +131,11 @@ type compiledCommon struct { func (c compiledCommon) Path() valuePath { return c.path } + func (c compiledCommon) LabelFromPath() map[string]valuePath { return c.labelFromPath } + func (c compiledCommon) Type() metric.Type { return c.t } @@ -477,6 +479,7 @@ func (e eachValue) DefaultLabels(defaults map[string]string) { } } } + func (e eachValue) ToMetric() *metric.Metric { var keys, values []string for k := range e.Labels { @@ -724,12 +727,12 @@ 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 } - if normalized == "false" || normalized == "no" { + if normalized == "false" || normalized == "no" || normalized == "unknown" { return 0, nil } // The string contains a RFC3339 timestamp