Skip to content

Commit 133cbc6

Browse files
authored
Fail fast if SampleFamily is empty after MAL filter expression (#13608)
1 parent ed5e729 commit 133cbc6

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

docs/en/changes/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Enhance the alarm kernel with recovered status notification capability
1010
* Fix BrowserWebVitalsPerfData `clsTime` to `cls` and make it double type.
1111
* Init `log-mal-rules` at module provider start stage to avoid re-init for every LAL.
12+
* Fail fast if SampleFamily is empty after MAL filter expression.
1213

1314
#### UI
1415
* Fix the missing icon in new native trace view.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ public void analyse(final ImmutableMap<String, SampleFamily> sampleFamilies) {
129129
}
130130
if (filterExpression != null) {
131131
input = filterExpression.filter(input);
132+
if (input.isEmpty()) {
133+
if (log.isDebugEnabled()) {
134+
log.debug("{} is ignored due to mismatch of filter {}", expression, filterExpression);
135+
}
136+
return;
137+
}
132138
}
133139
Result r = expression.run(input);
134140
if (!r.isSuccess()) {

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)