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

Remove namespace label from custom metrics #56

Merged
merged 1 commit into from
Jul 12, 2024
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
12 changes: 6 additions & 6 deletions controllers/tenant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,17 +718,17 @@ func (r *TenantReconciler) updateAllTenantNamespacesConfigMap(ctx context.Contex
func (r *TenantReconciler) setMetrics(tenant *cattagev1beta1.Tenant) {
switch tenant.Status.Health {
case cattagev1beta1.TenantHealthy:
metrics.HealthyVec.WithLabelValues(tenant.Name, tenant.Namespace).Set(1)
metrics.UnhealthyVec.WithLabelValues(tenant.Name, tenant.Namespace).Set(0)
metrics.HealthyVec.WithLabelValues(tenant.Name).Set(1)
metrics.UnhealthyVec.WithLabelValues(tenant.Name).Set(0)
case cattagev1beta1.TenantUnhealthy:
metrics.HealthyVec.WithLabelValues(tenant.Name, tenant.Namespace).Set(0)
metrics.UnhealthyVec.WithLabelValues(tenant.Name, tenant.Namespace).Set(1)
metrics.HealthyVec.WithLabelValues(tenant.Name).Set(0)
metrics.UnhealthyVec.WithLabelValues(tenant.Name).Set(1)
}
}

func (r *TenantReconciler) removeMetrics(tenant *cattagev1beta1.Tenant) {
metrics.HealthyVec.DeleteLabelValues(tenant.Name, tenant.Namespace)
metrics.UnhealthyVec.DeleteLabelValues(tenant.Name, tenant.Namespace)
metrics.HealthyVec.DeleteLabelValues(tenant.Name)
metrics.UnhealthyVec.DeleteLabelValues(tenant.Name)
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
76 changes: 38 additions & 38 deletions controllers/tenant_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,18 +623,18 @@ var _ = Describe("Tenant controller", Ordered, func() {
expected := `
# HELP cattage_tenant_healthy The tenant status about healthy condition
# TYPE cattage_tenant_healthy gauge
cattage_tenant_healthy{name="a-team",namespace=""} 1
cattage_tenant_healthy{name="c-team",namespace=""} 1
cattage_tenant_healthy{name="m-team",namespace=""} 1
cattage_tenant_healthy{name="x-team",namespace=""} 1
cattage_tenant_healthy{name="y-team",namespace=""} 1
cattage_tenant_healthy{name="a-team"} 1
cattage_tenant_healthy{name="c-team"} 1
cattage_tenant_healthy{name="m-team"} 1
cattage_tenant_healthy{name="x-team"} 1
cattage_tenant_healthy{name="y-team"} 1
# HELP cattage_tenant_unhealthy The tenant status about unhealthy condition
# TYPE cattage_tenant_unhealthy gauge
cattage_tenant_unhealthy{name="a-team",namespace=""} 0
cattage_tenant_unhealthy{name="c-team",namespace=""} 0
cattage_tenant_unhealthy{name="m-team",namespace=""} 0
cattage_tenant_unhealthy{name="x-team",namespace=""} 0
cattage_tenant_unhealthy{name="y-team",namespace=""} 0
cattage_tenant_unhealthy{name="a-team"} 0
cattage_tenant_unhealthy{name="c-team"} 0
cattage_tenant_unhealthy{name="m-team"} 0
cattage_tenant_unhealthy{name="x-team"} 0
cattage_tenant_unhealthy{name="y-team"} 0
`
expectedReader := strings.NewReader(expected)
if err := testutil.GatherAndCompare(k8smetrics.Registry, expectedReader, customMetricsNames...); err != nil {
Expand All @@ -661,18 +661,18 @@ var _ = Describe("Tenant controller", Ordered, func() {
expected := `
# HELP cattage_tenant_healthy The tenant status about healthy condition
# TYPE cattage_tenant_healthy gauge
cattage_tenant_healthy{name="a-team",namespace=""} 1
cattage_tenant_healthy{name="c-team",namespace=""} 1
cattage_tenant_healthy{name="m-team",namespace=""} 0
cattage_tenant_healthy{name="x-team",namespace=""} 1
cattage_tenant_healthy{name="y-team",namespace=""} 1
cattage_tenant_healthy{name="a-team"} 1
cattage_tenant_healthy{name="c-team"} 1
cattage_tenant_healthy{name="m-team"} 0
cattage_tenant_healthy{name="x-team"} 1
cattage_tenant_healthy{name="y-team"} 1
# HELP cattage_tenant_unhealthy The tenant status about unhealthy condition
# TYPE cattage_tenant_unhealthy gauge
cattage_tenant_unhealthy{name="a-team",namespace=""} 0
cattage_tenant_unhealthy{name="c-team",namespace=""} 0
cattage_tenant_unhealthy{name="m-team",namespace=""} 1
cattage_tenant_unhealthy{name="x-team",namespace=""} 0
cattage_tenant_unhealthy{name="y-team",namespace=""} 0
cattage_tenant_unhealthy{name="a-team"} 0
cattage_tenant_unhealthy{name="c-team"} 0
cattage_tenant_unhealthy{name="m-team"} 1
cattage_tenant_unhealthy{name="x-team"} 0
cattage_tenant_unhealthy{name="y-team"} 0
`
expectedReader := strings.NewReader(expected)
if err := testutil.GatherAndCompare(k8smetrics.Registry, expectedReader, customMetricsNames...); err != nil {
Expand All @@ -691,18 +691,18 @@ var _ = Describe("Tenant controller", Ordered, func() {
expected := `
# HELP cattage_tenant_healthy The tenant status about healthy condition
# TYPE cattage_tenant_healthy gauge
cattage_tenant_healthy{name="a-team",namespace=""} 1
cattage_tenant_healthy{name="c-team",namespace=""} 1
cattage_tenant_healthy{name="m-team",namespace=""} 1
cattage_tenant_healthy{name="x-team",namespace=""} 1
cattage_tenant_healthy{name="y-team",namespace=""} 1
cattage_tenant_healthy{name="a-team"} 1
cattage_tenant_healthy{name="c-team"} 1
cattage_tenant_healthy{name="m-team"} 1
cattage_tenant_healthy{name="x-team"} 1
cattage_tenant_healthy{name="y-team"} 1
# HELP cattage_tenant_unhealthy The tenant status about unhealthy condition
# TYPE cattage_tenant_unhealthy gauge
cattage_tenant_unhealthy{name="a-team",namespace=""} 0
cattage_tenant_unhealthy{name="c-team",namespace=""} 0
cattage_tenant_unhealthy{name="m-team",namespace=""} 0
cattage_tenant_unhealthy{name="x-team",namespace=""} 0
cattage_tenant_unhealthy{name="y-team",namespace=""} 0
cattage_tenant_unhealthy{name="a-team"} 0
cattage_tenant_unhealthy{name="c-team"} 0
cattage_tenant_unhealthy{name="m-team"} 0
cattage_tenant_unhealthy{name="x-team"} 0
cattage_tenant_unhealthy{name="y-team"} 0
`
expectedReader := strings.NewReader(expected)
if err := testutil.GatherAndCompare(k8smetrics.Registry, expectedReader, customMetricsNames...); err != nil {
Expand All @@ -719,16 +719,16 @@ var _ = Describe("Tenant controller", Ordered, func() {
expected := `
# HELP cattage_tenant_healthy The tenant status about healthy condition
# TYPE cattage_tenant_healthy gauge
cattage_tenant_healthy{name="a-team",namespace=""} 1
cattage_tenant_healthy{name="c-team",namespace=""} 1
cattage_tenant_healthy{name="x-team",namespace=""} 1
cattage_tenant_healthy{name="y-team",namespace=""} 1
cattage_tenant_healthy{name="a-team"} 1
cattage_tenant_healthy{name="c-team"} 1
cattage_tenant_healthy{name="x-team"} 1
cattage_tenant_healthy{name="y-team"} 1
# HELP cattage_tenant_unhealthy The tenant status about unhealthy condition
# TYPE cattage_tenant_unhealthy gauge
cattage_tenant_unhealthy{name="a-team",namespace=""} 0
cattage_tenant_unhealthy{name="c-team",namespace=""} 0
cattage_tenant_unhealthy{name="x-team",namespace=""} 0
cattage_tenant_unhealthy{name="y-team",namespace=""} 0
cattage_tenant_unhealthy{name="a-team"} 0
cattage_tenant_unhealthy{name="c-team"} 0
cattage_tenant_unhealthy{name="x-team"} 0
cattage_tenant_unhealthy{name="y-team"} 0
`
expectedReader := strings.NewReader(expected)
if err := testutil.GatherAndCompare(k8smetrics.Registry, expectedReader, customMetricsNames...); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ var (
Subsystem: tenantSubsystem,
Name: "healthy",
Help: "The tenant status about healthy condition",
}, []string{"name", "namespace"})
}, []string{"name"})

UnhealthyVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNameSpace,
Subsystem: tenantSubsystem,
Name: "unhealthy",
Help: "The tenant status about unhealthy condition",
}, []string{"name", "namespace"})
}, []string{"name"})
)

func init() {
Expand Down
Loading