RockteMQ-AI commented on code in PR #4278:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/4278#discussion_r3999636780


##########
web/src/utils/alertRuleAssetInsights.ts:
##########
@@ -0,0 +1,392 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { AlertRuleAssetInfo } from '../api/alertRuleAssets';
+import { buildCsv, type CsvColumn } from './download';
+
+export type AlertRuleAssetHealthLevel = 'healthy' | 'notice' | 'warning' | 
'critical';
+
+export type AlertRuleAssetDomain =
+  | 'broker'
+  | 'consumer'
+  | 'producer'
+  | 'topic'
+  | 'proxy'
+  | 'client'
+  | 'dlq'
+  | 'error'
+  | 'runtime'
+  | 'unknown';
+
+export type AlertRuleAssetIssueCode =
+  | 'NO_ASSETS'
+  | 'DUPLICATE_ASSET_NAME'
+  | 'EMPTY_RULE_ASSET'
+  | 'MISSING_SEVERITY'
+  | 'DOMAIN_UNCOVERED'
+  | 'DOMAIN_WITHOUT_CRITICAL';
+
+export interface AlertRuleAssetIssue {
+  code: AlertRuleAssetIssueCode;
+  level: AlertRuleAssetHealthLevel;
+  assetName?: string;
+  domain?: AlertRuleAssetDomain;
+  value?: number;
+}
+
+export interface AlertRuleAssetInsightRow {
+  key: string;
+  name: string;
+  group: string;
+  domain: AlertRuleAssetDomain;
+  ruleCount: number;
+  severities: string[];
+  hasCritical: boolean;
+  issues: AlertRuleAssetIssueCode[];
+}
+
+export interface AlertRuleAssetDomainInsight {
+  domain: AlertRuleAssetDomain;
+  assetCount: number;
+  ruleCount: number;
+  criticalAssetCount: number;
+  warningAssetCount: number;
+  infoAssetCount: number;
+  coveragePercent: number;
+  groups: string[];
+  assetNames: string[];
+  issues: AlertRuleAssetIssueCode[];
+}
+
+export interface AlertRuleAssetInsights {
+  level: AlertRuleAssetHealthLevel;
+  score: number;
+  totalAssets: number;
+  totalRules: number;
+  groupCount: number;
+  expectedDomainCount: number;
+  coveredExpectedDomainCount: number;
+  coveragePercent: number;
+  criticalAssetCount: number;
+  warningAssetCount: number;
+  infoAssetCount: number;
+  unknownSeverityAssetCount: number;
+  rows: AlertRuleAssetInsightRow[];
+  domainRows: AlertRuleAssetDomainInsight[];
+  issues: AlertRuleAssetIssue[];
+}
+
+export const EXPECTED_ALERT_RULE_ASSET_DOMAINS: AlertRuleAssetDomain[] = [
+  'broker',
+  'consumer',
+  'producer',
+  'topic',
+  'proxy',
+];
+
+const DOMAIN_ORDER: AlertRuleAssetDomain[] = [
+  ...EXPECTED_ALERT_RULE_ASSET_DOMAINS,
+  'client',
+  'dlq',
+  'error',
+  'runtime',
+  'unknown',
+];
+
+const SEVERITY_ORDER = ['critical', 'warning', 'info'];
+const EMPTY_ASSET_PENALTY = 16;
+const MISSING_SEVERITY_PENALTY = 10;
+const DUPLICATE_NAME_PENALTY = 12;
+const UNCOVERED_DOMAIN_PENALTY = 16;
+const SOFT_DOMAIN_GAP_PENALTY = 5;
+
+const issueLevelWeight: Record<AlertRuleAssetHealthLevel, number> = {
+  healthy: 0,
+  notice: 1,
+  warning: 2,
+  critical: 3,
+};
+
+const domainPatterns: Array<[AlertRuleAssetDomain, RegExp]> = [

Review Comment:
   **[Info]** The `domainPatterns` array has overlapping regex entries — `jvm` 
appears in both the `broker` pattern and the `runtime` pattern. Since 
`Array.find` returns the first match, an asset named e.g. `rocketmq-jvm-gc` 
would be classified as `broker` rather than `runtime`. Consider either removing 
`jvm` from the broker pattern or adding word-boundary anchoring to 
disambiguate. Not blocking — the current ordering is a reasonable default.



-- 
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]

Reply via email to