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

refactor: prepare for stable metrics static analysis by defining metric labels with same format #2258

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
037d3ec
refactor: prepare for stable metrics static anaylyze by defining labe…
CatherineF-dev Dec 6, 2023
ea52fa6
Update certificatesigningrequest
CatherineF-dev Dec 12, 2023
9fc41bf
Update clusterrole
CatherineF-dev Dec 12, 2023
d674997
Update clusterrolebinding
CatherineF-dev Dec 12, 2023
bf628fc
Update configmap
CatherineF-dev Dec 12, 2023
07b11b9
Update cronjob
CatherineF-dev Dec 12, 2023
9001aee
Update daemonset
CatherineF-dev Dec 12, 2023
e1bbffc
Update deployment
CatherineF-dev Dec 12, 2023
072f044
Update endpoint
CatherineF-dev Dec 12, 2023
0cbe72a
Update endpointslice
CatherineF-dev Dec 12, 2023
0886d57
Update horizontalpodautoscaler
CatherineF-dev Dec 12, 2023
7918e2c
Update ingress
CatherineF-dev Dec 12, 2023
3968710
Update ingressclass
CatherineF-dev Dec 12, 2023
6e2040f
Update job
CatherineF-dev Dec 12, 2023
b00c2ab
Update lease
CatherineF-dev Dec 12, 2023
7cf530f
Update limitrange
CatherineF-dev Dec 12, 2023
24f094f
Update mutatingwebhookconfiguration
CatherineF-dev Dec 12, 2023
11daeea
Update namespace
CatherineF-dev Dec 12, 2023
03dcba4
Update networkpolicy
CatherineF-dev Dec 12, 2023
e2355e9
Update node
CatherineF-dev Dec 12, 2023
22f3e9e
Update persistentvolume
CatherineF-dev Dec 12, 2023
29e0ab7
Update persistentvolumeclaim
CatherineF-dev Dec 12, 2023
7af15ae
Update poddisruptionbudget
CatherineF-dev Dec 12, 2023
8af682a
Update replicaset
CatherineF-dev Dec 12, 2023
5d61ac8
Update replicationcontroller
CatherineF-dev Dec 12, 2023
bfdc6d6
Update resourcequota
CatherineF-dev Dec 12, 2023
ecb9fe2
Update rolebinding
CatherineF-dev Dec 12, 2023
7c9a894
Update secret
CatherineF-dev Dec 12, 2023
6677a96
Update service
CatherineF-dev Dec 12, 2023
0acd7d3
Update serviceaccount
CatherineF-dev Dec 12, 2023
d1755d4
Update statefulset
CatherineF-dev Dec 12, 2023
f76480b
Update storageclass
CatherineF-dev Dec 12, 2023
f2fe924
Update role
CatherineF-dev Dec 12, 2023
53dab94
Update validatingwebhookconfiguration
CatherineF-dev Dec 12, 2023
6873732
Update volumeattachment
CatherineF-dev Dec 12, 2023
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
12 changes: 6 additions & 6 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ func (b *Builder) buildJobStores() []cache.Store {
}

func (b *Builder) buildLimitRangeStores() []cache.Store {
return b.buildStoresFunc(limitRangeMetricFamilies, &v1.LimitRange{}, createLimitRangeListWatch, b.useAPIServerCache)
return b.buildStoresFunc(limitRangeMetricFamilies(), &v1.LimitRange{}, createLimitRangeListWatch, b.useAPIServerCache)
}

func (b *Builder) buildMutatingWebhookConfigurationStores() []cache.Store {
return b.buildStoresFunc(mutatingWebhookConfigurationMetricFamilies, &admissionregistrationv1.MutatingWebhookConfiguration{}, createMutatingWebhookConfigurationListWatch, b.useAPIServerCache)
return b.buildStoresFunc(mutatingWebhookConfigurationMetricFamilies(), &admissionregistrationv1.MutatingWebhookConfiguration{}, createMutatingWebhookConfigurationListWatch, b.useAPIServerCache)
}

