Skip to content

Conversation

chrischdi
Copy link
Member

@chrischdi chrischdi commented Aug 28, 2024

This adds a generator to generate a customresource configuration file for kube-state-metrics from markers.

With that configuration it is possible to get metrics for CRs like kube-state-metrics exposes for core resources.
(xref)

Example usage:

controller-gen metrics output:metrics:stdout \
     paths=./api/...\
     > crd-config.yaml

Introduced markers:

$ controller-gen metrics -ww

Metric type Gauge


+Metrics:gauge type
	defines a Gauge metric and uses the implicit path to the field joined by the provided JSONPath as path for the metric configuration.
	[JSONPath=<string>]      specifies the relative path from this marker.                                          
	[help=<string>]          specifies the help text for the metric.                                                
	[labelFromKey=<string>]  specifies a label which will be added to the metric having the object's key as value.  
	[labelsFromPath=<>]      specifies additional labels where the value is taken from the given JSONPath.          
	name=<string>            specifies the Name of the metric.                                                      
	[nilIsZero=<bool>]       specifies to treat a not-existing field as zero value.                                 
	[valueFrom=<string>]     specifies the JSONPath to a numeric field that will be the metric value.               

+Metrics:gauge field
	defines a Gauge metric and uses the implicit path to the field joined by the provided JSONPath as path for the metric configuration.
	[JSONPath=<string>]      specifies the relative path from this marker.                                          
	[help=<string>]          specifies the help text for the metric.                                                
	[labelFromKey=<string>]  specifies a label which will be added to the metric having the object's key as value.  
	[labelsFromPath=<>]      specifies additional labels where the value is taken from the given JSONPath.          
	name=<string>            specifies the Name of the metric.                                                      
	[nilIsZero=<bool>]       specifies to treat a not-existing field as zero value.                                 
	[valueFrom=<string>]     specifies the JSONPath to a numeric field that will be the metric value.               

Metric type Info


+Metrics:info type
	defines a Info metric and uses the implicit path to the field as path for the metric configuration.
	[JSONPath=<string>]      specifies the relative path from this marker.                                          
	[help=<string>]          specifies the help text for the metric.                                                
	[labelFromKey=<string>]  specifies a label which will be added to the metric having the object's key as value.  
	[labelsFromPath=<>]      specifies additional labels where the value is taken from the given JSONPath.          
	name=<string>            specifies the Name of the metric.                                                      

+Metrics:info field
	defines a Info metric and uses the implicit path to the field as path for the metric configuration.
	[JSONPath=<string>]      specifies the relative path from this marker.                                          
	[help=<string>]          specifies the help text for the metric.                                                
	[labelFromKey=<string>]  specifies a label which will be added to the metric having the object's key as value.  
	[labelsFromPath=<>]      specifies additional labels where the value is taken from the given JSONPath.          
	name=<string>            specifies the Name of the metric.                                                      

Metric type StateSet


+Metrics:stateset type
	defines a StateSet metric and uses the implicit path to the field as path for the metric configuration.
	[JSONPath=<string>]   specifies the path to the field which gets used as value to compare against the list for equality.  
	[help=<string>]       specifies the help text for the metric.                                                             
	[labelName=<string>]  specifies the key of the label which is used for each entry in List to expose the value.            
	[labelsFromPath=<>]   specifies additional labels where the value is taken from the given JSONPath.                       
	list=<[]string>       specifies a list of values to compare the given JSONPath against.                                   
	name=<string>         specifies the Name of the metric.                                                                   

+Metrics:stateset field
	defines a StateSet metric and uses the implicit path to the field as path for the metric configuration.
	[JSONPath=<string>]   specifies the path to the field which gets used as value to compare against the list for equality.  
	[help=<string>]       specifies the help text for the metric.                                                             
	[labelName=<string>]  specifies the key of the label which is used for each entry in List to expose the value.            
	[labelsFromPath=<>]   specifies additional labels where the value is taken from the given JSONPath.                       
	list=<[]string>       specifies a list of values to compare the given JSONPath against.                                   
	name=<string>         specifies the Name of the metric.                                                                   

Metrics


+Metrics:gvk type
	enables the creation of a custom resource configuration entry and uses the given prefix for the metrics if configured.
	[namePrefix=<string>]  specifies the prefix for all metrics of this resource.  

