Skip to content

Commit

Permalink
[pinpoint-apm#10704] sort the order of data to improve user readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed May 20, 2024
1 parent 8c0142e commit 66e1252
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
public class DefaultApdexStatService implements ApdexStatService {

private static final TimeWindowSampler APDEX_SCORE_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(60 * 1000, 200);
public static final String MIN = "MIN";
public static final String AVG = "AVG";
public static final String MAX = "MAX";

private final ApplicationFactory applicationFactory;

Expand Down Expand Up @@ -114,9 +117,9 @@ private InspectorMetricData convertToInspectorMetricData(MetricDefinition metric

Field field = metricDefinition.getFields().get(0);
List<InspectorMetricValue> metricValueList = new ArrayList<>(3);
metricValueList.add(new InspectorMetricValue("AVG", field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
metricValueList.add(new InspectorMetricValue("MIN", field.getTags(), field.getChartType(), field.getUnit(), minValueList));
metricValueList.add(new InspectorMetricValue("MAX", field.getTags(), field.getChartType(), field.getUnit(), maxValueList));
metricValueList.add(new InspectorMetricValue(MIN, field.getTags(), field.getChartType(), field.getUnit(), minValueList));
metricValueList.add(new InspectorMetricValue(AVG, field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
metricValueList.add(new InspectorMetricValue(MAX, field.getTags(), field.getChartType(), field.getUnit(), maxValueList));

return new InspectorMetricData(metricDefinition.getTitle(), timestampList, metricValueList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -40,6 +41,9 @@
@Service
public class DefaultApplicationStatService implements ApplicationStatService {

private static final String MIN = "MIN";
private static final String AVG = "AVG";
private static final String MAX = "MAX";
private final Logger logger = LogManager.getLogger(this.getClass());

private final YMLInspectorManager ymlInspectorManager;
Expand Down Expand Up @@ -84,10 +88,33 @@ public InspectorMetricData selectApplicationStat(InspectorDataSearchKey inspecto
}

List<InspectorMetricValue> processedMetricValueList = postprocessMetricData(metricDefinition, metricValueList);
processedMetricValueList = sortingMetricValueList(processedMetricValueList);
List<Long> timeStampList = TimeUtils.createTimeStampList(timeWindow);
return new InspectorMetricData(metricDefinition.getTitle(), timeStampList, processedMetricValueList);
}

private List<InspectorMetricValue> sortingMetricValueList(List<InspectorMetricValue> processedMetricValueList) {
InspectorMetricValue[] sortedMetricValues = new InspectorMetricValue[3];

for (InspectorMetricValue value : processedMetricValueList) {
switch (value.getFieldName()) {
case MIN:
sortedMetricValues[0] = value;
break;
case AVG:
sortedMetricValues[1] = value;
break;
case MAX:
sortedMetricValues[2] = value;
break;
default:
throw new RuntimeException("not supported field name : " + value.getFieldName());
}
}

return Arrays.asList(sortedMetricValues);
}

@Override
public InspectorMetricGroupData selectApplicationStatWithGrouping(InspectorDataSearchKey inspectorDataSearchKey, TimeWindow timeWindow) {
MetricDefinition metricDefinition = ymlInspectorManager.findElementOfBasicGroup(inspectorDataSearchKey.getMetricDefinitionId());
Expand Down Expand Up @@ -122,10 +149,19 @@ public InspectorMetricGroupData selectApplicationStatWithGrouping(InspectorDataS
List<InspectorMetricValue> processedMetricValueList = postprocessMetricData(newMetricDefinition, metricValueList);
List<Long> timeStampList = TimeUtils.createTimeStampList(timeWindow);
Map<List<Tag>,List<InspectorMetricValue>> metricValueGroups = groupingMetricValue(processedMetricValueList, metricDefinition);

metricValueGroups = sortingMetricValueGroups(metricValueGroups);
return new InspectorMetricGroupData(metricDefinition.getTitle(), timeStampList, metricValueGroups);
}

private Map<List<Tag>, List<InspectorMetricValue>> sortingMetricValueGroups(Map<List<Tag>, List<InspectorMetricValue>> metricValueGroups) {
return metricValueGroups.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> sortingMetricValueList(entry.getValue())
)
);
}

private Map<List<Tag>,List<InspectorMetricValue>> groupingMetricValue(List<InspectorMetricValue> processedMetricValueList, MetricDefinition metricDefinition) {
switch (metricDefinition.getGroupingRule()) {
case TAG:
Expand Down Expand Up @@ -171,8 +207,8 @@ private List<InspectorMetricValue> splitMinMax(TimeWindow timeWindow, Field fiel
}

List<InspectorMetricValue> inspectorMetricValueList = new ArrayList<>(2);
inspectorMetricValueList.add(new InspectorMetricValue("MIN", field.getTags(), field.getChartType(), field.getUnit(), minValueList));
inspectorMetricValueList.add(new InspectorMetricValue("MAX", field.getTags(), field.getChartType(), field.getUnit(), maxValueList));
inspectorMetricValueList.add(new InspectorMetricValue(MIN, field.getTags(), field.getChartType(), field.getUnit(), minValueList));
inspectorMetricValueList.add(new InspectorMetricValue(MAX, field.getTags(), field.getChartType(), field.getUnit(), maxValueList));
return inspectorMetricValueList;
}

Expand All @@ -190,8 +226,8 @@ private Collection<InspectorMetricValue> splitAvgMin(TimeWindow timeWindow, Fiel
}

List<InspectorMetricValue> inspectorMetricValueList = new ArrayList<>(2);
inspectorMetricValueList.add(new InspectorMetricValue("MIN", field.getTags(), field.getChartType(), field.getUnit(), minValueList));
inspectorMetricValueList.add(new InspectorMetricValue("AVG", field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
inspectorMetricValueList.add(new InspectorMetricValue(MIN, field.getTags(), field.getChartType(), field.getUnit(), minValueList));
inspectorMetricValueList.add(new InspectorMetricValue(AVG, field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
return inspectorMetricValueList;
}

Expand All @@ -210,9 +246,9 @@ private List<InspectorMetricValue> splitAvgMinMax(TimeWindow timeWindow, Field f
}

List<InspectorMetricValue> inspectorMetricValueList = new ArrayList<>(3);
inspectorMetricValueList.add(new InspectorMetricValue("MIN", field.getTags(), field.getChartType(), field.getUnit(), minValueList));
inspectorMetricValueList.add(new InspectorMetricValue("AVG", field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
inspectorMetricValueList.add(new InspectorMetricValue("MAX", field.getTags(), field.getChartType(), field.getUnit(), maxValueList));
inspectorMetricValueList.add(new InspectorMetricValue(MIN, field.getTags(), field.getChartType(), field.getUnit(), minValueList));
inspectorMetricValueList.add(new InspectorMetricValue(AVG, field.getTags(), field.getChartType(), field.getUnit(), avgValueList));
inspectorMetricValueList.add(new InspectorMetricValue(MAX, field.getTags(), field.getChartType(), field.getUnit(), maxValueList));
return inspectorMetricValueList;
}

Expand Down

0 comments on commit 66e1252

Please sign in to comment.