Skip to content

Commit

Permalink
atlas: fix npe for grouped lwc gauges (#1064)
Browse files Browse the repository at this point in the history
When performing a group by, if there is a datapoint that does
not have all of the keys used in the grouping there would be
an NPE. They will now get ignored similar to the behavior for
counters or when not delaying the gauge aggregation.
  • Loading branch information
brharrington committed May 24, 2023
1 parent 68d5ae3 commit 2273095
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,15 @@ public EvalPayload eval(long timestamp) {
Map<String, String> tags = idMapper.apply(entry.getKey());
tags.putAll(commonTags);
if (delayGaugeAggr && consolidator.isGauge()) {
Map<String, String> resultTags = new HashMap<>(expr.resultTags(tags));
resultTags.put("atlas.aggr", idHash(entry.getKey()));
double acc = expr.isCount() ? 1.0 : v;
metrics.add(new EvalPayload.Metric(subId, resultTags, acc));
// When performing a group by, datapoints missing tag used for the grouping
// should be ignored
Map<String, String> rs = expr.resultTags(tags);
if (rs != null) {
Map<String, String> resultTags = new HashMap<>(rs);
resultTags.put("atlas.aggr", idHash(entry.getKey()));
double acc = expr.isCount() ? 1.0 : v;
metrics.add(new EvalPayload.Metric(subId, resultTags, acc));
}
} else {
TagsValuePair p = new TagsValuePair(tags, v);
aggregator.update(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ public void delayAggrGaugeGroupByCount() {
}
}

@Test
public void delayAggrGaugeGroupByMissingKey() {
List<Subscription> subs = new ArrayList<>();
subs.add(newSubscription("sum", ":true,:sum,(,foo,),:by"));

Evaluator evaluator = newEvaluator(true);
evaluator.sync(subs);
EvalPayload payload = evaluator.eval(0L, data("foo", 1.0, 2.0, 3.0));

Assertions.assertEquals(0, payload.getMetrics().size());
}

@Test
public void delayAggrGaugeMax() {
List<Subscription> subs = new ArrayList<>();
Expand Down

0 comments on commit 2273095

Please sign in to comment.