Skip to content

Commit fc6c098

Browse files
authored
Merge pull request #430 from fluxcd/stale-metrics
Delete stale metrics on object delete
2 parents 194a138 + 9344216 commit fc6c098

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/fluxcd/pkg/apis/event v0.5.2
1414
github.com/fluxcd/pkg/apis/meta v1.1.2
1515
github.com/fluxcd/pkg/oci v0.30.1
16-
github.com/fluxcd/pkg/runtime v0.41.0
16+
github.com/fluxcd/pkg/runtime v0.42.0
1717
github.com/fluxcd/pkg/version v0.2.2
1818
github.com/google/go-containerregistry v0.16.1
1919
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20230802205906-a54d64203cff

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ github.com/fluxcd/pkg/apis/meta v1.1.2 h1:Unjo7hxadtB2dvGpeFqZZUdsjpRA08YYSBb7dF
176176
github.com/fluxcd/pkg/apis/meta v1.1.2/go.mod h1:BHQyRHCskGMEDf6kDGbgQ+cyiNpUHbLsCOsaMYM2maI=
177177
github.com/fluxcd/pkg/oci v0.30.1 h1:XRCWzufSRtI6g6TvCH8pJHIqw9qXUf2+9fBH8pOpoU0=
178178
github.com/fluxcd/pkg/oci v0.30.1/go.mod h1:HAWYIdzEbCnAT7Me2YGVUlgA5y/CCBdJ0+tFdEOb2nI=
179-
github.com/fluxcd/pkg/runtime v0.41.0 h1:hjWUwVRCKDuGEUhovWrygt/6PRry4p278yKuJNgTfv8=
180-
github.com/fluxcd/pkg/runtime v0.41.0/go.mod h1:1GN+nxoQ7LmSsLJwjH8JW8pA27tBSO+KLH43HpywCDM=
179+
github.com/fluxcd/pkg/runtime v0.42.0 h1:a5DQ/f90YjoHBmiXZUpnp4bDSLORjInbmqP7K11L4uY=
180+
github.com/fluxcd/pkg/runtime v0.42.0/go.mod h1:p6A3xWVV8cKLLQW0N90GehKgGMMmbNYv+OSJ/0qB0vg=
181181
github.com/fluxcd/pkg/version v0.2.2 h1:ZpVXECeLA5hIQMft11iLp6gN3cKcz6UNuVTQPw/bRdI=
182182
github.com/fluxcd/pkg/version v0.2.2/go.mod h1:NGnh/no8S6PyfCDxRFrPY3T5BUnqP48MxfxNRU0z8C0=
183183
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

internal/controller/imagerepository_controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ func (r *ImageRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Requ
143143
return ctrl.Result{}, client.IgnoreNotFound(err)
144144
}
145145

146-
// Record suspended status metric.
147-
r.RecordSuspend(ctx, obj, obj.Spec.Suspend)
148-
149146
// Initialize the patch helper with the current version of the object.
150147
serialPatcher := patch.NewSerialPatcher(obj, r.Client)
151148

@@ -161,7 +158,8 @@ func (r *ImageRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Requ
161158
retErr = kerrors.NewAggregate([]error{retErr, err})
162159
}
163160

164-
// Always record readiness and duration metrics.
161+
// Always record suspend, readiness and duration metrics.
162+
r.Metrics.RecordSuspend(ctx, obj, obj.Spec.Suspend)
165163
r.Metrics.RecordReadiness(ctx, obj)
166164
r.Metrics.RecordDuration(ctx, obj, start)
167165
}()

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
feathelper "github.com/fluxcd/pkg/runtime/features"
4343
"github.com/fluxcd/pkg/runtime/leaderelection"
4444
"github.com/fluxcd/pkg/runtime/logger"
45+
"github.com/fluxcd/pkg/runtime/metrics"
4546
"github.com/fluxcd/pkg/runtime/pprof"
4647
"github.com/fluxcd/pkg/runtime/probes"
4748

@@ -202,7 +203,7 @@ func main() {
202203
os.Exit(1)
203204
}
204205

205-
metricsH := helper.MustMakeMetrics(mgr)
206+
metricsH := helper.NewMetrics(mgr, metrics.MustMakeRecorder(), imagev1.ImageRepositoryFinalizer)
206207

207208
if err := (&controller.ImageRepositoryReconciler{
208209
Client: mgr.GetClient(),

0 commit comments

Comments
 (0)