Merge pull request #5866 from CharlesQQ/fix-metrics

fix(cluster):  remove related metrics label when cluster is deleted
This commit is contained in:
karmada-bot 2025-02-14 11:12:10 +08:00 committed by GitHub
commit e75306d143
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -135,6 +135,7 @@ func (c *ClusterStatusController) Reconcile(ctx context.Context, req controllerr
c.GenericInformerManager.Stop(req.NamespacedName.Name) c.GenericInformerManager.Stop(req.NamespacedName.Name)
c.TypedInformerManager.Stop(req.NamespacedName.Name) c.TypedInformerManager.Stop(req.NamespacedName.Name)
c.clusterConditionCache.delete(req.NamespacedName.Name) c.clusterConditionCache.delete(req.NamespacedName.Name)
metrics.CleanupMetricsForCluster(req.NamespacedName.Name)
// stop lease controller after the cluster is gone. // stop lease controller after the cluster is gone.
// only used for clusters in Pull mode because no need to set up lease syncing for Push clusters. // only used for clusters in Pull mode because no need to set up lease syncing for Push clusters.

View File

@ -135,6 +135,20 @@ func RecordClusterSyncStatusDuration(cluster *v1alpha1.Cluster, startTime time.T
clusterSyncStatusDuration.WithLabelValues(cluster.Name).Observe(utilmetrics.DurationInSeconds(startTime)) clusterSyncStatusDuration.WithLabelValues(cluster.Name).Observe(utilmetrics.DurationInSeconds(startTime))
} }
// CleanupMetricsForCluster removes the cluster status metrics after the cluster is deleted.
func CleanupMetricsForCluster(clusterName string) {
clusterReadyGauge.DeleteLabelValues(clusterName)
clusterTotalNodeNumberGauge.DeleteLabelValues(clusterName)
clusterReadyNodeNumberGauge.DeleteLabelValues(clusterName)
clusterMemoryAllocatableGauge.DeleteLabelValues(clusterName)
clusterCPUAllocatableGauge.DeleteLabelValues(clusterName)
clusterPodAllocatableGauge.DeleteLabelValues(clusterName)
clusterMemoryAllocatedGauge.DeleteLabelValues(clusterName)
clusterCPUAllocatedGauge.DeleteLabelValues(clusterName)
clusterPodAllocatedGauge.DeleteLabelValues(clusterName)
clusterSyncStatusDuration.DeleteLabelValues(clusterName)
}
// ClusterCollectors returns the collectors about clusters. // ClusterCollectors returns the collectors about clusters.
func ClusterCollectors() []prometheus.Collector { func ClusterCollectors() []prometheus.Collector {
return []prometheus.Collector{ return []prometheus.Collector{