|
7 | 7 | 2. Filter apps to entries visible on the Cozystack dashboard. |
8 | 8 | 3. Merge case-insensitive / Pax* / legacy-name aliases into one canonical entry |
9 | 9 | per application, keeping the maximum instance count (zero-count entries |
10 | | - left after the merge are dropped from the table). |
11 | | -4. Pull `Tenant` out of the apps map and surface it as the top-level Tenants |
12 | | - summary card (the raw `total_tenants` field from the API is always zero). |
| 10 | + left after the merge are dropped from the table). Rows are emitted in a |
| 11 | + fixed canonical order (FIXED_ORDER) so the published table stays stable for |
| 12 | + copy-paste; apps not in that list are appended at the end (by count). |
| 13 | +4. Surface the Tenants summary card from the API `total_tenants` field (now |
| 14 | + populated per period), falling back to the point-in-time `Tenant` entry in |
| 15 | + the apps map only when `total_tenants` is zero/absent. |
13 | 16 | 5. Emit the payload in the shape consumed by `oss-health-app.html` + |
14 | 17 | `renderTelemetry`, including `summary_cards`, `apps`, `range`. |
15 | 18 |
|
|
78 | 81 | } |
79 | 82 |
|
80 | 83 |
|
| 84 | +# Fixed canonical row order for the published table. Keeping this stable (rather |
| 85 | +# than re-sorting by count every run) means the rows always line up for copy-paste |
| 86 | +# into external spreadsheets. Apps not listed here are appended at the end, sorted |
| 87 | +# by count desc — move them into this list once they should have a stable slot. |
| 88 | +FIXED_ORDER: list[str] = [ |
| 89 | + "VMDisk", "VMInstance", "Etcd", "Ingress", "Monitoring", "Kubernetes", |
| 90 | + "SeaweedFS", "Bucket", "Postgres", "MariaDB", "Harbor", "ClickHouse", |
| 91 | + "Redis", "VirtualPrivateCloud", "MongoDB", "Kafka", "OpenBAO", "RabbitMQ", |
| 92 | + "Qdrant", "NATS", "FoundationDB", "VPN", "TCPBalancer", "HTTPCache", |
| 93 | + "OpenSearch", "NFS", "ClearML", |
| 94 | +] |
| 95 | + |
| 96 | + |
81 | 97 | def normalize_key(raw: str) -> str: |
82 | 98 | return raw.lower().replace("-", "").replace("_", "") |
83 | 99 |
|
84 | 100 |
|
85 | 101 | def clean_apps(apps: dict[str, int]) -> list[dict[str, object]]: |
86 | | - """Filter, dedupe (max), drop zeros, sort desc by count.""" |
| 102 | + """Filter, dedupe (max), drop zeros, order by FIXED_ORDER (extras appended).""" |
87 | 103 | merged: dict[str, int] = {} |
88 | 104 | for raw_name, count in apps.items(): |
89 | 105 | canonical = ALIASES.get(normalize_key(raw_name)) |
90 | 106 | if not canonical: |
91 | 107 | continue |
92 | 108 | if count > merged.get(canonical, 0): |
93 | 109 | merged[canonical] = count |
94 | | - non_zero = [(name, n) for name, n in merged.items() if n > 0] |
95 | | - non_zero.sort(key=lambda item: (-item[1], item[0].lower())) |
96 | | - return [{"name": name, "value": str(count)} for name, count in non_zero] |
| 110 | + non_zero = {name: n for name, n in merged.items() if n > 0} |
| 111 | + rank = {name: i for i, name in enumerate(FIXED_ORDER)} |
| 112 | + ordered = sorted( |
| 113 | + non_zero.items(), |
| 114 | + key=lambda item: (rank.get(item[0], len(FIXED_ORDER)), -item[1], item[0].lower()), |
| 115 | + ) |
| 116 | + return [{"name": name, "value": str(count)} for name, count in ordered] |
97 | 117 |
|
98 | 118 |
|
99 | 119 | def transform_period(raw_period: dict, label_fallback: str) -> dict | None: |
100 | 120 | if not raw_period: |
101 | 121 | return None |
102 | 122 | apps_raw = raw_period.get("apps", {}) or {} |
103 | | - tenants = int(apps_raw.get("Tenant", 0)) |
| 123 | + # Prefer the per-period `total_tenants` field (now populated by the API); |
| 124 | + # fall back to the point-in-time `Tenant` entry only if it's zero/absent. |
| 125 | + tenants = int(raw_period.get("total_tenants") or 0) or int(apps_raw.get("Tenant", 0)) |
104 | 126 | clusters = int(raw_period.get("clusters", 0)) |
105 | 127 | total_nodes = int(raw_period.get("total_nodes", 0)) |
106 | 128 | avg_nodes = raw_period.get("avg_nodes_per_cluster") |
|
0 commit comments