Skip to content

Commit

Permalink
Add all stable metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
CatherineF-dev committed Oct 11, 2022
1 parent dc23fad commit 3e02fb7
Show file tree
Hide file tree
Showing 47 changed files with 742 additions and 551 deletions.
13 changes: 9 additions & 4 deletions internal/store/certificatesigningrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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 +59,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 +78,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 +99,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
66 changes: 33 additions & 33 deletions internal/store/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ func TestCronJobStore(t *testing.T) {
},
},
Want: `
# HELP kube_cronjob_created Unix creation timestamp
# HELP kube_cronjob_info Info about cronjob.
# HELP kube_cronjob_created [STABLE] Unix creation timestamp
# HELP kube_cronjob_info [STABLE] Info about cronjob.
# HELP kube_cronjob_annotations Kubernetes annotations converted to Prometheus labels.
# HELP kube_cronjob_labels Kubernetes labels converted to Prometheus labels.
# HELP 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.
# HELP kube_cronjob_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# HELP kube_cronjob_next_schedule_time [STABLE] 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.
# HELP kube_cronjob_spec_failed_job_history_limit Failed job history limit tells the controller how many failed jobs should be preserved.
# HELP kube_cronjob_spec_starting_deadline_seconds Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_starting_deadline_seconds [STABLE] Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_successful_job_history_limit Successful job history limit tells the controller how many completed jobs should be preserved.
# HELP kube_cronjob_spec_suspend Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active Active holds pointers to currently running jobs.
# HELP kube_cronjob_metadata_resource_version Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_status_last_schedule_time LastScheduleTime keeps information of when was the last time the job was successfully scheduled.
# HELP kube_cronjob_spec_suspend [STABLE] Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active [STABLE] Active holds pointers to currently running jobs.
# HELP kube_cronjob_metadata_resource_version [STABLE] Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_status_last_schedule_time [STABLE] LastScheduleTime keeps information of when was the last time the job was successfully scheduled.
# TYPE kube_cronjob_created gauge
# TYPE kube_cronjob_info gauge
# TYPE kube_cronjob_annotations gauge
Expand Down Expand Up @@ -212,16 +212,16 @@ func TestCronJobStore(t *testing.T) {
},
},
Want: `
# HELP kube_cronjob_created Unix creation timestamp
# HELP kube_cronjob_info Info about cronjob.
# HELP kube_cronjob_labels Kubernetes labels converted to Prometheus labels.
# HELP kube_cronjob_created [STABLE] Unix creation timestamp
# HELP kube_cronjob_info [STABLE] Info about cronjob.
# HELP kube_cronjob_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# HELP kube_cronjob_spec_failed_job_history_limit Failed job history limit tells the controller how many failed jobs should be preserved.
# HELP kube_cronjob_spec_starting_deadline_seconds Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_starting_deadline_seconds [STABLE] Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_successful_job_history_limit Successful job history limit tells the controller how many completed jobs should be preserved.
# HELP kube_cronjob_spec_suspend Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active Active holds pointers to currently running jobs.
# HELP kube_cronjob_metadata_resource_version Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_status_last_schedule_time LastScheduleTime keeps information of when was the last time the job was successfully scheduled.
# HELP kube_cronjob_spec_suspend [STABLE] Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active [STABLE] Active holds pointers to currently running jobs.
# HELP kube_cronjob_metadata_resource_version [STABLE] Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_status_last_schedule_time [STABLE] LastScheduleTime keeps information of when was the last time the job was successfully scheduled.
# HELP kube_cronjob_status_last_successful_time LastSuccessfulTime keeps information of when was the last time the job was completed successfully.
# TYPE kube_cronjob_created gauge
# TYPE kube_cronjob_info gauge
Expand Down Expand Up @@ -272,16 +272,16 @@ func TestCronJobStore(t *testing.T) {
},
},
Want: `
# HELP kube_cronjob_created Unix creation timestamp
# HELP kube_cronjob_info Info about cronjob.
# HELP kube_cronjob_labels Kubernetes labels converted to Prometheus labels.
# HELP kube_cronjob_created [STABLE] Unix creation timestamp
# HELP kube_cronjob_info [STABLE] Info about cronjob.
# HELP kube_cronjob_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# HELP kube_cronjob_spec_failed_job_history_limit Failed job history limit tells the controller how many failed jobs should be preserved.
# HELP kube_cronjob_spec_starting_deadline_seconds Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_starting_deadline_seconds [STABLE] Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_successful_job_history_limit Successful job history limit tells the controller how many completed jobs should be preserved.
# HELP kube_cronjob_spec_suspend Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active Active holds pointers to currently running jobs.
# HELP kube_cronjob_metadata_resource_version Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_status_last_schedule_time LastScheduleTime keeps information of when was the last time the job was successfully scheduled.
# HELP kube_cronjob_spec_suspend [STABLE] Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active [STABLE] Active holds pointers to currently running jobs.
# HELP kube_cronjob_metadata_resource_version [STABLE] Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_status_last_schedule_time [STABLE] LastScheduleTime keeps information of when was the last time the job was successfully scheduled.
# HELP kube_cronjob_status_last_successful_time LastSuccessfulTime keeps information of when was the last time the job was completed successfully.
# TYPE kube_cronjob_created gauge
# TYPE kube_cronjob_info gauge
Expand Down Expand Up @@ -334,17 +334,17 @@ func TestCronJobStore(t *testing.T) {
},
},
Want: `
# HELP kube_cronjob_created Unix creation timestamp
# HELP kube_cronjob_info Info about cronjob.
# HELP kube_cronjob_labels Kubernetes labels converted to Prometheus labels.
# HELP 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.
# HELP kube_cronjob_created [STABLE] Unix creation timestamp
# HELP kube_cronjob_info [STABLE] Info about cronjob.
# HELP kube_cronjob_labels [STABLE] Kubernetes labels converted to Prometheus labels.
# HELP kube_cronjob_next_schedule_time [STABLE] 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.
# HELP kube_cronjob_spec_failed_job_history_limit Failed job history limit tells the controller how many failed jobs should be preserved.
# HELP kube_cronjob_spec_starting_deadline_seconds Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_starting_deadline_seconds [STABLE] Deadline in seconds for starting the job if it misses scheduled time for any reason.
# HELP kube_cronjob_spec_successful_job_history_limit Successful job history limit tells the controller how many completed jobs should be preserved.
# HELP kube_cronjob_spec_suspend Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active Active holds pointers to currently running jobs.
# HELP kube_cronjob_spec_suspend [STABLE] Suspend flag tells the controller to suspend subsequent executions.
# HELP kube_cronjob_status_active [STABLE] Active holds pointers to currently running jobs.
# HELP kube_cronjob_status_last_successful_time LastSuccessfulTime keeps information of when was the last time the job was completed successfully.
# HELP kube_cronjob_metadata_resource_version Resource version representing a specific version of the cronjob.
# HELP kube_cronjob_metadata_resource_version [STABLE] Resource version representing a specific version of the cronjob.
# TYPE kube_cronjob_created gauge
# TYPE kube_cronjob_info gauge
# TYPE kube_cronjob_labels gauge
Expand Down
Loading

0 comments on commit 3e02fb7

Please sign in to comment.