func (b *Builder) buildNamespaceStores() []cache.Store {
Expand Down Expand Up @@ -434,7 +434,7 @@ func (b *Builder) buildReplicaSetStores() []cache.Store {
}

func (b *Builder) buildReplicationControllerStores() []cache.Store {
return b.buildStoresFunc(replicationControllerMetricFamilies, &v1.ReplicationController{}, createReplicationControllerListWatch, b.useAPIServerCache)
return b.buildStoresFunc(replicationControllerMetricFamilies(), &v1.ReplicationController{}, createReplicationControllerListWatch, b.useAPIServerCache)
}

func (b *Builder) buildResourceQuotaStores() []cache.Store {
Expand Down Expand Up @@ -470,15 +470,15 @@ func (b *Builder) buildCsrStores() []cache.Store {
}

func (b *Builder) buildValidatingWebhookConfigurationStores() []cache.Store {
return b.buildStoresFunc(validatingWebhookConfigurationMetricFamilies, &admissionregistrationv1.ValidatingWebhookConfiguration{}, createValidatingWebhookConfigurationListWatch, b.useAPIServerCache)
return b.buildStoresFunc(validatingWebhookConfigurationMetricFamilies(), &admissionregistrationv1.ValidatingWebhookConfiguration{}, createValidatingWebhookConfigurationListWatch, b.useAPIServerCache)
}

func (b *Builder) buildVolumeAttachmentStores() []cache.Store {
return b.buildStoresFunc(volumeAttachmentMetricFamilies, &storagev1.VolumeAttachment{}, createVolumeAttachmentListWatch, b.useAPIServerCache)
return b.buildStoresFunc(volumeAttachmentMetricFamilies(), &storagev1.VolumeAttachment{}, createVolumeAttachmentListWatch, b.useAPIServerCache)
}

func (b *Builder) buildLeasesStores() []cache.Store {
return b.buildStoresFunc(leaseMetricFamilies, &coordinationv1.Lease{}, createLeaseListWatch, b.useAPIServerCache)
return b.buildStoresFunc(leaseMetricFamilies(), &coordinationv1.Lease{}, createLeaseListWatch, b.useAPIServerCache)
}

func (b *Builder) buildClusterRoleStores() []cache.Store {
Expand Down
59 changes: 33 additions & 26 deletions internal/store/certificatesigningrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
descCSRAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descCSRLabelsName = "kube_certificatesigningrequest_labels"
descCSRLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descCSRLabelsDefaultLabels = []string{"certificatesigningrequest", "signer_name"}
descCSRLabelsDefaultLabels = SharedLabelKeys{"certificatesigningrequest", "signer_name"}
)

func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
Expand All @@ -53,15 +53,16 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", j.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: annotationValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, annotationKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -75,15 +76,16 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: labelValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, labelKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -96,12 +98,13 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
ms := []*metric.Metric{}
if !csr.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(csr.CreationTimestamp.Unix()),
})
}

metric.SetLabelKeys(ms, []string{})

return &metric.Family{
Metrics: ms,
}
Expand All @@ -126,15 +129,19 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
basemetrics.STABLE,
"",
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: []string{},
LabelValues: []string{},
Value: float64(len(csr.Status.Certificate)),
},

ms := []*metric.Metric{
{
LabelValues: []string{},
Value: float64(len(csr.Status.Certificate)),
},
}

metric.SetLabelKeys(ms, []string{})

return &metric.Family{
Metrics: ms,
}
}),
),
}
Expand Down Expand Up @@ -177,16 +184,16 @@ func addCSRConditionMetrics(cs certv1.CertificateSigningRequestStatus) []*metric
}
}

return []*metric.Metric{
ms := []*metric.Metric{
{
LabelValues: []string{"approved"},
Value: float64(cApproved),
LabelKeys: []string{"condition"},
},
{
LabelValues: []string{"denied"},
Value: float64(cDenied),
LabelKeys: []string{"condition"},
},
}
metric.SetLabelKeys(ms, []string{"condition"})
return ms
}
48 changes: 27 additions & 21 deletions internal/store/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
descClusterRoleAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descClusterRoleLabelsName = "kube_clusterrole_labels"
descClusterRoleLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descClusterRoleLabelsDefaultLabels = []string{"clusterrole"}
descClusterRoleLabelsDefaultLabels = SharedLabelKeys{"clusterrole"}
)

func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
Expand All @@ -52,15 +52,16 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", r.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: annotationValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, annotationKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -74,15 +75,16 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", r.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: labelValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, labelKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -92,12 +94,15 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
basemetrics.ALPHA,
"",
wrapClusterRoleFunc(func(r *rbacv1.ClusterRole) *metric.Family {
ms := []*metric.Metric{{
LabelValues: []string{},
Value: 1,
}}

metric.SetLabelKeys(ms, []string{})

return &metric.Family{
Metrics: []*metric.Metric{{
LabelKeys: []string{},
LabelValues: []string{},
Value: 1,
}},
Metrics: ms,
}
}),
),
Expand All @@ -112,12 +117,13 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [

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

metric.SetLabelKeys(ms, []string{})

return &metric.Family{
Metrics: ms,
}
Expand Down
47 changes: 26 additions & 21 deletions internal/store/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
descClusterRoleBindingAnnotationsHelp = "Kubernetes annotations converted to Prometheus labels."
descClusterRoleBindingLabelsName = "kube_clusterrolebinding_labels"
descClusterRoleBindingLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descClusterRoleBindingLabelsDefaultLabels = []string{"clusterrolebinding"}
descClusterRoleBindingLabelsDefaultLabels = SharedLabelKeys{"clusterrolebinding"}
)

func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
Expand All @@ -52,15 +52,16 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
return &metric.Family{}
}
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", r.Annotations, allowAnnotationsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: annotationKeys,
LabelValues: annotationValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: annotationValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, annotationKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -74,15 +75,16 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
return &metric.Family{}
}
labelKeys, labelValues := createPrometheusLabelKeysValues("label", r.Labels, allowLabelsList)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: labelValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, labelKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -94,12 +96,15 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
wrapClusterRoleBindingFunc(func(r *rbacv1.ClusterRoleBinding) *metric.Family {
labelKeys := []string{"roleref_kind", "roleref_name"}
labelValues := []string{r.RoleRef.Kind, r.RoleRef.Name}
ms := []*metric.Metric{{
LabelValues: labelValues,
Value: 1,
}}

metric.SetLabelKeys(ms, labelKeys)

return &metric.Family{
Metrics: []*metric.Metric{{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
}},
Metrics: ms,
}
}),
),
Expand All @@ -114,11 +119,11 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st

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

return &metric.Family{
Metrics: ms,
Expand Down
Loading