Skip to content

Improve AbstractHealthAggregator to allow customization of aggregated details #4674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.boot.actuate.health;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -26,19 +25,19 @@
* aggregating the {@link Status} instances and not deal with contextual details etc.
*
* @author Christian Dupuis
* @author Vedran Pavic
* @since 1.1.0
*/
public abstract class AbstractHealthAggregator implements HealthAggregator {

@Override
public final Health aggregate(Map<String, Health> healths) {
List<Status> statusCandidates = new ArrayList<Status>();
Map<String, Object> details = new LinkedHashMap<String, Object>();
for (Map.Entry<String, Health> entry : healths.entrySet()) {
details.put(entry.getKey(), entry.getValue());
statusCandidates.add(entry.getValue().getStatus());
}
return new Health.Builder(aggregateStatus(statusCandidates), details).build();
return new Health.Builder(
aggregateStatus(statusCandidates), aggregateDetails(healths)).build();
}

/**
Expand All @@ -49,4 +48,12 @@ public final Health aggregate(Map<String, Health> healths) {
*/
protected abstract Status aggregateStatus(List<Status> candidates);

/**
* Return the map of 'aggregate' details that should be used from the specified
* healths.
* @param healths the health instances to aggregate
* @return a map of details
*/
protected abstract Map<String, Object> aggregateDetails(Map<String, Health> healths);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.util.Assert;

Expand All @@ -32,6 +34,7 @@
* can be set by calling {@link #setStatusOrder(List)}.
*
* @author Christian Dupuis
* @author Vedran Pavic
* @since 1.1.0
*/
public class OrderedHealthAggregator extends AbstractHealthAggregator {
Expand Down Expand Up @@ -84,6 +87,11 @@ protected Status aggregateStatus(List<Status> candidates) {
return filteredCandidates.get(0);
}

@Override
protected Map<String, Object> aggregateDetails(Map<String, Health> healths) {
return new LinkedHashMap<String, Object>(healths);
}

/**
* {@link Comparator} used to order {@link Status}.
*/
Expand Down