Skip to content
Open
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
73 changes: 3 additions & 70 deletions internal/store/certificatesigningrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,80 +33,13 @@ import (
)

var (
descCSRAnnotationsName = "kube_certificatesigningrequest_annotations"
descCSRAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descCSRLabelsName = "kube_certificatesigningrequest_labels"
descCSRLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descCSRLabelsDefaultLabels = []string{"certificatesigningrequest", "signer_name"}
)

func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descCSRAnnotationsName,
descCSRAnnotationsHelp,
metric.Gauge,
basemetrics.ALPHA,
"",
wrapCSRFunc(func(j *certv1.CertificateSigningRequest) *metric.Family {
if len(allowAnnotationsList) == 0 {
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", j.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
},
}
}),
),
*generator.NewFamilyGeneratorWithStability(
descCSRLabelsName,
descCSRLabelsHelp,
metric.Gauge,
basemetrics.STABLE,
"",
wrapCSRFunc(func(j *certv1.CertificateSigningRequest) *metric.Family {
if len(allowLabelsList) == 0 {
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
},
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_certificatesigningrequest_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.STABLE,
"",
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
ms := []*metric.Metric{}
if !csr.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(csr.CreationTimestamp.Unix()),
})
}
metadataFamilies := createMetadataMetricFamiliesGenerator(allowAnnotationsList, allowLabelsList, descCSRLabelsDefaultLabels, "kube_certificatesigningrequest", wrapMetadataFunc)

return &metric.Family{
Metrics: ms,
}
}),
),
return append(metadataFamilies,
*generator.NewFamilyGeneratorWithStability(
"kube_certificatesigningrequest_condition",
"The number of each certificatesigningrequest condition",
Expand Down Expand Up @@ -137,7 +70,7 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}
}),
),
}
)
}

func wrapCSRFunc(f func(*certv1.CertificateSigningRequest) *metric.Family) func(interface{}) *metric.Family {
Expand Down
75 changes: 3 additions & 72 deletions internal/store/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,59 +32,12 @@ import (
)

var (
descClusterRoleAnnotationsName = "kube_clusterrole_annotations"
descClusterRoleAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descClusterRoleLabelsName = "kube_clusterrole_labels"
descClusterRoleLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descClusterRoleLabelsDefaultLabels = []string{"clusterrole"}
)

func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descClusterRoleAnnotationsName,
descClusterRoleAnnotationsHelp,
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
if len(allowAnnotationsList) == 0 {
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", r.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
},
}
}),
),
*generator.NewFamilyGeneratorWithStability(
descClusterRoleLabelsName,
descClusterRoleLabelsHelp,
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
if len(allowLabelsList) == 0 {
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", r.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
},
}
}),
),
metadataFamilies := createMetadataMetricFamiliesGenerator(allowAnnotationsList, allowLabelsList, descClusterRoleLabelsDefaultLabels, "kube_clusterrole", wrapMetadataFunc)
return append(metadataFamilies,
*generator.NewFamilyGeneratorWithStability(
"kube_clusterrole_info",
"Information about cluster role.",
Expand All @@ -101,28 +54,6 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_clusterrole_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
ms := []*metric.Metric{}

if !r.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(r.CreationTimestamp.Unix()),
})
}

return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_clusterrole_metadata_resource_version",
"Resource version representing a specific version of the cluster role.",
Expand All @@ -135,7 +66,7 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
}
}),
),
}
)
}

func createClusterRoleListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcher {
Expand Down
76 changes: 4 additions & 72 deletions internal/store/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,59 +32,13 @@ import (
)

var (
descClusterRoleBindingAnnotationsName = "kube_clusterrolebinding_annotations"
descClusterRoleBindingAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descClusterRoleBindingLabelsName = "kube_clusterrolebinding_labels"
descClusterRoleBindingLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descClusterRoleBindingLabelsDefaultLabels = []string{"clusterrolebinding"}
)

func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descClusterRoleBindingAnnotationsName,
descClusterRoleBindingAnnotationsHelp,
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleBindingFunc(func(r *rbacv1.ClusterRoleBinding) *metric.Family {
if len(allowAnnotationsList) == 0 {
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", r.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
},
}
}),
),
*generator.NewFamilyGeneratorWithStability(
descClusterRoleBindingLabelsName,
descClusterRoleBindingLabelsHelp,
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleBindingFunc(func(r *rbacv1.ClusterRoleBinding) *metric.Family {
if len(allowLabelsList) == 0 {
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", r.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
},
}
}),
),
metadataFamilies := createMetadataMetricFamiliesGenerator(allowAnnotationsList, allowLabelsList, descClusterRoleBindingLabelsDefaultLabels, "kube_clusterrolebinding", wrapMetadataFunc)

return append(metadataFamilies,
*generator.NewFamilyGeneratorWithStability(
"kube_clusterrolebinding_info",
"Information about clusterrolebinding.",
Expand All @@ -103,28 +57,6 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_clusterrolebinding_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapClusterRoleBindingFunc(func(r *rbacv1.ClusterRoleBinding) *metric.Family {
ms := []*metric.Metric{}

if !r.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(r.CreationTimestamp.Unix()),
})
}

return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_clusterrolebinding_metadata_resource_version",
"Resource version representing a specific version of the clusterrolebinding.",
Expand All @@ -137,7 +69,7 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
}
}),
),
}
)
}

func createClusterRoleBindingListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcher {
Expand Down
72 changes: 4 additions & 68 deletions internal/store/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,9 @@ var (
)

func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_annotations",
"Kubernetes annotations converted to Prometheus labels.",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
if len(allowAnnotationsList) == 0 {
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", c.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
},
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_labels",
"Kubernetes labels converted to Prometheus labels.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
if len(allowLabelsList) == 0 {
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", c.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
},
}
}),
),
metadataFamilies := createMetadataMetricFamiliesGenerator(allowAnnotationsList, allowLabelsList, descConfigMapLabelsDefaultLabels, "kube_configmap", wrapMetadataFunc)

return append(metadataFamilies,
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_info",
"Information about configmap.",
Expand All @@ -97,28 +55,6 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_created",
"Unix creation timestamp",
metric.Gauge,
basemetrics.STABLE,
"",
wrapConfigMapFunc(func(c *v1.ConfigMap) *metric.Family {
ms := []*metric.Metric{}

if !c.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(c.CreationTimestamp.Unix()),
})
}

return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_configmap_metadata_resource_version",
"Resource version representing a specific version of the configmap.",
Expand All @@ -131,7 +67,7 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
}
}),
),
}
)
}

func createConfigMapListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
Expand Down
Loading
Loading