@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "sort"
23+ "time"
2324
2425 certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
2526 k8creconciling "k8c.io/reconciler/pkg/reconciling"
@@ -40,6 +41,7 @@ import (
4041 "sigs.k8s.io/controller-runtime/pkg/reconcile"
4142
4243 "github.com/kcp-dev/kcp-operator/internal/controller/util"
44+ "github.com/kcp-dev/kcp-operator/internal/metrics"
4345 "github.com/kcp-dev/kcp-operator/internal/reconciling"
4446 "github.com/kcp-dev/kcp-operator/internal/resources"
4547 "github.com/kcp-dev/kcp-operator/internal/resources/frontproxy"
@@ -99,12 +101,19 @@ func (r *RootShardReconciler) SetupWithManager(mgr ctrl.Manager) error {
99101// For more details, check Reconcile and its Result here:
100102// - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile 101103func (r * RootShardReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (res ctrl.Result , recErr error ) {
104+ startTime := time .Now ()
105+ defer func () {
106+ duration := time .Since (startTime )
107+ metrics .RecordReconciliationMetrics (metrics .RootShardResourceType , duration .Seconds (), recErr )
108+ }()
109+
102110 logger := log .FromContext (ctx )
103111 logger .V (4 ).Info ("Reconciling" )
104112
105113 var rootShard operatorv1alpha1.RootShard
106114 if err := r .Get (ctx , req .NamespacedName , & rootShard ); err != nil {
107115 if ctrlruntimeclient .IgnoreNotFound (err ) != nil {
116+ metrics .RecordReconciliationError (metrics .RootShardResourceType , err .Error ())
108117 return ctrl.Result {}, fmt .Errorf ("failed to find %s/%s: %w" , req .Namespace , req .Name , err )
109118 }
110119
@@ -118,6 +127,14 @@ func (r *RootShardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
118127 recErr = kerrors .NewAggregate ([]error {recErr , err })
119128 }
120129
130+ metrics .RecordObjectMetrics (
131+ metrics .RootShardResourceType ,
132+ rootShard .Name ,
133+ req .Namespace ,
134+ string (rootShard .Status .Phase ),
135+ rootShard .Status .Conditions ,
136+ )
137+
121138 return ctrl.Result {}, recErr
122139}
123140
0 commit comments