Skip to content

Commit 68d76a1

Browse files
committed
logging improvements
1 parent e18532f commit 68d76a1

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ private void executeBufferedEvents(String customResourceUid) {
6868
resourceCache.getLatestResource(customResourceUid).get());
6969
log.debug("Executing events for custom resource. Scope: {}", executionScope);
7070
executor.execute(new ExecutionConsumer(executionScope, eventDispatcher, this));
71+
} else {
72+
log.debug("Not executing controller for {}, since currently under execution.", customResourceUid);
7173
}
7274
}
7375

7476
void eventProcessingFinished(ExecutionScope executionScope, PostExecutionControl postExecutionControl) {
7577
try {
7678
lock.lock();
79+
log.debug("Event processing finished. Scope: {}", executionScope);
7780
unsetUnderExecution(executionScope.getCustomResourceUid());
7881
defaultEventSourceManager.controllerExecuted(
7982
new ExecutionDescriptor(executionScope, postExecutionControl, LocalDateTime.now()));

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Map;
1515
import java.util.concurrent.ConcurrentHashMap;
1616

17+
import static io.javaoperatorsdk.operator.processing.ProcessingUtils.*;
18+
1719
/**
1820
* Dispatches events to the Controller and handles Finalizers for a single type of Custom Resource.
1921
*/
@@ -49,8 +51,10 @@ private PostExecutionControl handDispatch(ExecutionScope executionScope) {
4951
CustomResource resource = executionScope.getCustomResource();
5052
log.debug("Handling events: {} for resource {}", executionScope.getEvents(), resource.getMetadata());
5153

52-
if (ProcessingUtils.containsCustomResourceDeletedEvent(executionScope.getEvents())) {
54+
if (containsCustomResourceDeletedEvent(executionScope.getEvents())) {
5355
cleanup(executionScope.getCustomResource());
56+
log.debug("Skipping dispatch processing because of a Delete event: {} with version: {}",
57+
getUID(resource), getVersion(resource));
5458
return PostExecutionControl.defaultDispatch();
5559
}
5660
if ((markedForDeletion(resource) && !ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer))) {
@@ -76,19 +80,27 @@ private PostExecutionControl handleCreateOrUpdate(ExecutionScope executionScope,
7680
return PostExecutionControl.onlyFinalizerAdded();
7781
} else {
7882
if (!skipBecauseOfGenerations(executionScope)) {
83+
log.debug("Executing createOrUpdate for resource {} with version: {} with execution scope: {}",
84+
getUID(resource), getVersion(resource), executionScope);
7985
UpdateControl<? extends CustomResource> updateControl = controller.createOrUpdateResource(resource, context);
8086
if (updateControl.isUpdateStatusSubResource()) {
8187
customResourceFacade.updateStatus(updateControl.getCustomResource());
8288
} else if (updateControl.isUpdateCustomResource()) {
8389
updateCustomResource(updateControl.getCustomResource());
8490
}
8591
markLastGenerationProcessed(resource);
92+
} else {
93+
log.debug("Skipping event processing because generations: {} with version: {}",
94+
getUID(resource), getVersion(resource));
8695
}
8796
return PostExecutionControl.defaultDispatch();
8897
}
8998
}
9099

91100
private boolean skipBecauseOfGenerations(ExecutionScope executionScope) {
101+
if (!generationAware) {
102+
return false;
103+
}
92104
if (executionScope.getEvents().size() == 1) {
93105
Event<?> event = executionScope.getEvents().get(0);
94106
if (event instanceof CustomResourceEvent) {
@@ -104,14 +116,15 @@ private boolean skipBecauseOfGenerations(ExecutionScope executionScope) {
104116
}
105117

106118
private PostExecutionControl handleDelete(CustomResource resource, Context context) {
119+
log.debug("Executing delete for resource: {} with version: {}", getUID(resource), getVersion(resource));
107120
DeleteControl deleteControl = controller.deleteResource(resource, context);
108121
boolean hasFinalizer = ControllerUtils.hasGivenFinalizer(resource, resourceFinalizer);
109122
if (deleteControl == DeleteControl.DEFAULT_DELETE && hasFinalizer) {
110123
removeFinalizer(resource);
111124
cleanup(resource);
112125
} else {
113-
log.debug("Skipping finalizer remove. delete control: {}, hasFinalizer: {} ",
114-
deleteControl, hasFinalizer);
126+
log.debug("Skipping finalizer remove for resource: {} with version: {}. delete control: {}, hasFinalizer: {} ",
127+
getUID(resource), getVersion(resource), deleteControl, hasFinalizer);
115128
}
116129
return PostExecutionControl.defaultDispatch();
117130
}
@@ -138,22 +151,22 @@ private void markLastGenerationProcessed(CustomResource resource) {
138151
}
139152

140153
private void updateCustomResourceWithFinalizer(CustomResource resource) {
141-
log.debug("Adding finalizer for resource: {} version: {}", resource.getMetadata().getName(),
142-
resource.getMetadata().getResourceVersion());
154+
log.debug("Adding finalizer for resource: {} version: {}", getUID(resource),
155+
getVersion(resource));
143156
addFinalizerIfNotPresent(resource);
144157
replace(resource);
145158
}
146159

147-
private void updateCustomResource(CustomResource updatedResource) {
148-
log.debug("Updating resource: {} with version: {}", updatedResource.getMetadata().getName(),
149-
updatedResource.getMetadata().getResourceVersion());
150-
log.trace("Resource before update: {}", updatedResource);
151-
replace(updatedResource);
160+
private void updateCustomResource(CustomResource resource) {
161+
log.debug("Updating resource: {} with version: {}", getUID(resource),
162+
getVersion(resource));
163+
log.trace("Resource before update: {}", resource);
164+
replace(resource);
152165
}
153166

154167

155168
private void removeFinalizer(CustomResource resource) {
156-
log.debug("Removing finalizer on resource {}:", resource);
169+
log.debug("Removing finalizer on resource: {} with version: {}", getUID(resource), getVersion(resource));
157170
resource.getMetadata().getFinalizers().remove(resourceFinalizer);
158171
customResourceFacade.replaceWithLock(resource);
159172
}

0 commit comments

Comments
 (0)