Skip to content

Commit

Permalink
Merge pull request #35 from ru-fix/filter-null-value
Browse files Browse the repository at this point in the history
add filtering of null value returned by indicator
  • Loading branch information
swarmshine authored Sep 24, 2018
2 parents 1e3e1d8 + ce576bb commit 4c2e3e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ru.fix.aggregating.profiler.*;

import java.util.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -78,25 +79,32 @@ private ProfilerReport buildReportAndReset(Optional<String> tagName,
Map<String, Long> indicators = profiler.getIndicators()
.entrySet()
.stream()
.filter(entry -> ! tagName.isPresent() || entry.getValue().hasTag(tagName.get(), tagValue.orElse(null)))
.collect(Collectors.toMap(
e -> {
String name = e.getKey();
if (!name.endsWith(INDICATOR_SUFFIX)) {
name = name.concat(INDICATOR_SUFFIX);
}
return name;
},
e -> {
try {
return e.getValue().getProvider().get();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
return null;
}));

List<ProfiledCallReport> collect = new ArrayList<>();
.filter(entry -> ! tagName.isPresent()
|| entry.getValue().hasTag(tagName.get(), tagValue.orElse(null)))
.map(entry -> {
String name = entry.getKey();
if (!name.endsWith(INDICATOR_SUFFIX)) {
name = name.concat(INDICATOR_SUFFIX);
}
try {
return new SimpleEntry(name, entry.getValue().getProvider().get());
} catch (Exception ex) {
log.error("Retrieve value for "
+ entry.getKey()
+ " finished with '"
+ ex.getMessage()
+ "'",
ex);
return new SimpleEntry(name, null);
}
})
.filter(entry -> entry.getValue() != null)
.collect(
Collectors.toMap(
e -> (String)e.getKey(),
e -> (Long)e.getValue()));

List<ProfiledCallReport> collect = new ArrayList<>();

for (Iterator<Map.Entry<String, CallAggregate>> iterator = sharedCounters.entrySet().iterator();
iterator.hasNext(); ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,4 +814,13 @@ public void indicatorNameEndsWithIndicatorMaxSuffix(){
assertTrue(indicators.containsKey("my.indicator.indicatorMax"));
assertEquals(147L, indicators.get("my.indicator.indicatorMax").longValue());
}

@Test
public void indicatorNullReturnValue(){
Profiler profiler = new AggregatingProfiler();
profiler.attachIndicator("my.indicator", () -> null);
ProfilerReporter reporter = profiler.createReporter();
Map<String, Long> indicators = reporter.buildReportAndReset().getIndicators();
assertFalse(indicators.containsKey("my.indicator.indicatorMax"));
}
}

0 comments on commit 4c2e3e1

Please sign in to comment.