"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4679],{49984:(te,A,n)=>{n.r(A),n.d(A,{RuleViewer:()=>pe,default:()=>rt});var r=n(60234),$=n(20964),e=n(65237),B=n(47153),U=n(21677),L=n(81859),N=n(66917),V=n(49784),p=n(93048),v=n(88347),R=n(16693),Q=n(6741),z=n(48389),m=n(6335),E=n(60822),b=n(67262),h=n(22193),j=n(72254),T=n(75005),D=n(89949),I=n(66434),Z=n(15498),H=n(29586),P=n(29272),Y=n(50559),fe=n(69344),ve=n(55925),ae=n(79432),ye=n(31667),xe=n(51031),Re=n(89894),he=n(73383),Ce=n(18800),$e=n(3315),re=n(98401),Ne=n(35467),De=n(13378);const le=4;function Pe({data:t,refId:a,model:l,datasourceUid:c,relativeTimeRange:o,onTimeRangeChange:i,className:g}){const d=(0,p.l4)(),s=(0,p.wW)(be),u=(0,H.j)(l)?re.Fe:re.GC,[f,y]=(0,e.useState)(u),w=(0,xe.F)().getInstanceSettings(c),[C,F]=(0,e.useState)({frameIndex:0,showHeader:!0}),W=(0,e.useCallback)(O=>{const S=(0,ae.CQ)().unix()-O.unix();if(o){const K=o.from-o.to;i({from:S+K,to:S})}},[i,o]),_=(0,e.useCallback)(O=>O===0?(0,ae.CQ)():(0,ae.CQ)().subtract(O,"seconds"),[]);return t?w?e.createElement("div",{className:(0,r.cx)(s.content,g)},e.createElement(ve.Z,null,({width:O,height:S})=>e.createElement("div",{style:{width:O,height:S}},e.createElement("div",{className:s.header},e.createElement("div",{className:s.actions},!(0,H.j)(l)&&o?e.createElement(Ce.x,{date:_(o.to),onChange:W,maxDate:new Date}):null,e.createElement(De.j,{onChange:y,value:f,size:"md"}),e.createElement(Ne.q,{actions:[$e.AccessControlAction.DataSourcesExplore]},!(0,H.j)(l)&&e.createElement(e.Fragment,null,e.createElement("div",{className:s.spacing}),e.createElement(z.Qj,{size:"md",variant:"secondary",icon:"compass",target:"_blank",href:Me(w,l)},"View in Explore"))))),e.createElement(Re.$,{height:S-d.spacing.gridSize*le,width:O,data:t,pluginId:f,title:"",onOptionsChange:F,options:C})))):e.createElement("div",{className:(0,r.cx)(s.content,g)},e.createElement(v.b,{title:"Could not find datasource for query"}),e.createElement(he.p,{width:"100%",height:"250px",language:"json",showLineNumbers:!1,showMiniMap:!1,value:JSON.stringify(l,null,"	"),readOnly:!0})):null}function Me(t,a){const{name:l}=t,{refId:c,...o}=a;return ye.Cj.renderUrl(`${V.v.appSubUrl}/explore`,{left:JSON.stringify({datasource:l,queries:[{refId:"A",...o}],range:{from:"now-1h",to:"now"}})})}const be=t=>({content:r.css`
      width: 100%;
      height: 250px;
    `,header:r.css`
      height: ${t.spacing(le)};
      display: flex;
      align-items: center;
      justify-content: flex-end;
      white-space: nowrap;
    `,refId:r.css`
      font-weight: ${t.typography.fontWeightMedium};
      color: ${t.colors.text.link};
      overflow: hidden;
    `,dataSource:r.css`
      margin-left: ${t.spacing(1)};
      font-style: italic;
      color: ${t.colors.text.secondary};
    `,actions:r.css`
      display: flex;
      align-items: center;
    `,spacing:r.css`
      padding: ${t.spacing(0,1,0,0)};
    `,errorMessage:r.css`
      white-space: pre-wrap;
    `});function Te({queries:t,condition:a,evalDataByQuery:l={},evalTimeRanges:c={},onTimeRangeChange:o}){const i=(0,D.keyBy)(Object.values(V.v.datasources),u=>u.uid),g=t.filter(u=>!(0,H.j)(u.model)),d=t.filter(u=>(0,H.j)(u.model)),s=(0,p.wW)(ne);return e.createElement(N.Stack,{gap:2,direction:"column"},e.createElement("div",{className:s.maxWidthContainer},e.createElement(N.Stack,{gap:2},g.map(({model:u,relativeTimeRange:f,refId:y,datasourceUid:w},C)=>{const F=i[w];return e.createElement(oe,{key:C,refId:y,isAlertCondition:a===y,model:u,relativeTimeRange:f,evalTimeRange:c[y],dataSource:F,queryData:l[y],onEvalTimeRangeChange:W=>o(y,W)})}))),e.createElement("div",{className:s.maxWidthContainer},e.createElement(N.Stack,{gap:1},d.map(({model:u,refId:f,datasourceUid:y},w)=>{const C=i[y];return(0,H.j)(u)&&e.createElement(Oe,{key:w,refId:f,isAlertCondition:a===f,model:u,dataSource:C,evalData:l[f]})}))))}function oe({refId:t,relativeTimeRange:a,model:l,dataSource:c,queryData:o,evalTimeRange:i,onEvalTimeRangeChange:g}){const d=(0,p.wW)(Ie),s=[c?.name??"[[Data source not found]]"];return a&&s.push((0,Z.C_)(a).display),e.createElement(ce,{refId:t,headerItems:s,className:d.contentBox},e.createElement("pre",{className:d.code},e.createElement("code",null,(0,T.$w)(l))),c&&e.createElement(Pe,{refId:t,datasourceUid:c.uid,model:l,data:o,relativeTimeRange:i,onTimeRangeChange:g,className:d.visualization}))}const Ie=t=>({code:r.css`
    margin: ${t.spacing(1)};
  `,contentBox:r.css`
    flex: 1 0 100%; // RuleViewerVisualization uses AutoSizer which doesn't expand the box
  `,visualization:r.css`
    padding: ${t.spacing(1)};
  `});function Oe({refId:t,model:a,evalData:l,isAlertCondition:c}){function o(){switch(a.type){case P.Us.math:return e.createElement(Qe,{model:a});case P.Us.reduce:return e.createElement(Ae,{model:a});case P.Us.resample:return e.createElement(Ue,{model:a});case P.Us.classic:return e.createElement(we,{model:a});case P.Us.threshold:return e.createElement(Ve,{model:a});default:return e.createElement(e.Fragment,null,"Expression not supported: ",a.type)}}return e.createElement(ce,{refId:t,headerItems:[(0,D.startCase)(a.type)],isAlertCondition:c},o(),l&&e.createElement(fe.bw,{series:l.series,isAlertCondition:c}))}function ce({refId:t,headerItems:a=[],children:l,isAlertCondition:c,className:o}){const i=(0,p.wW)(Se);return e.createElement("div",{className:(0,r.cx)(i.container,o)},e.createElement("header",{className:i.header},e.createElement("span",{className:i.refId},t),a.map((g,d)=>e.createElement("span",{key:d,className:i.textBlock},g)),c&&e.createElement("div",{className:i.conditionIndicator},e.createElement(I.C,{color:"green",icon:"check",text:"Alert condition"}))),l)}const Se=t=>({container:r.css`
    flex: 1 0 25%;
    border: 1px solid ${t.colors.border.strong};
    max-width: 100%;
  `,header:r.css`
    display: flex;
    align-items: center;
    gap: ${t.spacing(1)};
    padding: ${t.spacing(1)};
    background-color: ${t.colors.background.secondary};
  `,textBlock:r.css`
    border: 1px solid ${t.colors.border.weak};
    padding: ${t.spacing(.5,1)};
    background-color: ${t.colors.background.primary};
  `,refId:r.css`
    color: ${t.colors.text.link};
    padding: ${t.spacing(.5,1)};
    border: 1px solid ${t.colors.border.weak};
  `,conditionIndicator:r.css`
    margin-left: auto;
  `});function we({model:t}){const a=(0,p.wW)(We),l=(0,D.keyBy)(Y.Z.reducerTypes,i=>i.value),c=(0,D.keyBy)(Y.Z.evalOperators,i=>i.value),o=(0,D.keyBy)(Y.Z.evalFunctions,i=>i.value);return e.createElement("div",{className:a.container},t.conditions?.map(({query:i,operator:g,reducer:d,evaluator:s},u)=>{const f=ie(s);return e.createElement(e.Fragment,{key:u},e.createElement("div",{className:a.blue},u===0?"WHEN":!!g?.type&&c[g?.type]?.text),e.createElement("div",{className:a.bold},d?.type&&l[d.type]?.text),e.createElement("div",{className:a.blue},"OF"),e.createElement("div",{className:a.bold},i.params[0]),e.createElement("div",{className:a.blue},o[s.type].text),e.createElement("div",{className:a.bold},f?`(${s.params[0]}; ${s.params[1]})`:s.params[0]))}))}const We=t=>({container:r.css`
    padding: ${t.spacing(1)};
    display: grid;
    grid-template-columns: max-content max-content max-content max-content max-content max-content;
    gap: ${t.spacing(0,1)};
  `,...q(t)});function Ae({model:t}){const a=(0,p.wW)(Be),{reducer:l,expression:c,settings:o}=t,i=P.SQ.find(s=>s.value===l),g=o?.mode??P.kN.Strict,d=P.YM.find(s=>s.value===g);return e.createElement("div",{className:a.container},e.createElement("div",{className:a.label},"Function"),e.createElement("div",{className:a.value},i?.label),e.createElement("div",{className:a.label},"Input"),e.createElement("div",{className:a.value},c),e.createElement("div",{className:a.label},"Mode"),e.createElement("div",{className:a.value},d?.label))}const Be=t=>({container:r.css`
    padding: ${t.spacing(1)};
    display: grid;
    gap: ${t.spacing(1)};
    grid-template-rows: 1fr 1fr;
    grid-template-columns: 1fr 1fr 1fr 1fr;

    > :nth-child(6) {
      grid-column: span 3;
    }
  `,...q(t)});function Ue({model:t}){const a=(0,p.wW)(Le),{expression:l,window:c,downsampler:o,upsampler:i}=t,g=P.Fr.find(s=>s.value===o),d=P.r8.find(s=>s.value===i);return e.createElement("div",{className:a.container},e.createElement("div",{className:a.label},"Input"),e.createElement("div",{className:a.value},l),e.createElement("div",{className:a.label},"Resample to"),e.createElement("div",{className:a.value},c),e.createElement("div",{className:a.label},"Downsample"),e.createElement("div",{className:a.value},g?.label),e.createElement("div",{className:a.label},"Upsample"),e.createElement("div",{className:a.value},d?.label))}const Le=t=>({container:r.css`
    padding: ${t.spacing(1)};
    display: grid;
    gap: ${t.spacing(1)};
    grid-template-columns: 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
  `,...q(t)});function Ve({model:t}){const a=(0,p.wW)(ne),{expression:l,conditions:c}=t,o=c&&c[0]?.evaluator,i=P.Mi.find(d=>d.value===o?.type),g=o?ie(o):!1;return e.createElement("div",{className:a.container},e.createElement("div",{className:a.label},"Input"),e.createElement("div",{className:a.value},l),o&&e.createElement(e.Fragment,null,e.createElement("div",{className:a.blue},i?.label),e.createElement("div",{className:a.bold},g?`(${o.params[0]}; ${o.params[1]})`:o.params[0])))}const ne=t=>{const{blue:a,bold:l,...c}=q(t);return{...c,maxWidthContainer:r.css`
      max-width: 100%;
    `,container:r.css`
      padding: ${t.spacing(1)};
      display: flex;
      gap: ${t.spacing(1)};
    `,blue:r.css`
      ${a};
      margin: auto 0;
    `,bold:r.css`
      ${l};
      margin: auto 0;
    `}};function Qe({model:t}){const a=(0,p.wW)(ne),{expression:l}=t;return e.createElement("div",{className:a.container},e.createElement("div",{className:a.label},"Input"),e.createElement("div",{className:a.value},l))}const q=t=>({blue:r.css`
    color: ${t.colors.text.link};
  `,bold:r.css`
    font-weight: ${t.typography.fontWeightBold};
  `,label:r.css`
    display: flex;
    align-items: center;
    padding: ${t.spacing(.5,1)};
    background-color: ${t.colors.background.secondary};
    font-size: ${t.typography.bodySmall.fontSize};
    line-height: ${t.typography.bodySmall.lineHeight};
    font-weight: ${t.typography.fontWeightBold};
  `,value:r.css`
    padding: ${t.spacing(.5,1)};
    border: 1px solid ${t.colors.border.weak};
  `});function ie(t){return t.type===Y.$.IsWithinRange||t.type===Y.$.IsOutsideRange}var ze=n(75065),X=n(45201),de=n(89745),G=n(55660),je=n(78906),Fe=n(24923),Ke=n(41595),Ze=n(89314);const He=({group:t})=>{const a=t.source_tenants??[];return e.createElement(X.C,{label:"Tenant sources"},e.createElement(e.Fragment,null,a.map(l=>e.createElement("div",{key:l},l))))};var Ge=n(95849),Je=n(31336),Ye=n(60963),Xe=n(61323),ke=n(21752),qe=n(30241),_e=n(2303),se=n(50328),J=n(2605);function ue(t){if(!t)return[];const{namespace:a,rulerRule:l}=t,{rulesSource:c}=a;if((0,se.HY)(c)&&(0,J.Pc)(l))return l.grafana_alert.data;if((0,se.jq)(c)){const o=tt(c,t);return[et(o,c.uid)]}return[]}function et(t,a){return{refId:t.refId,datasourceUid:a,queryType:"",model:t,relativeTimeRange:{from:360,to:0}}}function tt(t,a){const l="A";switch(t.type){case"prometheus":return{refId:l,expr:a.query};case"loki":return{refId:l,expr:a.query};default:throw new Error(`Query for datasource type ${t.type} is currently not supported by cloud alert rules.`)}}var at=n(92145);const me="Could not find data source for rule",ge="Could not view rule",k="View rule";function pe({match:t}){const a=(0,p.wW)(Ee),[l,c]=(0,B.Z)(!1),{id:o}=t.params,i=at.OA(o,!0),{loading:g,error:d,result:s}=(0,ke.H)(i,i?.ruleSourceName),u=(0,e.useMemo)(()=>new qe.v,[]),f=(0,U.Z)(u.get()),y=(0,e.useMemo)(()=>ue(s),[s]),w=(0,_e.$9)(s?.annotations||{}),[C,F]=(0,e.useState)({}),{allDataSourcesAvailable:W}=(0,Xe.S)(y),_=(0,e.useCallback)(()=>{if(y.length>0&&W){const x=y.map(M=>({...M,relativeTimeRange:C[M.refId]??M.relativeTimeRange}));u.run(x)}},[y,C,u,W]);(0,e.useEffect)(()=>{const x=ue(s),M=Object.fromEntries(x.map(ee=>[ee.refId,ee.relativeTimeRange??{from:0,to:0}]));F(M)},[s]),(0,e.useEffect)(()=>{W&&l&&_()},[_,W,l]),(0,e.useEffect)(()=>()=>u.destroy(),[u]);const O=(0,e.useCallback)((x,M)=>{const ee=(0,$.ZP)(C,ot=>{ot[x]=M});F(ee)},[C,F]);if(!i?.ruleSourceName)return e.createElement(G.$,{title:k},e.createElement(v.b,{title:ge},e.createElement("details",{className:a.errorMessage},me)));const S=(0,se.o_)(i.ruleSourceName);if(g)return e.createElement(G.$,{title:k},e.createElement(R.u,{text:"Loading rule..."}));if(d||!S)return e.createElement(G.$,{title:k},e.createElement(v.b,{title:ge},e.createElement("details",{className:a.errorMessage},d?.message??me,e.createElement("br",null),!!d?.stack&&d.stack)));if(!s)return e.createElement(G.$,{title:k},e.createElement("span",null,"Rule could not be found."));const K=(0,J.Jq)(s.group),lt=(0,J.Pc)(s.rulerRule)&&Boolean(s.rulerRule.grafana_alert.provenance);return e.createElement(G.$,{wrapInContent:!1,title:k},K&&e.createElement(v.b,{severity:"info",title:"This rule is part of a federated rule group."},e.createElement(Q.wc,null,"Federated rule groups are currently an experimental feature.",e.createElement(z.zx,{fill:"text",icon:"book"},e.createElement("a",{href:"https://grafana.com/docs/metrics-enterprise/latest/tenant-management/tenant-federation/#cross-tenant-alerting-and-recording-rule-federation"},"Read documentation")))),lt&&e.createElement(de.Xq,{resource:de.Uv.AlertRule}),e.createElement(G.l,null,e.createElement("div",null,e.createElement(N.Stack,{direction:"row",alignItems:"center",wrap:!1,gap:1},e.createElement(m.J,{name:"bell",size:"lg"})," ",e.createElement("span",{className:a.title},s.name)),e.createElement(Ye.p,{rule:s,isCreating:!1,isDeleting:!1}),e.createElement(je.f,{rule:s,rulesSource:S,isViewMode:!0})),e.createElement("div",{className:a.details},e.createElement("div",{className:a.leftSide},s.promRule&&e.createElement(X.C,{label:"Health",horizontal:!0},e.createElement(Je.V,{rule:s.promRule})),!!s.labels&&!!Object.keys(s.labels).length&&e.createElement(X.C,{label:"Labels",horizontal:!0},e.createElement(ze.s,{labels:s.labels,className:a.labels})),e.createElement(Ze.C,{rulesSource:S,rule:s,annotations:w}),e.createElement(Fe.J,{annotations:w})),e.createElement("div",{className:a.rightSide},e.createElement(Ke.C,{rule:s,rulesSource:S}),K&&e.createElement(He,{group:s.group}),e.createElement(X.C,{label:"Namespace / Group",className:a.rightSideDetails},s.namespace.name," / ",s.group.name),(0,J.Pc)(s.rulerRule)&&e.createElement(nt,{rule:s.rulerRule.grafana_alert}))),e.createElement("div",null,e.createElement(Ge.M,{rule:s,pagination:{itemsPerPage:j.gN}}))),e.createElement(E.U,{label:"Query & Results",isOpen:l,onToggle:c,loading:f&&st(f),collapsible:!0,className:a.collapse},(0,J.Pc)(s.rulerRule)&&!K&&e.createElement(Te,{condition:s.rulerRule.grafana_alert.condition,queries:y,evalDataByQuery:f,evalTimeRanges:C,onTimeRangeChange:O}),!(0,J.Pc)(s.rulerRule)&&!K&&f&&Object.keys(f).length>0&&e.createElement("div",{className:a.queries},y.map(x=>e.createElement(oe,{key:x.refId,refId:x.refId,model:x.model,dataSource:Object.values(V.v.datasources).find(M=>M.uid===x.datasourceUid),queryData:f[x.refId],relativeTimeRange:x.relativeTimeRange,evalTimeRange:C[x.refId],onEvalTimeRangeChange:M=>O(x.refId,M),isAlertCondition:!1}))),!K&&!W&&e.createElement(v.b,{title:"Query not available",severity:"warning",className:a.queryWarning},"Cannot display the query preview. Some of the data sources used in the queries are not available.")))}function nt({rule:t}){const a=(0,p.wW)(Ee),l=()=>navigator.clipboard&&navigator.clipboard.writeText(t.uid);return e.createElement(X.C,{label:"Rule UID",childrenWrapperClassName:a.ruleUid},t.uid," ",e.createElement(b.h,{name:"copy",onClick:l}))}function st(t){return!!Object.values(t).find(a=>a.state===L.Gu.Loading)}const Ee=t=>({errorMessage:r.css`
      white-space: pre-wrap;
    `,queries:r.css`
      height: 100%;
      width: 100%;
    `,collapse:r.css`
      margin-top: ${t.spacing(2)};
      border-color: ${t.colors.border.weak};
      border-radius: ${t.shape.borderRadius()};
    `,queriesTitle:r.css`
      padding: ${t.spacing(2,.5)};
      font-size: ${t.typography.h5.fontSize};
      font-weight: ${t.typography.fontWeightBold};
      font-family: ${t.typography.h5.fontFamily};
    `,query:r.css`
      border-bottom: 1px solid ${t.colors.border.medium};
      padding: ${t.spacing(2)};
    `,queryWarning:r.css`
      margin: ${t.spacing(4,0)};
    `,title:r.css`
      font-size: ${t.typography.h4.fontSize};
      font-weight: ${t.typography.fontWeightBold};

      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    `,details:r.css`
      display: flex;
      flex-direction: row;
      gap: ${t.spacing(4)};
    `,leftSide:r.css`
      flex: 1;
    `,rightSide:r.css`
      padding-right: ${t.spacing(3)};

      max-width: 360px;
      word-break: break-all;
      overflow: hidden;
    `,rightSideDetails:r.css`
      & > div:first-child {
        width: auto;
      }
    `,labels:r.css`
      justify-content: flex-start;
    `,ruleUid:r.css`
      display: flex;
      align-items: center;
      gap: ${t.spacing(1)};
    `}),rt=(0,h.Pf)(pe,{style:"page"})},35467:(te,A,n)=>{n.d(A,{q:()=>e});var r=n(65237),$=n(96237);const e=({actions:B,children:U,fallback:L=!0})=>B.some(N=>$.Vt.hasAccess(N,L))?r.createElement(r.Fragment,null,U):null},55660:(te,A,n)=>{n.d(A,{$:()=>L,l:()=>N});var r=n(60234),$=n(65237),e=n(93048),B=n(38992);const U={icon:"bell",id:"alert-rule-view",breadcrumbs:[{title:"Alert rules",url:"alerting/list"}]};function L(v){const{wrapInContent:R=!0,children:Q,title:z}=v,m=(0,e.wW)(V);return $.createElement(B.T,{pageNav:{...U,text:z},navId:"alert-list"},$.createElement(B.T.Contents,null,$.createElement("div",{className:m.content},R?$.createElement(N,{...v}):Q)))}function N({children:v,padding:R=2}){const Q=(0,e.wW)(p(R));return $.createElement("div",{className:Q.wrapper},v)}const V=v=>({content:r.css`
      max-width: ${v.breakpoints.values.xxl}px;
    `}),p=v=>R=>({wrapper:r.css`
      background: ${R.colors.background.primary};
      border: 1px solid ${R.colors.border.weak};
      border-radius: ${R.shape.borderRadius()};
      padding: ${R.spacing(v)};
    `})},21752:(te,A,n)=>{n.d(A,{H:()=>v,X:()=>R});var r=n(65237),$=n(15804),e=n(3315),B=n(99997),U=n(84078),L=n(92145),N=n(2605),V=n(15141),p=n(57811);function v(m,E){const b=Q(E),h=(0,V.Zo)(E),j=(0,r.useMemo)(()=>{if(!(!m||!E||h.length===0))for(const T of h)for(const D of T.groups)for(const I of D.rules){const Z=L.Yd(E,I);if(L.Dg(Z,m))return I}},[m,E,h]);return{...b,result:j}}function R(m,E){const b=Q(E),h=(0,V.Zo)(E),j=(0,r.useMemo)(()=>{if(!m||!E||h.length===0)return[];const T=[];for(const D of h)for(const I of D.groups)for(const Z of I.rules)Z.name===m&&T.push(Z);return T},[m,E,h]);return{...b,result:j}}function Q(m){const E=(0,e.useDispatch)(),b=(0,p._)(I=>I.promRules),h=z(m,b),j=(0,p._)(I=>I.rulerRules),T=z(m,j),{loading:D}=(0,$.Z)(async()=>{m&&await E((0,B.dn)({rulesSourceName:m}))},[E,m]);return{loading:D,error:h.error??(0,N.m$)(T)?void 0:T.error,dispatched:h.dispatched&&T.dispatched}}function z(m,E){if(!m)return U.oq;const b=E[m];return b||U.oq}}}]);

//# sourceMappingURL=AlertingRule.28cee77d3d22036d64f5.js.map