4444import io .javaoperatorsdk .operator .processing .retry .Retry ;
4545import io .javaoperatorsdk .operator .processing .retry .RetryExecution ;
4646
47- import static io .javaoperatorsdk .operator .processing .KubernetesResourceUtils .getName ;
48-
4947public class EventProcessor <P extends HasMetadata > implements EventHandler , LifecycleAware {
5048
5149 private static final Logger log = LoggerFactory .getLogger (EventProcessor .class );
@@ -187,9 +185,8 @@ private void submitReconciliationExecution(ResourceState state) {
187185 executor .execute (new ReconcilerExecutor (resourceID , executionScope ));
188186 } else {
189187 log .debug (
190- "Skipping executing controller for resource id: {} . Controller in execution: {}. Latest"
188+ "Skipping executing controller. Controller in execution: {}. Latest"
191189 + " Resource present: {}" ,
192- resourceID ,
193190 controllerUnderExecution ,
194191 maybeLatest .isPresent ());
195192 if (maybeLatest .isEmpty ()) {
@@ -198,7 +195,7 @@ private void submitReconciliationExecution(ResourceState state) {
198195 // resource. Other is that simply there is no primary resource present for an event, this
199196 // might indicate issue with the implementation, but could happen also naturally, thus
200197 // this is not necessarily a problem.
201- log .debug ("no primary resource found in cache with resource id: {}" , resourceID );
198+ log .debug ("No primary resource found in cache with resource id: {}" , resourceID );
202199 }
203200 }
204201 } finally {
@@ -209,7 +206,7 @@ private void submitReconciliationExecution(ResourceState state) {
209206 @ SuppressWarnings ("unchecked" )
210207 private P getResourceFromState (ResourceState state ) {
211208 if (triggerOnAllEvents ()) {
212- log .debug ("Getting resource from state for {}" , state . getId () );
209+ log .debug ("Getting resource from state" );
213210 return (P ) state .getLastKnownResource ();
214211 } else {
215212 throw new IllegalStateException (
@@ -218,19 +215,17 @@ private P getResourceFromState(ResourceState state) {
218215 }
219216
220217 private void handleEventMarking (Event event , ResourceState state ) {
221- final var relatedCustomResourceID = event .getRelatedCustomResourceID ();
222218 if (event instanceof ResourceEvent resourceEvent ) {
223219 if (resourceEvent .getAction () == ResourceAction .DELETED ) {
224- log .debug ("Marking delete event received for: {}" , relatedCustomResourceID );
220+ log .debug ("Marking delete event received" );
225221 state .markDeleteEventReceived (
226222 resourceEvent .getResource ().orElseThrow (),
227223 ((ResourceDeleteEvent ) resourceEvent ).isDeletedFinalStateUnknown ());
228224 } else {
229225 if (state .processedMarkForDeletionPresent () && isResourceMarkedForDeletion (resourceEvent )) {
230226 log .debug (
231227 "Skipping mark of event received, since already processed mark for deletion and"
232- + " resource marked for deletion: {}" ,
233- relatedCustomResourceID );
228+ + " resource marked for deletion" );
234229 return ;
235230 }
236231 // Normally when eventMarker is in state PROCESSED_MARK_FOR_DELETION it is expected to
@@ -260,8 +255,7 @@ private boolean isResourceMarkedForDeletion(ResourceEvent resourceEvent) {
260255
261256 private void handleRateLimitedSubmission (ResourceID resourceID , Duration minimalDuration ) {
262257 var minimalDurationMillis = minimalDuration .toMillis ();
263- log .debug (
264- "Rate limited resource: {}, rescheduled in {} millis" , resourceID , minimalDurationMillis );
258+ log .debug ("Rate limited resource; rescheduled in {} millis" , minimalDurationMillis );
265259 retryEventSource ()
266260 .scheduleOnce (
267261 resourceID , Math .max (minimalDurationMillis , MINIMAL_RATE_LIMIT_RESCHEDULE_DURATION ));
@@ -334,7 +328,7 @@ private void reScheduleExecutionIfInstructed(
334328 .ifPresentOrElse (
335329 delay -> {
336330 var resourceID = ResourceID .fromResource (customResource );
337- log .debug ("Rescheduling event for resource: {} with delay: {}" , resourceID , delay );
331+ log .debug ("Rescheduling event with delay: {}" , delay );
338332 retryEventSource ().scheduleOnce (resourceID , delay );
339333 },
340334 () -> scheduleExecutionForMaxReconciliationInterval (customResource ));
@@ -347,11 +341,7 @@ private void scheduleExecutionForMaxReconciliationInterval(P customResource) {
347341 m -> {
348342 var resourceID = ResourceID .fromResource (customResource );
349343 var delay = m .toMillis ();
350- log .debug (
351- "Rescheduling event for max reconciliation interval for resource: {} : "
352- + "with delay: {}" ,
353- resourceID ,
354- delay );
344+ log .debug ("Rescheduling event for max reconciliation interval with delay: {}" , delay );
355345 retryEventSource ().scheduleOnce (resourceID , delay );
356346 });
357347 }
@@ -375,16 +365,15 @@ private void handleRetryOnException(ExecutionScope<P> executionScope, Exception
375365
376366 retryAwareErrorLogging (state .getRetry (), eventPresent , exception , executionScope );
377367 if (eventPresent ) {
378- log .debug ("New events exists for for resource id: {}" , resourceID );
368+ log .debug ("New events exist for resource id" );
379369 submitReconciliationExecution (state );
380370 return ;
381371 }
382372 Optional <Long > nextDelay = state .getRetry ().nextDelay ();
383373
384374 nextDelay .ifPresentOrElse (
385375 delay -> {
386- log .debug (
387- "Scheduling timer event for retry with delay:{} for resource: {}" , delay , resourceID );
376+ log .debug ("Scheduling timer event for retry with delay:{}" , delay );
388377 metrics .failedReconciliation (executionScope .getResource (), exception , metricsMetadata );
389378 retryEventSource ().scheduleOnce (resourceID , delay );
390379 },
@@ -425,8 +414,7 @@ private void retryAwareErrorLogging(
425414 }
426415
427416 private void cleanupOnSuccessfulExecution (ExecutionScope <P > executionScope ) {
428- log .debug (
429- "Cleanup for successful execution for resource: {}" , getName (executionScope .getResource ()));
417+ log .debug ("Cleanup for successful execution" );
430418 if (isRetryConfigured ()) {
431419 resourceStateManager .getOrCreate (executionScope .getResourceID ()).setRetry (null );
432420 }
@@ -444,7 +432,7 @@ private ResourceState getOrInitRetryExecution(ExecutionScope<P> executionScope)
444432 }
445433
446434 private void cleanupForDeletedEvent (ResourceID resourceID ) {
447- log .debug ("Cleaning up for delete event for: {}" , resourceID );
435+ log .debug ("Cleaning up for delete event" );
448436 resourceStateManager .remove (resourceID );
449437 metrics .cleanupDoneFor (resourceID , metricsMetadata );
450438 }
@@ -509,6 +497,7 @@ public void run() {
509497 log .debug ("Event processor not running skipping resource processing: {}" , resourceID );
510498 return ;
511499 }
500+ MDCUtils .addResourceIDInfo (resourceID );
512501 log .debug ("Running reconcile executor for: {}" , executionScope );
513502 // change thread name for easier debugging
514503 final var thread = Thread .currentThread ();
@@ -518,9 +507,7 @@ public void run() {
518507 var actualResource = cache .get (resourceID );
519508 if (actualResource .isEmpty ()) {
520509 if (triggerOnAllEvents ()) {
521- log .debug (
522- "Resource not found in the cache, checking for delete event resource: {}" ,
523- resourceID );
510+ log .debug ("Resource not found in the cache, checking for delete event resource" );
524511 if (executionScope .isDeleteEvent ()) {
525512 var state = resourceStateManager .get (resourceID );
526513 actualResource =
@@ -538,7 +525,7 @@ public void run() {
538525 return ;
539526 }
540527 } else {
541- log .debug ("Skipping execution; primary resource missing from cache: {}" , resourceID );
528+ log .debug ("Skipping execution; primary resource missing from cache" );
542529 return ;
543530 }
544531 }
0 commit comments