这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 14 additions & 31 deletions src/main/java/com/netflix/simianarmy/janitor/AbstractJanitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ public abstract class AbstractJanitor implements Janitor {

/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJanitor.class);

/** Keep track of the number of cleaned resources */
protected final AtomicLong cleanedResourcesCount = new AtomicLong(0);

/** Keep track of the number of marked resources */
protected final AtomicLong markedResourcesCount = new AtomicLong(0);

/** Keep track of the number of failed to clean resources */
protected final AtomicLong failedToCleanResourcesCount = new AtomicLong(0);

/** Keep track of the number of unmarked resources */
protected final AtomicLong unmarkedResourcesCount = new AtomicLong(0);

/** Tags to attach to servo metrics */
@MonitorTags
Expand Down Expand Up @@ -213,7 +201,7 @@ public AbstractJanitor(Context ctx, ResourceType resourceType) {

// register this janitor with servo
String monitorObjName = String.format("simianarmy.janitor.%s.%s", this.resourceType.name(), this.region);
Monitors.registerObject(monitorObjName, this);
Monitors.registerObject(monitorObjName, this);
}

@Override
Expand All @@ -227,7 +215,7 @@ public ResourceType getResourceType() {
*/
@Override
public void markResources() {
markedResources.clear();
markedResources.clear();
unmarkedResources.clear();
Map<String, Resource> trackedMarkedResources = getTrackedMarkedResources();

Expand All @@ -253,7 +241,6 @@ public void markResources() {
recorder.recordEvent(evt);
}
resourceTracker.addOrUpdate(resource);
markedResourcesCount.incrementAndGet();
postMark(resource);
} else {
LOGGER.info(String.format(
Expand All @@ -279,7 +266,6 @@ public void markResources() {
resource.getId()));
}
unmarkedResources.add(resource);
unmarkedResourcesCount.incrementAndGet();
}
}

Expand Down Expand Up @@ -324,15 +310,13 @@ public void cleanupResources() {
recorder.recordEvent(evt);
}
cleanup(markedResource);
cleanedResourcesCount.incrementAndGet();
markedResource.setActualTerminationTime(now);
markedResource.setState(Resource.CleanupState.JANITOR_TERMINATED);
resourceTracker.addOrUpdate(markedResource);
} catch (Exception e) {
LOGGER.error(String.format("Failed to clean up the resource %s of type %s.",
markedResource.getId(), markedResource.getResourceType().name()), e);
failedToCleanResources.add(markedResource);
failedToCleanResourcesCount.incrementAndGet();
continue;
}
postCleanup(markedResource);
Expand Down Expand Up @@ -427,28 +411,27 @@ private void unmarkUserTerminatedResources(
markedResource.getId()));
}
unmarkedResources.add(markedResource);
unmarkedResourcesCount.incrementAndGet();
}
}
}

@Monitor(name="cleanedResourcesCount", type=DataSourceType.COUNTER)
public long getResourcesCleanedCount() {
return cleanedResourcesCount.get();
@Monitor(name="cleanedResourcesCount", type=DataSourceType.GAUGE)
public int getResourcesCleanedCount() {
return cleanedResources.size();
}

@Monitor(name="markedResourcesCount", type=DataSourceType.COUNTER)
public long getMarkedResourcesCount() {
return markedResourcesCount.get();
@Monitor(name="markedResourcesCount", type=DataSourceType.GAUGE)
public int getMarkedResourcesCount() {
return markedResources.size();
}

@Monitor(name="failedToCleanResourcesCount", type=DataSourceType.COUNTER)
public long getFailedToCleanResourcesCount() {
return failedToCleanResourcesCount.get();
@Monitor(name="failedToCleanResourcesCount", type=DataSourceType.GAUGE)
public int getFailedToCleanResourcesCount() {
return failedToCleanResources.size();
}

@Monitor(name="unmarkedResourcesCount", type=DataSourceType.COUNTER)
public long getUnmarkedResourcesCount() {
return unmarkedResourcesCount.get();
@Monitor(name="unmarkedResourcesCount", type=DataSourceType.GAUGE)
public int getUnmarkedResourcesCount() {
return unmarkedResources.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static void testLeashedJanitorForMarking() {
janitor.markResources();
Assert.assertEquals(janitor.getMarkedResources().size(), n / 2);
Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
Assert.assertEquals(janitor.getMarkedResourcesCount(), n / 2);

// No resource is really changed in tracker
Assert.assertEquals(resourceTracker.getResources(
Expand Down