Skip to content

Commit

Permalink
[FIXED JENKINS-25073] Avoid double-counting health metrics from subfo…
Browse files Browse the repository at this point in the history
…lders.
  • Loading branch information
jglick committed Oct 9, 2014
1 parent 70a4d47 commit 8328603
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Expand Up @@ -25,13 +25,11 @@
package com.cloudbees.hudson.plugins.folder.health;

import com.cloudbees.hudson.plugins.folder.Folder;
import com.cloudbees.hudson.plugins.folder.FolderProperty;
import hudson.DescriptorExtensionList;
import hudson.model.AbstractDescribableImpl;
import hudson.model.HealthReport;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.TopLevelItem;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -62,6 +60,11 @@ public static HealthReport getHealthReport(Item item) {
}

public static interface Reporter {
/**
* Called during recursive traversal of the tree from the folder on which this metric is specified.
* May be called on intermediate {@code Folder}s, so implementations should not call {@link #getHealthReport} in this case.
* @param item a {@link Folder} or any other {@link TopLevelItem}
*/
void observe(Item item);
List<HealthReport> report();
}
Expand Down
Expand Up @@ -24,6 +24,7 @@

package com.cloudbees.hudson.plugins.folder.health;

import com.cloudbees.hudson.plugins.folder.Folder;
import hudson.Extension;
import hudson.model.HealthReport;
import hudson.model.Item;
Expand Down Expand Up @@ -60,6 +61,10 @@ private static class ReporterImpl implements Reporter {
HealthReport worst = null;

public void observe(Item item) {
if (item instanceof Folder) {
// only interested in non-folders in order to prevent double counting
return;
}
HealthReport report = getHealthReport(item);
if (report != null && (worst == null || report.getScore() < worst.getScore())) {
worst = new HealthReport(report.getScore(), report.getIconUrl(),
Expand Down

0 comments on commit 8328603

Please sign in to comment.