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

Import k8s metrics stability framework #1844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
k8s.io/apimachinery v0.25.2
k8s.io/autoscaler/vertical-pod-autoscaler v0.12.0
k8s.io/client-go v0.25.2
k8s.io/component-base v0.25.2
k8s.io/klog/v2 v2.80.1
k8s.io/sample-controller v0.25.2
k8s.io/utils v0.0.0-20220922133306-665eaaec4324
Expand All @@ -40,6 +41,7 @@ require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
Expand Down Expand Up @@ -984,6 +985,8 @@ k8s.io/client-go v0.25.2/go.mod h1:i7cNU7N+yGQmJkewcRD2+Vuj4iz7b30kI8OcL3horQ4=
k8s.io/code-generator v0.25.0/go.mod h1:B6jZgI3DvDFAualltPitbYMQ74NjaCFxum3YeKZZ+3w=
k8s.io/code-generator v0.25.2/go.mod h1:f61OcU2VqVQcjt/6TrU0sta1TA5hHkOO6ZZPwkL9Eys=
k8s.io/component-base v0.25.0/go.mod h1:F2Sumv9CnbBlqrpdf7rKZTmmd2meJq0HizeyY/yAFxk=
k8s.io/component-base v0.25.2 h1:Nve/ZyHLUBHz1rqwkjXm/Re6IniNa5k7KgzxZpTfSQY=
k8s.io/component-base v0.25.2/go.mod h1:90W21YMr+Yjg7MX+DohmZLzjsBtaxQDDwaX4YxDkl60=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
Expand Down
14 changes: 10 additions & 4 deletions internal/store/certificatesigningrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package store
import (
"context"

basemetrics "k8s.io/component-base/metrics"

"k8s.io/kube-state-metrics/v2/pkg/metric"
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"

Expand Down Expand Up @@ -58,10 +60,11 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
descCSRLabelsName,
descCSRLabelsHelp,
metric.Gauge,
basemetrics.STABLE,
"",
wrapCSRFunc(func(j *certv1.CertificateSigningRequest) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
Expand All @@ -76,10 +79,11 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_certificatesigningrequest_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
ms := []*metric.Metric{}
Expand All @@ -96,21 +100,23 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_certificatesigningrequest_condition",
"The number of each certificatesigningrequest condition",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
return &metric.Family{
Metrics: addCSRConditionMetrics(csr.Status),
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_certificatesigningrequest_cert_length",
"Length of the issued cert",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
return &metric.Family{
Expand Down
8 changes: 4 additions & 4 deletions internal/store/certificatesigningrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (

func TestCsrStore(t *testing.T) {
const metadata = `
# HELP kube_certificatesigningrequest_labels Kubernetes labels converted to Prometheus labels.
# HELP kube_certificatesigningrequest_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# TYPE kube_certificatesigningrequest_labels gauge
# HELP kube_certificatesigningrequest_created Unix creation timestamp
# HELP kube_certificatesigningrequest_created [STABLE] Unix creation timestamp
# TYPE kube_certificatesigningrequest_created gauge
# HELP kube_certificatesigningrequest_condition The number of each certificatesigningrequest condition
# HELP kube_certificatesigningrequest_condition [STABLE] The number of each certificatesigningrequest condition
# TYPE kube_certificatesigningrequest_condition gauge
# HELP kube_certificatesigningrequest_cert_length Length of the issued cert
# HELP kube_certificatesigningrequest_cert_length [STABLE] Length of the issued cert
# TYPE kube_certificatesigningrequest_cert_length gauge
`
cases := []generateMetricsTestCase{
Expand Down
10 changes: 7 additions & 3 deletions internal/store/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/apimachinery/pkg/watch"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
basemetrics "k8s.io/component-base/metrics"

"k8s.io/kube-state-metrics/v2/pkg/metric"
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
Expand Down Expand Up @@ -54,10 +55,11 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_labels",
"Kubernetes labels converted to Prometheus labels.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", c.Labels, allowLabelsList)
Expand All @@ -72,10 +74,11 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_info",
"Information about configmap.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
return &metric.Family{
Expand All @@ -87,10 +90,11 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.STABLE,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
ms := []*metric.Metric{}
Expand Down
8 changes: 4 additions & 4 deletions internal/store/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func TestConfigMapStore(t *testing.T) {
},
Want: `
# HELP kube_configmap_annotations Kubernetes annotations converted to Prometheus labels.
# HELP kube_configmap_labels Kubernetes labels converted to Prometheus labels.
# HELP kube_configmap_info Information about configmap.
# HELP kube_configmap_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# HELP kube_configmap_info [STABLE] Information about configmap.
# HELP kube_configmap_metadata_resource_version Resource version representing a specific version of the configmap.
# TYPE kube_configmap_annotations gauge
# TYPE kube_configmap_labels gauge
Expand All @@ -82,8 +82,8 @@ func TestConfigMapStore(t *testing.T) {
},
},
Want: `
# HELP kube_configmap_created Unix creation timestamp
# HELP kube_configmap_info Information about configmap.
# HELP kube_configmap_created [STABLE] Unix creation timestamp
# HELP kube_configmap_info [STABLE] Information about configmap.
# HELP kube_configmap_metadata_resource_version Resource version representing a specific version of the configmap.
# TYPE kube_configmap_created gauge
# TYPE kube_configmap_info gauge
Expand Down
28 changes: 19 additions & 9 deletions internal/store/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/watch"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
basemetrics "k8s.io/component-base/metrics"

"k8s.io/kube-state-metrics/v2/pkg/metric"
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
Expand Down Expand Up @@ -62,10 +63,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
descCronJobLabelsName,
descCronJobLabelsHelp,
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
Expand All @@ -80,10 +82,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_info",
"Info about cronjob.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
return &metric.Family{
Expand All @@ -97,10 +100,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}
Expand All @@ -117,10 +121,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_status_active",
"Active holds pointers to currently running jobs.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
return &metric.Family{
Expand All @@ -134,10 +139,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_status_last_schedule_time",
"LastScheduleTime keeps information of when was the last time the job was successfully scheduled.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}
Expand Down Expand Up @@ -176,10 +182,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_spec_suspend",
"Suspend flag tells the controller to suspend subsequent executions.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}
Expand All @@ -197,10 +204,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_spec_starting_deadline_seconds",
"Deadline in seconds for starting the job if it misses scheduled time for any reason.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}
Expand All @@ -219,10 +227,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_next_schedule_time",
"Next time the cronjob should be scheduled. The time after lastScheduleTime, or after the cron job's creation time if it's never been scheduled. Use this to determine if the job is delayed.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
ms := []*metric.Metric{}
Expand All @@ -244,10 +253,11 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGenerator(
*generator.NewFamilyGeneratorWithStability(
"kube_cronjob_metadata_resource_version",
"Resource version representing a specific version of the cronjob.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
return &metric.Family{
Expand Down
Loading