@@ -221,25 +221,33 @@ public void cleanupDoneFor(ResourceID resourceID, Map<String, Object> metadata)
221221 public void reconcileCustomResource (
222222 HasMetadata resource , RetryInfo retryInfoNullable , Map <String , Object > metadata ) {
223223 Optional <RetryInfo > retryInfo = Optional .ofNullable (retryInfoNullable );
224- incrementCounter (
225- ResourceID .fromResource (resource ),
226- RECONCILIATIONS_STARTED ,
227- metadata ,
228- Tag .of (
229- RECONCILIATIONS_RETRIES_NUMBER ,
230- String .valueOf (retryInfo .map (RetryInfo ::getAttemptCount ).orElse (0 ))),
231- Tag .of (
232- RECONCILIATIONS_RETRIES_LAST ,
233- String .valueOf (retryInfo .map (RetryInfo ::isLastAttempt ).orElse (true ))));
224+ ResourceID resourceID = ResourceID .fromResource (resource );
225+
226+ // Record the counter without retry tags
227+ incrementCounter (resourceID , RECONCILIATIONS_STARTED , metadata );
228+
229+ // Update retry number gauge
230+ int retryNumber = retryInfo .map (RetryInfo ::getAttemptCount ).orElse (0 );
231+ updateGauge (resourceID , metadata , RECONCILIATIONS_RETRIES_NUMBER , retryNumber );
232+
233+ // Update retry last attempt gauge (1 for true, 0 for false)
234+ int isLastAttempt = retryInfo .map (RetryInfo ::isLastAttempt ).orElse (true ) ? 1 : 0 ;
235+ updateGauge (resourceID , metadata , RECONCILIATIONS_RETRIES_LAST , isLastAttempt );
234236
235237 var controllerQueueSize =
236238 gauges .get (controllerQueueSizeGaugeRefName (metadata .get (CONTROLLER_NAME ).toString ()));
237239 controllerQueueSize .incrementAndGet ();
238240 }
239241
240242 @ Override
241- public void finishedReconciliation (HasMetadata resource , Map <String , Object > metadata ) {
242- incrementCounter (ResourceID .fromResource (resource ), RECONCILIATIONS_SUCCESS , metadata );
243+ public void successfullyFinishedReconciliation (
244+ HasMetadata resource , Map <String , Object > metadata ) {
245+ ResourceID resourceID = ResourceID .fromResource (resource );
246+ incrementCounter (resourceID , RECONCILIATIONS_SUCCESS , metadata );
247+
248+ // Reset retry gauges on successful reconciliation
249+ updateGauge (resourceID , metadata , RECONCILIATIONS_RETRIES_NUMBER , 0 );
250+ updateGauge (resourceID , metadata , RECONCILIATIONS_RETRIES_LAST , 0 );
243251 }
244252
245253 @ Override
@@ -335,6 +343,32 @@ private void incrementCounter(
335343 counter .increment ();
336344 }
337345
346+ private void updateGauge (
347+ ResourceID id , Map <String , Object > metadata , String gaugeName , int value ) {
348+ final var tags = new ArrayList <Tag >(6 );
349+ addMetadataTags (id , metadata , tags , false );
350+
351+ final var gaugeRefName = buildGaugeRefName (id , gaugeName );
352+ AtomicInteger gauge =
353+ gauges .computeIfAbsent (
354+ gaugeRefName ,
355+ key -> {
356+ AtomicInteger newGauge =
357+ registry .gauge (PREFIX + gaugeName , tags , new AtomicInteger (0 ));
358+ // Find the meter in the registry and record it for cleanup
359+ var meter = registry .find (PREFIX + gaugeName ).tags (tags ).gauge ();
360+ if (meter != null ) {
361+ cleaner .recordAssociation (id , meter );
362+ }
363+ return newGauge ;
364+ });
365+ gauge .set (value );
366+ }
367+
368+ private String buildGaugeRefName (ResourceID id , String gaugeName ) {
369+ return gaugeName + "." + id .getName () + "." + id .getNamespace ().orElse (CLUSTER );
370+ }
371+
338372 protected Set <Meter .Id > recordedMeterIdsFor (ResourceID resourceID ) {
339373 return cleaner .recordedMeterIdsFor (resourceID );
340374 }
0 commit comments