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

✨ metrics: add generator for kube-state-metrics customresource configuration #1043

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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 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 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
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 alvaroaleman for approval. For more information see the Kubernetes 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

@@ -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
@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
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

@sbueringer
Copy link
Member

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

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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

3 participants