16
16
import io .javaoperatorsdk .operator .api .RetryInfo ;
17
17
import io .javaoperatorsdk .operator .api .config .ConfigurationService ;
18
18
import io .javaoperatorsdk .operator .api .config .ExecutorServiceManager ;
19
- import io .javaoperatorsdk .operator .api .monitoring .EventMonitor ;
19
+ import io .javaoperatorsdk .operator .api .monitoring .Metrics ;
20
20
import io .javaoperatorsdk .operator .processing .event .CustomResourceID ;
21
21
import io .javaoperatorsdk .operator .processing .event .DefaultEventSourceManager ;
22
22
import io .javaoperatorsdk .operator .processing .event .Event ;
@@ -43,7 +43,7 @@ public class DefaultEventHandler<R extends CustomResource<?, ?>> implements Even
43
43
private final ExecutorService executor ;
44
44
private final String controllerName ;
45
45
private final ReentrantLock lock = new ReentrantLock ();
46
- private final EventMonitor eventMonitor ;
46
+ private final Metrics metrics ;
47
47
private volatile boolean running ;
48
48
private final ResourceCache <R > resourceCache ;
49
49
private DefaultEventSourceManager <R > eventSourceManager ;
@@ -56,7 +56,7 @@ public DefaultEventHandler(ConfiguredController<R> controller, ResourceCache<R>
56
56
controller .getConfiguration ().getName (),
57
57
new EventDispatcher <>(controller ),
58
58
GenericRetry .fromConfiguration (controller .getConfiguration ().getRetryConfiguration ()),
59
- controller .getConfiguration ().getConfigurationService ().getMetrics (). getEventMonitor () ,
59
+ controller .getConfiguration ().getConfigurationService ().getMetrics (),
60
60
new EventMarker ());
61
61
}
62
62
@@ -68,7 +68,7 @@ public DefaultEventHandler(ConfiguredController<R> controller, ResourceCache<R>
68
68
69
69
private DefaultEventHandler (ResourceCache <R > resourceCache , ExecutorService executor ,
70
70
String relatedControllerName ,
71
- EventDispatcher <R > eventDispatcher , Retry retry , EventMonitor monitor ,
71
+ EventDispatcher <R > eventDispatcher , Retry retry , Metrics metrics ,
72
72
EventMarker eventMarker ) {
73
73
this .running = true ;
74
74
this .executor =
@@ -80,18 +80,14 @@ private DefaultEventHandler(ResourceCache<R> resourceCache, ExecutorService exec
80
80
this .eventDispatcher = eventDispatcher ;
81
81
this .retry = retry ;
82
82
this .resourceCache = resourceCache ;
83
- this .eventMonitor = monitor != null ? monitor : EventMonitor .NOOP ;
83
+ this .metrics = metrics != null ? metrics : Metrics .NOOP ;
84
84
this .eventMarker = eventMarker ;
85
85
}
86
86
87
87
public void setEventSourceManager (DefaultEventSourceManager <R > eventSourceManager ) {
88
88
this .eventSourceManager = eventSourceManager ;
89
89
}
90
90
91
- private EventMonitor monitor () {
92
- return eventMonitor ;
93
- }
94
-
95
91
@ Override
96
92
public void handleEvent (Event event ) {
97
93
lock .lock ();
@@ -101,16 +97,17 @@ public void handleEvent(Event event) {
101
97
log .debug ("Skipping event: {} because the event handler is shutting down" , event );
102
98
return ;
103
99
}
104
- final var monitor = monitor ();
105
100
final var resourceID = event .getRelatedCustomResourceID ();
106
- monitor . processedEvent (event );
101
+ metrics . processingEvent (event );
107
102
108
103
handleEventMarking (event );
109
104
if (!eventMarker .deleteEventPresent (resourceID )) {
110
105
submitReconciliationExecution (event );
111
106
} else {
112
107
cleanupForDeletedEvent (event );
113
108
}
109
+
110
+ metrics .processedEvent (event );
114
111
} finally {
115
112
lock .unlock ();
116
113
}
@@ -179,8 +176,8 @@ void eventProcessingFinished(
179
176
// Either way we don't want to retry.
180
177
if (isRetryConfigured () && postExecutionControl .exceptionDuringExecution () &&
181
178
!eventMarker .deleteEventPresent (customResourceID )) {
182
- handleRetryOnException (executionScope );
183
- monitor ().failedEvent ( executionScope . getTriggeringEvent ());
179
+ handleRetryOnException (executionScope ,
180
+ postExecutionControl . getRuntimeException ().orElseThrow ());
184
181
return ;
185
182
}
186
183
cleanupOnSuccessfulExecution (executionScope );
@@ -247,7 +244,8 @@ private void reScheduleExecutionIfInstructed(PostExecutionControl<R> postExecuti
247
244
* events (received meanwhile retry is in place or already in buffer) instantly or always wait
248
245
* according to the retry timing if there was an exception.
249
246
*/
250
- private void handleRetryOnException (ExecutionScope <R > executionScope ) {
247
+ private void handleRetryOnException (ExecutionScope <R > executionScope ,
77E9
248
+ RuntimeException exception ) {
251
249
RetryExecution execution = getOrInitRetryExecution (executionScope );
252
250
var customResourceID = executionScope .getCustomResourceID ();
253
251
boolean eventPresent = eventMarker .eventPresent (customResourceID );
@@ -267,6 +265,7 @@ private void handleRetryOnException(ExecutionScope<R> executionScope) {
267
265
"Scheduling timer event for retry with delay:{} for resource: {}" ,
268
266
delay ,
269
267
customResourceID );
268
+ metrics .failedEvent (executionScope .getTriggeringEvent (), exception );
270
269
eventSourceManager
271
270
.getRetryAndRescheduleTimerEventSource ()
272
271
.scheduleOnce (executionScope .getCustomResource (), delay );
0 commit comments