RockteMQ-AI commented on code in PR #2939:
URL:
https://github.com/apache/rocketmq-dashboard/pull/2939#discussion_r3909131355
##########
web/src/services/opsService.ts:
##########
@@ -159,9 +159,23 @@ export async function importAlertRulesTransfer(
): Promise<AlertRule[]> {
if (!isMockMode()) return opsApi.importAlertRulesTransfer(data, domain);
const startId = Date.now();
- const imported = data.rules.map((rule, index) => ({
- ...copyAlertRule(rule as AlertRule),
+ // The transfer file is user-supplied JSON; tolerate a missing rules array
and
+ // rules with missing fields using the same defaults as createAlertRule
instead
+ // of crashing the whole import.
+ const rules = Array.isArray(data?.rules) ? data.rules : [];
+ const imported = rules.map((rule, index) => ({
id: startId + index,
+ name: '',
+ metric: '',
+ operator: '>',
Review Comment:
The `id` property is set before `...rule`, so an imported rule that contains
its own `id` field will override the generated `startId + index`. This can
cause ID collisions with existing rules in `alertRulesState`. Move `id: startId
+ index` after `...rule` (or set it explicitly after the spread, similar to
`channels`) to guarantee a fresh, unique ID for every imported rule.
--
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]