@@ -176,7 +176,7 @@ private void runMeasured() {
176
176
synchronized (executor ) {
177
177
if (scratchPaths .isEmpty ()) {
178
178
log .finer ("No scratch paths available - postponing " + item );
179
- pending . put (item , Optional . empty () );
179
+ addPending (item , null );
180
180
return ;
181
181
}
182
182
scratchPath = scratchPaths .removeFirst ();
@@ -208,7 +208,7 @@ private void runMeasured() {
208
208
209
209
synchronized (executor ) {
210
210
scratchPaths .addLast (scratchPath );
211
- active . remove (item );
211
+ done (item );
212
212
213
213
// Some of the pending items may now be eligible for execution
214
214
var candidateItems = pending .entrySet ().stream ()
@@ -229,10 +229,8 @@ private void runMeasured() {
229
229
}
230
230
231
231
if (maySubmit ) {
232
- pending .remove (candidate );
233
- RunnableWorkItem runnableWorkItem = new RunnableWorkItem (candidate );
234
- executor .submit (runnableWorkItem );
235
- active .put (candidate , runnableWorkItem );
232
+ removePending (candidate );
233
+ submit (candidate );
236
234
log .finer ("Submitting candidate: " + candidate );
237
235
}
238
236
}
@@ -250,6 +248,16 @@ private void runMeasured() {
250
248
Counter .name ("skara_runner_scheduled" ).labels ("bot" , "work_item" ).register ();
251
249
private static final Counter .WithTwoLabels DISCARDED_COUNTER =
252
250
Counter .name ("skara_runner_discarded" ).labels ("bot" , "work_item" ).register ();
251
+ /**
252
+ * Gauge that tracks the number of active WorkItems for each kind
253
+ */
254
+ private final Gauge .WithTwoLabels activeGauge =
255
+ Gauge .name ("skara_runner_active" ).labels ("bot" , "work_item" ).register ();
256
+ /**
257
+ * Gauge that tracks the number of pending WorkItems for each kind
258
+ */
259
+ private final Gauge .WithTwoLabels pendingGauge =
260
+ Gauge .name ("skara_runner_pending" ).labels ("bot" , "work_item" ).register ();
253
261
254
262
private void submitOrSchedule (WorkItem item ) {
255
263
SCHEDULED_COUNTER .labels (item .botName (), item .workItemName ()).inc ();
@@ -263,23 +271,57 @@ private void submitOrSchedule(WorkItem item) {
263
271
log .finer ("Discarding obsoleted item " + pendingItem +
264
272
" in favor of item " + item );
265
273
DISCARDED_COUNTER .labels (item .botName (), item .workItemName ()).inc ();
266
- pending . remove (pendingItem );
274
+ removePending (pendingItem );
267
275
// There can't be more than one
268
276
break ;
269
277
}
270
278
}
271
279
272
- pending . put (item , Optional . of ( activeItem ) );
280
+ addPending (item , activeItem );
273
281
return ;
274
282
}
275
283
}
276
284
277
- RunnableWorkItem runnableWorkItem = new RunnableWorkItem (item );
278
- executor .submit (runnableWorkItem );
279
- active .put (item , runnableWorkItem );
285
+ submit (item );
280
286
}
281
287
}
282
288
289
+ /**
290
+ * Called to add a WorkItem to the pending queue
291
+ * @param item Item to queue
292
+ * @param activeItem Optional active item that this item is waiting for
293
+ */
294
+ private void addPending (WorkItem item , WorkItem activeItem ) {
295
+ pending .put (item , Optional .ofNullable (activeItem ));
296
+ pendingGauge .labels (item .botName (), item .workItemName ()).inc ();
297
+ }
298
+
299
+ /**
300
+ * Called to remove an item from the pending queue.
301
+ */
302
+ private void removePending (WorkItem item ) {
303
+ pending .remove (item );
304
+ pendingGauge .labels (item .botName (), item .workItemName ()).dec ();
305
+ }
306
+
307
+ /**
308
+ * Called to submit a WorkItem for execution
309
+ */
310
+ private void submit (WorkItem item ) {
311
+ RunnableWorkItem runnableWorkItem = new RunnableWorkItem (item );
312
+ executor .submit (runnableWorkItem );
313
+ active .put (item , runnableWorkItem );
314
+ activeGauge .labels (item .botName (), item .workItemName ()).inc ();
315
+ }
316
+
317
+ /**
318
+ * Called when a WorkItem is done executing
319
+ */
320
+ private void done (WorkItem item ) {
321
+ active .remove (item );
322
+ activeGauge .labels (item .botName (), item .workItemName ()).dec ();
323
+ }
324
+
283
325
private void drain (Duration timeout ) throws TimeoutException {
284
326
Instant start = Instant .now ();
285
327
1 commit comments
openjdk-notifier[bot] commentedon Sep 28, 2021
Review
Issues