kube-state-metrics icon indicating copy to clipboard operation
kube-state-metrics copied to clipboard

Support for Unknown status condition in Custom Resources

Open EronWright opened this issue 2 years ago • 4 comments

What would you like to be added: Improve support for producing a gauge for the status conditions of a custom resource, when the condition status is Unknown. Today, the data point cannot be produced due to a parse error:

[status,conditions]: [1]: [status]: strconv.ParseFloat: parsing \"Unknown\": invalid syntax

The gauge definition is:

    - name: "foo_status"
      help: "status condition "
      each:
        type: Gauge
        gauge:
          path: [status, conditions]
          labelsFromPath:
            type: ["type"]
          valueFrom: ["status"]

Why is this needed: This is needed to round out the support for status conditions. Unknown is a legit status value and should be supported.

Describe the solution you'd like it isn't totally clear what the gauge value should be. Here's a couple of options:

  1. Don't report an error message and skip reporting the data point. This means that Unknown would translate into the absence of a data point.
  2. Consider adding a valueMap structure to map the status values to a numerical value, e.g.
    - name: "foo_status"
      help: "status condition "
      each:
        type: Gauge
        gauge:
          path: [status, conditions]
          labelsFromPath:
            type: ["type"]
          valueFrom: ["status"]
          valueMap:
            - {from: "Unknown", to: 0}
            - {from: "True", to: 1}
            - {from: "False", to: 0}

EronWright avatar May 17 '23 19:05 EronWright

A related issue https://github.com/kubernetes/kube-state-metrics/issues/1978, so that you can use cel to extract what you want.

CatherineF-dev avatar May 18 '23 18:05 CatherineF-dev

/triage accepted /assign @CatherineF-dev

dgrisonnet avatar Jun 29 '23 16:06 dgrisonnet

I just ran into this issue and was able to workaround it by using a StateSet

- name: status_condition
  each:
    type: StateSet
    stateSet:
      path: [status, conditions]
      labelName: status
      valueFrom: [status]
      list: [True, False, Unknown]
      labelsFromPath:
        type: [type]

robbie-demuth avatar Oct 25 '23 16:10 robbie-demuth

I just ran into this issue and was able to workaround it by using a StateSet

- name: status_condition
  each:
    type: StateSet
    stateSet:
      path: [status, conditions]
      labelName: status
      valueFrom: [status]
      list: [True, False, Unknown]
      labelsFromPath:
        type: [type]

I feel like this suggestion should go into the docs here. Currently suggests using a Gauge for the status.conditions but this doesn't capture the 'unknown' status as suggested.

defenestration avatar Nov 22 '23 16:11 defenestration