Skip to content

Commit

Permalink
fix golanglint
Browse files Browse the repository at this point in the history
  • Loading branch information
Disper committed Mar 5, 2024
1 parent f7ecab2 commit e85d68a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/controller/gardener_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (controller *GardenerClusterController) Reconcile(ctx context.Context, req
return controller.resultWithRequeue(&cluster, requeueAfter), nil
}

func (controller *GardenerClusterController) unsetStateMetric(ctx context.Context, req ctrl.Request) {
func (controller *GardenerClusterController) unsetStateMetric(req ctrl.Request) {
controller.metrics.UnSetGardenerClusterStates(req.NamespacedName.Name)
}

Expand Down
24 changes: 12 additions & 12 deletions internal/controller/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ func NewMetrics() Metrics {
}

func (m Metrics) SetGardenerClusterStates(cluster v1.GardenerCluster) {
var runtimeId = cluster.GetLabels()[runtimeIDLabel]
var runtimeID = cluster.GetLabels()[runtimeIDLabel]

if runtimeId != "" {
if runtimeID != "" {
if len(cluster.Status.Conditions) != 0 {
var reason = cluster.Status.Conditions[0].Reason

// first clean the old metric
m.cleanUpGardenerClusterGauge(runtimeId)
m.gardenerClustersStateGaugeVec.WithLabelValues(runtimeId, string(cluster.Status.State), reason).Set(1)
m.cleanUpGardenerClusterGauge(runtimeID)
m.gardenerClustersStateGaugeVec.WithLabelValues(runtimeID, string(cluster.Status.State), reason).Set(1)
}
}
}

func (m Metrics) UnSetGardenerClusterStates(runtimeId string) {
m.cleanUpGardenerClusterGauge(runtimeId)
func (m Metrics) UnSetGardenerClusterStates(runtimeID string) {
m.cleanUpGardenerClusterGauge(runtimeID)
}

func (m Metrics) cleanUpGardenerClusterGauge(runtimeId string) {
var readyMetric, _ = m.gardenerClustersStateGaugeVec.GetMetricWithLabelValues(runtimeId, "Ready")
func (m Metrics) cleanUpGardenerClusterGauge(runtimeID string) {
var readyMetric, _ = m.gardenerClustersStateGaugeVec.GetMetricWithLabelValues(runtimeID, "Ready")
if readyMetric != nil {
readyMetric.Set(0)
}
var errorMetric, _ = m.gardenerClustersStateGaugeVec.GetMetricWithLabelValues(runtimeId, "Error")
var errorMetric, _ = m.gardenerClustersStateGaugeVec.GetMetricWithLabelValues(runtimeID, "Error")
if errorMetric != nil {
errorMetric.Set(0)
}
fmt.Printf("GardenerClusterStates set value to 0 for %v", runtimeId)
fmt.Printf("GardenerClusterStates set value to 0 for %v", runtimeID)

metricsDeleted := m.gardenerClustersStateGaugeVec.DeletePartialMatch(prometheus.Labels{
runtimeIDKeyName: runtimeId,
runtimeIDKeyName: runtimeID,
})

if metricsDeleted > 0 {
fmt.Printf("gardenerClusterStateGauge deleted %d metrics for runtimeId %v", metricsDeleted, runtimeId)
fmt.Printf("gardenerClusterStateGauge deleted %d metrics for runtimeID %v", metricsDeleted, runtimeID)
}
}

0 comments on commit e85d68a

Please sign in to comment.