Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
p-se committed Feb 27, 2024
1 parent 09310a3 commit b5087dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
4 changes: 2 additions & 2 deletions internal/metrics/bundle_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func CollectBundleMetrics(bundle *fleet.Bundle) {
labels := prometheus.Labels{
"name": bundle.Name,
"namespace": bundle.Namespace,
"commit": bundle.ObjectMeta.Labels["fleet.cattle.io/commit"],
"repo": bundle.ObjectMeta.Labels["fleet.cattle.io/repo-name"],
"commit": bundle.ObjectMeta.Labels[commitLabel],
"repo": bundle.ObjectMeta.Labels[repoNameLabel],
"generation": fmt.Sprintf("%d", bundle.ObjectMeta.Generation),
"state": string(summary.GetSummaryState(bundle.Status.Summary)),
}
Expand Down
21 changes: 11 additions & 10 deletions internal/metrics/bundledeployment_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
"name",
"namespace",
"cluster_name",
"cluster_namespace",
"repo",
"commit",
"bundle",
Expand Down Expand Up @@ -53,16 +54,16 @@ func CollectBundleDeploymentMetrics(bundleDep *fleet.BundleDeployment) {
}

labels := prometheus.Labels{
"name": bundleDep.Name,
"namespace": bundleDep.Namespace,
"cluster_name": bundleDep.ObjectMeta.Labels["fleet.cattle.io/cluster"],
// "cluster_display_name": clusterDisplayName, // TODO fetch with meta metric
"repo": bundleDep.ObjectMeta.Labels["fleet.cattle.io/repo-name"],
"commit": bundleDep.ObjectMeta.Labels["fleet.cattle.io/commit"],
"bundle": bundleDep.ObjectMeta.Labels["fleet.cattle.io/bundle-name"],
"bundle_namespace": bundleDep.ObjectMeta.Labels["fleet.cattle.io/bundle-namespace"],
"generation": fmt.Sprintf("%d", bundleDep.ObjectMeta.Generation),
"state": string(summary.GetDeploymentState(bundleDep)),
"name": bundleDep.Name,
"namespace": bundleDep.Namespace,
"cluster_name": bundleDep.ObjectMeta.Labels["fleet.cattle.io/cluster"],
"cluster_namespace": bundleDep.ObjectMeta.Labels["fleet.cattle.io/cluster-namespace"],
"repo": bundleDep.ObjectMeta.Labels[repoNameLabel],
"commit": bundleDep.ObjectMeta.Labels[commitLabel],
"bundle": bundleDep.ObjectMeta.Labels["fleet.cattle.io/bundle-name"],
"bundle_namespace": bundleDep.ObjectMeta.Labels["fleet.cattle.io/bundle-namespace"],
"generation": fmt.Sprintf("%d", bundleDep.ObjectMeta.Generation),
"state": string(summary.GetDeploymentState(bundleDep)),
}
bundleDeploymentObserved.With(labels).Inc()

Expand Down
10 changes: 2 additions & 8 deletions internal/metrics/cluster_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
"generation",
"state",
}

clusterNameLabel = "management.cattle.io/cluster-name"
clusterDisplayNameLabel = "management.cattle.io/cluster-display-name"
clusterStates = []string{
Expand Down Expand Up @@ -161,17 +162,10 @@ func CollectClusterMetrics(cluster *fleet.Cluster) {
return
}

clusterName := cluster.ObjectMeta.Labels[clusterNameLabel]
if clusterName == "" {
// Local clusters have no `management.cattle.io/cluster-name` label but
// have `name` label. Is that an inconsistency or a feature?
clusterName = cluster.ObjectMeta.Labels["name"]
}

labels := prometheus.Labels{
"name": cluster.Name,
"namespace": cluster.Namespace,
"cluster_name": clusterName,
"cluster_name": cluster.ObjectMeta.Labels[clusterNameLabel],
"cluster_display_name": cluster.ObjectMeta.Labels[clusterDisplayNameLabel],
"generation": fmt.Sprintf("%d", cluster.ObjectMeta.Generation),
"state": cluster.Status.Display.State,
Expand Down
8 changes: 4 additions & 4 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ var (
// The namespace for the metrics, not the Kubernetes namespace of the
// resources. This is the prefix for the metric (e.g. `fleet_` for value
// `fleet`).
namespace = "fleet"

namespace = "fleet"
bundleStates = []fleet.BundleState{
fleet.Ready,
fleet.NotReady,
Expand All @@ -17,8 +16,9 @@ var (
fleet.WaitApplied,
fleet.ErrApplied,
}

enabled = false
commitLabel = "fleet.cattle.io/commit"
repoNameLabel = "fleet.cattle.io/repo-name"
enabled = false
)

func RegisterMetrics() {
Expand Down

0 comments on commit b5087dc

Please sign in to comment.