Skip to content

Commit d2385a6

Browse files
author
weixiang
committed
FilterExpression#filter filter out unmatched metrics directly instead of returning EMPTY
1 parent 454e446 commit d2385a6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public void analyse(final ImmutableMap<String, SampleFamily> sampleFamilies) {
129129
}
130130
if (filterExpression != null) {
131131
input = filterExpression.filter(input);
132-
boolean empty = input.values().stream().allMatch(s -> s == SampleFamily.EMPTY);
133-
if (empty) {
132+
if (input.isEmpty()) {
134133
if (log.isDebugEnabled()) {
135134
log.debug("{} is ignored due to mismatch of filter {}", expression, filterExpression);
136135
}

oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/FilterExpression.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
import groovy.lang.Closure;
2222
import groovy.lang.GroovyShell;
23+
import java.util.HashMap;
2324
import java.util.Map;
25+
import java.util.Objects;
2426
import lombok.ToString;
2527
import lombok.extern.slf4j.Slf4j;
2628

27-
import static java.util.stream.Collectors.toMap;
28-
2929
@Slf4j
3030
@ToString(of = {"literal"})
3131
public class FilterExpression {
@@ -42,10 +42,14 @@ public FilterExpression(final String literal) {
4242

4343
public Map<String, SampleFamily> filter(final Map<String, SampleFamily> sampleFamilies) {
4444
try {
45-
return sampleFamilies.entrySet().stream().collect(toMap(
46-
Map.Entry::getKey,
47-
it -> it.getValue().filter(filterClosure)
48-
));
45+
Map<String, SampleFamily> result = new HashMap<>();
46+
for (Map.Entry<String, SampleFamily> entry : sampleFamilies.entrySet()) {
47+
SampleFamily afterFilter = entry.getValue().filter(filterClosure);
48+
if (!Objects.equals(afterFilter, SampleFamily.EMPTY)) {
49+
result.put(entry.getKey(), afterFilter);
50+
}
51+
}
52+
return result;
4953
} catch (Throwable t) {
5054
log.error("failed to run \"{}\"", literal, t);
5155
}

0 commit comments

Comments
 (0)