controller-tools icon indicating copy to clipboard operation
controller-tools copied to clipboard

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

Open chrischdi opened this issue 1 year ago • 4 comments

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: https://github.com/kubernetes-sigs/cluster-api/pull/9347

chrischdi avatar Aug 28 '24 07:08 chrischdi