This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch bulletin
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/bulletin by this push:
new fb25e1364 [feat(bulletin)] optimize data loading and column generation
in bulletin componentRefactor the bulletin component to optimize data loading
from the service layer and dynamically generate columns based on the response
data. This change improves the flexibility and performance of the component by
avoiding unnecessary data transformations and supporting a more dynamic data
representation.
fb25e1364 is described below
commit fb25e1364965dea3ea81ac3adf25a101a9fe30b1
Author: zqr10159 <[email protected]>
AuthorDate: Sat Jul 13 00:03:22 2024 +0800
[feat(bulletin)] optimize data loading and column generation in bulletin
componentRefactor the bulletin component to optimize data loading from the
service layer and dynamically generate columns based on the response data. This
change improves the flexibility and performance of the component by avoiding
unnecessary data transformations and supporting a more dynamic data
representation.
BREAKING CHANGE: The method signature for loadData has been changed to
accommodate the new optimization strategy. Any consumers of the loadData method
will need to update their implementations accordingly.
---
.../manager/controller/BulletinController.java | 11 ++--
.../src/app/routes/bulletin/bulletin.component.ts | 64 ++++++++++++----------
web-app/src/app/service/bulletin-define.service.ts | 4 ++
3 files changed, 45 insertions(+), 34 deletions(-)
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
index 7f17bd053..166b3eef0 100644
---
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
+++
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
@@ -19,6 +19,7 @@
package org.apache.hertzbeat.manager.controller;
import static org.apache.hertzbeat.common.constants.CommonConstants.FAIL_CODE;
+import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.persistence.criteria.CriteriaBuilder;
@@ -32,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.dto.Field;
import org.apache.hertzbeat.common.entity.dto.Message;
@@ -43,7 +45,6 @@ import
org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinVo;
import org.apache.hertzbeat.common.entity.message.CollectRep;
import org.apache.hertzbeat.manager.service.BulletinService;
-import org.apache.hertzbeat.warehouse.store.history.HistoryDataReader;
import org.apache.hertzbeat.warehouse.store.realtime.RealTimeDataReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -59,12 +60,14 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
/**
* Bulletin Controller
*/
-@Controller
-@RequestMapping("/api/bulletin")
+@Slf4j
+@RestController
+@RequestMapping(value = "/api/bulletin", produces = {APPLICATION_JSON_VALUE})
public class BulletinController {
@Autowired
@@ -145,7 +148,7 @@ public class BulletinController {
Bulletin bulletin = bulletinOptional.get();
List<String> metrics = bulletin.getMetrics().stream().map(metric ->
metric.split("-")[0]).distinct().toList();
List<CollectRep.MetricsData> metricsDataList =
metrics.stream().map(metric ->
realTimeDataReader.getCurrentMetricsData(bulletin.getMonitorId(),
metric)).toList();
- List<MetricsData> dataList = new LinkedList<>();
+ List<MetricsData> dataList = new ArrayList<>();
for (CollectRep.MetricsData storageData : metricsDataList) {
MetricsData.MetricsDataBuilder dataBuilder = MetricsData.builder();
dataBuilder.id(storageData.getId()).app(storageData.getApp()).metrics(storageData.getMetrics())
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.ts
b/web-app/src/app/routes/bulletin/bulletin.component.ts
index 71531e70f..e76ffe4a5 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.ts
+++ b/web-app/src/app/routes/bulletin/bulletin.component.ts
@@ -75,6 +75,7 @@ export class BulletinComponent implements OnInit {
loading: boolean = false;
listOfData: any[] = [];
listOfColumns: Array<{ key: string; title: string }> = [];
+ responseData: any[] = [];
metrics: string[] = [];
id: any;
@@ -85,6 +86,7 @@ export class BulletinComponent implements OnInit {
ngOnInit(): void {
this.loadBulletinDefineTable();
this.tabDefines = this.defines;
+ this.loadData(402372614668544);
}
sync() {
@@ -654,43 +656,45 @@ export class BulletinComponent implements OnInit {
});
}
- loadData(monitorId: number, metric: string) {
+ loadData(bulletinId: number) {
this.loading = true;
- let metricData$ = this.monitorSvc
- .getMonitorMetricsData(monitorId, metric)
+ let metricData$ = this.bulletinDefineSvc
+ .getMonitorMetricsData(bulletinId)
.pipe(finalize(() => (this.loading = false)))
.subscribe(
message => {
metricData$.unsubscribe();
if (message.code === 0 && message.data) {
- const { id, app, metrics, fields, valueRows } = message.data;
- this.id = id;
- this.app = app;
- this.metric = metrics;
- this.fields = fields;
- this.valueRows = valueRows;
-
- this.listOfColumns.push(
- fields.map((field: { name: string; unit: any }) => ({
- key: field.name,
- title: field.name.toUpperCase() + (field.unit ? `
(${field.unit})` : '')
- }))
- );
-
- this.listOfData.push(
- valueRows.map((row: { labels: any; values: any[] }) => {
- const rowData: any = { ...row.labels };
- row.values.forEach((value, index) => {
- rowData[fields[index].name] = value.origin;
- });
- return rowData;
- })
- );
-
- console.info(this.listOfData);
+ this.responseData = message.data;
+ this.responseData.forEach((item: any) => {
+ const { id, app, metrics, fields, valueRows } = message.data;
+ this.id = id;
+ this.app = app;
+ this.metric = metrics;
+ this.fields = fields;
+ this.valueRows = valueRows;
+
+ this.listOfColumns.push(
+ fields.map((field: { name: string; unit: any }) => ({
+ key: field.name,
+ title: field.name.toUpperCase() + (field.unit ? `
(${field.unit})` : '')
+ }))
+ );
+
+ this.listOfData.push(
+ valueRows.map((row: { labels: any; values: any[] }) => {
+ const rowData: any = { ...row.labels };
+ row.values.forEach((value, index) => {
+ rowData[fields[index].name] = value.origin;
+ });
+ return rowData;
+ })
+ );
+ });
+
} else if (message.code !== 0) {
- this.notifySvc.warning(`${metric}:${message.msg}`, '');
- console.info(`${metric}:${message.msg}`);
+ this.notifySvc.warning(`${message.msg}`, '');
+ console.info(`${message.msg}`);
}
},
error => {
diff --git a/web-app/src/app/service/bulletin-define.service.ts
b/web-app/src/app/service/bulletin-define.service.ts
index 15c14c2b7..93a3b4342 100644
--- a/web-app/src/app/service/bulletin-define.service.ts
+++ b/web-app/src/app/service/bulletin-define.service.ts
@@ -79,5 +79,9 @@ export class BulletinDefineService {
console.log("deleteBulletinDefine");
}
+ public getMonitorMetricsData(bulletinId: number): Observable<Message<any>> {
+ return
this.http.get<Message<any>>(`${bulletin_define_uri}/metrics/${bulletinId}`);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]