1import{p as O,r as L,u as T,j as e,L as E}from"./react-vendor-CSsSSEML.js";import{S as b}from"./StatCard-Gdh9hhJb.js";import{C as D}from"./Card-BaivSs1M.js";import{a4 as M,a5 as S,a6 as $,S as I,r as h,a7 as B}from"./index-BVsjb7mB.js";import{E as W}from"./ErrorState-CE1mnLGb.js";import{L as K}from"./LiveBadge-Dqdxs81d.js";import{E as z}from"./EventDetailDrawer-7uPZB0fc.js";import{R as A}from"./RecommendationDetailDrawer-h1NGSiGJ.js";import"./InfoTooltip-riKjpznF.js";import"./tanstack-vendor-D2LStv3_.js";import"./sentry-vendor-DQkRq1-W.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"33b2f1a2eb67da61a8a79f4c3c0fca45c630c2e5"};var d=new t.Error().stack;d&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[d]="b3a8593d-0dc4-4112-a622-d0986e5d085e",t._sentryDebugIdIdentifier="sentry-dbid-b3a8593d-0dc4-4112-a622-d0986e5d085e")}catch{}})();const F=e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]}),H=e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("circle",{cx:"12",cy:"16",r:"0.5",fill:"currentColor"})]}),_=e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),Q=e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})});function N({title:t,items:d=[],severity:i="warning",emptyMessage:l,onItemClick:x}){const m=i==="danger"?"border-l-danger-500":"border-l-warning-500",p=i==="danger"?"bg-danger-500":"bg-warning-500";return e.jsxs(D,{className:`!p-0 border-l-[3px] ${m}`,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${p}`}),e.jsx("h3",{className:"text-[13px] font-semibold text-text-primary",children:t})]}),e.jsx(h,{variant:i,size:"sm",children:d.length})]}),e.jsx("div",{className:"px-4 py-3",children:d.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:l}):e.jsx("div",{className:"space-y-2 max-h-52 overflow-y-auto",children:d.map((a,o)=>{const j=typeof x=="function",u=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-medium text-text-primary",children:a.name||a.Name}),(a.namespace||a.Namespace)&&e.jsx("span",{className:"text-text-muted text-[10px]",children:a.namespace||a.Namespace})]}),(a.message||a.Message)&&e.jsx("p",{className:"text-text-muted mt-0.5 line-clamp-1 text-[11px]",children:a.message||a.Message})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[(a.restarts>0||a.Restarts>0)&&e.jsxs("span",{className:"text-[10px] font-medium text-danger-500",children:[a.restarts||a.Restarts,"x"]}),a.ready!=null&&a.desired!=null&&e.jsxs("span",{className:"text-[10px] text-text-muted font-mono",children:[a.ready,"/",a.desired]})]})]});return j?e.jsx("button",{type:"button",onClick:()=>x(a),className:"w-full text-left flex items-start gap-2 text-xs py-1.5 border-b border-border/50 last:border-0 rounded px-1 -mx-1 hover:bg-surface-tertiary/60 cursor-pointer transition-colors",children:u},o):e.jsx("div",{className:"flex items-start gap-2 text-xs py-1.5 border-b border-border/50 last:border-0",children:u},o)})})})]})}function U({event:t,onClick:d}){const i=t.reason||t.Reason||"",l=["BackOff","Failed","FailedScheduling","OOMKilling","Unhealthy"].some(x=>i.includes(x));return e.jsxs("button",{type:"button",onClick:d,className:`w-full text-left flex items-start gap-2.5 py-2 px-3 rounded-lg text-xs border transition-colors cursor-pointer hover:shadow-sm ${l?"bg-danger-400/5 border-danger-400/20 hover:bg-danger-400/10":"bg-warning-400/5 border-warning-400/20 hover:bg-warning-400/10"}`,children:[e.jsx(h,{variant:l?"danger":"warning",size:"sm",children:i}),(t.count||t.Count)>1&&e.jsxs("span",{className:"shrink-0 text-text-muted font-mono mt-0.5",children:["x",t.count||t.Count]}),e.jsx("span",{className:"text-text-secondary flex-1 line-clamp-2 leading-relaxed",children:t.message||t.Message})]})}function P(t){const d=t.lastTimestamp||t.LastTimestamp||t.firstTimestamp||t.FirstTimestamp||"";if(!d)return 0;const i=new Date(d).getTime();return Number.isNaN(i)?0:i}function V(t,d,i){const l=t?.items??[],x=d?.items??[],m=i?.items??[],p=l.length,a=l.filter(s=>s.status==="Running"||s.Status==="Running").length,o=l.filter(s=>(s.status||s.Status)==="Failed"?!0:(s.containers??s.Containers??[]).some(n=>{const c=n.stateReason||n.StateReason||"";return c==="CrashLoopBackOff"||c==="OOMKilled"||c==="Error"&&(n.restartCount??n.RestartCount??0)>0})).length,j=l.reduce((s,r)=>s+(r.restarts??r.Restarts??0),0),u=x.length,w=x.filter(s=>{const r=s.readyReplicas??s.ReadyReplicas??0,n=s.replicas??s.Replicas??0;return n>0&&r>=n}).length,R=l.filter(s=>(s.containers??s.Containers??[]).some(r=>{const n=r.stateReason||r.StateReason||"",c=r.restartCount??r.RestartCount??0;return n==="CrashLoopBackOff"||n==="Error"&&c>0||!r.ready&&c>=3})).map(s=>{const r=Math.max(0,...(s.containers??s.Containers??[]).map(n=>n.restartCount??n.RestartCount??0));return{name:s.name||s.Name,namespace:s.namespace||s.Namespace,restarts:r}}),y=l.filter(s=>(s.containers??s.Containers??[]).some(r=>{const n=r.stateReason||r.StateReason||"",c=r.lastTerminationReason||r.LastTerminationReason||"";return n==="OOMKilled"||c==="OOMKilled"})).map(s=>{const r=Math.max(0,...(s.containers??s.Containers??[]).map(n=>n.restartCount??n.RestartCount??0));return{name:s.name||s.Name,namespace:s.namespace||s.Namespace,restarts:r}}),k=Date.now()-300*1e3,C=l.filter(s=>{const r=s.status||s.Status,n=new Date(s.creationTime||s.CreationTime).getTime();return r==="Pending"&&n<k}),v=x.filter(s=>{const r=s.readyReplicas??s.ReadyReplicas??0,n=s.replicas??s.Replicas??0;return n>0&&r<n}).map(s=>({name:s.name||s.Name,namespace:s.namespace||s.Namespace,kind:"Deployment",ready:s.readyReplicas??s.ReadyReplicas??0,desired:s.replicas??s.Replicas??0})),g=m.filter(s=>(s.type||s.Type)==="Warning").sort((s,r)=>P(r)-P(s));return{totalPods:p,runningPods:a,failedPods:o,totalRestarts:j,totalDeployments:u,healthyDeployments:w,crashLoopPods:R,oomKilledPods:y,pendingPods:C,unconvergedWorkloads:v,warningEvents:g}}function oe(){const{clusterResId:t,cluster:d}=O(),i=M(t,"pod","all"),l=M(t,"deployment","all"),x=S(t,"all",{limit:500}),m=i.isLoading||l.isLoading,p=i.isError&&l.isError,a=i.error||l.error,o=L.useMemo(()=>V(i.data,l.data,x.data),[i.data,l.data,x.data]),{items:j,isError:u,isLoading:w}=$(d),[R,y]=L.useState(null),[k,C]=L.useState(null),v=T(),g=window.location.pathname.match(/\/k8s\/clusters\/([^/]+)/)?.[1],s=c=>{if(!g)return;const f=c.namespace||c.Namespace||"";v(`/k8s/clusters/${g}/pods${f?`?ns=${f}`:""}`)},r=c=>{if(!g)return;const f=c.namespace||c.Namespace||"";v(`/k8s/clusters/${g}/deployments${f?`?ns=${f}`:""}`)},n=o.crashLoopPods.length+o.oomKilledPods.length+o.pendingPods.length+o.unconvergedWorkloads.length;return m?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(I,{})}):p?e.jsx(W,{error:a,onRetry:()=>{i.refetch(),l.refetch()}}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:"Overview"}),e.jsxs("div",{className:"flex items-center gap-2",children:[n>0?e.jsxs(h,{variant:"warning",children:[n," issues"]}):e.jsx(h,{variant:"success",children:"Everything healthy"}),e.jsx(K,{})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(b,{label:"Running Pods",value:`${o.runningPods} / ${o.totalPods}`,icon:F}),e.jsx(b,{label:"Failed Pods",value:o.failedPods,icon:H}),e.jsx(b,{label:"Healthy Deployments",value:`${o.healthyDeployments} / ${o.totalDeployments}`,icon:_}),e.jsx(b,{label:"Total Restarts",value:o.totalRestarts,icon:Q})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsx(N,{title:"CrashLoopBackOff",items:o.crashLoopPods,severity:"danger",emptyMessage:"No issues",onItemClick:s}),e.jsx(N,{title:"OOMKilled (last hour)",items:o.oomKilledPods,severity:"danger",emptyMessage:"No issues",onItemClick:s}),e.jsx(N,{title:"Pending > 5 min",items:o.pendingPods,severity:"warning",emptyMessage:"No issues",onItemClick:s})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(N,{title:"Workloads not converged",items:o.unconvergedWorkloads,severity:"warning",emptyMessage:"No issues",onItemClick:r}),e.jsxs(D,{className:"!p-0 border-l-[3px] border-l-warning-500",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-warning-500"}),e.jsx("h3",{className:"text-[13px] font-semibold text-text-primary",children:"Recent warning events"})]}),e.jsx(h,{variant:"warning",size:"sm",children:o.warningEvents.length})]}),e.jsx("div",{className:"px-4 py-3 space-y-2 max-h-80 overflow-y-auto",children:o.warningEvents.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:"No warning events"}):o.warningEvents.map((c,f)=>e.jsx(U,{event:c,onClick:()=>y(c)},f))})]})]}),e.jsx(Y,{recs:j,clusterId:g,isError:u,isLoading:w}),e.jsx(z,{event:R,onClose:()=>y(null)}),e.jsx(A,{rec:k,onClose:()=>C(null)})]})}function Y({recs:t,clusterId:d,isError:i,isLoading:l}){const x=Array.isArray(t)?t:[],m={high:0,medium:0,low:0};for(const o of x){const u=B(o?.situation?.rule_type)?.severity??"unknown";m[u]!=null&&(m[u]+=1)}const p=m.high+m.medium,a=d?`/k8s/clusters/${d}/recommendations`:"#";return l?e.jsx("div",{className:"rounded-lg border border-border bg-surface overflow-hidden","data-testid":"recs-teaser-loading",children:e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-surface-tertiary"}),e.jsx("h3",{className:"text-[13px] font-semibold text-text-primary",children:"Recommendations"})]}),e.jsx("div",{className:"h-4 w-40 rounded bg-surface-tertiary animate-pulse"}),e.jsx("div",{className:"ml-auto h-4 w-20 rounded bg-surface-tertiary animate-pulse"})]})}):i?e.jsx(E,{to:a,className:"block rounded-lg border border-border bg-surface hover:border-text-primary/30 hover:shadow-sm transition-all overflow-hidden group","data-testid":"recs-teaser-error",children:e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-warning-500"}),e.jsx("h3",{className:"text-[13px] font-semibold text-text-primary",children:"Recommendations"})]}
1),e.jsx("span",{className:"text-xs text-warning-600 dark:text-warning-400",children:"Couldn't load recommendations â refresh to retry"}),e.jsx("span",{className:"ml-auto text-xs text-text-secondary group-hover:text-text-primary font-medium",children:"Open page â"})]})}):e.jsx(E,{to:a,className:"block rounded-lg border border-border bg-surface hover:border-text-primary/30 hover:shadow-sm transition-all overflow-hidden group",children:e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-primary-500"}),e.jsx("h3",{className:"text-[13px] font-semibold text-text-primary",children:"Recommendations"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.high>0&&e.jsxs(h,{variant:"danger",size:"sm",children:[m.high," High"]}),m.medium>0&&e.jsxs(h,{variant:"warning",size:"sm",children:[m.medium," Medium"]}),m.low>0&&e.jsxs(h,{variant:"neutral",size:"sm",children:[m.low," Low"]}),x.length===0&&e.jsx("span",{className:"text-xs text-text-muted",children:"No active recommendations"})]}),e.jsx("span",{className:"ml-auto text-xs text-text-secondary group-hover:text-text-primary font-medium",children:x.length>0?p>0?`${p} need attention â`:"View all â":"Open page â"})]})})}export{Y as RecommendationsTeaser,oe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.