Skip to content

Commit

Permalink
Merge pull request #344 from kubewharf/fix-metrics
Browse files Browse the repository at this point in the history
feat: adjust cluster state metrics
  • Loading branch information
mrlihanbo authored Dec 17, 2024
2 parents 5f4140c + 7324ab2 commit 1b837da
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
12 changes: 2 additions & 10 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
coverage:
status:
project:
default:
target: auto
threshold: 2%
# https://docs.codecov.com/docs/commit-status#patch-status
patch:
default:
target: 60%
if_ci_failed: error
# https://docs.codecov.com/docs/ignoring-paths
project: off
patch: off
ignore:
- "charts"
- "config"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
files: ./coverage.out
flags: unittests
# https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
fail_ci_if_error: true
fail_ci_if_error: false
verbose: true

lint:
Expand Down
19 changes: 6 additions & 13 deletions pkg/controllers/federatedcluster/clusterstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,39 +486,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 1b837da

Please sign in to comment.