@@ -304,15 +304,16 @@ public void cleanupResources() {
304304 markedResource .getId (), markedResource .getResourceType ().name ()));
305305 if (!leashed ) {
306306 try {
307+ cleanup (markedResource );
308+ markedResource .setActualTerminationTime (now );
309+ markedResource .setState (Resource .CleanupState .JANITOR_TERMINATED );
310+ resourceTracker .addOrUpdate (markedResource );
307311 if (recorder != null ) {
308312 Event evt = recorder .newEvent (Type .JANITOR , EventTypes .CLEANUP_RESOURCE , region ,
309313 markedResource .getId ());
314+ addFieldsAndTagsToEvent (markedResource , evt );
310315 recorder .recordEvent (evt );
311316 }
312- cleanup (markedResource );
313- markedResource .setActualTerminationTime (now );
314- markedResource .setState (Resource .CleanupState .JANITOR_TERMINATED );
315- resourceTracker .addOrUpdate (markedResource );
316317 } catch (Exception e ) {
317318 LOGGER .error (String .format ("Failed to clean up the resource %s of type %s." ,
318319 markedResource .getId (), markedResource .getResourceType ().name ()), e );
@@ -330,7 +331,20 @@ public void cleanupResources() {
330331 }
331332 }
332333
333- /** Determines if the input resource can be cleaned. The Janitor calls this method
334+ /**
335+ * Adds selected resource fields and all the tags from the given resource as additional fields on the event.
336+ * @param resource the resource with the the source data
337+ * @param event the event that will hold the source data as additional fields
338+ */
339+ private void addFieldsAndTagsToEvent (Resource resource , Event event ) {
340+ for (String key : resource .getAllTagKeys ()) {
341+ event .addField (key , resource .getTag (key ));
342+ }
343+ event .addField ("ResourceDescription" , resource .getDescription ());
344+ event .addField ("ResourceType" , resource .getResourceType ().toString ());
345+ }
346+
347+ /** Determines if the input resource can be cleaned. The Janitor calls this method
334348 * before cleaning up a resource and only cleans the resource when the method returns
335349 * true. A resource is considered to be OK to clean if
336350 * 1) it is marked as cleanup candidates
0 commit comments