+Metrics:labelFromPath type
	specifies additional labels for all metrics of this field or type.
	JSONPath=<string>  specifies the relative path to the value for the label.  
	name=<string>      specifies the name of the label.                         

+Metrics:labelFromPath field
	specifies additional labels for all metrics of this field or type.
	JSONPath=<string>  specifies the relative path to the value for the label.  
	name=<string>      specifies the name of the label.                         

Example usage: kubernetes-sigs/cluster-api#9347

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 28, 2024
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 28, 2024
@chrischdi chrischdi force-pushed the pr-metrics-generator branch 3 times, most recently from 9e798ce to 3b209a2 Compare August 29, 2024 13:44
@@ -0,0 +1,122 @@
/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If wanted, I can volunteer to maintain this part of controller-gen (and/or also help on other parts of controller-tools) :-)

@chrischdi chrischdi force-pushed the pr-metrics-generator branch 2 times, most recently from 9b0a996 to f7862f4 Compare August 30, 2024 07:40
@chrischdi chrischdi changed the title ✨ [WIP] metrics: add generator for kube-state-metrics customresource configuration ✨ metrics: add generator for kube-state-metrics customresource configuration Aug 30, 2024
@chrischdi chrischdi force-pushed the pr-metrics-generator branch from f7862f4 to 28f149a Compare August 30, 2024 08:58
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2024
@sbueringer
Copy link
Member

We'll get back to this eventually, just low bandwith at the moment

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 26, 2025
@sbueringer
Copy link
Member

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 27, 2025
@chrischdi chrischdi force-pushed the pr-metrics-generator branch from 8fe2d86 to 8e10d2c Compare March 20, 2025 14:32
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 20, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 30, 2025
@chrischdi chrischdi force-pushed the pr-metrics-generator branch from 6d632a5 to 3cfbf5e Compare March 30, 2025 06:25
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 30, 2025
@chrischdi chrischdi force-pushed the pr-metrics-generator branch from 341107f to b2a1646 Compare August 15, 2025 07:52
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: chrischdi
Once this PR has been reviewed and has the lgtm label, please assign vincepri for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 15, 2025
@chrischdi chrischdi force-pushed the pr-metrics-generator branch from b2a1646 to fb8e57d Compare August 15, 2025 07:54
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 14, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@chrischdi
Copy link
Member Author

/reopen

@k8s-ci-robot k8s-ci-robot reopened this Oct 15, 2025
@k8s-ci-robot
Copy link
Contributor

@chrischdi: Reopened this PR.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@chrischdi
Copy link
Member Author

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Oct 15, 2025
@sbueringer
Copy link
Member

sbueringer commented Oct 15, 2025

@JoelSpeed If you're fine with this in general (already discussed this with Vince+Alvaro in the past and they are okay with it as long as we mark it experimental in some way for now) + we all have time to push this towards completion. Happy to invest time in reviews

@JoelSpeed
Copy link
Contributor

I'm not going to have time to do a deep dive on this until next week, but at the high level this seems like a reasonable addition.

Would like to have some discussion (maybe at the DV subproject meeting) about precedence for similar markers, and the patterns for defining the markers so that we can be somewhat consistent

@sbueringer
Copy link
Member

sbueringer commented Oct 15, 2025

I'm not going to have time to do a deep dive on this until next week, but at the high level this seems like a reasonable addition.

Sounds good, no rush!

Would like to have some discussion (maybe at the DV subproject meeting) about precedence for similar markers, and the patterns for defining the markers so that we can be somewhat consistent

Sounds reasonable. @chrischdi would be good if you could bring this up and drive forward.
Depending on bandwidth of course (don't want to just assume that you currently have the right bandwidth/priority mix for this :)). The meeting Joel is referring to is this one: https://docs.google.com/document/d/1cYXfDHZpalzoew-PKfgh1XHQB_6JjiEsidsM4zYGAzc/edit?pli=1&tab=t.0#heading=h.xf24wnv1ochq (bi-weekly Tuesday, next ocurrence next week)

@chrischdi chrischdi force-pushed the pr-metrics-generator branch from fb8e57d to 623b301 Compare October 17, 2025 07:29
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants