Ensure that we include counters in Status History when present
This closes
@@ -30,6 +30,7 @@ public class StandardStatusSnapshot implements StatusSnapshot {
private Map<MetricDescriptor<?>, Long> counterValues = null;
private Date timestamp = new Date();
+ private Set<MetricDescriptor<?>> metricDescriptorsWithCounters = null;
public StandardStatusSnapshot(final Set<MetricDescriptor<?>> metricDescriptors) {
@@ -49,7 +50,17 @@ public class StandardStatusSnapshot implements StatusSnapshot {
@Override
public Set<MetricDescriptor<?>> getMetricDescriptors() {
+ if (counterValues == null || counterValues.isEmpty()) {
return metricDescriptors;
+ } else {
+ if (metricDescriptorsWithCounters == null) {
+ metricDescriptorsWithCounters = new LinkedHashSet<>();
+ metricDescriptorsWithCounters.addAll(metricDescriptors);
+ metricDescriptorsWithCounters.addAll(counterValues.keySet());
+ }
+
+ return metricDescriptorsWithCounters;
+ }
}
@Override
@@ -75,7 +86,7 @@ public class StandardStatusSnapshot implements StatusSnapshot {
}
public StandardStatusSnapshot withoutCounters() {
- if (counterValues == null) {
+ if (counterValues == null || counterValues.isEmpty()) {
return this;
}
@@ -90,7 +101,7 @@ public class StandardStatusSnapshot implements StatusSnapshot {
@Override
public StatusSnapshot reduce(final List<StatusSnapshot> values) {
Date reducedTimestamp = null;
- final Set<MetricDescriptor<?>> allDescriptors = new LinkedHashSet<>(metricDescriptors);
+ final Set<MetricDescriptor<?>> allDescriptors = new LinkedHashSet<>(getMetricDescriptors());
for (final StatusSnapshot statusSnapshot : values) {
if (reducedTimestamp == null) {
