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

[bugfix] jpa data save logic repair #1863

Merged
merged 5 commits into from
Apr 27, 2024
Merged
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 @@ -128,15 +128,16 @@ void saveData(CollectRep.MetricsData metricsData) {
String metrics = metricsData.getMetrics();
List<CollectRep.Field> fieldsList = metricsData.getFieldsList();
try {
List<History> historyList = new LinkedList<>();
History.HistoryBuilder historyBuilder = History.builder()
.monitorId(metricsData.getId())
.app(monitorType)
.metrics(metrics)
.time(metricsData.getTime());
List<History> allHistoryList = new LinkedList<>();
for (CollectRep.ValueRow valueRow : metricsData.getValuesList()) {
List<History> singleHistoryList = new LinkedList<>();
Map<String, String> labels = new HashMap<>(8);
for (int i = 0; i < fieldsList.size(); i++) {
History.HistoryBuilder historyBuilder = History.builder()
.monitorId(metricsData.getId())
.app(monitorType)
.metrics(metrics)
.time(metricsData.getTime());
final CollectRep.Field field = fieldsList.get(i);
final int fieldType = field.getType();
final String fieldName = field.getName();
Expand Down Expand Up @@ -183,11 +184,12 @@ void saveData(CollectRep.MetricsData metricsData) {
}
}

historyList.add(historyBuilder.build());
singleHistoryList.add(historyBuilder.build());
}
historyBuilder.instance(JsonUtil.toJson(labels));
singleHistoryList.forEach(history -> history.setInstance(JsonUtil.toJson(labels)));
allHistoryList.addAll(singleHistoryList);
}
historyDao.saveAll(historyList);
historyDao.saveAll(allHistoryList);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down
Loading