Copilot commented on code in PR #3710:
URL:
https://github.com/apache/rocketmq-dashboard/pull/3710#discussion_r3941868196
##########
server/src/main/java/org/apache/rocketmq/studio/ops/alert/MybatisPlusAlertRepository.java:
##########
@@ -201,6 +201,29 @@ public PageResult<SystemAlertVO>
findAlertsPage(SystemAlertQuery query) {
result.getTotal(), query.page(), query.pageSize());
}
+ @Override
+ public SystemAlertSummaryVO summarizeAlerts(SystemAlertQuery query) {
+ QueryWrapper<RmqSystemAlert> conditions = new
QueryWrapper<RmqSystemAlert>()
+ .select(
+ "COUNT(*) AS total_count",
+ "COALESCE(SUM(CASE WHEN acknowledged = 0 THEN 1 ELSE 0
END), 0) AS unacknowledged_count")
+ .eq(StringUtils.hasText(query.level()), "level",
normalizeLevel(query.level()))
+ .eq(query.domain() != null, "domain", query.domain() == null ?
null : query.domain().name())
+ .eq(StringUtils.hasText(query.instanceId()), "instance_id",
trimToNull(query.instanceId()))
+ .eq(StringUtils.hasText(query.transition()), "transition",
normalizeTransition(query.transition()))
+ .eq(query.notificationSuppressed() != null,
"notification_suppressed", query.notificationSuppressed())
+ .apply(StringUtils.hasText(query.labelKey()),
+ "JSON_CONTAINS(labels_json, JSON_OBJECT({0}, {1}))",
query.labelKey(), query.labelValue())
+ .ge(query.from() != null, "time", query.from())
+ .le(query.to() != null, "time", query.to());
+ List<Map<String, Object>> rows = alertMapper.selectMaps(conditions);
+ Map<String, Object> row = rows.isEmpty() ? Map.of() : rows.get(0);
+ return SystemAlertSummaryVO.builder()
+ .total(asLong(row, "total_count"))
+ .unacknowledged(asLong(row, "unacknowledged_count"))
+ .build();
+ }
Review Comment:
`summarizeAlerts` calls `asLong(row, ...)`, but there is no `asLong` helper
defined or imported in this class, so this will not compile. Add a local helper
to safely coerce the aggregate columns to `long` (defaulting to 0 when absent).
##########
web/src/services/opsService.ts:
##########
@@ -380,6 +381,18 @@ export async function listSystemAlertsPage(
};
}
+export async function getSystemAlertSummary(
+ params: SystemAlertQuery = {},
+): Promise<SystemAlertSummary> {
+ if (!isMockMode()) return opsApi.fetchSystemAlertSummary(params);
+
+ const page = await listSystemAlertsPage({ ...params, page: 1, pageSize: 100
});
+ return {
+ total: page.total,
+ unacknowledged: page.items.filter((alert) => !alert.acknowledged).length,
+ };
Review Comment:
In mock mode, `getSystemAlertSummary` only loads the first 100 alerts and
counts unacknowledged within that subset, so the returned `unacknowledged`
value can be wrong when the filtered result set exceeds 100. Use a pageSize
that covers the entire mock dataset so the summary is result-set wide in
dev/mock mode too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]