@huawei-iac-tools/landingzone-workbench 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +85 -2
- package/cordis.patch.yml +21 -0
- package/knowledge/account-qualification.md +128 -0
- package/knowledge/blueprints/_base/blueprint.json +481 -0
- package/knowledge/blueprints/_base/defaults.json +127 -0
- package/knowledge/blueprints/foundation-lz/blueprint.json +43 -0
- package/knowledge/blueprints/foundation-lz/defaults.json +47 -0
- package/knowledge/blueprints/full-lz/blueprint.json +11 -0
- package/knowledge/blueprints/full-lz/defaults.json +8 -0
- package/knowledge/config.json +43 -0
- package/knowledge/error-rules.json +14 -0
- package/knowledge/ic-policies.json +21 -0
- package/knowledge/modules/account-structure.md +101 -0
- package/knowledge/modules/compliance/config-rms.md +212 -0
- package/knowledge/modules/compliance/cts.md +179 -0
- package/knowledge/modules/compliance/obs-lts.md +155 -0
- package/knowledge/modules/ic-policies.json +21 -0
- package/knowledge/modules/identity-center.md +603 -0
- package/knowledge/modules/module-layers.md +169 -0
- package/knowledge/modules/network/er.md +222 -0
- package/knowledge/modules/network/nat-eip.md +123 -0
- package/knowledge/modules/network/ram-share.md +92 -0
- package/knowledge/modules/network/vpc-subnet.md +142 -0
- package/knowledge/modules/organization-security/scp.md +122 -0
- package/knowledge/modules/organizations.md +212 -0
- package/knowledge/modules/recommended-config.md +157 -0
- package/knowledge/modules/recommended-rules.json +175 -0
- package/knowledge/modules/scp-policies.json +111 -0
- package/knowledge/modules/security/aad.md +94 -0
- package/knowledge/modules/security/cfw.md +105 -0
- package/knowledge/modules/security/waf.md +110 -0
- package/knowledge/param-mappings.json +133 -0
- package/knowledge/prompts.md +83 -0
- package/knowledge/resource-types.json +1162 -0
- package/knowledge/scp-policies.json +111 -0
- package/knowledge/state-machine.md +33 -0
- package/lib/client.js +21 -0
- package/lib/index.js +28592 -0
- package/lib/types/account-role.d.ts +19 -0
- package/lib/types/account-scope.d.ts +10 -0
- package/lib/types/agency.d.ts +38 -0
- package/lib/types/client/DropdownSelect.d.ts +49 -0
- package/lib/types/client/LoginGate.d.ts +20 -0
- package/lib/types/client/PanelIcon.d.ts +11 -0
- package/lib/types/client/WorkbenchShell.d.ts +21 -0
- package/lib/types/client/account-role.d.ts +15 -0
- package/lib/types/client/credential-status.d.ts +15 -0
- package/lib/types/client/huawei-mark.d.ts +37 -0
- package/lib/types/client/index.d.ts +26 -0
- package/lib/types/client/layout-ref.d.ts +23 -0
- package/lib/types/client/pages/ConfigPage/AdviceCard.d.ts +26 -0
- package/lib/types/client/pages/ConfigPage/AuditBar.d.ts +21 -0
- package/lib/types/client/pages/ConfigPage/ChangeSummaryCard.d.ts +22 -0
- package/lib/types/client/pages/ConfigPage/ChangesCard.d.ts +27 -0
- package/lib/types/client/pages/ConfigPage/ComplianceDetail.d.ts +25 -0
- package/lib/types/client/pages/ConfigPage/ComplianceSummaryCard.d.ts +31 -0
- package/lib/types/client/pages/ConfigPage/FindingsCard.d.ts +21 -0
- package/lib/types/client/pages/ConfigPage/GlossaryDrawer.d.ts +17 -0
- package/lib/types/client/pages/ConfigPage/OrgComplianceDetail.d.ts +15 -0
- package/lib/types/client/pages/ConfigPage/Pager.d.ts +32 -0
- package/lib/types/client/pages/ConfigPage/ResourceDrawer.d.ts +26 -0
- package/lib/types/client/pages/ConfigPage/ResourcesTable.d.ts +35 -0
- package/lib/types/client/pages/ConfigPage/RollupPanel.d.ts +17 -0
- package/lib/types/client/pages/ConfigPage/RuleDetailDrawer.d.ts +23 -0
- package/lib/types/client/pages/ConfigPage/StatusCards.d.ts +26 -0
- package/lib/types/client/pages/ConfigPage/UncoveredDialog.d.ts +22 -0
- package/lib/types/client/pages/ConfigPage/config-api.d.ts +101 -0
- package/lib/types/client/pages/ConfigPage/config-store.d.ts +57 -0
- package/lib/types/client/pages/ConfigPage/index.d.ts +21 -0
- package/lib/types/client/pages/ConfigPage/paging.d.ts +46 -0
- package/lib/types/client/pages/ConfigPage/scope-options.d.ts +51 -0
- package/lib/types/client/pages/CostPage/AccountAllocation.d.ts +24 -0
- package/lib/types/client/pages/CostPage/AccountBars.d.ts +20 -0
- package/lib/types/client/pages/CostPage/AccountColumns.d.ts +24 -0
- package/lib/types/client/pages/CostPage/AccountDonut.d.ts +18 -0
- package/lib/types/client/pages/CostPage/AccountSwitcher.d.ts +25 -0
- package/lib/types/client/pages/CostPage/AdviceCard.d.ts +43 -0
- package/lib/types/client/pages/CostPage/AdviceFindings.d.ts +43 -0
- package/lib/types/client/pages/CostPage/BillingPanels.d.ts +23 -0
- package/lib/types/client/pages/CostPage/BudgetCard.d.ts +36 -0
- package/lib/types/client/pages/CostPage/GlossaryDrawer.d.ts +16 -0
- package/lib/types/client/pages/CostPage/KpiRow.d.ts +23 -0
- package/lib/types/client/pages/CostPage/MarkdownBlock.d.ts +16 -0
- package/lib/types/client/pages/CostPage/ReportView.d.ts +17 -0
- package/lib/types/client/pages/CostPage/ResourceColumns.d.ts +19 -0
- package/lib/types/client/pages/CostPage/ResourceDonut.d.ts +18 -0
- package/lib/types/client/pages/CostPage/ResourcesCard.d.ts +40 -0
- package/lib/types/client/pages/CostPage/RuleDetailDrawer.d.ts +23 -0
- package/lib/types/client/pages/CostPage/SavingView.d.ts +38 -0
- package/lib/types/client/pages/CostPage/ServiceDonut.d.ts +17 -0
- package/lib/types/client/pages/CostPage/TrendChart.d.ts +24 -0
- package/lib/types/client/pages/CostPage/budget-input.d.ts +30 -0
- package/lib/types/client/pages/CostPage/cost-api.d.ts +266 -0
- package/lib/types/client/pages/CostPage/cost-store.d.ts +25 -0
- package/lib/types/client/pages/CostPage/format.d.ts +37 -0
- package/lib/types/client/pages/CostPage/index.d.ts +34 -0
- package/lib/types/client/pages/CostPage/trend-fold.d.ts +32 -0
- package/lib/types/client/pages/CostPage/useEcharts.d.ts +70 -0
- package/lib/types/client/pages/OrgStructurePage/AccountStatsCard.d.ts +22 -0
- package/lib/types/client/pages/OrgStructurePage/CoreAccountsCard.d.ts +18 -0
- package/lib/types/client/pages/OrgStructurePage/CreateAccountDialog.d.ts +28 -0
- package/lib/types/client/pages/OrgStructurePage/ManageUsersDialog.d.ts +28 -0
- package/lib/types/client/pages/OrgStructurePage/MemberAccountsTable.d.ts +32 -0
- package/lib/types/client/pages/OrgStructurePage/MoveAccountDialog.d.ts +29 -0
- package/lib/types/client/pages/OrgStructurePage/OrgGlossaryDrawer.d.ts +13 -0
- package/lib/types/client/pages/OrgStructurePage/OrgTreeCard.d.ts +31 -0
- package/lib/types/client/pages/OrgStructurePage/index.d.ts +21 -0
- package/lib/types/client/pages/OrgStructurePage/org-api.d.ts +166 -0
- package/lib/types/client/pages/OverviewPage/AnchorRow.d.ts +24 -0
- package/lib/types/client/pages/OverviewPage/AttentionList.d.ts +29 -0
- package/lib/types/client/pages/OverviewPage/OverviewCharts.d.ts +79 -0
- package/lib/types/client/pages/OverviewPage/OverviewGlossaryDrawer.d.ts +15 -0
- package/lib/types/client/pages/OverviewPage/index.d.ts +22 -0
- package/lib/types/client/pages/OverviewPage/overview-api.d.ts +115 -0
- package/lib/types/client/pages/ResourcePage/AccountResourceList.d.ts +21 -0
- package/lib/types/client/pages/ResourcePage/components/GlossaryDrawer.d.ts +20 -0
- package/lib/types/client/pages/ResourcePage/components/MetricCards.d.ts +19 -0
- package/lib/types/client/pages/ResourcePage/components/MultiSelect.d.ts +27 -0
- package/lib/types/client/pages/ResourcePage/components/PanelPager.d.ts +26 -0
- package/lib/types/client/pages/ResourcePage/components/RankBars.d.ts +25 -0
- package/lib/types/client/pages/ResourcePage/components/ScopeSelect.d.ts +27 -0
- package/lib/types/client/pages/ResourcePage/components/SourceConfigModal.d.ts +21 -0
- package/lib/types/client/pages/ResourcePage/components/SyncControls.d.ts +18 -0
- package/lib/types/client/pages/ResourcePage/components/TrendChart.d.ts +14 -0
- package/lib/types/client/pages/ResourcePage/components/useColumnWidths.d.ts +12 -0
- package/lib/types/client/pages/ResourcePage/format.d.ts +9 -0
- package/lib/types/client/pages/ResourcePage/index.d.ts +20 -0
- package/lib/types/client/pages/ResourcePage/summary-api.d.ts +205 -0
- package/lib/types/client/pages/SetupPage/AskPanel.d.ts +21 -0
- package/lib/types/client/pages/SetupPage/ChatEmbed.d.ts +40 -0
- package/lib/types/client/pages/SetupPage/ChatTab.d.ts +17 -0
- package/lib/types/client/pages/SetupPage/FormTab.d.ts +12 -0
- package/lib/types/client/pages/SetupPage/FormTabV2.d.ts +14 -0
- package/lib/types/client/pages/SetupPage/ProgressTreeView.d.ts +15 -0
- package/lib/types/client/pages/SetupPage/StageFlow.d.ts +16 -0
- package/lib/types/client/pages/SetupPage/index.d.ts +10 -0
- package/lib/types/client/pages/SetupPage/progress-types.d.ts +36 -0
- package/lib/types/client/pages/SetupPage/session-binding.d.ts +38 -0
- package/lib/types/client/pages/SetupPage/session-store.d.ts +57 -0
- package/lib/types/client/pages/SetupPage/sessions-ref.d.ts +5 -0
- package/lib/types/client/pages/SetupPage/setup-replan.d.ts +13 -0
- package/lib/types/client/pages/SetupPage/wb-api.d.ts +192 -0
- package/lib/types/client/pages/list-preview.d.ts +36 -0
- package/lib/types/client/permission-mode.d.ts +53 -0
- package/lib/types/client/store.d.ts +22 -0
- package/lib/types/collect.d.ts +78 -0
- package/lib/types/config/account-scope.d.ts +61 -0
- package/lib/types/config/advice-findings.d.ts +31 -0
- package/lib/types/config/advice-prompt.d.ts +60 -0
- package/lib/types/config/advice.d.ts +116 -0
- package/lib/types/config/cts.d.ts +30 -0
- package/lib/types/config/evidence/rules.d.ts +31 -0
- package/lib/types/config/evidence/types.d.ts +103 -0
- package/lib/types/config/failure-note.d.ts +46 -0
- package/lib/types/config/fingerprint-cache.d.ts +45 -0
- package/lib/types/config/identity.d.ts +67 -0
- package/lib/types/config/query.d.ts +49 -0
- package/lib/types/config/rms.d.ts +412 -0
- package/lib/types/config/routes.d.ts +32 -0
- package/lib/types/config/types.d.ts +785 -0
- package/lib/types/config/views.d.ts +158 -0
- package/lib/types/cost/accounts.d.ts +29 -0
- package/lib/types/cost/advice-findings.d.ts +77 -0
- package/lib/types/cost/advice-model.d.ts +19 -0
- package/lib/types/cost/advice-prompt.d.ts +73 -0
- package/lib/types/cost/advice-subagent-types.d.ts +6 -0
- package/lib/types/cost/advice-subagent.d.ts +116 -0
- package/lib/types/cost/advice-types.d.ts +63 -0
- package/lib/types/cost/advice.d.ts +125 -0
- package/lib/types/cost/aggregate.d.ts +157 -0
- package/lib/types/cost/assume.d.ts +43 -0
- package/lib/types/cost/bss.d.ts +166 -0
- package/lib/types/cost/budget-overview.d.ts +38 -0
- package/lib/types/cost/budget.d.ts +56 -0
- package/lib/types/cost/cache.d.ts +58 -0
- package/lib/types/cost/caliber.d.ts +40 -0
- package/lib/types/cost/console-links.d.ts +27 -0
- package/lib/types/cost/credentials.d.ts +38 -0
- package/lib/types/cost/data-window.d.ts +38 -0
- package/lib/types/cost/evidence/catalog.d.ts +35 -0
- package/lib/types/cost/evidence/index.d.ts +70 -0
- package/lib/types/cost/evidence/inventory.d.ts +44 -0
- package/lib/types/cost/evidence/pricing.d.ts +72 -0
- package/lib/types/cost/evidence/projects.d.ts +18 -0
- package/lib/types/cost/evidence/rules.d.ts +66 -0
- package/lib/types/cost/evidence/state.d.ts +38 -0
- package/lib/types/cost/evidence/thresholds.d.ts +68 -0
- package/lib/types/cost/evidence/types.d.ts +288 -0
- package/lib/types/cost/evidence/utilization.d.ts +37 -0
- package/lib/types/cost/history.d.ts +36 -0
- package/lib/types/cost/ledger.d.ts +97 -0
- package/lib/types/cost/normalize.d.ts +37 -0
- package/lib/types/cost/period-projection.d.ts +57 -0
- package/lib/types/cost/plan-check.d.ts +102 -0
- package/lib/types/cost/plan-db.d.ts +73 -0
- package/lib/types/cost/plan-types.d.ts +183 -0
- package/lib/types/cost/plan.d.ts +63 -0
- package/lib/types/cost/quote.d.ts +45 -0
- package/lib/types/cost/report.d.ts +136 -0
- package/lib/types/cost/resources.d.ts +108 -0
- package/lib/types/cost/routes.d.ts +38 -0
- package/lib/types/cost/scope.d.ts +42 -0
- package/lib/types/cost/types.d.ts +335 -0
- package/lib/types/cost/unit-prices-derive.d.ts +19 -0
- package/lib/types/cost/unit-prices.d.ts +23 -0
- package/lib/types/db.d.ts +228 -0
- package/lib/types/host-log.d.ts +7 -0
- package/lib/types/http.d.ts +42 -0
- package/lib/types/index.d.ts +30 -0
- package/lib/types/inventory.d.ts +286 -0
- package/lib/types/obs.d.ts +16 -0
- package/lib/types/org/aggregate.d.ts +36 -0
- package/lib/types/org/churn.d.ts +10 -0
- package/lib/types/org/orgs.d.ts +258 -0
- package/lib/types/org/routes.d.ts +28 -0
- package/lib/types/org-types.d.ts +156 -0
- package/lib/types/per-service.d.ts +39 -0
- package/lib/types/setup/blueprint-loader.d.ts +81 -0
- package/lib/types/setup/caller.d.ts +105 -0
- package/lib/types/setup/engine.d.ts +41 -0
- package/lib/types/setup/form-store.d.ts +13 -0
- package/lib/types/setup/nodes/n1-check.d.ts +14 -0
- package/lib/types/setup/nodes/n10-governance.d.ts +6 -0
- package/lib/types/setup/nodes/n11-infra.d.ts +6 -0
- package/lib/types/setup/nodes/n12-reconcile.d.ts +6 -0
- package/lib/types/setup/nodes/n2-region.d.ts +6 -0
- package/lib/types/setup/nodes/n3-blueprint.d.ts +6 -0
- package/lib/types/setup/nodes/n4-modules.d.ts +6 -0
- package/lib/types/setup/nodes/n5-details.d.ts +6 -0
- package/lib/types/setup/nodes/n6-plan.d.ts +6 -0
- package/lib/types/setup/nodes/n7-verify.d.ts +6 -0
- package/lib/types/setup/nodes/n8-approve.d.ts +6 -0
- package/lib/types/setup/nodes/n9-buildmode.d.ts +6 -0
- package/lib/types/setup/plan-state.d.ts +10 -0
- package/lib/types/setup/prompt-loader.d.ts +16 -0
- package/lib/types/setup/routes.d.ts +22 -0
- package/lib/types/setup/session-notify.d.ts +30 -0
- package/lib/types/setup/tools.d.ts +19 -0
- package/lib/types/setup/types.d.ts +157 -0
- package/lib/types/sse-bus.d.ts +23 -0
- package/lib/types/tools/config-facts.d.ts +16 -0
- package/lib/types/tools/cost-facts.d.ts +10 -0
- package/lib/types/tools/register.d.ts +18 -0
- package/lib/types/wb-conventions.d.ts +140 -0
- package/package.json +77 -4
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资源级发现的类型(**纯类型 + 纯常量**,浏览器与宿主共用)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个文件:卡片要渲染这些行,而采集逻辑要碰 node 与华为云。
|
|
5
|
+
* 客户端一旦 import 到带 `fetch`/`fs` 的模块,打包器就会把宿主的一半拖进浏览器。
|
|
6
|
+
* 所以类型与标签常量住在这里,`index.ts` / `rules.ts` 只在宿主侧引用。
|
|
7
|
+
*
|
|
8
|
+
* @module @huaweidevtools/landingzone-workbench/cost/evidence/types
|
|
9
|
+
*/
|
|
10
|
+
/** 规则编号:一条建议为什么成立。 */
|
|
11
|
+
export type FindingKind =
|
|
12
|
+
/** 实例长期低负载(CPU)。 */
|
|
13
|
+
'idle_compute'
|
|
14
|
+
/** 同上,但属于某个 CCE 节点池 —— 动作是缩容不是关机。 */
|
|
15
|
+
| 'idle_node'
|
|
16
|
+
/** 规格明显大于负载(CPU/内存不足一档)。金额需要目录价,宿主不给。 */
|
|
17
|
+
| 'oversized'
|
|
18
|
+
/** 云硬盘无挂载点。 */
|
|
19
|
+
| 'unattached_volume'
|
|
20
|
+
/** 弹性公网 IP 未绑定任何实例。 */
|
|
21
|
+
| 'unbound_eip'
|
|
22
|
+
/** 负载均衡后端成员为 0。 */
|
|
23
|
+
| 'empty_elb'
|
|
24
|
+
/** NAT 网关既无 SNAT 也无 DNAT 规则。 */
|
|
25
|
+
| 'empty_nat'
|
|
26
|
+
/** 已停机/已停止,但账期里仍有账单行。 */
|
|
27
|
+
| 'stopped_billing'
|
|
28
|
+
/** 连判据都没有:没有监控数据,判不了是否浪费(如实列出来,不猜)。 */
|
|
29
|
+
| 'no_metrics'
|
|
30
|
+
/** 非生产资源,可以按工作时段定时停机(不吃利用率证据,吃的是"该不该 24 小时开着")。 */
|
|
31
|
+
| 'offhours_candidate';
|
|
32
|
+
/**
|
|
33
|
+
* 一条发现落在哪一层 —— 决定它进不进合计。
|
|
34
|
+
*
|
|
35
|
+
* 这是这份功能最重要的一层语义:`certain` 的金额是"这个资源自己的账单行",
|
|
36
|
+
* 可以加总;`watching` 是"看着像但观测不够",只列清单;`oversized` 是
|
|
37
|
+
* "方向明确但没有目录价算不出钱";`undecided` 是"连判据都没有"。
|
|
38
|
+
*
|
|
39
|
+
* `schedulable` 是第五层:它的钱按**时段假设**算(周一到周五 10 小时),
|
|
40
|
+
* 不是账单行本身,所以单独一层、单独展示、**不进合计** ——
|
|
41
|
+
* 把"删了就不再花钱"和"每天晚上关掉"混成一个数字,等于把两种承诺混为一谈。
|
|
42
|
+
*/
|
|
43
|
+
export type FindingLayer = 'certain' | 'schedulable' | 'watching' | 'oversized' | 'undecided';
|
|
44
|
+
/**
|
|
45
|
+
* 把这条发现「做掉」的动作类型 —— 它决定钱什么时候、以什么形式落地。
|
|
46
|
+
*
|
|
47
|
+
* 为什么在层(layer)之外还要有它:`certain` 这一层里混着四种完全不同的可执行性。
|
|
48
|
+
* · 删一只空盘,账单**当月归零**;
|
|
49
|
+
* · 节点池缩容,得先看缩几台、Pod 能不能迁走,省多少**不是**那 8 台节点的整机账单;
|
|
50
|
+
* · 关机只停计算费,**盘与带宽照收**;
|
|
51
|
+
* · 定时停机是按"周一到周五 10 小时"的**假设**算出来的,不是账单。
|
|
52
|
+
* 把这四类加成一个"确定性可回收",用户照着做会省不到标题上的钱 —— 一次就够毁掉信任。
|
|
53
|
+
*/
|
|
54
|
+
export type ActionClass = 'release' | 'downgrade' | 'stop' | 'schedule';
|
|
55
|
+
/** 账单能不能回答"这个资源现在花多少钱"(见 `Finding.billing_state`)。 */
|
|
56
|
+
export type BillingState = 'billed' | 'no_bill_line' | 'created_after_cycle' | 'not_attributable';
|
|
57
|
+
/** 标签(页面与报告共用一套话说)。 */
|
|
58
|
+
export declare const BILLING_STATE_LABEL: Readonly<Record<BillingState, string>>;
|
|
59
|
+
/** 老缓存没有这个字段:用 amount 兜底推导,不让 undefined 冒到页面上。 */
|
|
60
|
+
export declare function billingStateOf(finding: Finding): BillingState;
|
|
61
|
+
/** 四类动作的短标签(页面、报告、prompt 都用这一份)。 */
|
|
62
|
+
export declare const ACTION_CLASS_LABEL: Readonly<Record<ActionClass, string>>;
|
|
63
|
+
/** 这一类动作**能带走哪一块钱**(一句话,直接印在金额旁边)。 */
|
|
64
|
+
export declare const ACTION_CLASS_SCOPE: Readonly<Record<ActionClass, string>>;
|
|
65
|
+
/** 金额该怎么读。`saving` 才是"可省",其余是现状或假设。 */
|
|
66
|
+
export type AmountSemantics = 'saving' | 'bill' | 'assumption';
|
|
67
|
+
/** 金额语义标签(**不许混用**:把账单读成可省是这一块最大的信任风险)。 */
|
|
68
|
+
export declare const AMOUNT_SEMANTICS_LABEL: Readonly<Record<AmountSemantics, string>>;
|
|
69
|
+
/** 监控统计(某个指标在一个观测窗口内的形状)。 */
|
|
70
|
+
export interface UtilizationStats {
|
|
71
|
+
readonly metric: string;
|
|
72
|
+
/** 均值。 */
|
|
73
|
+
readonly avg: number;
|
|
74
|
+
/** 95 分位(按点排序后取 95% 位置,不是插值)。 */
|
|
75
|
+
readonly p95: number;
|
|
76
|
+
readonly max: number;
|
|
77
|
+
/** 有数据的点数(1 小时粒度)。 */
|
|
78
|
+
readonly hours: number;
|
|
79
|
+
/** 覆盖到的不同自然日数。 */
|
|
80
|
+
readonly days: number;
|
|
81
|
+
}
|
|
82
|
+
/** 一条发现。 */
|
|
83
|
+
export interface Finding {
|
|
84
|
+
readonly kind: FindingKind;
|
|
85
|
+
readonly layer: FindingLayer;
|
|
86
|
+
/**
|
|
87
|
+
* 动作类型。老版本缓存没有这个字段 —— 读的时候走 `actionClassOf()`,
|
|
88
|
+
* 它按 kind 兜底,而不是让 undefined 冒到页面上。
|
|
89
|
+
*/
|
|
90
|
+
readonly action_class?: ActionClass | null;
|
|
91
|
+
/** 引用键(模型只能引用它,宿主据此换算金额)。 */
|
|
92
|
+
readonly ref: string;
|
|
93
|
+
readonly account_id: string;
|
|
94
|
+
readonly account_name: string;
|
|
95
|
+
readonly resource_id: string;
|
|
96
|
+
readonly resource_name: string;
|
|
97
|
+
readonly region: string;
|
|
98
|
+
/** 规格:`c9.xlarge.2` / `100GB GPSSD` / `50Mbps 按流量`。拿不到为 null。 */
|
|
99
|
+
readonly spec: string | null;
|
|
100
|
+
/** 资源状态:`active` / `available` / `stopped`… */
|
|
101
|
+
readonly status: string | null;
|
|
102
|
+
/** 一句人话证据,含具体数字。 */
|
|
103
|
+
readonly evidence: string;
|
|
104
|
+
/**
|
|
105
|
+
* 这个资源在账期里的**账单行**(元)。`null` = 查不到账单行。
|
|
106
|
+
*
|
|
107
|
+
* 注意它不是"可回收金额":盘、EIP 是独立的账单行,见 reclaim。
|
|
108
|
+
*/
|
|
109
|
+
readonly amount: number | null;
|
|
110
|
+
/**
|
|
111
|
+
* 账单能不能回答"这个资源现在花多少钱"。
|
|
112
|
+
*
|
|
113
|
+
* `billed` = 账单里有以它的 resource_id 出账的行;`no_bill_line` = 没有。
|
|
114
|
+
* 后者**不是"0 元"**:可能是按带宽/共享带宽计费(费用不挂在 IP 上)、
|
|
115
|
+
* 刚建还没出账、或费用由别的资源分摊。页面与报告必须把这个区别说出来。
|
|
116
|
+
*/
|
|
117
|
+
readonly billing_state?: BillingState | null;
|
|
118
|
+
/** 资源创建时间(ISO 8601)。EIP 来自 RMS 的 `createAt`;其它类型可能没有。 */
|
|
119
|
+
readonly created_at?: string | null;
|
|
120
|
+
/**
|
|
121
|
+
* 官网价估算(元/月)——**没有账单行时的替代口径**,永远不进「可省」合计。
|
|
122
|
+
*
|
|
123
|
+
* 算法:同账号、同区域、同样按带宽独享的其它 EIP,用它们的账单除以带宽,
|
|
124
|
+
* 取中位数作为「每 Mbps 月费」,再乘本资源的带宽。这是"拿同类的真实账单反推",
|
|
125
|
+
* 不是官网标价,也不绑定固定价格表(价格随区域与时点变)。
|
|
126
|
+
*/
|
|
127
|
+
readonly estimate?: number | null;
|
|
128
|
+
/** 估算怎么来的(样本数 + 每 Mbps 单价),给复核用。 */
|
|
129
|
+
readonly estimate_note?: string | null;
|
|
130
|
+
/**
|
|
131
|
+
* 这笔 `amount` 是从哪一行账单来的。
|
|
132
|
+
*
|
|
133
|
+
* 按带宽计费的 EIP 就是这样:**费用出在「带宽」的 id 上,不在 IP 的 id 上**
|
|
134
|
+
* (2026-11-15 实测:两个账号 25 只按带宽 EIP,IP 一级 0 行,带宽一级全部有行)。
|
|
135
|
+
*/
|
|
136
|
+
readonly amount_source?: 'resource' | 'bandwidth' | null;
|
|
137
|
+
/**
|
|
138
|
+
* 预期可省(元/月)——**目前只有「规格过大」会给**。
|
|
139
|
+
*
|
|
140
|
+
* 它是「账单行 × (1 − 目标档价 / 当前档价)」算出来的估算,不是账单本身。
|
|
141
|
+
* 与 `amount` 是两件事,绝不相加:`amount` 回答"这台机器现在花多少钱",
|
|
142
|
+
* `saving` 回答"降一档能少花多少"。
|
|
143
|
+
*/
|
|
144
|
+
readonly saving?: number | null;
|
|
145
|
+
/** 这笔估算怎么来的(目标档位 + 两端官网价),给复核用。 */
|
|
146
|
+
readonly saving_note?: string | null;
|
|
147
|
+
/** 回收边界:这次动作能带走哪一块。 */
|
|
148
|
+
readonly reclaim: string;
|
|
149
|
+
/** 建议动作(含控制台路径)。 */
|
|
150
|
+
readonly action: string;
|
|
151
|
+
readonly risk: 'low' | 'medium' | 'high';
|
|
152
|
+
/** 该资源是否被 Terraform 管理(来自工作台资源清单)。 */
|
|
153
|
+
readonly managed: boolean | null;
|
|
154
|
+
/** 参与判定用到的监控摘要。 */
|
|
155
|
+
readonly cpu?: UtilizationStats;
|
|
156
|
+
readonly mem?: UtilizationStats;
|
|
157
|
+
}
|
|
158
|
+
/** 一个分组的汇总。 */
|
|
159
|
+
export interface FindingsGroup {
|
|
160
|
+
readonly kind: FindingKind;
|
|
161
|
+
readonly layer: FindingLayer;
|
|
162
|
+
readonly label: string;
|
|
163
|
+
readonly count: number;
|
|
164
|
+
/** 组内「确定性」的个数(金额只算这一层)。 */
|
|
165
|
+
readonly certain_count: number;
|
|
166
|
+
/** 组内「待观察」的个数(观测不足,只列不计钱)。 */
|
|
167
|
+
readonly watching_count: number;
|
|
168
|
+
/** 组内账单行合计(元);`null` 表示这一组没有可加的金额。 */
|
|
169
|
+
readonly amount: number | null;
|
|
170
|
+
/** 组内**可省**合计(元);只有「规格过大」会填 —— 它是估算,不是账单。 */
|
|
171
|
+
readonly saving: number | null;
|
|
172
|
+
readonly findings: readonly Finding[];
|
|
173
|
+
}
|
|
174
|
+
/** 采集失败/无法覆盖的账号(不静默跳过)。 */
|
|
175
|
+
export interface FindingsGap {
|
|
176
|
+
readonly account_id: string;
|
|
177
|
+
readonly account_name: string;
|
|
178
|
+
readonly reason: string;
|
|
179
|
+
}
|
|
180
|
+
/** 一份完整的采集结果。 */
|
|
181
|
+
export interface FindingsResult {
|
|
182
|
+
readonly cycle: string;
|
|
183
|
+
readonly account_id: string | null;
|
|
184
|
+
readonly account_name: string | null;
|
|
185
|
+
/** 采集完成的时刻(ISO 8601)。 */
|
|
186
|
+
readonly generated_at: string;
|
|
187
|
+
/** 监控观测窗口的天数。 */
|
|
188
|
+
readonly window_days: number;
|
|
189
|
+
/** 判定所需的最少观测小时数(低于它只进 watching)。 */
|
|
190
|
+
readonly min_hours: number;
|
|
191
|
+
readonly accounts: {
|
|
192
|
+
readonly candidates: number;
|
|
193
|
+
readonly scanned: number;
|
|
194
|
+
readonly failed: readonly FindingsGap[];
|
|
195
|
+
};
|
|
196
|
+
readonly groups: readonly FindingsGroup[];
|
|
197
|
+
/** 确定性可回收合计(元)—— 只有 `certain` 层的账单行相加。 */
|
|
198
|
+
readonly total_certain: number;
|
|
199
|
+
/** 待观察合计(元)—— 只展示,不进合计。 */
|
|
200
|
+
readonly total_watching: number;
|
|
201
|
+
/** 可定时停机合计(元)—— 按时段假设算出的**可省**金额,不进合计。 */
|
|
202
|
+
readonly total_schedulable: number;
|
|
203
|
+
readonly counts: Readonly<Record<FindingLayer, number>>;
|
|
204
|
+
/** 需要让用户知道的限制(例如"某账号换不到临时凭据")。 */
|
|
205
|
+
readonly notes: readonly string[];
|
|
206
|
+
}
|
|
207
|
+
/** 分组标题(也用于卡片与模板正文)。 */
|
|
208
|
+
export declare const GROUP_LABEL: Readonly<Record<FindingKind, string>>;
|
|
209
|
+
/** 层的人话。 */
|
|
210
|
+
export declare const LAYER_LABEL: Readonly<Record<FindingLayer, string>>;
|
|
211
|
+
/** 这一层的金额能不能进合计。 */
|
|
212
|
+
export declare function countsTowardTotal(layer: FindingLayer): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* 层的优先级顺序(卡片、prompt、引用编号都用它)。
|
|
215
|
+
*
|
|
216
|
+
* 判断依据不是"钱多少",而是"这件事现在能不能动手":
|
|
217
|
+
* 1. `certain` —— 钱确定能省,先做;
|
|
218
|
+
* 2. `oversized` —— 方向明确、只差一个目录价就能算钱,先取价再降配;
|
|
219
|
+
* 3. `watching` —— 要等观测,现在做不了任何决定(账单大也不该排在前面);
|
|
220
|
+
* 4. `undecided` —— 连判据都没有,只做交代。
|
|
221
|
+
*
|
|
222
|
+
* 层内再按账单金额降序:同样是"确定能省",当然先省大的。
|
|
223
|
+
*/
|
|
224
|
+
export declare const LAYER_PRIORITY: readonly FindingLayer[];
|
|
225
|
+
/**
|
|
226
|
+
* kind → 动作类型的兜底表。
|
|
227
|
+
*
|
|
228
|
+
* 规则引擎会显式写 `action_class`,这张表只服务两种情况:老版本缓存(字段不存在)
|
|
229
|
+
* 与手工构造的测试数据。两份必须一致 —— 不一致会表现为"同一条建议今天显示 A、
|
|
230
|
+
* 明天显示 B"。
|
|
231
|
+
*/
|
|
232
|
+
export declare const KIND_ACTION_CLASS: Readonly<Record<FindingKind, ActionClass | null>>;
|
|
233
|
+
/** 一条发现(或一个分组)的动作类型。 */
|
|
234
|
+
export declare function actionClassOf(finding: Pick<Finding, 'kind'> & {
|
|
235
|
+
readonly action_class?: ActionClass | null;
|
|
236
|
+
}): ActionClass | null;
|
|
237
|
+
/**
|
|
238
|
+
* 这张金额该怎么读。
|
|
239
|
+
*
|
|
240
|
+
* `null` 表示"没有金额可读"(要么没账单行,要么要目录价)—— 此时页面不显示数字,
|
|
241
|
+
* 而不是显示一个 0。
|
|
242
|
+
*/
|
|
243
|
+
export declare function amountSemanticsOf(layer: FindingLayer, actionClass: ActionClass | null): AmountSemantics | null;
|
|
244
|
+
/** 一类动作的汇总。 */
|
|
245
|
+
export interface ClassTotal {
|
|
246
|
+
readonly action_class: ActionClass;
|
|
247
|
+
readonly count: number;
|
|
248
|
+
/** 该类金额合计(元)。语义见 amountSemanticsOf —— 可能是可省,也可能是现状账单。 */
|
|
249
|
+
readonly amount: number;
|
|
250
|
+
/** 可省额:只有 `saving` / `assumption` 语义才有值,其余为 null。 */
|
|
251
|
+
readonly saving: number | null;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* 按动作类型汇总一份采集结果。
|
|
255
|
+
*
|
|
256
|
+
* 这是「确定性可回收 ¥21,162.49」这个数字被拆开的地方:A 释放的钱真的会归零,
|
|
257
|
+
* B 降配和 C 停机的钱是现状账单,D 定时是假设。四类分开报,谁都不冒充谁。
|
|
258
|
+
*
|
|
259
|
+
* **只统计 `certain` / `schedulable` / `oversized` 三层**:`watching` 的资源之所以
|
|
260
|
+
* 在那一层,正是因为证据不足(观测不满 7 天)—— 它们的账单是"这个月已经花掉的",
|
|
261
|
+
* 既不是可省,也不能因为金额大就排到前面。把它们折进动作汇总,就等于用"钱多"
|
|
262
|
+
* 替"证据足"做了决定。
|
|
263
|
+
*
|
|
264
|
+
* `oversized` 进来是因为价目表已经接通:那一层的钱来自 `saving`(价差比例 × 账单),
|
|
265
|
+
* 不是 `amount`(账单本身)。两者取哪个由层决定,不混用。
|
|
266
|
+
*/
|
|
267
|
+
export declare function classTotals(result: FindingsResult): readonly ClassTotal[];
|
|
268
|
+
/** 一个账号的机会(口径与 `classTotals` 一致)。 */
|
|
269
|
+
export interface AccountTotal {
|
|
270
|
+
readonly account_id: string;
|
|
271
|
+
readonly account_name: string;
|
|
272
|
+
/** 可省:A 释放的账单 + B 降配的价差估算。 */
|
|
273
|
+
readonly saving: number;
|
|
274
|
+
/** 按时段假设的可省(D 定时),单列 —— 不混进 `saving`。 */
|
|
275
|
+
readonly schedule_saving: number;
|
|
276
|
+
/** 涉及的资源数。 */
|
|
277
|
+
readonly count: number;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 按账号汇总机会 —— 回答"该先找谁"。
|
|
281
|
+
*
|
|
282
|
+
* 为什么按账号而不是按服务:账单是按账号归属的,人也是按账号归属的。
|
|
283
|
+
* 同一份数据,服务维度回答"钱花在哪",账号维度才回答"该找谁去做"。
|
|
284
|
+
*
|
|
285
|
+
* 排序:可省降序,其次定时可省降序 —— 与卡片上"先省大的"一致。
|
|
286
|
+
*/
|
|
287
|
+
export declare function accountTotals(result: FindingsResult): readonly AccountTotal[];
|
|
288
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 利用率:CES 的批量查监控数据。
|
|
3
|
+
*
|
|
4
|
+
* 没有它,判"闲置"就只能靠账单大小猜 —— 那正是上一版的做法。有了它,
|
|
5
|
+
* "这台 64C256G 的机器 14 天 CPU 均值 2.2%"是**可复核的数字**。
|
|
6
|
+
*
|
|
7
|
+
* ⚠ 三个实测坑:
|
|
8
|
+
* 1. 路径是 `batch-query-metric-data`,不是 `metric-data/batch-query`(后者 404)。
|
|
9
|
+
* 2. 请求体字段是 `metrics`(**复数**);返回也是 `metrics`,不是 `metric_data`。
|
|
10
|
+
* 3. 内存指标 `mem_util` 需要装 Agent;本组织 52 台 ECS **全部没有**,返回的
|
|
11
|
+
* `datapoints` 是空数组。所以内存只能"有就用、没有就明说",不能拿 CPU 顶替。
|
|
12
|
+
*
|
|
13
|
+
* 观测覆盖率也要如实报:14 天窗口对一个 3 天前新建的实例只会返回 72 个点。
|
|
14
|
+
* `hours` 就是这个事实,规则层用它决定"这条算不算数"。
|
|
15
|
+
*
|
|
16
|
+
* @module @huaweidevtools/landingzone-workbench/cost/evidence/utilization
|
|
17
|
+
*/
|
|
18
|
+
import { type BssContext, type BssOutcome } from '../bss.ts';
|
|
19
|
+
import type { UtilizationStats } from './types.ts';
|
|
20
|
+
/** 默认观测窗口(天)。 */
|
|
21
|
+
export declare const WINDOW_DAYS = 14;
|
|
22
|
+
/** 一个实例的监控摘要。 */
|
|
23
|
+
export interface InstanceMetrics {
|
|
24
|
+
readonly cpu?: UtilizationStats;
|
|
25
|
+
readonly mem?: UtilizationStats;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 批量取 ECS 的 CPU/内存。
|
|
29
|
+
*
|
|
30
|
+
* @param ctx 该账号的临时凭据。
|
|
31
|
+
* @param projectId 该区域的 projectId。
|
|
32
|
+
* @param region 区域名(host 用它)。
|
|
33
|
+
* @param instanceIds ECS 实例 id。
|
|
34
|
+
* @param days 观测窗口。
|
|
35
|
+
*/
|
|
36
|
+
export declare function fetchEcsMetrics(ctx: BssContext, projectId: string, region: string, instanceIds: readonly string[], days?: number): Promise<BssOutcome<ReadonlyMap<string, InstanceMetrics>>>;
|
|
37
|
+
//# sourceMappingURL=utilization.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FindingsResult } from './evidence/types.ts';
|
|
2
|
+
import { type AccountTotal, type FindingLayer } from './evidence/types.ts';
|
|
3
|
+
/** 一次采集的摘要。 */
|
|
4
|
+
export interface OpportunitySnapshot {
|
|
5
|
+
readonly cycle: string;
|
|
6
|
+
readonly account_id: string | null;
|
|
7
|
+
/** 采集完成的时刻。 */
|
|
8
|
+
readonly generated_at: string;
|
|
9
|
+
/**
|
|
10
|
+
* 金额是**成本口径**(ListCosts 的资源账单合计),不是账单口径。
|
|
11
|
+
* `cost_type` 记录它按哪个口径算;旧记录为 `UNKNOWN`(口径切换前,来源不可证)。
|
|
12
|
+
*/
|
|
13
|
+
readonly bill: number;
|
|
14
|
+
/** 可省:A 释放的账单 + B 降配的价差估算(**不含** D 定时)。 */
|
|
15
|
+
readonly saving: number;
|
|
16
|
+
/** 按时段假设的可省(D 定时),永远单列。 */
|
|
17
|
+
readonly schedule: number;
|
|
18
|
+
readonly counts: Readonly<Record<FindingLayer, number>>;
|
|
19
|
+
/** 前几名账号(最多 8 个,够看"该找谁")。 */
|
|
20
|
+
readonly accounts: readonly AccountTotal[];
|
|
21
|
+
/** 这份快照按哪个成本口径算的;迁移前的记录为 `UNKNOWN`。 */
|
|
22
|
+
readonly cost_type?: string;
|
|
23
|
+
}
|
|
24
|
+
/** 旧版的存档目录(只在迁移时读一次)。 */
|
|
25
|
+
export declare function historyDir(): string;
|
|
26
|
+
/** 由一份采集结果算摘要。 */
|
|
27
|
+
export declare function snapshotOf(result: FindingsResult): OpportunitySnapshot;
|
|
28
|
+
/** 读历史(按账期正序);库不可用或没数据就是空数组。 */
|
|
29
|
+
export declare function readHistory(accountId?: string | null): Promise<readonly OpportunitySnapshot[]>;
|
|
30
|
+
/**
|
|
31
|
+
* 记一次快照(同账期覆盖)。
|
|
32
|
+
*
|
|
33
|
+
* 覆盖而不是追加:同一账期内刷新十次,历史里就该有一个点,不是十个。
|
|
34
|
+
*/
|
|
35
|
+
export declare function rememberSnapshot(result: FindingsResult): Promise<void>;
|
|
36
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type CostCapability } from './types.ts';
|
|
2
|
+
/** 一行资源级账单对比。 */
|
|
3
|
+
export interface LedgerRow {
|
|
4
|
+
readonly account_id: string;
|
|
5
|
+
readonly account_name: string;
|
|
6
|
+
readonly resource_id: string;
|
|
7
|
+
readonly resource_name: string;
|
|
8
|
+
readonly service: string;
|
|
9
|
+
readonly resource_type: string;
|
|
10
|
+
/** 上期(同口径天数)金额,元。 */
|
|
11
|
+
readonly prev: number;
|
|
12
|
+
/** 本期(同口径天数)金额,元。 */
|
|
13
|
+
readonly cur: number;
|
|
14
|
+
/** `prev - cur`:正数 = 少花了(可能是省下的),负数 = 多了。 */
|
|
15
|
+
readonly delta: number;
|
|
16
|
+
}
|
|
17
|
+
/** 对比窗口。 */
|
|
18
|
+
export interface LedgerWindow {
|
|
19
|
+
/** 两期各取多少天(都从 1 日开始)。 */
|
|
20
|
+
readonly days: number;
|
|
21
|
+
readonly prev_cycle: string;
|
|
22
|
+
readonly cur_cycle: string;
|
|
23
|
+
readonly prev_begin: string;
|
|
24
|
+
readonly prev_end: string;
|
|
25
|
+
readonly cur_begin: string;
|
|
26
|
+
readonly cur_end: string;
|
|
27
|
+
/** 天数是怎么定的(例如"按数据截止日 11-10")。 */
|
|
28
|
+
readonly basis: string;
|
|
29
|
+
}
|
|
30
|
+
/** 一个账号没算成的理由。 */
|
|
31
|
+
export interface LedgerGap {
|
|
32
|
+
readonly account_id: string;
|
|
33
|
+
readonly account_name: string;
|
|
34
|
+
readonly reason: string;
|
|
35
|
+
}
|
|
36
|
+
/** 账本视图。 */
|
|
37
|
+
export interface LedgerView {
|
|
38
|
+
readonly cycle: string;
|
|
39
|
+
readonly window: LedgerWindow;
|
|
40
|
+
readonly generated_at: string;
|
|
41
|
+
/** 两期总额(全部账号)。 */
|
|
42
|
+
readonly totals: {
|
|
43
|
+
readonly prev: number;
|
|
44
|
+
readonly cur: number;
|
|
45
|
+
readonly delta: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 同篮子:只统计**上期就存在**的资源,看它们本期花了多少。
|
|
49
|
+
* 这是唯一能说"省了多少钱"的口径 —— `totals` 里还混着新增资源。
|
|
50
|
+
*/
|
|
51
|
+
readonly same_basket: {
|
|
52
|
+
readonly resource_count: number;
|
|
53
|
+
readonly prev: number;
|
|
54
|
+
readonly cur: number;
|
|
55
|
+
readonly delta: number;
|
|
56
|
+
};
|
|
57
|
+
/** 上期有钱、本期为 0 的资源(省钱的候选证据)。 */
|
|
58
|
+
readonly gone: readonly LedgerRow[];
|
|
59
|
+
/** 上期为 0、本期有钱的资源(多出来的开销)。 */
|
|
60
|
+
readonly added: readonly LedgerRow[];
|
|
61
|
+
/** 两期都有钱且差额显著(≥¥1)的资源。 */
|
|
62
|
+
readonly changed: readonly LedgerRow[];
|
|
63
|
+
readonly accounts: {
|
|
64
|
+
readonly candidates: number;
|
|
65
|
+
readonly scanned: number;
|
|
66
|
+
readonly failed: readonly LedgerGap[];
|
|
67
|
+
};
|
|
68
|
+
readonly notes: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** 采集参数。 */
|
|
71
|
+
export interface LedgerOptions {
|
|
72
|
+
readonly cycle: string;
|
|
73
|
+
/** 空/undefined = 全组织。 */
|
|
74
|
+
readonly accountId?: string | undefined;
|
|
75
|
+
readonly force?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** 刷新时清掉(与 `/refresh` 一起)。 */
|
|
78
|
+
export declare function forgetLedger(): void;
|
|
79
|
+
/**
|
|
80
|
+
* 定窗口。
|
|
81
|
+
*
|
|
82
|
+
* @param cycle 本期账期。
|
|
83
|
+
* @param lastStatDate 本期数据的截止日(`YYYY-MM-DD`,可能为 null)。
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveWindow(cycle: string, lastStatDate: string | null): LedgerWindow;
|
|
86
|
+
/** 对外入口(带 10 分钟内存缓存)。 */
|
|
87
|
+
export declare function getLedger(options: LedgerOptions): Promise<{
|
|
88
|
+
readonly ok: true;
|
|
89
|
+
readonly view: LedgerView;
|
|
90
|
+
readonly cached: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
readonly ok: false;
|
|
93
|
+
readonly capability: CostCapability;
|
|
94
|
+
}>;
|
|
95
|
+
/** 账期合法性(给路由层用)。 */
|
|
96
|
+
export declare function isCycle(value: string): boolean;
|
|
97
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把 ListCosts 的响应拍平成事实行。
|
|
3
|
+
*
|
|
4
|
+
* 原始结构是「分组 → 时间序列」:每个 cost_data[i] 是一组维度(账号/服务/项目),
|
|
5
|
+
* 组内 costs[] 才是按天或按月的金额。看板侧(normalize_cost_payload)就是这么做的,
|
|
6
|
+
* 这里保持同一语义,方便两边的数字能对得上。
|
|
7
|
+
*
|
|
8
|
+
* @module @huaweidevtools/landingzone-workbench/cost/normalize
|
|
9
|
+
*/
|
|
10
|
+
import type { CostMonthRow, CostRow } from './types.ts';
|
|
11
|
+
import type { ListCostsResponse } from './bss.ts';
|
|
12
|
+
type Group = NonNullable<ListCostsResponse['cost_data']>[number];
|
|
13
|
+
/**
|
|
14
|
+
* 拍平成日粒度事实行。
|
|
15
|
+
*
|
|
16
|
+
* @param groups ListCosts 返回的 cost_data。
|
|
17
|
+
* @param fallbackAccountId 成本数据没带账号维度时用的兜底账号(避免出现空账号)。
|
|
18
|
+
*/
|
|
19
|
+
export declare function toDailyRows(groups: readonly Group[], fallbackAccountId?: string): CostRow[];
|
|
20
|
+
/** 拍平成月粒度事实行。 */
|
|
21
|
+
export declare function toMonthlyRows(groups: readonly Group[], fallbackAccountId?: string): CostMonthRow[];
|
|
22
|
+
/** 金额求和(按分避免浮点尾差)。 */
|
|
23
|
+
export declare function sumAmount<T>(rows: readonly T[], pick: (row: T) => number): number;
|
|
24
|
+
/**
|
|
25
|
+
* 按 key 分桶累加**分**。
|
|
26
|
+
*
|
|
27
|
+
* 必须按分累加:直接累加浮点会让各分桶的和与总额差一分(1387.63 vs 1387.64),
|
|
28
|
+
* 这种分位差异在"未归集金额 + 已归集金额 ≠ 总额"时会被人当成 bug 追。
|
|
29
|
+
*/
|
|
30
|
+
export declare function bucketCents<K>(rows: readonly {
|
|
31
|
+
key: K;
|
|
32
|
+
amount: number;
|
|
33
|
+
}[]): Map<K, number>;
|
|
34
|
+
/** 保留两位。 */
|
|
35
|
+
export declare const round2: (value: number) => number;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 按"时间进度"折算的档位对比。
|
|
3
|
+
*
|
|
4
|
+
* 问题:日/周卡的当期是**没走完**的(今天到现在、本周到现在),直接拿它除以上一期
|
|
5
|
+
* 的**整日/整周**,结果由"还剩多少时间"决定,而不是费用真的变了 —— 周一早上看周环比
|
|
6
|
+
* 能跌 90%,那是 1 天比 7 天的结构性结果。
|
|
7
|
+
*
|
|
8
|
+
* 做法:把基准折算到"同样的时间进度"再比。
|
|
9
|
+
* - 日:前一日整日(元/日)÷ 1440 × 今日已过分钟(2026-11-23 用户定稿:环比就是
|
|
10
|
+
* "昨天同时段",不拿近 7 天均值顶替);
|
|
11
|
+
* - 周:上一周同期**完整日** 1:1,仅"今天"这一截按分钟折算
|
|
12
|
+
* (上周同一天整日 × 今日已过分钟 / 1440)。
|
|
13
|
+
*
|
|
14
|
+
* 这是**速率环比**,不是"同一时刻的实测金额":数据源(ListCosts)只有日/月粒度,
|
|
15
|
+
* 拿不到"昨天 17:00 的累计"。所以卡片必须写明"折算预期"与"已过多少",不能让人
|
|
16
|
+
* 把它当成真实同期值。
|
|
17
|
+
*
|
|
18
|
+
* 两个常量:
|
|
19
|
+
* - `METERING_LAG_MINUTES`:原始成本约 1 小时计量时延。`dataAsOf` 是**查询时刻**,
|
|
20
|
+
* 不是数据截止时刻;不减这一小时,折算预期会系统性偏高(60/1440 ≈ 4%)。
|
|
21
|
+
* - `MIN_PROJECTION_MINUTES`:每天刚开始的几十分钟里,"速率"几乎全是噪声
|
|
22
|
+
* (一笔预留实例扣费就能翻几倍),不到半小时就不出数。
|
|
23
|
+
*
|
|
24
|
+
* @module @huaweidevtools/landingzone-workbench/cost/period-projection
|
|
25
|
+
*/
|
|
26
|
+
/** 计量时延(分钟):`dataAsOf` 之后的数据还没落账。 */
|
|
27
|
+
export declare const METERING_LAG_MINUTES = 60;
|
|
28
|
+
/** 太少分钟不做折算(噪声大于信号)。 */
|
|
29
|
+
export declare const MIN_PROJECTION_MINUTES = 30;
|
|
30
|
+
/** 一天 / 一周的分钟数。 */
|
|
31
|
+
export declare const DAY_MINUTES = 1440;
|
|
32
|
+
export declare const WEEK_MINUTES: number;
|
|
33
|
+
/** 折算预期:`baseline` 是"一整档"的金额。 */
|
|
34
|
+
export declare function projectedExpected(baselineTotal: number | null, elapsedMinutes: number, periodMinutes: number): number | null;
|
|
35
|
+
/** 环比:实际 ÷ 折算预期 − 1(保留 4 位,和月环比一致)。 */
|
|
36
|
+
export declare function projectedRatio(actual: number, expected: number | null): number | null;
|
|
37
|
+
/** 已过分钟:不足阈值算"太早",不做折算。 */
|
|
38
|
+
export declare function clampElapsed(minutes: number, periodMinutes: number, minMinutes?: number): number | null;
|
|
39
|
+
/** ISO 日期(本地时区)→ Date 的零点。 */
|
|
40
|
+
export declare function startOfDate(iso: string): Date;
|
|
41
|
+
/** Date → 本地 ISO 日期。 */
|
|
42
|
+
export declare function isoOfDate(date: Date): string;
|
|
43
|
+
/** 某天所在周的周一(本地时区)。 */
|
|
44
|
+
export declare function mondayOf(date: Date): Date;
|
|
45
|
+
/**
|
|
46
|
+
* 周折算基准:上周同期完整日 1:1 + 今天按分钟折算。
|
|
47
|
+
*
|
|
48
|
+
* 为什么不是"上周整周 ÷ 10080 × 本周已过分钟":本周此刻往往只走到周一(或周二),
|
|
49
|
+
* 拿整周均值(含周末低/高消费)当基准,会把周末的速率混进工作日的窗口。完整日
|
|
50
|
+
* 一天对一天是精确的,只有"今天"这一截需要折算。
|
|
51
|
+
*/
|
|
52
|
+
export declare function weekProjectedExpected(prevWeek: ReadonlyMap<string, number>, weekStartIso: string, todayIso: string, elapsedTodayMinutes: number): {
|
|
53
|
+
expected: number;
|
|
54
|
+
baseline: number;
|
|
55
|
+
completeDays: number;
|
|
56
|
+
} | null;
|
|
57
|
+
//# sourceMappingURL=period-projection.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { CostCapability } from './types.ts';
|
|
2
|
+
import type { PlanItem } from './plan-types.ts';
|
|
3
|
+
/** 一个资源在核验里的结论。 */
|
|
4
|
+
export type PlanResourceState =
|
|
5
|
+
/** 清单里没了,账单也归零。 */
|
|
6
|
+
'released'
|
|
7
|
+
/** 清单里没了,但账单还在 —— 残留计费项。 */
|
|
8
|
+
| 'released_billing'
|
|
9
|
+
/** 清单里还在,状态不是 active(停机/关机)。 */
|
|
10
|
+
| 'stopped'
|
|
11
|
+
/** 清单里还在且 active。 */
|
|
12
|
+
| 'running'
|
|
13
|
+
/** 旧 id 没了,但同名资源在 —— 疑似重建,不能算删除。 */
|
|
14
|
+
| 'rebuilt'
|
|
15
|
+
/** 连现状都拿不到(清单不可读,或这条项没有基线)。 */
|
|
16
|
+
| 'unknown';
|
|
17
|
+
/** 一个资源的核验结果。 */
|
|
18
|
+
export interface PlanCheckResource {
|
|
19
|
+
readonly resource_id: string;
|
|
20
|
+
readonly resource_name: string;
|
|
21
|
+
/** 基线里的状态(加入计划那一刻)。 */
|
|
22
|
+
readonly baseline_status: string | null;
|
|
23
|
+
/** 现在清单里有没有。 */
|
|
24
|
+
readonly present: boolean;
|
|
25
|
+
/** 现在的状态。 */
|
|
26
|
+
readonly status: string | null;
|
|
27
|
+
readonly state: PlanResourceState;
|
|
28
|
+
/** 疑似重建时,新出现的那个 id。 */
|
|
29
|
+
readonly rebuilt_as: string | null;
|
|
30
|
+
}
|
|
31
|
+
/** 一条处置项的核验结果。 */
|
|
32
|
+
export interface PlanCheckItem {
|
|
33
|
+
readonly item_id: string;
|
|
34
|
+
readonly title: string;
|
|
35
|
+
readonly action_class: PlanItem['action_class'];
|
|
36
|
+
readonly resource_count: number;
|
|
37
|
+
readonly resources: readonly PlanCheckResource[];
|
|
38
|
+
readonly counts: Readonly<Record<PlanResourceState, number>>;
|
|
39
|
+
/** 这条项加入计划时有没有基线;没有就只能看现状,分不清"没做"与"早就没了"。 */
|
|
40
|
+
readonly has_baseline: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** 一次核验。 */
|
|
43
|
+
export interface PlanCheckView {
|
|
44
|
+
readonly cycle: string;
|
|
45
|
+
readonly checked_at: string;
|
|
46
|
+
readonly items: readonly PlanCheckItem[];
|
|
47
|
+
readonly accounts: {
|
|
48
|
+
readonly scanned: number;
|
|
49
|
+
readonly failed: readonly {
|
|
50
|
+
readonly account_id: string;
|
|
51
|
+
readonly account_name: string;
|
|
52
|
+
readonly reason: string;
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
readonly notes: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/** 采集参数。 */
|
|
58
|
+
export interface PlanCheckOptions {
|
|
59
|
+
readonly cycle: string;
|
|
60
|
+
readonly accountId?: string | undefined;
|
|
61
|
+
readonly force?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 调用者角色与自身 domain id。
|
|
64
|
+
*
|
|
65
|
+
* 为什么需要:核验要读资源清单,主账号靠 assume 换到目标账号,而成员账号**没有**
|
|
66
|
+
* iam:tokens:assume —— 照旧走 assume 只会得到一屏"换不到临时凭据"。成员核自己的
|
|
67
|
+
* 资源根本不用换凭据,直接用本人 ctx 即可。
|
|
68
|
+
*/
|
|
69
|
+
readonly role?: 'management' | 'member' | undefined;
|
|
70
|
+
readonly ownAccountId?: string | undefined;
|
|
71
|
+
}
|
|
72
|
+
/** 刷新时清掉。 */
|
|
73
|
+
export declare function forgetPlanCheck(): void;
|
|
74
|
+
/**
|
|
75
|
+
* 单条资源的状态判定(纯函数,便于测试)。
|
|
76
|
+
*
|
|
77
|
+
* 判定顺序就是语义优先级:**在清单里 > 疑似重建 > 看不见 > 才敢说已释放**。
|
|
78
|
+
* 其中"看不见"有两种:这次没扫到它(unresolved),或者压根不该判缺席
|
|
79
|
+
* (canJudgeAbsence=false:没扫过任何账号 / 有账号读不到 / 兜底没做)。
|
|
80
|
+
* 三种都不是"已经释放"(2026-11-16:跨账号的计划项被误判成已释放)。
|
|
81
|
+
*/
|
|
82
|
+
export declare function judgeResourceState(input: {
|
|
83
|
+
readonly present: boolean;
|
|
84
|
+
readonly presentStatus: string | null;
|
|
85
|
+
readonly rebuiltAs: string | null;
|
|
86
|
+
readonly canJudgeAbsence: boolean;
|
|
87
|
+
readonly unresolved: boolean;
|
|
88
|
+
}): PlanResourceState;
|
|
89
|
+
/**
|
|
90
|
+
* 跑一次计划核验。
|
|
91
|
+
*
|
|
92
|
+
* 只查**计划里出现过的账号**(而不是全组织):核验不是盘点,没必要为不在计划里的
|
|
93
|
+
* 账号打清单接口。
|
|
94
|
+
*/
|
|
95
|
+
export declare function checkPlan(options: PlanCheckOptions): Promise<{
|
|
96
|
+
readonly ok: true;
|
|
97
|
+
readonly view: PlanCheckView;
|
|
98
|
+
} | {
|
|
99
|
+
readonly ok: false;
|
|
100
|
+
readonly capability: CostCapability;
|
|
101
|
+
}>;
|
|
102
|
+
//# sourceMappingURL=plan-check.d.ts.map
|