Skip to content

Commit

Permalink
helmrepo: Delete cache metrics on object delete
Browse files Browse the repository at this point in the history
The cache event metrics for a given helmrepo continues to be exported
even after the object is deleted.

This change deletes the cache event metrics when the object is deleted.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Jul 31, 2023
1 parent 96f6041 commit f5a4b54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/cache/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (r *CacheRecorder) IncCacheEvents(event, name, namespace string) {
r.cacheEventsCounter.WithLabelValues(event, name, namespace).Inc()
}

// DeleteCacheEvent deletes the cache event metric.
func (r *CacheRecorder) DeleteCacheEvent(event, name, namespace string) {
r.cacheEventsCounter.DeleteLabelValues(event, name, namespace)
}

// MustMakeMetrics creates a new CacheRecorder, and registers the metrics collectors in the controller-runtime metrics registry.
func MustMakeMetrics() *CacheRecorder {
r := NewCacheRecorder()
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ func (r *HelmRepositoryReconciler) reconcileDelete(ctx context.Context, obj *hel
controllerutil.RemoveFinalizer(obj, sourcev1.SourceFinalizer)
}

// Delete cache metrics.
r.DeleteCacheEvent(cache.CacheEventTypeHit, obj.Name, obj.Namespace)
r.DeleteCacheEvent(cache.CacheEventTypeMiss, obj.Name, obj.Namespace)

// Stop reconciliation as the object is being deleted
return sreconcile.ResultEmpty, nil
}
Expand Down

0 comments on commit f5a4b54

Please sign in to comment.