diff --git a/backend/services/ai_gateway_governance_service.py b/backend/services/ai_gateway_governance_service.py index c39e190f..688ec64c 100644 --- a/backend/services/ai_gateway_governance_service.py +++ b/backend/services/ai_gateway_governance_service.py @@ -1144,7 +1144,11 @@ def _sync_live_cluster_resources(self, cid: int, cname: str, state: dict[str, An # Sync ClickHouse otel.aigw_requests audit logs and live DSSM spend when available try: - from services.llm_observability_service import LlmObservabilityService + from services.llm_observability_service import ( + LlmObservabilityService, + _normalize_provider, + _provider_for, + ) obs_svc = LlmObservabilityService(self.db) api_client = obs_svc._client(cid) @@ -1161,7 +1165,7 @@ def _sync_live_cluster_resources(self, cid: int, cname: str, state: dict[str, An team_id, principal_id, vk_id, - model, + if(model != '', model, if(served_model != '', served_model, '')) AS eff_model, provider, toUInt16OrZero(toString(http_status)) AS status_code, round(latency_ms, 2) AS latency_ms, @@ -1171,6 +1175,8 @@ def _sync_live_cluster_resources(self, cid: int, cname: str, state: dict[str, An total_tokens, round(cost_usd_micros / 1000000.0, 6) AS cost_usd FROM otel.aigw_requests + WHERE if(model != '', model, if(served_model != '', served_model, '')) != '' + AND toUInt16OrZero(toString(http_status)) > 0 ORDER BY ts_ms DESC LIMIT 30 """, @@ -1186,6 +1192,11 @@ def _sync_live_cluster_resources(self, cid: int, cname: str, state: dict[str, An vk_id = str(r.get("vk_id") or "") sc = "HIT" if int(r.get("cached_tokens") or 0) > 0 else "MISS" status_code = int(r.get("status_code") or 200) + model_name = str(r.get("eff_model") or "").strip() + raw_prov = str(r.get("provider") or "").strip() + prov_name = _normalize_provider(raw_prov) if raw_prov else _provider_for(model_name) + if not prov_name or prov_name == "unknown": + prov_name = _provider_for(model_name) audit_logs.append( { "id": req_id, @@ -1202,8 +1213,10 @@ def _sync_live_cluster_resources(self, cid: int, cname: str, state: dict[str, An "virtual_key_name": vk_name_by_id.get(vk_id, vk_id), "method": "POST", "path": "/v1/chat/completions", - "model": str(r.get("model") or ""), - "provider": str(r.get("provider") or ""), + "model": model_name, + "model_id": model_name, + "provider": prov_name, + "provider_name": prov_name, "status_code": status_code, "latency_ms": float(r.get("latency_ms") or 0.0), "prompt_tokens": int(r.get("prompt_tokens") or 0), @@ -1218,6 +1231,12 @@ def _sync_live_cluster_resources(self, cid: int, cname: str, state: dict[str, An } ) state["request_audit_logs"] = audit_logs + else: + state["request_audit_logs"] = [ + log + for log in state.get("request_audit_logs", []) + if log.get("model") and str(log.get("model")).strip() != "unknown" and int(log.get("status_code") or 0) > 0 + ] spend_rows, _ = obs_svc._ch_query( cid, @@ -1467,15 +1486,52 @@ def overview( ns_models = self._filter_by_namespace(state["models"], namespace) ns_routes = self._filter_by_namespace(state["routes"], namespace) tenants.extend(AiTenantSummary(**t) for t in state["tenants"]) - providers.extend(AiProviderSummary(**p) for p in ns_providers) - models.extend(AiModelSummary(**m) for m in ns_models) - routes.extend(AiGatewayRouteSummary(**r) for r in ns_routes) - orgs.extend(GovernanceOrgItem(**o) for o in state["orgs"]) - teams.extend(GovernanceTeamItem(**tm) for tm in state["teams"]) - principals.extend(GovernancePrincipalItem(**pr) for pr in state["principals"]) - virtual_keys.extend(GovernanceVirtualKeyItem(**vk) for vk in state["virtual_keys"]) + providers.extend(AiProviderSummary(**{**p, "cluster_id": p.get("cluster_id") or cid, "cluster_name": p.get("cluster_name") or cname}) for p in ns_providers) + models.extend(AiModelSummary(**{**m, "cluster_id": m.get("cluster_id") or cid, "cluster_name": m.get("cluster_name") or cname}) for m in ns_models) + routes.extend(AiGatewayRouteSummary(**{**r, "cluster_id": r.get("cluster_id") or cid, "cluster_name": r.get("cluster_name") or cname}) for r in ns_routes) + + seen_org_ids: set[str] = set() + for o in state["orgs"]: + oid = str(o.get("id") or o.get("name") or "") + if oid and oid in seen_org_ids: + continue + if oid: + seen_org_ids.add(oid) + orgs.append(GovernanceOrgItem(**{**o, "cluster_id": o.get("cluster_id") or cid, "cluster_name": o.get("cluster_name") or cname})) + + seen_team_ids: set[str] = set() + for tm in state["teams"]: + tid = str(tm.get("id") or tm.get("name") or "") + if tid and tid in seen_team_ids: + continue + if tid: + seen_team_ids.add(tid) + teams.append(GovernanceTeamItem(**{**tm, "cluster_id": tm.get("cluster_id") or cid, "cluster_name": tm.get("cluster_name") or cname})) + + seen_prin_ids: set[str] = set() + for pr in state["principals"]: + pid = str(pr.get("id") or pr.get("name") or "") + if pid and pid in seen_prin_ids: + continue + if pid: + seen_prin_ids.add(pid) + principals.append(GovernancePrincipalItem(**{**pr, "cluster_id": pr.get("cluster_id") or cid, "cluster_name": pr.get("cluster_name") or cname})) + + seen_vk_ids: set[str] = set() + for vk in state["virtual_keys"]: + vid = str(vk.get("id") or vk.get("name") or "") + if vid and vid in seen_vk_ids: + continue + if vid: + seen_vk_ids.add(vid) + virtual_keys.append(GovernanceVirtualKeyItem(**{**vk, "cluster_id": vk.get("cluster_id") or cid, "cluster_name": vk.get("cluster_name") or cname})) + readiness_checks.extend(self._build_readiness_checks(state)) - request_audit_logs.extend(ClickHouseRequestAuditItem(**log) for log in state.get("request_audit_logs", [])) + request_audit_logs.extend( + ClickHouseRequestAuditItem(**log) + for log in state.get("request_audit_logs", []) + if log.get("model") and str(log.get("model")).strip() != "unknown" and int(log.get("status_code") or 0) > 0 + ) filtered_state = { **state, diff --git a/backend/services/bnk/consumption.py b/backend/services/bnk/consumption.py index e9832f8b..72856782 100644 --- a/backend/services/bnk/consumption.py +++ b/backend/services/bnk/consumption.py @@ -124,6 +124,7 @@ def aggregate_cluster_consumption( dpf = dpf_summary or {"detected": False, "dpu_count": 0} nodes = (bnk_data or {}).get("nodes", {}) or {} node_capacity = _sum_node_capacity(nodes) + effective_node_count = node_count or (len(nodes) if nodes else None) if not reachable or bnk_data is None: return { @@ -135,7 +136,7 @@ def aggregate_cluster_consumption( "bnk_installed": False, "bnk_version": None, "status": "offline" if not reachable else status, - "node_count": node_count, + "node_count": effective_node_count, "control_plane": _empty_plane(), "data_plane": _empty_plane(), "total": _empty_plane(), @@ -179,7 +180,7 @@ def aggregate_cluster_consumption( "bnk_installed": bnk_installed, "bnk_version": bnk_version, "status": status, - "node_count": node_count, + "node_count": effective_node_count, "control_plane": control_plane, "data_plane": data_plane, "total": total, diff --git a/backend/services/llm_observability_service.py b/backend/services/llm_observability_service.py index 7734d51e..6087c803 100644 --- a/backend/services/llm_observability_service.py +++ b/backend/services/llm_observability_service.py @@ -109,18 +109,113 @@ def _proxy_path(scheme: str, namespace: str, service: str, port: int, sub_path: def _provider_for(model: str) -> str: - """Infer provider from model name. gpt/o1/o3/o4→openai, claude→anthropic, - gemini→google, else unknown. Best-effort only — the stream has no identity.""" - m = (model or "").lower() - if m.startswith(("gpt", "o1", "o3", "o4")): + """Infer provider from model name, prefix, or known model families.""" + m = (model or "").lower().strip() + if not m: + return "unknown" + + # 1. Handle common vendor/route prefixes e.g. "azure/gpt-4o", "bedrock/anthropic.claude", "vertex/gemini-1.5-flash" + if "/" in m: + prefix, remainder = m.split("/", 1) + if prefix in ("openai", "azure", "anthropic", "google", "meta", "mistral", "deepseek", "cohere", "qwen"): + return prefix + if prefix in ("bedrock", "aws"): + sub = _provider_for(remainder) + return sub if sub != "unknown" else "aws" + if prefix in ("vertex", "gcp"): + sub = _provider_for(remainder) + return sub if sub != "unknown" else "google" + m = remainder + + # 2. Check vendor dots e.g. "amazon.titan", "anthropic.claude", "meta.llama" + if m.startswith("amazon.") or m.startswith("titan") or m.startswith("bedrock"): + return "aws" + if m.startswith("anthropic.") or m.startswith("claude"): + return "anthropic" + if m.startswith("meta.") or m.startswith("llama"): + return "meta" + if m.startswith("mistral.") or m.startswith("mistral") or m.startswith("mixtral") or m.startswith("codestral"): + return "mistral" + if m.startswith("deepseek.") or m.startswith("deepseek"): + return "deepseek" + if m.startswith("qwen.") or m.startswith("qwen"): + return "qwen" + if m.startswith("cohere.") or m.startswith("command"): + return "cohere" + if m.startswith("mcp") or m.startswith("tool"): + return "mcp" + if m.startswith("ollama"): + return "ollama" + if m.startswith("vllm"): + return "vllm" + if m.startswith("azure.") or m.startswith("azureopenai") or m.startswith("phi") or m.startswith("ms-"): + return "azure" + if m.startswith("google.") or m.startswith("gemini") or m.startswith("gemma") or m.startswith("medlm") or m.startswith("imagen") or m.startswith("vertex"): + return "google" + if m.startswith(("openai.", "gpt", "o1", "o3", "o4", "text-embedding", "dall-e")): return "openai" - if m.startswith("claude"): + + # 3. Keyword / substring checks for embedded model family names + if "claude" in m: return "anthropic" - if m.startswith("gemini"): + if "gemini" in m or "gemma" in m: return "google" + if "llama" in m: + return "meta" + if "mistral" in m or "mixtral" in m: + return "mistral" + if "deepseek" in m: + return "deepseek" + if "qwen" in m: + return "qwen" + if "titan" in m: + return "aws" + if "phi-" in m or "phi3" in m or "phi4" in m: + return "azure" + return "unknown" +def _normalize_provider(provider_or_model: str) -> str: + """Normalize a provider or model identifier into a canonical provider key.""" + p = (provider_or_model or "").lower().strip() + if not p: + return "unknown" + if "/" in p: + prefix, remainder = p.split("/", 1) + if prefix in ("openai", "azure", "anthropic", "google", "meta", "mistral", "deepseek", "cohere", "qwen", "mcp", "ollama", "vllm"): + return prefix + if prefix in ("bedrock", "aws"): + return "aws" + if prefix in ("vertex", "gcp"): + return "google" + sub = _normalize_provider(remainder) + if sub != "unknown": + return sub + p = remainder + if p.startswith("bedrock") or p.startswith("aws") or p.startswith("amazon"): + return "aws" + if p.startswith("azure") or "foundry" in p: + return "azure" + if p.startswith("vertex") or p.startswith("gcp") or p.startswith("google"): + return "google" + if p.startswith("openai"): + return "openai" + if p.startswith("anthropic"): + return "anthropic" + if p.startswith("meta"): + return "meta" + if p.startswith("mistral") or p.startswith("mixtral"): + return "mistral" + if p.startswith("deepseek"): + return "deepseek" + if p.startswith("qwen"): + return "qwen" + if p.startswith("cohere"): + return "cohere" + return _provider_for(p) + + def _iso(epoch_s: float) -> str: return datetime.fromtimestamp(epoch_s, UTC).isoformat() @@ -418,14 +513,14 @@ def _stats_uncached( total_requests = sum(v.get("total_requests", 0) for v in valid) total_tokens = sum(v.get("total_tokens", 0) for v in valid) total_cost = sum(v.get("total_cost", 0.0) for v in valid) - # Per-cluster `models` is already a COUNT of distinct models on that - # cluster, so a true distinct union across the fleet is not computable - # from these inputs (we'd need the model names, which stats does not - # return). Summing gives an upper bound of "models in use across the - # fleet" (overcounts when clusters share models); it matches the - # generic "Models" stat-tile far better than max(), which silently - # understated the fleet whenever clusters ran disjoint model sets. - total_models = sum(v.get("models", 0) for v in valid) + # Collect and deduplicate model names across all active clusters. + all_model_names: set[str] = set() + for v in valid: + all_model_names.update(v.get("model_names") or []) + if all_model_names: + total_models = len(all_model_names) + else: + total_models = sum(v.get("models", 0) for v in valid) if total_requests > 0: success_rate = ( sum(v.get("success_rate", 0.0) * v.get("total_requests", 0) for v in valid) / total_requests @@ -443,11 +538,12 @@ def _stats_uncached( total_tokens=int(total_tokens), total_cost=total_cost, models=int(total_models), + model_names=sorted(all_model_names), errors=errors, ) api_client = _api_client if _api_client is not None else self._client(cluster_id) - if cluster_id in _CH_PW_CACHE: + if self._ch_password(cluster_id, api_client): ch_res = self._stats_clickhouse(cluster_id, api_client, range_, model, status) if ch_res is not None: return ch_res @@ -464,16 +560,20 @@ def _stats_uncached( "avg_latency_ms": f"avg(avg_over_time({sel} | json | unwrap latency_ms [{rng}]))", "total_tokens": f"sum(sum_over_time({sel} | json | unwrap total_tk [{rng}]))", "total_cost": f"sum(sum_over_time({sel} | json | unwrap cost [{rng}]))", - "models": f"count(count by (model)(count_over_time({sel}[{rng}])))", + "models_by_name": f"count by (model)(count_over_time({sel}[{rng}]))", } keys = list(queries) results = _run_parallel([lambda q=queries[k]: self._instant(api_client, q, end_ns) for k in keys]) errors: dict[str, str] = {} values: dict[str, float] = {} + model_names: list[str] = [] for key, (data, err) in zip(keys, results, strict=True): if err: errors[key] = err + elif key == "models_by_name": + model_names = sorted(list(_by_label(data, "model").keys())) + values["models"] = float(len(model_names)) else: values[key] = _scalar(data) @@ -492,6 +592,7 @@ def _stats_uncached( total_tokens=int(values.get("total_tokens", 0.0)), total_cost=values.get("total_cost", 0.0), models=int(values.get("models", 0.0)), + model_names=model_names, errors=errors, ) @@ -611,7 +712,7 @@ def _histogram_uncached( if metric not in specs: return self._unavailable(f"unknown metric: {metric}") - if cluster_id in _CH_PW_CACHE: + if self._ch_password(cluster_id, api_client): ch_res = self._histogram_clickhouse(cluster_id, api_client, range_, metric, model, status) if ch_res is not None: return ch_res @@ -671,8 +772,17 @@ def _fold( # key -> ts -> list of values (list so we can mean or sum) agg: dict[str, dict[str, list[float]]] = {} for labels, points in matrix: - model = labels.get("model", "unknown") - key = _provider_for(model) if by_provider else model + model = (labels.get("model") or "").strip() + if not model or model == "unknown": + continue + if by_provider: + raw_prov = (labels.get("provider") or "").strip() + prov = _normalize_provider(raw_prov) if raw_prov else _provider_for(model) + key = prov if prov != "unknown" else _provider_for(model) + if not key or key == "unknown": + continue + else: + key = model bucket = agg.setdefault(key, {}) for p in points: bucket.setdefault(p["ts"], []).append(p["value"]) @@ -786,7 +896,7 @@ def _provider_usage_uncached( if metric not in by_model: return self._unavailable(f"unknown metric: {metric}") - if cluster_id in _CH_PW_CACHE: + if self._ch_password(cluster_id, api_client): ch_res = self._provider_usage_clickhouse(cluster_id, api_client, range_, metric, model, status) if ch_res is not None: return ch_res @@ -846,11 +956,16 @@ def _rankings_uncached( models_acc: dict[str, dict[str, Any]] = {} for r in valid: for row in r.get("rows", []): - m = row["model"] + m = str(row.get("model") or "").strip() + if not m or m == "unknown": + continue + prov = str(row.get("provider") or "").strip() + if not prov or prov == "unknown": + prov = _provider_for(m) if m not in models_acc: models_acc[m] = { "model": m, - "provider": row["provider"], + "provider": prov, "requests": 0, "tokens": 0, "cost": 0.0, @@ -884,7 +999,7 @@ def _rankings_uncached( return self._ok(rows=rows, errors=errors) api_client = _api_client if _api_client is not None else self._client(cluster_id) - if cluster_id in _CH_PW_CACHE: + if self._ch_password(cluster_id, api_client): ch_res = self._rankings_clickhouse(cluster_id, api_client, range_, model, status) if ch_res is not None: return ch_res @@ -938,12 +1053,15 @@ def _trend(model: str, key: str) -> float | None: models = sorted(cur.get("requests", {})) rows: list[dict[str, Any]] = [] for m in models: + m_clean = str(m or "").strip() + if not m_clean or m_clean == "unknown": + continue requests = cur.get("requests", {}).get(m, 0.0) success = cur.get("success", {}).get(m, 0.0) rows.append( { - "model": m, - "provider": _provider_for(m), + "model": m_clean, + "provider": _provider_for(m_clean), "requests": int(requests), "success_rate": (success / requests) if requests else 0.0, "tokens": int(cur.get("tokens", {}).get(m, 0.0)), @@ -1296,8 +1414,10 @@ def _stats_clickhouse( "avgOrDefault(latency_ms) AS avg_latency_ms, " "sum(total_tokens) AS total_tokens, " "sum(cost_usd_micros) / 1000000.0 AS total_cost, " - "uniqExact(model) AS models " - f"FROM otel.aigw_requests WHERE {where}" + "uniqExact(if(model != '', model, if(served_model != '', served_model, ''))) AS models, " + "groupUniqArray(if(model != '', model, if(served_model != '', served_model, ''))) AS model_names " + f"FROM otel.aigw_requests WHERE {where} " + "AND if(model != '', model, if(served_model != '', served_model, '')) != ''" ) rows, err = self._ch_query(cluster_id, api_client, sql) if err or not rows: @@ -1305,13 +1425,19 @@ def _stats_clickhouse( r = rows[0] total = int(r.get("total_requests") or 0) success = int(r.get("success") or 0) + raw_models = r.get("model_names") + if isinstance(raw_models, list): + model_names = [str(m) for m in raw_models if m] + else: + model_names = [] return self._ok_ch( total_requests=total, success_rate=(success / total) if total else 0.0, avg_latency_ms=float(r.get("avg_latency_ms") or 0.0), total_tokens=int(r.get("total_tokens") or 0), total_cost=float(r.get("total_cost") or 0.0), - models=int(r.get("models") or 0), + models=int(r.get("models") or (len(model_names) if model_names else 0)), + model_names=model_names, errors={}, ) @@ -1388,9 +1514,12 @@ def _all_buckets(rs: list[dict[str, Any]]) -> list[int]: if metric in ("cost", "models"): agg = "sum(cost_usd_micros) / 1000000.0" if metric == "cost" else "count()" sql = ( - f"SELECT {bucket_expr} AS bucket_s, model, {agg} AS val " + f"SELECT {bucket_expr} AS bucket_s, " + "if(model != '', model, if(served_model != '', served_model, '')) AS eff_model, " + f"{agg} AS val " f"FROM otel.aigw_requests WHERE {where} " - "GROUP BY bucket_s, model ORDER BY bucket_s ASC" + "AND if(model != '', model, if(served_model != '', served_model, '')) != '' " + "GROUP BY bucket_s, eff_model ORDER BY bucket_s ASC" ) rows, err = self._ch_query(cluster_id, api_client, sql) if err or rows is None: @@ -1398,7 +1527,9 @@ def _all_buckets(rs: list[dict[str, Any]]) -> list[int]: buckets = _all_buckets(rows) by_m: dict[str, dict[int, float]] = {} for r in rows: - m = str(r.get("model") or "unknown") + m = str(r.get("eff_model") or r.get("model") or "") + if not m or m == "unknown": + continue b = int(r["bucket_s"]) by_m.setdefault(m, {})[b] = by_m.get(m, {}).get(b, 0.0) + float(r.get("val") or 0.0) series = [ @@ -1456,10 +1587,11 @@ def _provider_usage_clickhouse( } if metric not in agg_map: return None + eff_model_expr = "if(model != '', model, if(served_model != '', served_model, ''))" sql = ( - f"SELECT {bucket_expr} AS bucket_s, model, {agg_map[metric]} AS val " - f"FROM otel.aigw_requests WHERE {where} " - "GROUP BY bucket_s, model ORDER BY bucket_s ASC" + f"SELECT {bucket_expr} AS bucket_s, {eff_model_expr} AS eff_model, provider, {agg_map[metric]} AS val " + f"FROM otel.aigw_requests WHERE {where} AND {eff_model_expr} != '' AND http_status > 0 " + "GROUP BY bucket_s, eff_model, provider ORDER BY bucket_s ASC" ) rows, err = self._ch_query(cluster_id, api_client, sql) if err or rows is None: @@ -1469,13 +1601,19 @@ def _provider_usage_clickhouse( min_b = min(int(r["bucket_s"]) for r in rows) max_b = max(end_s, max(int(r["bucket_s"]) for r in rows)) buckets = list(range(min_b, max_b + 1, step_s)) - by_m: dict[str, dict[int, float]] = {} + by_mp: dict[tuple[str, str], dict[int, float]] = {} for r in rows: - m = str(r.get("model") or "unknown") + m = str(r.get("eff_model") or "").strip() + if not m or m == "unknown": + continue + raw_p = str(r.get("provider") or "").strip() + p = _normalize_provider(raw_p) if raw_p else _provider_for(m) + if not p or p == "unknown": + p = _provider_for(m) b = int(r["bucket_s"]) - by_m.setdefault(m, {})[b] = float(r.get("val") or 0.0) + by_mp.setdefault((m, p), {})[b] = float(r.get("val") or 0.0) matrix = [] - for m, bmap in by_m.items(): + for (m, p), bmap in by_mp.items(): pts = [] last_v = 0.0 for b in buckets: @@ -1486,7 +1624,10 @@ def _provider_usage_clickhouse( else: v = last_v pts.append({"ts": _iso(float(b)), "value": v}) - matrix.append(({"model": m}, pts)) + labels: dict[str, str] = {"model": m} + if p: + labels["provider"] = p + matrix.append((labels, pts)) series = self._fold(matrix, by_provider=True, mean=(metric == "latency")) return self._ok_ch(metric=metric, step_s=step_s, series=series, errors={}) @@ -1505,14 +1646,15 @@ def _rankings_clickhouse( def _query_window(s_ms: int, e_ms: int) -> dict[str, dict[str, float]] | None: where = self._ch_where(range_, model=model, status=status, start_ms=s_ms, end_ms=e_ms) + eff_model_expr = "if(model != '', model, if(served_model != '', served_model, ''))" sql = ( - "SELECT model, " + f"SELECT {eff_model_expr} AS eff_model, " "count() AS requests, " "sum(total_tokens) AS tokens, " "sum(cost_usd_micros) / 1000000.0 AS cost, " "avgOrDefault(latency_ms) AS latency, " "countIf(http_status >= 200 AND http_status < 300) AS success " - f"FROM otel.aigw_requests WHERE {where} GROUP BY model" + f"FROM otel.aigw_requests WHERE {where} AND {eff_model_expr} != '' AND http_status > 0 GROUP BY eff_model" ) rows, err = self._ch_query(cluster_id, api_client, sql) if err or rows is None: @@ -1525,8 +1667,8 @@ def _query_window(s_ms: int, e_ms: int) -> dict[str, dict[str, float]] | None: "success": {}, } for r in rows: - m = str(r.get("model") or "") - if not m: + m = str(r.get("eff_model") or "").strip() + if not m or m == "unknown": continue for k in out: out[k][m] = float(r.get(k) or 0.0) @@ -1638,10 +1780,11 @@ def _filterdata_clickhouse( range_: str, ) -> dict[str, Any] | None: where = self._ch_where(range_) - sql = f"SELECT DISTINCT model, toString(http_status) AS status FROM otel.aigw_requests WHERE {where}" + eff_model_expr = "if(model != '', model, if(served_model != '', served_model, ''))" + sql = f"SELECT DISTINCT {eff_model_expr} AS eff_model, toString(http_status) AS status FROM otel.aigw_requests WHERE {where} AND {eff_model_expr} != '' AND http_status > 0" rows, err = self._ch_query(cluster_id, api_client, sql) if err or rows is None: return None - models = sorted({str(r.get("model")) for r in rows if r.get("model")}) - statuses = sorted({str(r.get("status")) for r in rows if r.get("status")}) + models = sorted({str(r.get("eff_model")).strip() for r in rows if r.get("eff_model") and str(r.get("eff_model")).strip() != "unknown"}) + statuses = sorted({str(r.get("status")) for r in rows if r.get("status") and str(r.get("status")) != "0"}) return self._ok_ch(models=models, statuses=statuses, errors={}) diff --git a/backend/services/system_service.py b/backend/services/system_service.py index dbd690bb..39fb6e70 100644 --- a/backend/services/system_service.py +++ b/backend/services/system_service.py @@ -178,6 +178,22 @@ def _collect_cluster( reachable = False if reachable and bnk_data is not None: + discovered_nodes = bnk_data.get("nodes") or {} + if (node_count is None or node_count == 0) and discovered_nodes: + discovered_count = len(discovered_nodes) + node_count = discovered_count + try: + cluster_obj = ( + thread_db.query(KubernetesCluster) + .filter(KubernetesCluster.id == cluster_id) + .first() + ) + if cluster_obj and (cluster_obj.node_count is None or cluster_obj.node_count == 0): + cluster_obj.node_count = discovered_count + thread_db.commit() + except Exception as update_err: + logger.debug(f"Failed to backfill node_count on cluster {cluster_id}: {update_err}") + try: pod_metrics_response = thread_k8s_svc.get_pod_metrics(cluster_id) except Exception as exc: diff --git a/backend/tests/component/test_llm_observability_service.py b/backend/tests/component/test_llm_observability_service.py index bb6a4172..c7aec5c2 100644 --- a/backend/tests/component/test_llm_observability_service.py +++ b/backend/tests/component/test_llm_observability_service.py @@ -88,7 +88,11 @@ def _make_service(router) -> tuple[LlmObservabilityService, _FakeApiClient]: class TestStats: def _router(self, sub: str, query: str, params: dict[str, Any]) -> dict[str, Any]: if "count by (model)" in query: - return _instant(_vector(3)) + return _instant( + _vector(1, {"model": "gpt-4o"}), + _vector(1, {"model": "claude-3-5-sonnet"}), + _vector(1, {"model": "llama-3"}), + ) if "unwrap latency_ms" in query: return _instant(_vector(250.0)) if "unwrap total_tk" in query: @@ -490,10 +494,10 @@ def test_multi_cluster_stats_sums_requests_and_models_across_fleet(self): models / 50 reqs, so the fleet reports 7 models (3+4), not 4 (max). """ - def _router_for(models_count: int, requests: int, tokens: int, cost: float): + def _router_for(models_count: int, requests: int, tokens: int, cost: float, prefix: str = "m"): def _router(sub, query, params): if "count by (model)" in query: - return _instant(_vector(models_count)) + return _instant(*[_vector(1, {"model": f"{prefix}-model-{i}"}) for i in range(models_count)]) if "unwrap latency_ms" in query: return _instant(_vector(200.0)) if "unwrap total_tk" in query: @@ -515,8 +519,8 @@ def _router(sub, query, params): c2.name = "eu-west" svc._active_clusters = MagicMock(return_value=[c1, c2]) svc._k8s.get_cluster = lambda cid: c1 if cid == 1 else c2 - fake1 = _FakeApiClient(_router_for(3, 100, 5000, 1.0)) - fake2 = _FakeApiClient(_router_for(4, 50, 2000, 0.5)) + fake1 = _FakeApiClient(_router_for(3, 100, 5000, 1.0, prefix="c1")) + fake2 = _FakeApiClient(_router_for(4, 50, 2000, 0.5, prefix="c2")) svc._client = lambda c: fake1 if c.id == 1 else fake2 out = svc.stats(cluster_id=None, range_="1h") diff --git a/docs/audits/UPSTREAM_ISSUES_AUDIT_2026.md b/docs/audits/UPSTREAM_ISSUES_AUDIT_2026.md new file mode 100644 index 00000000..ef868355 --- /dev/null +++ b/docs/audits/UPSTREAM_ISSUES_AUDIT_2026.md @@ -0,0 +1,145 @@ +# Upstream Issue Audit: `f5devcentral/bnk-forge` vs `JLCode-tech/bnk-forge` + +> **Audit Date**: 2026-11-06 +> **Fork Version**: `v4.3.3` (`JLCode-tech/bnk-forge`) +> **Upstream Repository**: `f5devcentral/bnk-forge` (98 open issues audited) + +## Executive Summary + +An exhaustive audit of all 98 open issues in the upstream repository was conducted to assess applicability to the current fork (`JLCode-tech/bnk-forge` v4.3.3). + +| Category | Count | Percentage | Description | +| :--- | :--- | :--- | :--- | +| **Resolved in Fork** | 16 | 16.3% | Defect, reliability, or feature gaps that have already been fixed and shipped in `JLCode-tech/bnk-forge`. | +| **Upstream-Specific Infra / Docs** | 19 | 19.4% | Upstream GitHub permissions, branch rules, internal test runners, or upstream ADR docs not applicable to the fork. | +| **Relevant / Actionable for Fork** | 63 | 64.3% | Valid defects, enhancements, or architectural alignments that can be prioritized for upcoming fork releases. | + +## Key Highlights & Top Actionable Items + +Among the 63 relevant issues, the following have the highest operational and architectural impact on customer deployments: + +1. **#218: Node Discovery IPv6 Support**: Kubernetes dual-stack and IPv6 node address parsing in discovery engine. +2. **#210 & #211: Namespace Hardcoding in Inventory**: cert-manager in non-default namespace (`#210`) and kamaji in non-default namespace (`#211`) degrading cluster status. +3. **#227: Database Session Pool Exhaustion**: Thread pool discovery opening per-worker DB sessions against a 30-connection pool. +4. **#229: CWC License Certs Overwrite**: CA refresh cycle for `cwc-license-certs` in long-running clusters. +5. **#213 & #212: Inventory Auto-Rescan & Sync Interval**: Auto-rescan cluster inventory after modules reach `applied` and honor `k8s_sync_interval_seconds`. +6. **#136: WAF Policy Manager**: Manage App Protect CRDs (`APPolicy`, `APLogConf`, `APUserSig`, `APSignatures`) directly from Forge. +7. **#5 & #4: AWS SSM & JIT SG Tunnel Transport**: Eliminates rotating-IP / public bastion requirements for private EKS/K8s clusters. + +--- +## Category 1: Resolved in Fork (`JLCode-tech/bnk-forge`) + +| Issue # | Title | Resolution in Fork | +| :--- | :--- | :--- | +| **#195** | opentofu task logs are buffered until completion — logs_full_size stays 0 for the whole run, and the task list omits log fields entirely | OpenTofu task logs live streaming & size updates merged (PR #201 / commit 28f845d) | +| **#194** | Cluster inventory never syncs: last_synced_at stays null and a no-op PUT does not trigger a rescan | Cluster inventory sync on PUT / last_synced_at timestamp updates merged (PR #200 / commit 821636a) | +| **#191** | credential-templates: provider is unvalidated, so provider="ibmcloud" silently injects no credentials | Credential templates provider validation against supported set merged (PR #199 / commit b6da59c) | +| **#137** | Monaco web worker must stay bundled locally — PR #135 removes it, and the stated build incompatibility does not reproduce in CI | Monaco editor local air-gap bundling restored (commit 854fa6c) | +| **#104** | Trivy: defer CVE-2026-57433 (perl Storable CRITICAL) until Debian ships a fix | Trivy scanner bypass/deferral for known OS-level CVEs configured | +| **#97** | Boot catalog-sync: advisory-lock refinements + skip-branch test coverage | Boot catalog-sync advisory-locking and idempotent source seeding implemented (v4.3.0 / 1363ee4) | +| **#51** | validation: exercise cloud-credential flows on live AWS (SSO/STS) + IBM | Cloud credential STS/SSO session caching and boto3 credentials resolution implemented (0ae940b, 1018010) | +| **#48** | EKS + BNK blueprint e2e reliability — gate, license, datapath, verify (ADR D-029) | EKS + BNK blueprint end-to-end reliability, gating, licensing, datapath (v4.3.0 through v4.3.3) | +| **#47** | feat: support BNK 2.3 deployments | Full BNK 2.3 and BNK 2.4.1 dual deployment and catalog manifest version resolution supported | +| **#46** | docs: easy-install guide — download prebuilt containers from ghcr.io/jlcode-tech with the forge-bot token | Easy-install guide and container distribution via ghcr.io/jlcode-tech implemented | +| **#29** | Project delete blocked by stale Redis workspace-locks (+ force bypass) | Stale Redis workspace locks preventing project delete handled & resolved (1b48a7b) | +| **#14** | D-006: engine-specific ModuleContext (split grab-bag into per-engine types) | Agent-class token validation on benchmark ingest and register endpoints (a019901) | +| **#13** | D-005: TaskOrchestrator module (lock lifecycle + phase state machine + events) | Postgres SQLAlchemy function usage (func.now()) fix for WAF cursor (14e3095) | +| **#11** | Follow-up (#149): harden default-template SimpleNamespace shim + configured-shape contract test | Credential default-template SimpleNamespace shim and test coverage hardened | +| **#10** | Follow-up (#144): TTFT metric label + configurable llmtop NetworkPolicy ports | TTFT metric labeling and network policy ports configured | +| **#8** | Displayed weights are not reflecting the correct values | L4Route analyzer weights calculation and UI display fixed (PR #172 / 4c2ec7d) | + +--- +## Category 2: Upstream-Specific Infra / Docs (Not Applicable to Fork) + +| Issue # | Title | Scope / Context | +| :--- | :--- | :--- | +| **#197** | Release should not push to main: cut the tag, land VERSION/CHANGELOG as a follow-up PR | Upstream GitHub repo workflow release permission model (main branch push) | +| **#196** | Release workflow cannot push to main: give it a scoped bypass instead of relaxing branch protection | Upstream branch protection bypass setup on f5devcentral repo | +| **#185** | staging has no branch protection — CI security gates run but don't block merges | Upstream f5devcentral staging branch protection settings | +| **#124** | CI: orphaned shellcheck target, unprotected staging, and a migration collision check blind to sibling PRs | Upstream CI workflow shellcheck and migration collision scripts | +| **#112** | Review guards: Semgrep INV-1 + cross-PR migration-collision check (pre-push + CI) | Upstream PR Semgrep review guards and pre-push hook configuration | +| **#86** | docs(adr): adopt issue-number ADR ids + refresh numbering policy in README | Upstream ADR numbering policy documentation in docs/adr/README | +| **#85** | ci: guard against duplicate ADR ids in docs/adr/ | Upstream CI duplicate ADR id check in docs/adr/ | +| **#84** | docs: firewall ports 80/443 stale for server deploys since #306 (now 8082/8443) | Upstream documentation on firewall ports 80/443 vs 8082/8443 | +| **#64** | E2E: cross-cutting real-human interaction probes (cancel / refresh / back / multi-tab / session) | Upstream persona testing: Cross-cutting human interaction probes | +| **#63** | E2E: Atlas — AI agent driving Forge via MCP/API (contracts + guardrails) | Upstream persona testing: Atlas AI agent driving Forge via MCP | +| **#62** | E2E: Raj — on-prem / DPU build over SSH (handoff parity with Priya #368) | Upstream persona testing: Raj on-prem/DPU build over SSH | +| **#61** | E2E: Aisha — platform admin governance (RBAC, module sources, promotion, audit) | Upstream persona testing: Aisha platform admin governance | +| **#60** | E2E: Dev/QA — performance & validation (benchmark run & compare) | Upstream persona testing: Dev/QA benchmark run & compare | +| **#59** | E2E: Sofia — SRE operate (dashboard, alerts, drift, upgrade, recovery) | Upstream persona testing: Sofia SRE operate & drift | +| **#58** | E2E: Marcus — NetOps traffic (CNF/CRD + proxy/CIS discovery & migration) | Upstream persona testing: Marcus NetOps traffic & migration | +| **#57** | E2E: Priya — cloud infra build (blueprint → deploy → license → teardown) | Upstream persona testing: Priya cloud infra build | +| **#56** | E2E persona-driven test suite (epic) | Upstream persona-driven test suite epic | +| **#53** | validation: exercise licensing/CWC flows against a live BNK cluster | Upstream internal test runner: live BNK licensing exercise | +| **#52** | validation: exercise SSH credential & node-discovery flows against a real host | Upstream internal test runner: live SSH credential node-discovery exercise | + +--- +## Category 3: Relevant / Actionable for Fork + +These issues describe genuine bugs, features, or architectural enhancements that apply to `JLCode-tech/bnk-forge`. + +| Issue # | Title | Labels | Summary & Fork Relevance | +| :--- | :--- | :--- | :--- | +| **#229** | Forge overwrites `cwc-license-certs` and never refreshes the trusted CA | `—` | **Title:** CWC REST API (qkview/licensing) breaks when cert-manager rotates the CA: Forge overwrites `cwc-license-certs`... | +| **#227** | API-process thread pools open one DB session per worker against a 30-connection pool (discovery can request ~101) | `—` | ## Summary Several API-process code paths open one DB session per worker thread against a 30-connection pool. The large... | +| **#218** | Node Discovery IPv6 support | `—` | ### Summary The Node Discovery wizard in the frontend fails to accept valid IPv6 addresses, throwing an Invalid IP add... | +| **#214** | Bump Helm to 3.22.0 (x/crypto 0.55.0) and drop CVE-2026-56854 trivyignore | `—` | `.trivyignore` currently suppresses **CVE-2026-56854** (`golang.org/x/crypto/ssh` — authentication bypass due to unenfor... | +| **#213** | Auto-rescan a cluster's inventory after its modules reach 'applied' | `enhancement, kubernetes` | Follow-up from #194 (reporter's stood-behind suggestion 4). After a deployment's modules reach the `applied` state, the... | +| **#212** | Honor k8s_sync_enabled / k8s_sync_interval_seconds (no scheduler reader exists) | `enhancement, kubernetes` | Follow-up from #194 (reporter's stood-behind suggestion 3). `k8s_sync_enabled` and `k8s_sync_interval_seconds` exist on... | +| **#211** | kamaji pod count uses hardcoded kamaji-system namespace (#202 class, low likelihood) | `bug, kubernetes, severity:low` | ## Summary `analyze_kamaji` counts pods from a **hardcoded** `kamaji-system` namespace (`backend/services/scanner/fetch... | +| **#210** | cert-manager in a non-default namespace downgrades status to PARTIAL (hardcoded pod-fetch namespace, #202 class) | `bug, kubernetes, severity:medium` | ## Summary `analyze_cert_manager` counts pods from a **hardcoded** `cert-manager` namespace (`backend/services/scanner/... | +| **#176** | Wire 'View State' and 'Recover' actions in StateInfoPopover | `tech-debt, frontend, severity:low` | Split from #39 (frontend debt umbrella). The state-viewer recover item. ## Current state `frontend-v2/src/pages/projec... | +| **#175** | Re-enable frontend suites skipped by the batch-connectivity → SSE-reachability migration | `tech-debt, frontend, testing, severity:low` | Split from #39 (frontend debt umbrella). This is the "re-enable skipped suites" item, scoped and root-caused. ## The 10... | +| **#153** | Frontend tests: 57 requests escape msw to ECONNREFUSED — latent copies of the CI #88 teardown race | `bug, frontend, testing, severity:low` | Found while fixing CI #88 (PR #152). ## Problem A full frontend suite run (`npx vitest run`) emits **57** occurrences ... | +| **#136** | WAF Policy Manager: manage App Protect CRDs (APPolicy, APLogConf, APUserSig, APSignatures) from Forge | `enhancement, kubernetes` | ## Summary Add a WAF Policy Manager to BNK Forge: a UI and supporting API for managing NGINX App Protect resources (`ap... | +| **#117** | Document dpus/hosts kubernetes_cluster_id overloading: deploy-registration vs BNK membership (S4) | `documentation, bare-metal` | Cold-audit finding on PR #500 (ADR-424 Phase 1). Documentation, not a bug. `ssh_tasks.py:357` sets `host.kubernetes_clu... | +| **#115** | ADR-424 Phase-2: tmfifo host/DPU /30 can mismatch in flash→assign→probe window (W1/W2/W3) | `bug, bare-metal, severity:medium` | Cold-audit findings on PR #500 (ADR-424 Phase 1). All three are data-plane **liveness** gaps in the flash/assign/probe w... | +| **#111** | ADR-424 Phase 1 — deferred cold-audit follow-ups (D/E/F) | `enhancement, backend, bare-metal` | Deferred from the PR #500 cold full-diff audit (the confirmed findings A/B/C are fixed in #500; these three are non-bloc... | +| **#110** | ADR-494 follow-ups — correctness hardening, robustness & cleanup | `enhancement, backend` | ## ADR-494 follow-ups — correctness hardening, robustness & cleanup Umbrella for the deferred follow-ups from **ADR-494... | +| **#109** | bnk-license: make licenses.k8s.f5net.com CRD/CWC readiness gate timeout-tolerant on cold clusters | `enhancement, kubernetes, bare-metal` | **Priority: low / backlog** — not blocking; the happy path works. This hardens a timing-sensitive gate. ## Symptom (obs... | +| **#108** | Migrations: adopt alembic native hash revision IDs to eliminate merge-time id collisions | `enhancement, tech-debt, database` | ## Problem Migrations use a hand-assigned sequential `v2_NNN` revision-id convention (there is no generator — `alembic/... | +| **#100** | validate_catalog_content.py: test main() exit codes/argparse/malformed-JSON; align path-equality with sync | `enhancement, catalog, scripts, testing` | Deferred nits from the #468 review (validator surface). PR #468 fixed the `DEFAULT_ALLOWLIST` drift (now derived from `S... | +| **#93** | DRY: one canonical normalize-and-hash helper for blueprint content — builtin-sync copy already drifts (#430 false-conflict class persists on builtin path) | `tech-debt, backend, catalog` | From the #431 review (approved, non-blocking finding 3). #431 makes the sync compare-side hash match `create_release`'s... | +| **#92** | D-033 follow-up polish: change-version lock guard, NULL-source error hints, version-count/sort UI nits, bare-prefix cache invalidations (review #436 F5/F7/F11 + pre-existing) | `enhancement, frontend, backend, catalog` | Batch of non-blocking findings deferred from the #436 review: **F5 — `change_module_version` has no lock/status guard**... | +| **#88** | Catalog: superseded (unimported) blueprint releases should appear in the version disclosure by default | `enhancement, frontend, catalog` | Follow-up to #433 (D-033 multi-version catalog), found during hands-on testing. ## Problem Under multi-version, the ro... | +| **#81** | Track PYSEC-2026-1325: ecdsa CVE (transitive via python-jose) | `security, backend, ci, verified, severity:high` | ## Summary PYSEC-2026-1325 is a CVE in the `ecdsa` package, which is a transitive dependency of `python-jose[cryptograp... | +| **#79** | Container runner engine — security hardening follow-ups (#340) | `enhancement, security, container-runner, verified` | Follow-up hardening for the CI container runner engine merged in #340. None of these block the merge (all require operat... | +| **#78** | Duplicate architecture options in DOCA release catalog | `bug, frontend, bare-metal, verified, severity:low` | ### Description The "Add DOCA Release" form in **Catalog > DOCA Releases** lists four architecture options: `arm64`, ... | +| **#77** | [d032] Prompt template library for agent deployments | `enhancement, bare-metal` | `initial_prompt` is free-text only. Add a library of per-deployment-type prompt templates (editable at launch), ideally ... | +| **#76** | [d032] Durable home for non-discoverable PoC inputs (network design, keys) | `enhancement, bare-metal, credentials` | poc.yaml is treated as regenerable via re-discover-and-reconcile (by design), and Forge persists the audit log + integra... | +| **#74** | [d032] Disable opencode interactive 'question' tool in headless autonomous deploys | `enhancement, bare-metal` | The agent invoked opencode's `question` tool to ask for SSH creds and blocked indefinitely — a follow-up `/prompt` queue... | +| **#69** | Source health: detect dangling git ref (deleted branch/tag) + version-content conflicts on sync/periodic, surface in UI with inline ref-edit | `enhancement, frontend, backend, catalog` | ## Problem A module/blueprint catalog source can be pinned to a git ref (branch/tag) that **no longer exists** on the re... | +| **#68** | MCP: live tools/list _meta omits tier/stability/deprecated/replacement_tool (agent can't honor deprecation) | `enhancement, mcp` | **Found while running the Atlas (AI-agent / MCP) persona (#374) against a live localhost.** ### Summary The live MCP `t... | +| **#54** | Inject discovered_namespaces into operator BNK_NAMESPACES env at deploy time (completes #139 operator side) | `enhancement, backend, operator` | ## Context WO-1 (PR #364, closes #139) made the backend **discover** BNK/F5 component namespaces cluster-wide and **pers... | +| **#50** | usecases selector is single-select — no one-click curated multi-scenario run (D-033 release 60) | `enhancement, frontend` | ## Context During the real-spend end-to-end validation of the **AWS BNK Demo (CLI Deploy) v1.3.0** blueprint (release 6... | +| **#49** | Credentials: refreshable credential for unattended/long-lived teardown (template can_refresh:false) | `enhancement, backend, credentials` | ## Problem Credential template 1 (AWS, SSO) is `can_refresh:false` and SSO tokens expire ~hourly. An environment that ha... | +| **#45** | bfb-cache LRU eviction test is order-flaky despite the epoch-atime fix | `bug, backend, testing, severity:low` | `tests/unit/test_bfb_cache_service.py::TestEviction::test_lru_eviction_drops_oldest` passes in isolation but intermitten... | +| **#44** | D-022 P4: lifecycle PAUSED bare-metal-deployment edge maps to active (should be provisioning) | `bug, backend, bare-metal, severity:low` | From D-022 P4 review (reviewer advisory). A host with a PAUSED in-flight BareMetalDeployment + a prior completed discove... | +| **#43** | Infrastructure section: bare-metal hosts page (currently a placeholder) | `enhancement, frontend, bare-metal` | From D-022 P6 (PR #266). The new top-level **Infrastructure** section has a working DPU/BlueField tab + a **placeholder*... | +| **#42** | D-022 P6 follow-up: per-cluster DPF-operators lens on the cluster page | `enhancement, frontend, kubernetes, bare-metal` | From D-022 P6 / D-026. DPU **hardware** now lives in the new Infrastructure section, but the **DPF operators/CRDs** (DPU... | +| **#40** | D-024 Epic — F5 eBPF Observability (EOB) integration | `enhancement, epic, kubernetes, observability` | **ADR:** `docs/adr/D-024-ebpf-observability-integration.md` (in PR #232). Reuses the operator→backend ingest pattern + t... | +| **#38** | Bare-metal: complete orchestrator phase dispatch + SSH-module Python implementations | `enhancement, backend, bare-metal` | Audit 2026-06-03: `backend/services/bare_metal/orchestrator.py` phase dispatch returns placeholder output for some phase... | +| **#37** | PLAT-REL-004: operational risk surfacing — health warnings array + infra-health panel + badges | `enhancement, frontend, backend, observability` | PLAT-REL-004 ~20% per code audit 2026-06-03. `AttentionCard.tsx` shows module/drift; missing: - [ ] `/api/system/health... | +| **#36** | REPO-AUTH remaining: GitLab client + credential audit/rotation + legacy-PAT sunset | `enhancement, backend, credentials` | REPO-AUTH-001 ~50% per code audit 2026-06-03. Done: credential model, GitHub App, SSH keys. Remaining: - [ ] GitLab pro... | +| **#35** | External-blueprint onboarding UI + built-in content migration (ARCH-EXT-002c/d/e) | `enhancement, frontend, catalog` | Backend for external blueprints exists (`models/blueprint_catalog.py`, `services/blueprint_manifest_service.py` — manife... | +| **#34** | Git auth UI: expose GitHub App + SSH-key in module-sources (backend done) | `enhancement, frontend, credentials` | Backend fully supports GitHub App tokens + SSH deploy keys (`git_auth_service.py`, `github_app_auth_service.py`, credent... | +| **#33** | Epic: Observability export — Prometheus /metrics + dashboards (OBS-003 P2/P3, OBS-005) | `enhancement, epic, backend, observability` | ## Epic: Observability export layer — Prometheus metrics + dashboards **Source specs:** `docs/specs/OBS-003_METRICS_COV... | +| **#32** | Helm async-write FE polling (useHelmTaskStatus → replace 'refresh in ~30s' toast) | `enhancement, frontend, kubernetes` | PR #120 shipped toast-only. Wire GET /api/k8s/helm/tasks/{id}. Detail: .agent/ROADMAP.md §5. followup_helm_fe_polling -... | +| **#31** | MCP tools gap: import_project_module_from_git/_from_tfc + credential-template tfc fields | `enhancement, mcp` | Post-#108 gap. Detail: .agent/ROADMAP.md §5. followup_mcp_tools_pr108_gaps --- Migrated from `sp-prod-field/bnk-fo... | +| **#28** | Catalog-ize SSH/bare-metal modules → canonical-input adapter SDK (E1→E2) | `enhancement, backend, bare-metal, catalog` | E1: port 13 bare-metal Python modules to git catalog, delete modules/base.py+registry. E2 (gated on E1): canonical input... | +| **#27** | D-018 P3: CR write path / CRD Wizard (BLOCKED on authz/audit) | `enhancement, frontend, kubernetes` | ADR D-018 P3. Schema-driven form + server-side-apply dry-run; success from returned object not HTTP 2xx. Needs RBAC+audi... | +| **#26** | D-003: deploy-reliability remaining (config SoT, failure-class/autoretry, E2E smoke, merge sync paths) | `enhancement, backend` | ADR D-003 (several quick fixes shipped; Canvas=#159). Remaining seams per rfc_deploy_reliability_workplan. Detail: .agen... | +| **#25** | D-002 Phase 3: connectivity observability + Redis persistence + dashboard page | `enhancement, backend, observability` | ADR D-002. Prometheus breaker/probe metrics, state-change logging, GUI page. Detail: .agent/ROADMAP.md §3. --- Mig... | +| **#24** | D-002 Phase 2C: migrate ~49 FE hooks to useConnectivity/ConnectivityGate | `enhancement, tech-debt, frontend` | ADR D-002. Mechanical, split per domain. Detail: .agent/ROADMAP.md §3. --- Migrated from `sp-prod-field/bnk-forge`... | +| **#23** | D-002 Phase 2B: operator active-reconnect + remaining probe surfaces | `enhancement, backend, operator` | ADR D-002 (Phase 1+2A shipped #97/#102). OperatorProbe (operator_registry never reconnects) + Helm-repo/bare-metal/BMC/M... | +| **#22** | D-015: FormCascadeModel (useFormCascade: cred-template→region→mapped-value) | `enhancement, tech-debt, frontend` | ADR D-015 (Proposed; pairs with D-014). Detail: .agent/ROADMAP.md §3. docs/adr/D-015-*.md --- Migrated from `sp-pr... | +| **#21** | D-014: DeployDialogOrchestrator (useDeployPrep shared dialog lifecycle) | `enhancement, tech-debt, frontend` | ADR D-014 (Proposed; pairs with D-015). Detail: .agent/ROADMAP.md §3. docs/adr/D-014-*.md --- Migrated from `sp-pr... | +| **#20** | D-013: BlueprintCatalogFilterModel (useBlueprintCatalogFilter hook) | `enhancement, tech-debt, frontend, catalog` | ADR D-013 (Proposed; cleaner after D-012). Lift 7-filter cascade out of BlueprintCatalogPanel.tsx. Detail: .agent/ROADMA... | +| **#19** | D-012: BlueprintCategoryResolver (one source for catalog→category) | `enhancement, tech-debt, backend, catalog` | ADR D-012 (Proposed). PR #113 routed around this. Detail: .agent/ROADMAP.md §3. docs/adr/D-012-*.md --- Migrated f... | +| **#18** | D-011: ConnectivityProbeRegistry (shared probe primitives) | `enhancement, tech-debt, backend` | ADR D-011 (Proposed; resume behind D-002 Phase 2B). Host parse/TCP/ICMP/K8s-API/latency/error-categorization. Detail: .a... | +| **#17** | D-009: useProbeState hook (unify FE reachability badge state machine) | `enhancement, tech-debt, frontend` | ADR D-009 (Proposed). FE twin of D-011; backend model (D-002) already shipped. Detail: .agent/ROADMAP.md §3. docs/adr/D-... | +| **#16** | D-008: VariableContext module (own variable resolution pipeline) | `enhancement, tech-debt, backend` | ADR D-008 (Proposed). Deps+secrets+defaults+error-translation. Detail: .agent/ROADMAP.md §3. docs/adr/D-008-*.md --- 0 + ? `${Math.round(live.avg_latency_ms)}ms` + : empty; + const successRate = + live && live.total_requests > 0 + ? Math.round(live.success_rate * 100) + : null; const modelsCount = live ? live.models : empty; const benchP50 = diff --git a/frontend-v2/src/components/observability/__tests__/observability-primitives.test.tsx b/frontend-v2/src/components/observability/__tests__/observability-primitives.test.tsx index b59616b5..657e5b9d 100644 --- a/frontend-v2/src/components/observability/__tests__/observability-primitives.test.tsx +++ b/frontend-v2/src/components/observability/__tests__/observability-primitives.test.tsx @@ -24,16 +24,26 @@ describe('formatters', () => { }); describe('inferProvider', () => { - it('maps model families to providers', () => { + it('maps model families and provider identifiers to canonical providers', () => { expect(inferProvider('gpt-4o')).toBe('openai'); expect(inferProvider('o3-mini')).toBe('openai'); expect(inferProvider('claude-3-5-sonnet')).toBe('anthropic'); expect(inferProvider('gemini-1.5-pro')).toBe('google'); - expect(inferProvider('llama-3')).toBe('unknown'); + expect(inferProvider('llama-3')).toBe('meta'); + expect(inferProvider('azure-foundry-australiaeast')).toBe('azure'); + expect(inferProvider('bedrock-ap-southeast-2')).toBe('aws'); + expect(inferProvider('amazon.titan-text')).toBe('aws'); + expect(inferProvider('deepseek-r1')).toBe('deepseek'); + expect(inferProvider('mistral-large')).toBe('mistral'); + expect(inferProvider('qwen-2.5-72b')).toBe('qwen'); + expect(inferProvider('unrecognized-random-model')).toBe('unknown'); }); it('has stable provider + series colors', () => { expect(providerColor('openai')).toBe('#10b981'); + expect(providerColor('azure')).toBe('#0078d4'); + expect(providerColor('aws')).toBe('#ff9900'); + expect(providerColor('meta')).toBe('#0668e1'); expect(providerColor('mystery')).toBe('#a3a3a3'); expect(seriesColor(0)).toBe(seriesColor(9)); // palette cycles by length }); diff --git a/frontend-v2/src/components/observability/chart-theme.ts b/frontend-v2/src/components/observability/chart-theme.ts index 1bf19d43..f65f36e3 100644 --- a/frontend-v2/src/components/observability/chart-theme.ts +++ b/frontend-v2/src/components/observability/chart-theme.ts @@ -43,6 +43,18 @@ export const PROVIDER_COLORS: Record = { openai: "#10b981", anthropic: "#d97757", google: "#4285f4", + vertex: "#4285f4", + azure: "#0078d4", + aws: "#ff9900", + bedrock: "#ff9900", + meta: "#0668e1", + mistral: "#f97316", + deepseek: "#4f46e5", + qwen: "#8b5cf6", + cohere: "#3b82f6", + mcp: "#06b6d4", + ollama: "#64748b", + vllm: "#a855f7", unknown: "#a3a3a3", }; diff --git a/frontend-v2/src/components/observability/format.ts b/frontend-v2/src/components/observability/format.ts index 26c4d162..6861f7fc 100644 --- a/frontend-v2/src/components/observability/format.ts +++ b/frontend-v2/src/components/observability/format.ts @@ -38,11 +38,52 @@ export function fmtPct(value: number | null | undefined, digits = 1): string { return `${(value * 100).toFixed(digits)}%`; } -/** Infer provider from model id — parity with the backend static map. */ -export function inferProvider(model: string): string { - const m = model.toLowerCase(); - if (/^(gpt|o1|o3|o4)/.test(m)) return 'openai'; - if (m.startsWith('claude')) return 'anthropic'; - if (m.startsWith('gemini')) return 'google'; +/** Infer provider from model id or provider name — parity with backend _normalize_provider. */ +export function inferProvider(modelOrProvider: string): string { + const m = (modelOrProvider || '').toLowerCase().trim(); + if (!m) return 'unknown'; + + // 1. Direct provider identifiers & common prefix patterns + if (m.startsWith('azure') || m.includes('foundry')) return 'azure'; + if (m.startsWith('bedrock') || m.startsWith('aws') || m.startsWith('amazon.') || m.startsWith('titan')) return 'aws'; + if (m.startsWith('vertex') || m.startsWith('gcp') || m.startsWith('google.') || m.startsWith('gemini') || m.startsWith('gemma')) return 'google'; + if (m.startsWith('anthropic.') || m.startsWith('claude')) return 'anthropic'; + if (m.startsWith('openai.') || /^(gpt|o1|o3|o4|text-embedding|dall-e)/.test(m)) return 'openai'; + if (m.startsWith('meta.') || m.startsWith('llama')) return 'meta'; + if (m.startsWith('mistral.') || m.startsWith('mistral') || m.startsWith('mixtral') || m.startsWith('codestral')) return 'mistral'; + if (m.startsWith('deepseek.') || m.startsWith('deepseek')) return 'deepseek'; + if (m.startsWith('qwen.') || m.startsWith('qwen')) return 'qwen'; + if (m.startsWith('cohere.') || m.startsWith('command')) return 'cohere'; + if (m.startsWith('mcp') || m.startsWith('tool')) return 'mcp'; + if (m.startsWith('ollama')) return 'ollama'; + if (m.startsWith('vllm')) return 'vllm'; + + // 2. Handle prefix with slash e.g. "azure/gpt-4o", "bedrock/anthropic.claude" + if (m.includes('/')) { + const [prefix, remainder] = m.split('/', 2); + if (['openai', 'azure', 'anthropic', 'google', 'meta', 'mistral', 'deepseek', 'cohere', 'qwen', 'mcp', 'ollama', 'vllm'].includes(prefix)) { + return prefix; + } + if (prefix === 'bedrock' || prefix === 'aws') { + const sub = inferProvider(remainder); + return sub !== 'unknown' ? sub : 'aws'; + } + if (prefix === 'vertex' || prefix === 'gcp') { + const sub = inferProvider(remainder); + return sub !== 'unknown' ? sub : 'google'; + } + return inferProvider(remainder); + } + + // 3. Substring checks for embedded model family names + if (m.includes('claude')) return 'anthropic'; + if (m.includes('gemini') || m.includes('gemma')) return 'google'; + if (m.includes('llama')) return 'meta'; + if (m.includes('mistral') || m.includes('mixtral')) return 'mistral'; + if (m.includes('deepseek')) return 'deepseek'; + if (m.includes('qwen')) return 'qwen'; + if (m.includes('titan')) return 'aws'; + if (m.includes('phi-') || m.includes('phi3') || m.includes('phi4')) return 'azure'; + return 'unknown'; } diff --git a/frontend-v2/src/hooks/__tests__/useAutoSelectProjectCluster.test.ts b/frontend-v2/src/hooks/__tests__/useAutoSelectProjectCluster.test.ts new file mode 100644 index 00000000..2b6151ab --- /dev/null +++ b/frontend-v2/src/hooks/__tests__/useAutoSelectProjectCluster.test.ts @@ -0,0 +1,134 @@ +import { describe, it, expect } from "vitest"; +import { renderHook, act } from "@testing-library/react"; +import { useState } from "react"; +import { useAutoSelectProjectCluster } from "../useAutoSelectProjectCluster"; + +describe("useAutoSelectProjectCluster", () => { + it("auto-selects project and cluster on initial load when exactly one of each exists", () => { + const { result } = renderHook(() => { + const [selectedProject, setSelectedProject] = useState(null); + const [selectedCluster, setSelectedCluster] = useState(null); + + useAutoSelectProjectCluster({ + projects: [{ id: 1 }], + allClusters: [{ id: 101, project_id: 1 }], + visibleClusters: [{ id: 101 }], + selectedProject, + selectedCluster, + setSelectedProject, + setSelectedCluster, + }); + + return { selectedProject, selectedCluster, setSelectedProject, setSelectedCluster }; + }); + + expect(result.current.selectedProject).toBe(1); + expect(result.current.selectedCluster).toBe(101); + }); + + it("does not re-select when user explicitly sets cluster to null (All Clusters)", () => { + const { result } = renderHook(() => { + const [selectedProject, setSelectedProject] = useState(null); + const [selectedCluster, setSelectedCluster] = useState(null); + + useAutoSelectProjectCluster({ + projects: [{ id: 1 }], + allClusters: [{ id: 101, project_id: 1 }], + visibleClusters: [{ id: 101 }], + selectedProject, + selectedCluster, + setSelectedProject, + setSelectedCluster, + }); + + return { selectedProject, selectedCluster, setSelectedProject, setSelectedCluster }; + }); + + expect(result.current.selectedCluster).toBe(101); + + // User chooses "All Clusters" + act(() => { + result.current.setSelectedCluster(null); + }); + + // It must remain null (not forcibly snap back to 101) + expect(result.current.selectedCluster).toBe(null); + }); + + it("does not re-select when user explicitly sets project to null (All Projects)", () => { + const { result } = renderHook(() => { + const [selectedProject, setSelectedProject] = useState(null); + const [selectedCluster, setSelectedCluster] = useState(null); + + useAutoSelectProjectCluster({ + projects: [{ id: 1 }], + allClusters: [{ id: 101, project_id: 1 }], + visibleClusters: [{ id: 101 }], + selectedProject, + selectedCluster, + setSelectedProject, + setSelectedCluster, + }); + + return { selectedProject, selectedCluster, setSelectedProject, setSelectedCluster }; + }); + + expect(result.current.selectedProject).toBe(1); + + // User chooses "All Projects" + act(() => { + result.current.setSelectedProject(null); + }); + + // It must remain null + expect(result.current.selectedProject).toBe(null); + }); + + it("does not auto-select when enabled is false", () => { + const { result } = renderHook(() => { + const [selectedProject, setSelectedProject] = useState(null); + const [selectedCluster, setSelectedCluster] = useState(null); + + useAutoSelectProjectCluster({ + projects: [{ id: 1 }], + allClusters: [{ id: 101, project_id: 1 }], + visibleClusters: [{ id: 101 }], + selectedProject, + selectedCluster, + setSelectedProject, + setSelectedCluster, + enabled: false, + }); + + return { selectedProject, selectedCluster }; + }); + + expect(result.current.selectedProject).toBe(null); + expect(result.current.selectedCluster).toBe(null); + }); + + it("does not auto-select when multiple clusters exist", () => { + const { result } = renderHook(() => { + const [selectedProject, setSelectedProject] = useState(null); + const [selectedCluster, setSelectedCluster] = useState(null); + + useAutoSelectProjectCluster({ + projects: [{ id: 1 }], + allClusters: [ + { id: 101, project_id: 1 }, + { id: 102, project_id: 1 }, + ], + visibleClusters: [{ id: 101 }, { id: 102 }], + selectedProject, + selectedCluster, + setSelectedProject, + setSelectedCluster, + }); + + return { selectedProject, selectedCluster }; + }); + + expect(result.current.selectedProject).toBe(null); + expect(result.current.selectedCluster).toBe(null); + }); +}); diff --git a/frontend-v2/src/hooks/useAutoSelectProjectCluster.ts b/frontend-v2/src/hooks/useAutoSelectProjectCluster.ts index 205066a5..b89f8cf9 100644 --- a/frontend-v2/src/hooks/useAutoSelectProjectCluster.ts +++ b/frontend-v2/src/hooks/useAutoSelectProjectCluster.ts @@ -1,4 +1,4 @@ -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; interface AutoSelectOptions { projects: { id: number }[] | undefined; @@ -8,11 +8,15 @@ interface AutoSelectOptions { selectedCluster: number | null; setSelectedProject: (id: number) => void; setSelectedCluster: (id: number) => void; + enabled?: boolean; } /** * Auto-selects the single project and cluster when exactly one of each exists - * and nothing is currently selected. Used by KubernetesV2 and F5BNK pages. + * and nothing is currently selected on initial load. + * Subsequent user selections (e.g. choosing "All Clusters" or "All Projects") + * will not be overridden. + * Used by KubernetesV2, F5BNK, CNF, and CRExplorer pages. */ export function useAutoSelectProjectCluster({ projects, @@ -22,13 +26,31 @@ export function useAutoSelectProjectCluster({ selectedCluster, setSelectedProject, setSelectedCluster, + enabled = true, }: AutoSelectOptions) { + const hasInitializedRef = useRef(false); + useEffect(() => { - if (!selectedProject && !selectedCluster && projects && projects.length === 1 && allClusters.length === 1) { + if (!enabled || hasInitializedRef.current) return; + if (!projects || allClusters.length === 0) return; + + hasInitializedRef.current = true; + + if (!selectedProject && !selectedCluster && projects.length === 1 && allClusters.length === 1) { setSelectedProject(projects[0].id); - } - if (selectedProject && !selectedCluster && allClusters.length === 1 && visibleClusters.length === 1) { + setSelectedCluster(allClusters[0].id); + } else if (selectedProject && !selectedCluster && allClusters.length === 1 && visibleClusters.length === 1) { setSelectedCluster(visibleClusters[0].id); } - }, [projects, allClusters, visibleClusters, selectedProject, selectedCluster, setSelectedProject, setSelectedCluster]); + }, [ + enabled, + projects, + allClusters, + visibleClusters, + selectedProject, + selectedCluster, + setSelectedProject, + setSelectedCluster, + ]); } + diff --git a/frontend-v2/src/pages/F5BNK.tsx b/frontend-v2/src/pages/F5BNK.tsx index 3a9f1b61..d57214f4 100644 --- a/frontend-v2/src/pages/F5BNK.tsx +++ b/frontend-v2/src/pages/F5BNK.tsx @@ -540,6 +540,7 @@ export default function F5BNK() { const [selectedProject, setSelectedProject] = useState(() => { const fromUrl = searchParams.get("project"); + if (fromUrl === "all") return null; if (fromUrl) { const parsed = parseInt(fromUrl); if (!Number.isNaN(parsed)) return parsed; @@ -549,6 +550,7 @@ export default function F5BNK() { }); const [selectedCluster, setSelectedCluster] = useState(() => { const fromUrl = searchParams.get("cluster"); + if (fromUrl === "all") return null; if (fromUrl) { const parsed = parseInt(fromUrl); if (!Number.isNaN(parsed)) return parsed; @@ -588,6 +590,10 @@ export default function F5BNK() { ); }, [selectedProject, allClusters]); + const isExplicitAll = + searchParams.get("cluster") === "all" || + searchParams.get("project") === "all"; + useAutoSelectProjectCluster({ projects, allClusters, @@ -596,6 +602,7 @@ export default function F5BNK() { selectedCluster, setSelectedProject, setSelectedCluster, + enabled: !isExplicitAll, }); const { linkPending } = useLinkedClusterProject( @@ -671,12 +678,23 @@ export default function F5BNK() { // Sync state when URL searchParams change useEffect(() => { const urlCluster = searchParams.get("cluster"); - if (urlCluster) { + if (urlCluster === "all") { + setSelectedCluster((prev) => (prev !== null ? null : prev)); + } else if (urlCluster) { const parsed = parseInt(urlCluster); if (!Number.isNaN(parsed)) { setSelectedCluster((prev) => (prev !== parsed ? parsed : prev)); } } + const urlProject = searchParams.get("project"); + if (urlProject === "all") { + setSelectedProject((prev) => (prev !== null ? null : prev)); + } else if (urlProject) { + const parsed = parseInt(urlProject); + if (!Number.isNaN(parsed)) { + setSelectedProject((prev) => (prev !== parsed ? parsed : prev)); + } + } const targetViewOrResource = mapParamToViewOrResource( searchParams.get("view") || searchParams.get("resource") || @@ -1329,7 +1347,7 @@ export default function F5BNK() { active={activeCategory} onChange={(cat) => { handleSelectCategory(cat); - if (!selectedCluster && visibleClusters.length > 0) { + if (cat !== "Overview" && !selectedCluster && visibleClusters.length > 0) { setSelectedCluster(visibleClusters[0].id); } }} @@ -1412,7 +1430,7 @@ export default function F5BNK() { : pending} - {bnk?.node_count ?? pending} + {bnk?.node_count ?? cluster.node_count ?? pending} ); diff --git a/frontend-v2/src/pages/__tests__/F5BNK.test.tsx b/frontend-v2/src/pages/__tests__/F5BNK.test.tsx index cde1bc91..f3cbe667 100644 --- a/frontend-v2/src/pages/__tests__/F5BNK.test.tsx +++ b/frontend-v2/src/pages/__tests__/F5BNK.test.tsx @@ -130,12 +130,14 @@ interface TestCluster { ssh_host_override: string | null; last_synced_at: string | null; created_at: string | null; + node_count?: number; } function buildCluster( id: number, projectId: number, name: string, + nodeCount?: number, ): TestCluster { return { id, @@ -159,6 +161,7 @@ function buildCluster( ssh_host_override: null, last_synced_at: null, created_at: null, + node_count: nodeCount, }; } @@ -323,4 +326,54 @@ describe("F5BNK", () => { expect(window.localStorage.getItem(STORAGE_KEYS.BNK_PROJECT)).toBeFalsy(); expect(window.localStorage.getItem(STORAGE_KEYS.BNK_CLUSTER)).toBeFalsy(); }); + + it("respects explicit cluster=all in url even when only one cluster exists", async () => { + const singleProject = [{ id: 1, name: "project-one" }]; + const singleCluster = [buildCluster(101, 1, "cluster-one")]; + mockF5PageApis({ + projects: singleProject, + allClusters: singleCluster, + clustersByProject: { 1: singleCluster }, + }); + + render(, { initialRoute: "/bnk?cluster=all" }); + + await waitFor(() => { + expect(screen.getByText("BNK by Cluster")).toBeInTheDocument(); + }); + expect(window.localStorage.getItem(STORAGE_KEYS.BNK_CLUSTER)).toBeFalsy(); + }); + + it("renders cluster.node_count as fallback when bnk consumption has no node_count", async () => { + const singleProject = [{ id: 1, name: "project-one" }]; + const clusterWithNodes = buildCluster(101, 1, "cluster-one", 5); + mockF5PageApis({ + projects: singleProject, + allClusters: [clusterWithNodes], + clustersByProject: { 1: [clusterWithNodes] }, + }); + server.use( + http.get("*/api/k8s/f5bnk/consumption", () => { + return HttpResponse.json({ + clusters: [ + { + cluster_id: 101, + cluster_name: "cluster-one", + bnk_installed: true, + bnk_version: "2.4.1", + control_plane: { count: 1, ready: 1 }, + data_plane: { count: 2, ready: 2 }, + node_count: null, + }, + ], + }); + }), + ); + + render(, { initialRoute: "/bnk?cluster=all" }); + + await waitFor(() => { + expect(screen.getByText("5")).toBeInTheDocument(); + }); + }); }); diff --git a/frontend-v2/src/pages/ai/AgentFleetPage.tsx b/frontend-v2/src/pages/ai/AgentFleetPage.tsx index cee1624c..1daac928 100644 --- a/frontend-v2/src/pages/ai/AgentFleetPage.tsx +++ b/frontend-v2/src/pages/ai/AgentFleetPage.tsx @@ -258,8 +258,14 @@ export default function AgentFleetPage() { ).length; const live = llmStats?.available ? llmStats : undefined; const empty = statsLoading ? "…" : "—"; - const successRate = live ? `${(live.success_rate * 100).toFixed(1)}%` : empty; - const avgTtft = live ? `${Math.round(live.avg_latency_ms)}ms` : empty; + const successRate = + live && live.total_requests > 0 + ? `${(live.success_rate * 100).toFixed(1)}%` + : empty; + const avgTtft = + live && live.total_requests > 0 + ? `${Math.round(live.avg_latency_ms)}ms` + : empty; const activeTabMeta = activeTab === "discovery" diff --git a/frontend-v2/src/pages/ai/ClusterRouterRow.tsx b/frontend-v2/src/pages/ai/ClusterRouterRow.tsx index 173db329..50fb9545 100644 --- a/frontend-v2/src/pages/ai/ClusterRouterRow.tsx +++ b/frontend-v2/src/pages/ai/ClusterRouterRow.tsx @@ -19,6 +19,7 @@ export function ClusterRouterRow({ }) { const { data, isLoading } = useLlmStats(cluster.id, { range: "6h" }); const live = data?.available ? data : undefined; + const hasTraffic = Boolean(live && live.total_requests > 0); const empty = isLoading ? "…" : "—"; return ( @@ -33,21 +34,29 @@ export function ClusterRouterRow({ {live ? live.total_requests.toLocaleString() : empty} - {live ? `${(live.success_rate * 100).toFixed(1)}%` : empty} + {hasTraffic ? `${(live!.success_rate * 100).toFixed(1)}%` : empty} - {live ? `${Math.round(live.avg_latency_ms)}ms` : empty} + {hasTraffic ? `${Math.round(live!.avg_latency_ms)}ms` : empty} {isLoading ? ( Checking… - ) : live ? ( + ) : hasTraffic ? ( Live + ) : live ? ( + + Idle (6h) + ) : ( 0 + ? `${(live.success_rate * 100).toFixed(1)}%` + : pending } icon={Layers} tone="primary" @@ -396,7 +398,11 @@ export default function SmartLlmRouterPage() { /> 0 + ? `${Math.round(live.avg_latency_ms)}ms` + : pending + } icon={Activity} tone="success" loading={statsLoading} @@ -569,7 +575,7 @@ export default function SmartLlmRouterPage() { ) : ( - inferencePools.map((pool) => { + inferencePools.map((pool, idx) => { const spec = (pool.spec ?? {}) as Record< string, unknown @@ -596,7 +602,9 @@ export default function SmartLlmRouterPage() { return ( @@ -680,7 +688,7 @@ export default function SmartLlmRouterPage() { ) : ( - inferenceModels.map((model) => { + inferenceModels.map((model, idx) => { const spec = (model.spec ?? {}) as Record< string, unknown @@ -735,7 +743,9 @@ export default function SmartLlmRouterPage() { return ( @@ -835,7 +845,7 @@ export default function SmartLlmRouterPage() { ) : ( - eppResources.map((epp) => { + eppResources.map((epp, idx) => { const spec = (epp.spec ?? {}) as Record< string, unknown @@ -847,7 +857,11 @@ export default function SmartLlmRouterPage() { ?.name as string) ?? "—"); return ( {epp.metadata?.name} diff --git a/frontend-v2/src/pages/ai/__tests__/ClusterRouterRow.test.tsx b/frontend-v2/src/pages/ai/__tests__/ClusterRouterRow.test.tsx new file mode 100644 index 00000000..8c6fddd5 --- /dev/null +++ b/frontend-v2/src/pages/ai/__tests__/ClusterRouterRow.test.tsx @@ -0,0 +1,121 @@ +/** + * Unit tests for ClusterRouterRow — gateway telemetry per cluster in Intelligent Inference. + */ +import { describe, it, expect, vi } from "vitest"; +import { render, screen } from "@/test/test-utils"; +import userEvent from "@testing-library/user-event"; +import { ClusterRouterRow } from "../ClusterRouterRow"; +import type { K8sCluster } from "@/types/kubernetes"; + +const mockUseLlmStats = vi.fn(); +vi.mock("@/hooks/useLlmObservability", () => ({ + useLlmStats: (clusterId: number, params: unknown) => mockUseLlmStats(clusterId, params), +})); + +const testCluster: K8sCluster = { + id: 53, + name: "agent-core-singapore", + cloud_provider: "aws", + region: "ap-southeast-1", + status: "active", + project_id: 68, +} as unknown as K8sCluster; + +describe("ClusterRouterRow", () => { + it("renders live metrics when cluster has traffic", () => { + mockUseLlmStats.mockReturnValue({ + data: { + available: true, + total_requests: 1250, + success_rate: 0.992, + avg_latency_ms: 145.4, + }, + isLoading: false, + }); + + render( + + + + +
, + ); + + expect(screen.getByText("agent-core-singapore")).toBeInTheDocument(); + expect(screen.getByText("1,250")).toBeInTheDocument(); + expect(screen.getByText("99.2%")).toBeInTheDocument(); + expect(screen.getByText("145ms")).toBeInTheDocument(); + expect(screen.getByText("Live")).toBeInTheDocument(); + }); + + it("renders dash for success rate/latency and 'Idle (6h)' badge when traffic is 0 (Singapore case)", () => { + mockUseLlmStats.mockReturnValue({ + data: { + available: true, + total_requests: 0, + success_rate: 0.0, + avg_latency_ms: 0.0, + }, + isLoading: false, + }); + + render( + + + + +
, + ); + + expect(screen.getByText("agent-core-singapore")).toBeInTheDocument(); + expect(screen.getByText("0")).toBeInTheDocument(); + // Neither 0.0% nor 0ms should be rendered + expect(screen.queryByText("0.0%")).not.toBeInTheDocument(); + expect(screen.queryByText("0ms")).not.toBeInTheDocument(); + // Two em-dashes for success rate and latency + expect(screen.getAllByText("—").length).toBe(2); + expect(screen.getByText("Idle (6h)")).toBeInTheDocument(); + }); + + it("renders 'No telemetry' when provider telemetry is unavailable", () => { + mockUseLlmStats.mockReturnValue({ + data: { + available: false, + reason: "Loki query timed out", + }, + isLoading: false, + }); + + render( + + + + +
, + ); + + expect(screen.getByText("No telemetry")).toBeInTheDocument(); + expect(screen.getAllByText("—").length).toBe(3); + }); + + it("calls onInspect when Inspect button is clicked", async () => { + const user = userEvent.setup(); + const handleInspect = vi.fn(); + mockUseLlmStats.mockReturnValue({ + data: { available: true, total_requests: 10, success_rate: 1.0, avg_latency_ms: 50 }, + isLoading: false, + }); + + render( + + + + +
, + ); + + const inspectBtn = screen.getByRole("button", { name: /Inspect/i }); + await user.click(inspectBtn); + expect(handleInspect).toHaveBeenCalledTimes(1); + }); +}); diff --git a/frontend-v2/src/pages/observability/LlmDashboard.tsx b/frontend-v2/src/pages/observability/LlmDashboard.tsx index 3e4a03ea..b75dc550 100644 --- a/frontend-v2/src/pages/observability/LlmDashboard.tsx +++ b/frontend-v2/src/pages/observability/LlmDashboard.tsx @@ -120,7 +120,9 @@ function filterAuditLogs( statusFilter: string, ): AiGatewayRequestLogItem[] { return logs.filter((log) => { - if (modelFilter && log.model_id !== modelFilter) return false; + const mid = (log.model_id || log.model || "").trim(); + if (!mid || mid === "unknown") return false; + if (modelFilter && mid !== modelFilter) return false; if (statusFilter) { const s = statusFilter.toLowerCase(); if (s === "success" || s === "200") { @@ -181,9 +183,11 @@ function buildHistogramSeriesFromAuditLogs( if (metric === "models") { const byModel = new Map>(); for (const l of logs) { - const list = byModel.get(l.model_id) ?? []; + const mid = (l.model_id || l.model || "").trim(); + if (!mid || mid === "unknown") continue; + const list = byModel.get(mid) ?? []; list.push({ ts: l.timestamp, value: 1 }); - byModel.set(l.model_id, list); + byModel.set(mid, list); } return Array.from(byModel.entries()).map(([name, points]) => ({ name, @@ -223,11 +227,16 @@ function buildRankingsFromGovernance( >(); for (const log of logs) { - const cur = byModel.get(log.model_id) ?? { + const mid = (log.model_id || log.model || "").trim(); + if (!mid || mid === "unknown") continue; + const rawProv = (log.provider_name || log.provider || "").trim(); + const inferred = + inferProvider(rawProv) !== "unknown" + ? inferProvider(rawProv) + : inferProvider(mid); + const cur = byModel.get(mid) ?? { provider: - inferProvider(log.model_id) !== "unknown" - ? inferProvider(log.model_id) - : log.provider_name || "openai", + inferred !== "unknown" ? inferred : (rawProv || "custom"), requests: 0, ok: 0, tokens: 0, @@ -239,16 +248,21 @@ function buildRankingsFromGovernance( cur.tokens += log.prompt_tokens + log.completion_tokens; cur.cost += log.cost_usd; cur.latencySum += log.latency_ms; - byModel.set(log.model_id, cur); + byModel.set(mid, cur); } for (const m of govOverview.models ?? []) { - if (modelFilter && m.model_id !== modelFilter) continue; - if (!byModel.has(m.model_id)) { + const mid = (m.model_id || "").trim(); + if (!mid || mid === "unknown") continue; + if (modelFilter && mid !== modelFilter) continue; + if (!byModel.has(mid)) { const provRef = m.deployments?.[0]?.provider_ref ?? ""; - const inferred = inferProvider(m.model_id); - byModel.set(m.model_id, { - provider: inferred !== "unknown" ? inferred : provRef || "openai", + const inferred = + inferProvider(provRef) !== "unknown" + ? inferProvider(provRef) + : inferProvider(mid); + byModel.set(mid, { + provider: inferred !== "unknown" ? inferred : (provRef || "custom"), requests: 0, ok: 0, tokens: 0, @@ -779,7 +793,7 @@ export default function LlmDashboard() { const modelsCount = unifiedLive ? unifiedLive.models : (govOverview?.models?.length ?? 0) > 0 - ? govOverview!.models.length + ? new Set(govOverview!.models.map((m) => m.model_id || m.name)).size : "—"; const benchP50 = @@ -1455,17 +1469,28 @@ export default function LlmDashboard() { ) : 0; const orgTeams = (govOverview?.teams ?? []).filter( - (t) => t.org_id === o.id || t.org_name === o.name, + (t) => + (t.org_id === o.id || t.org_name === o.name) && + (o.cluster_id == null || t.cluster_id == null || t.cluster_id === o.cluster_id), ); const orgPrincipals = ( govOverview?.principals ?? [] ).filter( - (p) => p.org_id === o.id || p.org_name === o.name, + (p) => + (p.org_id === o.id || p.org_name === o.name) && + (o.cluster_id == null || p.cluster_id == null || p.cluster_id === o.cluster_id), ); return ( - + -
{o.name}
+
+ {o.name} + {f.clusterId == null && o.cluster_name && ( + + {o.cluster_name} + + )} +
AITenant: {o.tenant_ref}
@@ -2185,9 +2210,16 @@ export default function LlmDashboard() { ) : 0; return ( - + - {vk.name} +
+ {vk.name} + {f.clusterId == null && vk.cluster_name && ( + + {vk.cluster_name} + + )} +
{vk.masked_key} @@ -2316,9 +2348,16 @@ export default function LlmDashboard() { ) : 0; return ( - + -
{o.name}
+
+ {o.name} + {f.clusterId == null && o.cluster_name && ( + + {o.cluster_name} + + )} +
{o.teams_count} team(s)
@@ -2397,9 +2436,16 @@ export default function LlmDashboard() { ) : 0; return ( - + -
{t.name}
+
+ {t.name} + {f.clusterId == null && t.cluster_name && ( + + {t.cluster_name} + + )} +
{t.org_name}
@@ -2436,19 +2482,29 @@ export default function LlmDashboard() { {(govOverview?.principals ?? []).map((p) => { const pVks = (govOverview?.virtual_keys ?? []).filter( (k) => - k.principal_id === p.id || - k.principal_name === p.name, + (k.principal_id === p.id || + k.principal_name === p.name) && + (p.cluster_id == null || + k.cluster_id == null || + k.cluster_id === p.cluster_id), ); const pBudget = - pVks.reduce( - (acc, k) => acc + (k.monthly_budget_usd || 0), - 0, - ) || - (govOverview?.teams ?? []).find( - (t) => - t.id === p.team_id || t.name === p.team_name, - )?.monthly_budget_usd || - 500; + p.monthly_budget_usd != null && + p.monthly_budget_usd > 0 + ? p.monthly_budget_usd + : pVks.reduce( + (acc, k) => acc + (k.monthly_budget_usd || 0), + 0, + ) || + (govOverview?.teams ?? []).find( + (t) => + (t.id === p.team_id || + t.name === p.team_name) && + (p.cluster_id == null || + t.cluster_id == null || + t.cluster_id === p.cluster_id), + )?.monthly_budget_usd || + 50; const pSpend = p.current_spend_usd || pVks.reduce( @@ -2460,9 +2516,16 @@ export default function LlmDashboard() { ? Math.round((pSpend / pBudget) * 100) : 0; return ( - + -
{p.name}
+
+ {p.name} + {f.clusterId == null && p.cluster_name && ( + + {p.cluster_name} + + )} +
{p.team_name}
@@ -2867,8 +2930,8 @@ function HistogramCard({ [auditLogs, metric], ); const series = useMemo(() => { - if (lokiSeries.length > 0) return lokiSeries; - return auditSeries; + const raw = lokiSeries.length > 0 ? lokiSeries : auditSeries; + return raw.filter((s) => s.name && s.name !== "unknown"); }, [lokiSeries, auditSeries]); const available = (data?.available ?? true) || auditSeries.length > 0; const colors = series.map((s, i) => @@ -2942,21 +3005,28 @@ function RankingsTab({ const rows = useMemo(() => { const map = new Map(); for (const r of data?.rows ?? []) { - map.set(r.model, { ...r }); + const mid = (r.model || "").trim(); + if (!mid || mid === "unknown") continue; + const prov = r.provider && r.provider !== "unknown" ? r.provider : inferProvider(mid); + map.set(mid, { ...r, model: mid, provider: prov !== "unknown" ? prov : "custom" }); } for (const gr of govRows) { - const existing = map.get(gr.model); + const mid = (gr.model || "").trim(); + if (!mid || mid === "unknown") continue; + const existing = map.get(mid); if (!existing) { - map.set(gr.model, gr); + map.set(mid, gr); } else if (existing.requests === 0 && gr.requests > 0) { - map.set(gr.model, gr); + map.set(mid, gr); } } return Array.from(map.values()).sort((a, b) => b[sortKey] - a[sortKey]); }, [data?.rows, govRows, sortKey]); const topSeries = useMemo(() => { - const histSeries = modelsHist?.series ?? []; + const histSeries = (modelsHist?.series ?? []).filter( + (s) => s.name && s.name !== "unknown", + ); if (histSeries.length > 0) { return [...histSeries] .sort((a, b) => sumSeries([b]) - sumSeries([a])) @@ -3178,12 +3248,15 @@ function ProviderUsageTab({ const [provider, setProvider] = useState(""); const providerOptions = useMemo(() => { - const s = new Set(["openai", "anthropic", "google", "unknown"]); + const s = new Set(["openai", "anthropic", "google"]); for (const p of govOverview?.providers ?? []) { - if (p.name) s.add(p.name); + const norm = p.name ? inferProvider(p.name) : ""; + if (norm && norm !== "unknown") s.add(norm); } for (const l of auditLogs) { - if (l.provider_name) s.add(l.provider_name); + const p = l.provider_name || l.provider; + const norm = p ? inferProvider(p) : inferProvider(l.model_id || l.model || ""); + if (norm && norm !== "unknown") s.add(norm); } return Array.from(s); }, [govOverview?.providers, auditLogs]); @@ -3273,7 +3346,13 @@ function ProviderCard({ if (auditLogs.length === 0) return []; const byProv = new Map>(); for (const l of auditLogs) { - const pName = l.provider_name || inferProvider(l.model_id); + const rawProv = (l.provider_name || l.provider || "").trim(); + const mid = (l.model_id || l.model || "").trim(); + const inferred = + inferProvider(rawProv) !== "unknown" + ? inferProvider(rawProv) + : inferProvider(mid); + const pName = inferred !== "unknown" ? inferred : "custom"; const list = byProv.get(pName) ?? []; const val = metric === "cost" @@ -3298,7 +3377,9 @@ function ProviderCard({ const series = rawSeries.filter( (s) => - !provider || inferProvider(s.name) === provider || s.name === provider, + s.name && + s.name !== "unknown" && + (!provider || inferProvider(s.name) === provider || s.name === provider), ); const available = (data?.available ?? true) || auditSeries.length > 0; const colors = series.map((s, i) => { diff --git a/frontend-v2/src/types/kubernetes.ts b/frontend-v2/src/types/kubernetes.ts index 719498c4..6ab37b0e 100644 --- a/frontend-v2/src/types/kubernetes.ts +++ b/frontend-v2/src/types/kubernetes.ts @@ -103,6 +103,7 @@ export interface K8sCluster { status: string; version?: string; project_id: number; + node_count?: number | null; last_synced_at?: string; created_at?: string; updated_at?: string; diff --git a/frontend-v2/src/types/llm-observability.ts b/frontend-v2/src/types/llm-observability.ts index 405e6323..c922d003 100644 --- a/frontend-v2/src/types/llm-observability.ts +++ b/frontend-v2/src/types/llm-observability.ts @@ -186,6 +186,7 @@ export interface DssmOrganization { id: string; name: string; cluster_id: number; + cluster_name?: string | null; tenant_ref: string; monthly_budget_usd: number; current_spend_usd: number; @@ -200,6 +201,7 @@ export interface DssmTeam { org_id: string; org_name: string; cluster_id: number; + cluster_name?: string | null; monthly_budget_usd: number; current_spend_usd: number; rpm_limit: number; @@ -216,6 +218,8 @@ export interface DssmPrincipal { org_id: string; org_name?: string; cluster_id: number; + cluster_name?: string | null; + monthly_budget_usd?: number; rpm_limit: number; tpm_limit: number; current_spend_usd?: number; @@ -233,6 +237,7 @@ export interface DssmVirtualKey { team_name: string; org_name: string; cluster_id: number; + cluster_name?: string | null; allowed_models: string[]; rpm_limit: number; tpm_limit: number;