Skip to content

Commit

Permalink
apply review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleygo committed Nov 4, 2024
1 parent 17c6969 commit 70088ed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/metrics/extend/customresourcestate-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go>
* Percentages ending with a "%" are parsed to float
Expand Down
4 changes: 2 additions & 2 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 70088ed

Please sign in to comment.