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" not avaliable #1868

Closed
hdxj-kaoy opened this issue Oct 25, 2022 · 2 comments
Closed

"LabelFromKey" not avaliable #1868

hdxj-kaoy opened this issue Oct 25, 2022 · 2 comments
Assignees

Comments

@hdxj-kaoy
Copy link

hdxj-kaoy commented Oct 25, 2022

labelFromKey does not work when I use the config below

kube-state-metrics --port=8880 --telemetry-port=8881 --kubeconfig=/config --custom-resource-state-config-file=/crsm.yaml

crsm.yaml

kind: CustomResourceStateMetrics
spec:
  resources:
    - groupVersionKind:
        group: bbb
        kind: "xxx"
        version: "v1alpha1"
      labelsFromPath:
        name: [metadata, name]
      metrics:
        - name: "np"
          help: "xxx"
          each:
            type: Gauge
            gauge:
              path: [status, nodeProgress]
              # does not work
              labelFromKey: type

CR looks like:

apiVersion: bbb/v1alpha1
kind: xxx
  ...
  ...
  ...
status:
  np:
    key1: 100
    key2: 100

I got :

kube_bbb_v1alpha1_xxx_np{name="aaa"} 100
kube_bbb_v1alpha1_xxx_np{name="aaa"} 100

instead of

kube_bbb_v1alpha1_xxx_np{name="aaa",type="key1"} 100
kube_bbb_v1alpha1_xxx_np{name="aaa",type="key2"} 100

After checking the source code and changing

return &compiledGauge{
compiledCommon: *cc,
ValueFrom: valueFromPath,
NilIsZero: m.Gauge.NilIsZero,
}, nil

to

 return &compiledGauge{ 
 	compiledCommon: *cc, 
 	ValueFrom:      valueFromPath, 
 	NilIsZero:      m.Gauge.NilIsZero, 
	LabelFromKey:   m.Gauge.LabelFromKey,
 }, nil 

I get the result I want.

I wonder whether this is intentional or there are other solutions that do not need to modify the source code.

@rexagod
Copy link
Member

rexagod commented Oct 28, 2022

/assign
I don't think this was intentional. This makes sense to me. #1871 is more or less similar to this as well.

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.
@mrueg
Copy link
Member

mrueg commented Nov 27, 2022

v2.7.0 has been released, feel free to reopen if this is not resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants