Skip to content

<feature>[zwatch]: add OVN instance default alarms#3500

Open
zstack-robot-1 wants to merge 1 commit into5.5.12from
sync/zhangjianjun/ZSTAC-73154-2@@2
Open

<feature>[zwatch]: add OVN instance default alarms#3500
zstack-robot-1 wants to merge 1 commit into5.5.12from
sync/zhangjianjun/ZSTAC-73154-2@@2

Conversation

@zstack-robot-1
Copy link
Collaborator

DBImpact

Resolves: ZSTAC-73154

Change-Id: I7a6b69706374636e6d65716c6e7571657766636c

Signed-off-by: zhangjianjun jianjun.zhang@zstack.io

sync from gitlab !9359

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

在数据库升级脚本 conf/db/upgrade/V5.5.12__schema.sql 中新增三条 ActiveAlarmTemplateVO 插入语句,分别为 OvnVmInstance-DiskAllUsedCapacityInPercentOvnVmInstance-MemoryUsedInPercentOvnVmInstance-CPUAverageUsedUtilization(threshold=80,period=300,repeatInterval=1800,namespace=ZStack/OvnVmInstance),插入位于 DROP PROCEDURE IF EXISTS ModifyUsedIpVOForeignKey; 之后。

Changes

Cohort / File(s) Summary
数据库升级脚本
conf/db/upgrade/V5.5.12__schema.sql
添加三条 ActiveAlarmTemplateVO 插入语句(OVN VM 的 DiskAllUsedCapacityInPercent、MemoryUsedInPercent、CPUAverageUsedUtilization),均使用 GreaterThanOrEqualTo、threshold=80、period=300、repeatInterval=1800、namespace=ZStack/OvnVmInstance,插入位于 DROP PROCEDURE ... ModifyUsedIpVOForeignKey 之后以保证可重复执行。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

庆祝诗

🐰 新告警入库心欢畅,
磁盘内存与 CPU 同航,
阈值八十静候光,
升级脚本里落成行,
兔子鼓掌跳一趟。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题遵循了[scope]: 格式,长度为50字符(在72字符以内),清晰描述了添加OVN实例默认告警的变更。
Description check ✅ Passed PR描述与变更集相关,提及了数据库影响、关联的JIRA工单(ZSTAC-73154)和同步源信息。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/zhangjianjun/ZSTAC-73154-2@@2
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 36-38: The three INSERTs into ActiveAlarmTemplateVO (rows with
UUIDs 'f1a6c2d85e7b8c9d3e4f5a6b7c8d9e0f', 'b3c8e4f07a9d0e1f5a6b7c8d9e0f1a2b',
'd5e0a6b29c1f2a3b7c8d9e0f1a2b3c4d' and alarmNames
OvnVmInstance-DiskAllUsedCapacityInPercent, OvnVmInstance-MemoryUsedInPercent,
OvnVmInstance-CPUAverageUsedUtilization) are not idempotent and will fail on
re-run; change them to be idempotent by either using INSERT IGNORE or converting
each to a conditional insert that checks existence (e.g., INSERT ... SELECT ...
WHERE NOT EXISTS (SELECT 1 FROM ActiveAlarmTemplateVO WHERE uuid = '<uuid>' OR
alarmName = '<alarmName>')) so repeated upgrades do not cause primary-key
conflicts; apply this pattern to all three INSERT statements.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 25c52d43-a054-42cd-9457-afc7b31effa6

📥 Commits

Reviewing files that changed from the base of the PR and between 327b1cc and 322e5ec.

📒 Files selected for processing (1)
  • conf/db/upgrade/V5.5.12__schema.sql

@MatheMatrix MatheMatrix force-pushed the sync/zhangjianjun/ZSTAC-73154-2@@2 branch 3 times, most recently from e64b2b0 to 767bb87 Compare March 17, 2026 06:02
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 130-132: Prefix the table references in the three INSERT
statements to explicitly target the zstack schema: replace occurrences of
ActiveAlarmTemplateVO in the INSERT IGNORE INTO lines with
zstack.`ActiveAlarmTemplateVO` (so the INSERTs that insert templates like
'OvnVmInstance-DiskAllUsedCapacityInPercent',
'OvnVmInstance-MemoryUsedInPercent', and
'OvnVmInstance-CPUAverageUsedUtilization' run against the zstack schema
regardless of the current DB context); apply the same schema-qualified pattern
for any other unqualified table names in this upgrade script.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: fee3bbb8-09f7-4c4f-b760-ff0bad311860

