@@ -32,9 +32,13 @@ func TestResourceQuotaStore(t *testing.T) {
3232 // output so we only have to modify a single place when doing adjustments.
3333 const metadata = `
3434 # HELP kube_resourcequota [STABLE] Information about resource quota.
35+ # HELP kube_resourcequota_annotations Kubernetes annotations converted to Prometheus labels.
3536 # TYPE kube_resourcequota gauge
3637 # HELP kube_resourcequota_created [STABLE] Unix creation timestamp
38+ # HELP kube_resourcequota_labels [STABLE] Kubernetes labels converted to Prometheus labels.
39+ # TYPE kube_resourcequota_annotations gauge
3740 # TYPE kube_resourcequota_created gauge
41+ # TYPE kube_resourcequota_labels gauge
3842 `
3943 cases := []generateMetricsTestCase {
4044 // Verify populating base metric and that metric for unset fields are skipped.
@@ -132,10 +136,38 @@ func TestResourceQuotaStore(t *testing.T) {
132136 kube_resourcequota{namespace="testNS",resource="storage",resourcequota="quotaTest",type="used"} 9e+09
133137 ` ,
134138 },
139+ // Verify kube_resourcequota_annotations and kube_resourcequota_labels are shown.
140+ {
141+ AllowAnnotationsList : []string {
142+ "foo" ,
143+ },
144+ AllowLabelsList : []string {
145+ "hello" ,
146+ },
147+ Obj : & v1.ResourceQuota {
148+ ObjectMeta : metav1.ObjectMeta {
149+ Name : "quotaTest" ,
150+ CreationTimestamp : metav1.Time {Time : time .Unix (1500000000 , 0 )},
151+ Namespace : "testNS" ,
152+ Annotations : map [string ]string {
153+ "foo" : "bar" ,
154+ },
155+ Labels : map [string ]string {
156+ "hello" : "world" ,
157+ },
158+ },
159+ Status : v1.ResourceQuotaStatus {},
160+ },
161+ Want : metadata + `
162+ kube_resourcequota_annotations{annotation_foo="bar",namespace="testNS",resourcequota="quotaTest"} 1
163+ kube_resourcequota_created{namespace="testNS",resourcequota="quotaTest"} 1.5e+09
164+ kube_resourcequota_labels{label_hello="world",namespace="testNS",resourcequota="quotaTest"} 1
165+ ` ,
166+ },
135167 }
136168 for i , c := range cases {
137- c .Func = generator .ComposeMetricGenFuncs (resourceQuotaMetricFamilies )
138- c .Headers = generator .ExtractMetricFamilyHeaders (resourceQuotaMetricFamilies )
169+ c .Func = generator .ComposeMetricGenFuncs (resourceQuotaMetricFamilies ( c . AllowAnnotationsList , c . AllowLabelsList ) )
170+ c .Headers = generator .ExtractMetricFamilyHeaders (resourceQuotaMetricFamilies ( c . AllowAnnotationsList , c . AllowLabelsList ) )
139171 if err := c .run (); err != nil {
140172 t .Errorf ("unexpected collecting result in %vth run:\n %s" , i , err )
141173 }
0 commit comments