This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new c4aee27f1 [bugfix] jpa data save logic repair (#1863)
c4aee27f1 is described below
commit c4aee27f1c92f5f3218f217d9ded5e0468b6887a
Author: Jast <[email protected]>
AuthorDate: Sat Apr 27 13:53:34 2024 +0800
[bugfix] jpa data save logic repair (#1863)
Co-authored-by: zhangshenghang <[email protected]>
Co-authored-by: zhangshenghang <[email protected]>
Co-authored-by: tomsun28 <[email protected]>
---
.../store/HistoryJpaDatabaseDataStorage.java | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
index 24c9847e7..2d4f37a3b 100644
---
a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
+++
b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java
@@ -128,15 +128,16 @@ public class HistoryJpaDatabaseDataStorage extends
AbstractHistoryDataStorage {
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();
@@ -183,11 +184,12 @@ public class HistoryJpaDatabaseDataStorage extends
AbstractHistoryDataStorage {
}
}
- 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);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]