wu-sheng commented on a change in pull request #6427: URL: https://github.com/apache/skywalking/pull/6427#discussion_r581147284
########## File path: oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java ########## @@ -175,7 +176,10 @@ public SampleFamily min(List<String> by) { } public SampleFamily avg(List<String> by) { - ExpressionParsingContext.get().ifPresent(ctx -> ctx.aggregationLabels.addAll(by)); + ExpressionParsingContext.get().ifPresent(ctx -> { + ctx.aggregationLabels.addAll(by); + ctx.downsampling = DownsamplingType.AVG; Review comment: Got it. A suggestion, could you use this PR to format `SampleFamily` a little better? Such as put `avg` in this way ``` public SampleFamily avg(List<String> by) { ExpressionParsingContext.get().ifPresent(ctx -> ctx.aggregationLabels.addAll(by)); if (this == EMPTY) { return EMPTY; } if (by == null) { double result = Arrays.stream(samples).mapToDouble(s -> s.value).average().orElse(0.0D); return SampleFamily.build(this.context, newSample(ImmutableMap.of(), samples[0].timestamp, result)); } return SampleFamily.build( this.context, Arrays.stream(samples) .map(sample -> Tuple.of( by.stream() .collect(toImmutableMap( labelKey -> labelKey, labelKey -> sample.labels.getOrDefault(labelKey, "")) ), sample) ) .collect(groupingBy(Tuple2::_1, mapping(Tuple2::_2, toList()))) .entrySet().stream() .map(entry -> newSample(entry.getKey(), entry.getValue().get(0).timestamp, entry.getValue().stream().mapToDouble(s -> s.value).average().orElse(0.0D))) .toArray(Sample[]::new) ); } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org