Skip to content

Commit

Permalink
feat: adjust cluster state metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Poor12 committed Dec 17, 2024
1 parent 26a5bcb commit 2ce7086
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
19 changes: 6 additions & 13 deletions pkg/controllers/federatedcluster/clusterstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,39 +483,32 @@ func shouldCollectClusterStatus(cluster *fedcorev1a1.FederatedCluster, collectIn
}

func (c *FederatedClusterController) recordClusterStatus(cluster *fedcorev1a1.FederatedCluster, startTime time.Time) {
readyReason, joinedReason, offlineReason := clusterutil.GetClusterConditionReasons(&cluster.Status)
if clusterutil.IsClusterReady(&cluster.Status) {
c.metrics.Store(metrics.ClusterReadyState,
1,
stats.Tag{Name: "cluster_name", Value: cluster.Name},
stats.Tag{Name: "reason", Value: readyReason})
stats.Tag{Name: "cluster_name", Value: cluster.Name})
} else {
c.metrics.Store(metrics.ClusterReadyState,
0,
stats.Tag{Name: "cluster_name", Value: cluster.Name},
stats.Tag{Name: "reason", Value: readyReason})
stats.Tag{Name: "cluster_name", Value: cluster.Name})
}
if clusterutil.IsClusterOffline(&cluster.Status) {
c.metrics.Store(metrics.ClusterOfflineState,
1,
stats.Tag{Name: "cluster_name", Value: cluster.Name},
stats.Tag{Name: "reason", Value: offlineReason})
stats.Tag{Name: "cluster_name", Value: cluster.Name})
} else {
c.metrics.Store(metrics.ClusterOfflineState,
0,
stats.Tag{Name: "cluster_name", Value: cluster.Name},
stats.Tag{Name: "reason", Value: offlineReason})
stats.Tag{Name: "cluster_name", Value: cluster.Name})
}
if clusterutil.IsClusterJoined(&cluster.Status) {
c.metrics.Store(metrics.ClusterJoinedState,
1,
stats.Tag{Name: "cluster_name", Value: cluster.Name},
stats.Tag{Name: "reason", Value: joinedReason})
stats.Tag{Name: "cluster_name", Value: cluster.Name})
} else {
c.metrics.Store(metrics.ClusterJoinedState,
0,
stats.Tag{Name: "cluster_name", Value: cluster.Name},
stats.Tag{Name: "reason", Value: joinedReason})
stats.Tag{Name: "cluster_name", Value: cluster.Name})
}
c.metrics.Duration(metrics.ClusterSyncStatusDuration,
startTime,
Expand Down
16 changes: 0 additions & 16 deletions pkg/util/cluster/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,3 @@ func IsClusterOffline(clusterStatus *fedcorev1a1.FederatedClusterStatus) bool {
}
return false
}

func GetClusterConditionReasons(clusterStatus *fedcorev1a1.FederatedClusterStatus) (readyReason, joinedReason, offlineReason string) {
for _, condition := range clusterStatus.Conditions {
switch condition.Type {
case fedcorev1a1.ClusterReady:
readyReason = condition.Reason
case fedcorev1a1.ClusterJoined:
joinedReason = condition.Reason
case fedcorev1a1.ClusterOffline:
offlineReason = condition.Reason
default:
continue
}
}
return readyReason, joinedReason, offlineReason
}

0 comments on commit 2ce7086

Please sign in to comment.