Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor getMetricHistoryData endpoint #20

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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