kubernetes / kube-state-metrics

Add-on agent to generate and expose cluster-level metrics.
https://kubernetes.io/docs/concepts/cluster-administration/kube-state-metrics/
Apache License 2.0
5.34k stars 1.99k forks source link

Read custom resource metrics configuration from a Custom Resource Definition #1948

Open chrischdi opened 1 year ago

chrischdi commented 1 year ago

What would you like to be added:

As of today, kube-state-metrics allows to define a configuration file which is read on startup to define metrics for custom resources via configuration.

Instead of using a configuration file to define custom metrics, kube-state-metrics could define its own Custom Resource Definition, which defines the metric configuration for a single Custom Resource instead.

Why is this needed:

Custom Resource Definitions can be deployed dynamically. The same could apply to the configuration of metrics for the same.

There are also had been several comments and discussions which now results in this issue (see additional context below).

Describe the solution you'd like

UX:

Additional context

The pattern would be similar to what the ServiceMonitor CRD is for the Prometheus operator.

logicalhan commented 1 year ago

/assign @mrueg /triage accepted

nathanperkins commented 1 year ago

When I originally saw the custom resource metrics configuration YAML, I thought it was a CRD 😄.

Glad to see this proposal; it would be a great solution for our current problem. We maintain multiple components using CRDs across multiple platforms, which each deploy their own KSM instance. We would like to define the metrics gathering configurations alongside the component CRDs so that they can be included in all platforms that use the component and maintained easily.

In the current situation, we would have to come up with some mechanism to merge the configs from each component into a single config, either at build time or using a sidecar in the KSM pod.

This would be so much better! Thanks for the suggestion!

cwrau commented 1 year ago

Heyho, is implementing a CRD a done decision?

Nothing against that, I was just thinking that maybe loading configmaps like grafana does might be easier? 🤔

nathanperkins commented 1 year ago

From the user side, CRDs are much easier to use than configmaps for structured APIs and the standard thing to do in Kubernetes.

guettli commented 1 year ago

I see many people are interested to configure metrics for CRDs via a CRD.

I think it will take several months until kube-state-metrics will be able to handle this.

Maybe there is already an alternative solution (without kube-state-metrics)?

If you know an alternative CRD based solution, please leave a comment here.

chrischdi commented 1 year ago

For folks which are interested: I've got a working poc implementation which dynamically reads configurations from configmaps which uses the kiwigrid/k8s-sidecar.

It also uses ClusterRole aggregation.

So for new metrics I would deploy a

https://github.com/chrischdi/cluster-api/tree/experiment-metrics-gen-flags/hack/observability/kube-state-metrics

chrischdi commented 1 year ago

Cleaned up to a new branch in CAPI: https://github.com/kubernetes-sigs/cluster-api/pull/9390

k8s-triage-robot commented 1 week ago

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted