kube-state-metrics
kube-state-metrics copied to clipboard
customresourcestatemetrics readme improvement suggestions and questions
Just wanted to give some suggestions since I read through the doc several times but still had some uncertainties and questions.
- There have been use cases in CRSM where the
/path/to/config.yamlis a Configmap which has a CustomResourceStateMetrics yaml config in the data field. For example, mentioned here https://www.youtube.com/live/rkaG4M5mo-8?si=2c-BNmmcdpGcCGsT&t=1237 in a talk given by @chrischdi . Can we have a section on how this exactly works? From the docs alone, there seems to be no mention of this feature. - Regarding Multiple Metrics/Kitchen Sink
- I still could not quite understand what it means for "whole objects" to be "copied into labels". Can more detail be added about the the '*' and '**' syntax? From what I can see in the produced metric, this copies the key/value pairs in metadata labels and annotations into new metric labels, but not sure what the difference is. Also, what is the behavior if we have fields that have layers of nested lists?
- It would be helpful to know how to deal with multiple layers deep nested fields/labels and how we can extract the leaf level values. Or if this is not possible yet, explicitly stated. For the sake of example:
spec:
cities:
- name: "paris"
foods:
- name: "snails"
price: 7.99
- name: "tokyo"
foods:
- name: "ramen"
price: 10.99
- name: "sushi"
price: 7.99
If we want to produce an Info metric on a per city basis, where we list the food name and food price such as:
city_metric{city_name: "tokyo", food_name: "ramen", price: "10.99"} 1
city_metric{city_name: "tokyo", food_name: "sushi", price: "7.99"} 1
city_metric{city_name: "paris", food_name: "snails", price: "7.99"} 1
what would the metric definition look like? I am aware that we can do something like the below to get the food_name and price:
type: Info
info:
path: [spec, cities, foods]
labelsFromPath:
food_name: [name]
price: [price]
how would we get the name of the city?
Lastly, if we have fields that are lists of primitive values, how can we incorporate these into metrics? For example if we added an 'ingredients' field to each food object:
spec:
cities:
- name: "paris"
foods:
- name: "snails"
price: 7.99
ingredients: ["snail"]
- name: "tokyo"
foods:
- name: "ramen"
price: 10.99
ingredients: ["noodles", "pork", "scallion"]
- name: "sushi"
price: 7.99
ingredients: ["rice", "fish"]
how(or what is the best way) may we add this extra dimension to the metrics listed above?
Thanks for looking.
- There have been use cases in CRSM where the
/path/to/config.yamlis a Configmap which has a CustomResourceStateMetrics yaml config in the data field. For example, mentioned here youtube.com/live/rkaG4M5mo-8?si=2c-BNmmcdpGcCGsT&t=1237 in a talk given by @chrischdi . Can we have a section on how this exactly works? From the docs alone, there seems to be no mention of this feature.
I hope I do not get your first ask wrong :-)
Regarding configmaps there are very good docs directly from Kubernetes: https://kubernetes.io/docs/concepts/configuration/configmap/
The additional thing needed is the flag --custom-resource-state-config-file /path/to/config.yaml ( which is described in https://github.com/kubernetes/kube-state-metrics/blob/main/docs/customresourcestate-metrics.md#configuration )
Maybe its worth adding a link to the helm chart which allows adding the configuration as value there:
https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-state-metrics/values.yaml#L346-L349
I'm sure that contributions to improve the documentation here to make it more clear are more than welcome 🙂
Hi @chrischdi thanks for getting back on my question, I see how that works now!
Do you have any insights on the other use case with multilayer nested lists?
Also wondering the same. Any response would be helpful!
Disclamer: I did not dig deep into it.
Regarding Multiple Metrics/Kitchen Sink:
I'm not a user of that feature so I can't help out here in this case. What you could do is try to take a look at the code and experiment how this works. We would be happy to improve the docs though! We would happily accept pull requests on that.
Regarding the multiple layers deep nested fields/labels:
I think this is currently not possible as of today (get the .spec.cities[].name as label, when you want to expose something which is nested below that).
What I usually see is more something like: you would have multiple CRD's instead:
- A CRD which describes a group of countries (don't know if continent is what would match your above example)
- A CRD which represents a country itself (including a reference to the "group of countries"
- A CRD which represents a Food (including a reference to a country)
And expose metrics for each single crd. Aggregation logic in prometheus may then be able to group the metrics.
/assign @rexagod /triage accepted