📥 Commits

Reviewing files that changed from the base of the PR and between e64b2b0 and 767bb87.

📒 Files selected for processing (1)
  • conf/db/upgrade/V5.5.12__schema.sql

Comment on lines +130 to +132
INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('f1a6c2d85e7b8c9d3e4f5a6b7c8d9e0f','OvnVmInstance-DiskAllUsedCapacityInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','DiskAllUsedCapacityInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('b3c8e4f07a9d0e1f5a6b7c8d9e0f1a2b','OvnVmInstance-MemoryUsedInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','MemoryUsedInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('d5e0a6b29c1f2a3b7c8d9e0f1a2b3c4d','OvnVmInstance-CPUAverageUsedUtilization','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','CPUAverageUsedUtilization',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

建议在 Line 130-132 显式加上 zstack schema 前缀。

当前写法依赖默认库上下文;升级脚本里建议统一写成 zstack.ActiveAlarmTemplateVO,避免在非常规执行上下文下写入错误库。

💡 建议修改
-INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('f1a6c2d85e7b8c9d3e4f5a6b7c8d9e0f','OvnVmInstance-DiskAllUsedCapacityInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','DiskAllUsedCapacityInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
-INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('b3c8e4f07a9d0e1f5a6b7c8d9e0f1a2b','OvnVmInstance-MemoryUsedInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','MemoryUsedInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
-INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('d5e0a6b29c1f2a3b7c8d9e0f1a2b3c4d','OvnVmInstance-CPUAverageUsedUtilization','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','CPUAverageUsedUtilization',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
+INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('f1a6c2d85e7b8c9d3e4f5a6b7c8d9e0f','OvnVmInstance-DiskAllUsedCapacityInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','DiskAllUsedCapacityInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
+INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('b3c8e4f07a9d0e1f5a6b7c8d9e0f1a2b','OvnVmInstance-MemoryUsedInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','MemoryUsedInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
+INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('d5e0a6b29c1f2a3b7c8d9e0f1a2b3c4d','OvnVmInstance-CPUAverageUsedUtilization','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','CPUAverageUsedUtilization',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);

Based on learnings: "In ZStack, the database schema name is fixed as 'zstack'. For SQL upgrade scripts under conf/db/upgrade, continue using TABLE_SCHEMA = 'zstack' and reference tables as zstack.UsedIpVO."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 130 - 132, Prefix the table
references in the three INSERT statements to explicitly target the zstack
schema: replace occurrences of ActiveAlarmTemplateVO in the INSERT IGNORE INTO
lines with zstack.`ActiveAlarmTemplateVO` (so the INSERTs that insert templates
like 'OvnVmInstance-DiskAllUsedCapacityInPercent',
'OvnVmInstance-MemoryUsedInPercent', and
'OvnVmInstance-CPUAverageUsedUtilization' run against the zstack schema
regardless of the current DB context); apply the same schema-qualified pattern
for any other unqualified table names in this upgrade script.

@MatheMatrix MatheMatrix force-pushed the sync/zhangjianjun/ZSTAC-73154-2@@2 branch 2 times, most recently from c3d5ae6 to d7423b1 Compare March 18, 2026 02:03
@MatheMatrix
Copy link
Owner

Comment from gitlab:

自上次添加REVIEWED标签(2026-03-17 19:40:57.000Z)后, 有新的COMMIT更新(2026-03-18 10:03:35.812Z), 所以移除了REVIEWED标签

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
conf/db/upgrade/V5.5.12__schema.sql (1)

183-185: ⚠️ Potential issue | 🟡 Minor

请为插入目标表显式加上 zstack schema 前缀。

当前写法依赖默认库上下文;在非常规执行环境中可能写入到错误 schema。建议改为 INSERT IGNORE INTO \zstack`.`ActiveAlarmTemplateVO``。

💡 建议修复
-INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('f1a6c2d85e7b8c9d3e4f5a6b7c8d9e0f','OvnVmInstance-DiskAllUsedCapacityInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','DiskAllUsedCapacityInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
-INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('b3c8e4f07a9d0e1f5a6b7c8d9e0f1a2b','OvnVmInstance-MemoryUsedInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','MemoryUsedInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
-INSERT IGNORE INTO `ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('d5e0a6b29c1f2a3b7c8d9e0f1a2b3c4d','OvnVmInstance-CPUAverageUsedUtilization','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','CPUAverageUsedUtilization',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
+INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('f1a6c2d85e7b8c9d3e4f5a6b7c8d9e0f','OvnVmInstance-DiskAllUsedCapacityInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','DiskAllUsedCapacityInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
+INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('b3c8e4f07a9d0e1f5a6b7c8d9e0f1a2b','OvnVmInstance-MemoryUsedInPercent','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','MemoryUsedInPercent',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);
+INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO` (`uuid`,`alarmName`,`comparisonOperator`,`period`,`repeatInterval`,`namespace`,`metricName`,`threshold`,`lastOpDate`,`createDate`,`repeatCount`,`enableRecovery`,`emergencyLevel`,`labels`) VALUES ('d5e0a6b29c1f2a3b7c8d9e0f1a2b3c4d','OvnVmInstance-CPUAverageUsedUtilization','GreaterThanOrEqualTo',300,1800,'ZStack/OvnVmInstance','CPUAverageUsedUtilization',80,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP(),-1,0,'Important',NULL);

Based on learnings: "In ZStack, the database schema name is fixed as 'zstack'. For SQL upgrade scripts under conf/db/upgrade, continue using TABLE_SCHEMA = 'zstack' and reference tables as zstack.UsedIpVO."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 183 - 185, The INSERT
statements targeting ActiveAlarmTemplateVO rely on the current default schema;
update each INSERT IGNORE INTO `ActiveAlarmTemplateVO` to explicitly reference
the zstack schema (INSERT IGNORE INTO `zstack`.`ActiveAlarmTemplateVO`) so the
three inserts (rows for alarmName values
OvnVmInstance-DiskAllUsedCapacityInPercent, OvnVmInstance-MemoryUsedInPercent,
OvnVmInstance-CPUAverageUsedUtilization) always write into the zstack schema
regardless of execution context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 183-185: The INSERT statements targeting ActiveAlarmTemplateVO
rely on the current default schema; update each INSERT IGNORE INTO
`ActiveAlarmTemplateVO` to explicitly reference the zstack schema (INSERT IGNORE
INTO `zstack`.`ActiveAlarmTemplateVO`) so the three inserts (rows for alarmName
values OvnVmInstance-DiskAllUsedCapacityInPercent,
OvnVmInstance-MemoryUsedInPercent, OvnVmInstance-CPUAverageUsedUtilization)
always write into the zstack schema regardless of execution context.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 225a764d-596c-4162-b967-6ea113a0f91a

📥 Commits

Reviewing files that changed from the base of the PR and between 767bb87 and d7423b1.

📒 Files selected for processing (1)
  • conf/db/upgrade/V5.5.12__schema.sql

DBImpact

Resolves: ZSTAC-73154

Change-Id: I7a6b69706374636e6d65716c6e7571657766636c

Signed-off-by: zhangjianjun <jianjun.zhang@zstack.io>
@MatheMatrix
Copy link
Owner

Comment from gitlab:

自上次添加REVIEWED标签(2026-03-18 20:01:22.000Z)后, 有新的COMMIT更新(2026-03-19 19:56:58.950Z), 所以移除了REVIEWED标签

@MatheMatrix MatheMatrix force-pushed the sync/zhangjianjun/ZSTAC-73154-2@@2 branch from d7423b1 to ec18635 Compare March 19, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants