Skip to content

Commit 70088ed

Browse files
committed
apply review comment
1 parent 17c6969 commit 70088ed

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

docs/metrics/extend/customresourcestate-metrics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ Supported types are:
337337
* `nil` is generally mapped to `0.0` if NilIsZero is `true`, otherwise it will throw an error
338338
* for bool `true` is mapped to `1.0` and `false` is mapped to `0.0`
339339
* for string the following logic applies
340-
* `"true"` and `"yes"` are mapped to `1.0`, `"false"`, `"no"` and `"unknown"` are mapped to `0.0` (all case-insensitive)
340+
* `"true"` and `"yes"` are mapped to `1.0`, `"false"` and `"no"` are mapped to `0.0` (all case-insensitive)
341+
* `"unknown"` is mapped to `-1.0` (all case-insensitive)
341342
* RFC3339 times are parsed to float timestamp
342343
* Quantities like "250m" or "512Gi" are parsed to float using <https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go>
343344
* Percentages ending with a "%" are parsed to float

pkg/customresourcestate/registry_factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ func toFloat64(value interface{}, nilIsZero bool) (float64, error) {
727727
}
728728
return 0, nil
729729
case string:
730-
// The string contains a boolean as a string
730+
// The string is a boolean or `"unknown"` according to https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Condition
731731
normalized := strings.ToLower(value.(string))
732732
if normalized == "true" || normalized == "yes" {
733733
return 1, nil
@@ -736,7 +736,7 @@ func toFloat64(value interface{}, nilIsZero bool) (float64, error) {
736736
return 0, nil
737737
}
738738
if normalized == "unknown" {
739-
return 0, nil
739+
return -1, nil
740740
}
741741
// The string contains a RFC3339 timestamp
742742
if t, e := time.Parse(time.RFC3339, value.(string)); e == nil {

0 commit comments

Comments
 (0)