Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labelFromKey is just for Gauge, other types (eg. Info) don't have the attribute #1871

Closed
ningan123 opened this issue Oct 26, 2022 · 1 comment · Fixed by #1880
Closed

labelFromKey is just for Gauge, other types (eg. Info) don't have the attribute #1871

ningan123 opened this issue Oct 26, 2022 · 1 comment · Fixed by #1880
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@ningan123
Copy link

ningan123 commented Oct 26, 2022

What would you like to be added:
I need a labelFromKey for Info, not just Gauge.

Why is this needed:
If a CR (eg. Foo) is like this,

kind: Foo
apiVersion: myteam.io/vl
metadata:
    annotations:
        bar: baz
        qux: quxx
    labels:
        foo: bar
    name: foo
spec:
    version: v1.2.3
    order:
        - id: 1
          value: true
        - id: 3
          value: false
    replicas: 1
status:
    phase: Pending
    active:
        type-a: 1   # focus on this
        type-b: 3   # focus on this

we can get the metric label using the following YAML:

kind: CustomResourceStateMetrics
spec:
  resources:
    - groupVersionKind:
        group: myteam.io
        kind: "Foo"
        version: "v1"
      metrics:
        - name: "active"
          help: "Foo active"
          each:
            type: Gauge
            gauge:
              path: [status, active]
              labelFromKey: type

The output metrics are like this:

kube_xxx_active{type=type-a} 1
kube_xxx_active{type=type-b} 3

However, if a CR (eg. Foo) is like this:

kind: Foo
apiVersion: myteam.io/vl
metadata:
    annotations:
        bar: baz
        qux: quxx
    labels:
        foo: bar
    name: foo
spec:
    version: v1.2.3
    order:
        - id: 1
          value: true
        - id: 3
          value: false
    replicas: 1
status:
    phase: Pending
    active:
        type-a: running  # focus on this
        type-b: failed   # focus on this

Because the value of "type-a" is not a number, we need to use Info, not Gauge. How can I get a metric with the label "type=type-a"?

Describe the solution you'd like

  1. I need a labelFromKey for Info to get a metric with the label "type=type-a"
  2. I want to get the value of "type-a" to use as a label "state=running"

The expected YAML is like this:

kind: CustomResourceStateMetrics
spec:
  resources:
    - groupVersionKind:
        group: myteam.io
        kind: "Foo"
        version: "v1"
      metrics:
        - name: "active"
          help: "Foo active"
          each:
            type: Info
            info:
              path: [status, active]
              labelFromKey: type
              labelsFromPath:
                state: [???]  # I don't know how to write it

The expected output metrics are like this:

kube_xxx_active{type=type-a, state=running} 1
kube_xxx_active{type=type-b, state=failed} 1

thanks~

Additional context

#1871 (comment)

@ningan123 ningan123 added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 26, 2022
@ningan123 ningan123 changed the title labelFromKey is just labelFromKey is just for Gauge, other types (eg. Info) don't have the attribute Oct 26, 2022
@rexagod
Copy link
Member

rexagod commented Oct 28, 2022

/assign

rexagod added a commit to rexagod/kube-state-metrics that referenced this issue Nov 3, 2022
Allow `labelFromKey` field for all types:
* Gauge: Done.
* Info, StateSets: Pending.

Fixes: kubernetes#1871 and kubernetes#1868.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants