Skip to content

Commit

Permalink
refactor getMetricHistoryData endpoint (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 committed Feb 21, 2023
1 parent c314d09 commit a18aff8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
* 历史单指标数据
Expand All @@ -50,6 +49,7 @@ public class MetricsHistoryData {
@Schema(title = "监控指标")
private Field field;

@Schema(description = "监控指标历史值 instance<==>values")
private Map<String, List<Value>> values;
@Schema(description = "监控指标历史值")
private List<ValueRow> values;

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -142,8 +143,15 @@ public ResponseEntity<Message<MetricsHistoryData>> getMetricHistoryData(
} else {
instanceValuesMap = historyDataStorage.getHistoryIntervalMetricData(monitorId, app, metrics, metric, instance, history);
}
List<ValueRow> valueRows = new LinkedList<>();
if (instanceValuesMap != null) {
valueRows = instanceValuesMap.entrySet().stream().map(item -> ValueRow.builder()
.instance(item.getKey())
.values(item.getValue())
.build()).collect(Collectors.toList());
}
MetricsHistoryData historyData = MetricsHistoryData.builder()
.id(monitorId).metric(metrics).values(instanceValuesMap)
.id(monitorId).metric(metrics).values(valueRows)
.field(Field.builder().name(metric).type(CommonConstants.TYPE_NUMBER).build())
.build();
return ResponseEntity.ok().body(new Message<>(historyData));
Expand Down

0 comments on commit a18aff8

Please sign in to comment.