Skip to content

Commit

Permalink
Remove group and support labels in the meter histogram-percentile fun…
Browse files Browse the repository at this point in the history
…ction. (#12101)
  • Loading branch information
wankai123 authored Apr 15, 2024
1 parent ee01ce8 commit a8b0d18
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 610 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -159,9 +158,9 @@ public void analyse(final ImmutableMap<String, SampleFamily> sampleFamilies) {
break;
case histogram:
case histogramPercentile:
Stream.of(ss).map(s -> Tuple.of(composeGroup(s.getLabels(), k -> !Objects.equals("le", k)), s))
Stream.of(ss).map(s -> Tuple.of(getDataLabels(s.getLabels(), k -> !Objects.equals("le", k)), s))
.collect(groupingBy(Tuple2::_1, mapping(Tuple2::_2, toList())))
.forEach((group, subSs) -> {
.forEach((dataLabel, subSs) -> {
if (subSs.size() < 1) {
return;
}
Expand All @@ -178,7 +177,7 @@ public void analyse(final ImmutableMap<String, SampleFamily> sampleFamilies) {
vv[i] = getValue(s);
}
BucketedValues bv = new BucketedValues(bb, vv);
bv.setGroup(group);
bv.setLabels(dataLabel);
long time = subSs.get(0).getTimestamp();
if (metricType == MetricType.histogram) {
AcceptableValue<BucketedValues> v = meterSystem.buildMetrics(
Expand Down Expand Up @@ -207,9 +206,10 @@ private long getValue(Sample sample) {
return Math.round(sample.getValue());
}

private String composeGroup(ImmutableMap<String, String> labels, Predicate<String> filter) {
return labels.keySet().stream().filter(filter).sorted().map(labels::get)
.collect(Collectors.joining("-"));
private DataLabel getDataLabels(ImmutableMap<String, String> labels, Predicate<String> filter) {
DataLabel dataLabel = new DataLabel();
labels.keySet().stream().filter(filter).forEach(k -> dataLabel.put(k, labels.get(k)));
return dataLabel;
}

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testHistogramPercentile() {
doAnswer(invocationOnMock -> {
AvgHistogramPercentileFunction actValue = (AvgHistogramPercentileFunction) invocationOnMock.getArgument(
0, AcceptableValue.class);
if (actValue.getSummation().hasKey("instance1:25")) {
if (actValue.getSummation().hasKey("{instance=instance1}:25")) {
actValues.put("instance1", actValue);
} else {
actValues.put("instance2", actValue);
Expand All @@ -233,12 +233,12 @@ public void testHistogramPercentile() {
});
AvgHistogramPercentileFunction instance1 = actValues.get("instance1");
AvgHistogramPercentileFunction instance2 = actValues.get("instance2");
assertEquals(100L, instance1.getSummation().get("instance1:25"), 0.0);
assertEquals(300L, instance1.getSummation().get("instance1:1250"), 0.0);
assertEquals(1L, instance1.getCount().get("instance1:25"), 0.0);
assertEquals(1L, instance1.getCount().get("instance1:1250"), 0.0);
assertEquals(100L, instance1.getSummation().get("{instance=instance1}:25"), 0.0);
assertEquals(300L, instance1.getSummation().get("{instance=instance1}:1250"), 0.0);
assertEquals(1L, instance1.getCount().get("{instance=instance1}:25"), 0.0);
assertEquals(1L, instance1.getCount().get("{instance=instance1}:1250"), 0.0);

assertEquals(122L, instance2.getSummation().get("instance2:750"), 0.0);
assertEquals(1L, instance2.getCount().get("instance2:750"), 0.0);
assertEquals(122L, instance2.getSummation().get("{instance=instance2}:750"), 0.0);
assertEquals(1L, instance2.getCount().get("{instance=instance2}:750"), 0.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.apache.skywalking.oap.server.core.analysis.metrics.DataLabel;
import org.apache.skywalking.oap.server.core.analysis.metrics.DataTable;
import org.apache.skywalking.oap.server.core.query.type.Bucket;
import org.apache.skywalking.oap.server.core.query.type.HeatMap;
Expand All @@ -34,9 +35,8 @@
@ToString
@Getter
public class BucketedValues {

@Setter
private String group;
private DataLabel labels = new DataLabel();
/**
* The element in the buckets represent the minimal value of this bucket, the max is defined by the next element.
* Such as 0, 10, 50, 100 means buckets are [0, 10), [10, 50), [50, 100), [100, infinite+).
Expand Down Expand Up @@ -76,7 +76,7 @@ public boolean isCompatible(DataTable dataset) {
if (key.equals(Bucket.INFINITE_NEGATIVE)) {
existedBuckets[i] = Long.MIN_VALUE;
} else {
// remove the group name
// remove the label name
if (key.contains(":")) {
key = StringUtils.substringAfterLast(key, ":");
}
Expand Down
Loading

0 comments on commit a8b0d18

Please sign in to comment.