"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4679],{77110:(te,U,n)=>{n.r(U),n.d(U,{RuleViewer:()=>pe,default:()=>st});var r=n(52423),P=n(64421),e=n(68404),w=n(86253),L=n(3499),V=n(49922),b=n(35645),p=n(72648),O=n(45253),C=n(61744),$=n(52081),S=n(31403),z=n(39904),m=n(2352),E=n(8180),T=n(53546),N=n(84952),j=n(20091),R=n(82897),W=n(26418),I=n(19985),K=n(25482),Z=n(75e3),M=n(97573),Y=n(67162),fe=n(76726),ve=n(89050),ae=n(46519),ye=n(27677),Re=n(86647),xe=n(98825),he=n(9405),Ce=n(35575),$e=n(81168),re=n(37190),Ne=n(51981),De=n(74542);const le=4;function Pe({data:t,refId:a,model:l,datasourceUid:c,relativeTimeRange:o,onTimeRangeChange:i,className:g}){const u=(0,p.l4)(),s=(0,p.wW)(be),d=(0,Z.j)(l)?re.Fe:re.GC,[f,v]=(0,e.useState)(d),x=(0,Re.F)().getInstanceSettings(c),[A,B]=(0,e.useState)({frameIndex:0,showHeader:!0}),J=(0,e.useCallback)(D=>{const Q=(0,ae.CQ)().unix()-D.unix();if(o){const F=o.from-o.to;i({from:Q+F,to:Q})}},[i,o]),_=(0,e.useCallback)(D=>D===0?(0,ae.CQ)():(0,ae.CQ)().subtract(D,"seconds"),[]);return t?x?e.createElement("div",{className:(0,r.cx)(s.content,g)},e.createElement(ve.Z,null,({width:D,height:Q})=>e.createElement("div",{style:{width:D,height:Q}},e.createElement("div",{className:s.header},e.createElement("div",{className:s.actions},!(0,Z.j)(l)&&o?e.createElement(Ce.x,{date:_(o.to),onChange:J,maxDate:new Date}):null,e.createElement(De.j,{onChange:v,value:f,size:"md"}),e.createElement(Ne.q,{actions:[$e.AccessControlAction.DataSourcesExplore]},!(0,Z.j)(l)&&e.createElement(e.Fragment,null,e.createElement("div",{className:s.spacing}),e.createElement(S.Qj,{size:"md",variant:"secondary",icon:"compass",target:"_blank",href:Me(x,l)},"View in Explore"))))),e.createElement(xe.$,{height:Q-u.spacing.gridSize*le,width:D,data:t,pluginId:f,title:"",onOptionsChange:B,options:A})))):e.createElement("div",{className:(0,r.cx)(s.content,g)},e.createElement(O.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(`${b.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 Oe({queries:t,condition:a,evalDataByQuery:l={},evalTimeRanges:c={},onTimeRangeChange:o}){const i=(0,R.keyBy)(Object.values(b.v.datasources),d=>d.uid),g=t.filter(d=>!(0,Z.j)(d.model)),u=t.filter(d=>(0,Z.j)(d.model)),s=(0,p.wW)(ne);return e.createElement(W.Stack,{gap:2,direction:"column"},e.createElement("div",{className:s.maxWidthContainer},e.createElement(W.Stack,{gap:2},g.map(({model:d,relativeTimeRange:f,refId:v,datasourceUid:x},A)=>{const B=i[x];return e.createElement(oe,{key:A,refId:v,isAlertCondition:a===v,model:d,relativeTimeRange:f,evalTimeRange:c[v],dataSource:B,queryData:l[v],onEvalTimeRangeChange:J=>o(v,J)})}))),e.createElement("div",{className:s.maxWidthContainer},e.createElement(W.Stack,{gap:1},u.map(({model:d,refId:f,datasourceUid:v},x)=>{const A=i[v];return(0,Z.j)(d)&&e.createElement(Ie,{key:x,refId:f,isAlertCondition:a===f,model:d,dataSource:A,evalData:l[f]})}))))}function oe({refId:t,relativeTimeRange:a,model:l,dataSource:c,queryData:o,evalTimeRange:i,onEvalTimeRangeChange:g}){const u=(0,p.wW)(Te),s=[c?.name??"[[Data source not found]]"];return a&&s.push((0,K.C_)(a).display),e.createElement(ce,{refId:t,headerItems:s,className:u.contentBox},e.createElement("pre",{className:u.code},e.createElement("code",null,(0,j.$w)(l))),c&&e.createElement(Pe,{refId:t,datasourceUid:c.uid,model:l,data:o,relativeTimeRange:i,onTimeRangeChange:g,className:u.visualization}))}const Te=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 Ie({refId:t,model:a,evalData:l,isAlertCondition:c}){function o(){switch(a.type){case M.Us.math:return e.createElement(Qe,{model:a});case M.Us.reduce:return e.createElement(Be,{model:a});case M.Us.resample:return e.createElement(we,{model:a});case M.Us.classic:return e.createElement(We,{model:a});case M.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,R.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,u)=>e.createElement("span",{key:u,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)(Ae),l=(0,R.keyBy)(Y.Z.reducerTypes,i=>i.value),c=(0,R.keyBy)(Y.Z.evalOperators,i=>i.value),o=(0,R.keyBy)(Y.Z.evalFunctions,i=>i.value);return e.createElement("div",{className:a.container},t.conditions?.map(({query:i,operator:g,reducer:u,evaluator:s},d)=>{const f=ie(s);return e.createElement(e.Fragment,{key:d},e.createElement("div",{className:a.blue},d===0?"WHEN":!!g?.type&&c[g?.type]?.text),e.createElement("div",{className:a.bold},u?.type&&l[u.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 Ae=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 Be({model:t}){const a=(0,p.wW)(Ue),{reducer:l,expression:c,settings:o}=t,i=M.SQ.find(s=>s.value===l),g=o?.mode??M.kN.Strict,u=M.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},u?.label))}const Ue=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 we({model:t}){const a=(0,p.wW)(Le),{expression:l,window:c,downsampler:o,upsampler:i}=t,g=M.Fr.find(s=>s.value===o),u=M.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},u?.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=M.Mi.find(u=>u.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 je=n(52694),X=n(80498),ue=n(40106),H=n(28104),Fe=n(49279),ze=n(68854),Ke=n(24990),Ze=n(8674);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(78443),Je=n(80399),Ye=n(48208),Xe=n(69369),ke=n(76277),qe=n(81001),se=n(45849),G=n(79662);function de(t){if(!t)return[];const{namespace:a,rulerRule:l}=t,{rulesSource:c}=a;if((0,se.HY)(c)&&(0,G.Pc)(l))return l.grafana_alert.data;if((0,se.jq)(c)){const o=et(c,t);return[_e(o,c.uid)]}return[]}function _e(t,a){return{refId:t.refId,datasourceUid:a,queryType:"",model:t,relativeTimeRange:{from:360,to:0}}}function et(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 tt=n(60048);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,w.Z)(!1),{id:o}=t.params,i=tt.OA(o,!0),{loading:g,error:u,result:s}=(0,ke.H)(i,i?.ruleSourceName),d=(0,e.useMemo)(()=>new qe.v,[]),f=(0,L.Z)(d.get()),v=(0,e.useMemo)(()=>de(s),[s]),[x,A]=(0,e.useState)({}),{allDataSourcesAvailable:B}=(0,Xe.S)(v),J=(0,e.useCallback)(()=>{if(v.length>0&&B){const y=v.map(h=>({...h,relativeTimeRange:x[h.refId]??h.relativeTimeRange}));d.run(y)}},[v,x,d,B]);(0,e.useEffect)(()=>{const y=de(s),h=Object.fromEntries(y.map(ee=>[ee.refId,ee.relativeTimeRange??{from:0,to:0}]));A(h)},[s]),(0,e.useEffect)(()=>{B&&l&&J()},[J,B,l]),(0,e.useEffect)(()=>()=>d.destroy(),[d]);const _=(0,e.useCallback)((y,h)=>{const ee=(0,P.ZP)(x,lt=>{lt[y]=h});A(ee)},[x,A]);if(!i?.ruleSourceName)return e.createElement(H.$,{title:k},e.createElement(O.b,{title:ge},e.createElement("details",{className:a.errorMessage},me)));const D=(0,se.o_)(i.ruleSourceName);if(g)return e.createElement(H.$,{title:k},e.createElement(C.u,{text:"Loading rule..."}));if(u||!D)return e.createElement(H.$,{title:k},e.createElement(O.b,{title:ge},e.createElement("details",{className:a.errorMessage},u?.message??me,e.createElement("br",null),!!u?.stack&&u.stack)));if(!s)return e.createElement(H.$,{title:k},e.createElement("span",null,"Rule could not be found."));const Q=Object.entries(s.annotations).filter(([y,h])=>!!h.trim()),F=(0,G.Jq)(s.group),rt=(0,G.Pc)(s.rulerRule)&&Boolean(s.rulerRule.grafana_alert.provenance);return e.createElement(H.$,{wrapInContent:!1,title:k},F&&e.createElement(O.b,{severity:"info",title:"This rule is part of a federated rule group."},e.createElement($.wc,null,"Federated rule groups are currently an experimental feature.",e.createElement(S.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")))),rt&&e.createElement(ue.Xq,{resource:ue.Uv.AlertRule}),e.createElement(H.l,null,e.createElement("div",null,e.createElement("h4",null,e.createElement(z.J,{name:"bell",size:"lg"})," ",s.name),e.createElement(Ye.p,{rule:s,isCreating:!1,isDeleting:!1}),e.createElement(Fe.f,{rule:s,rulesSource:D,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(je.s,{labels:s.labels,className:a.labels})),e.createElement(Ze.C,{rulesSource:D,rule:s,annotations:Q}),e.createElement(ze.J,{annotations:Q})),e.createElement("div",{className:a.rightSide},e.createElement(Ke.C,{rule:s,rulesSource:D}),F&&e.createElement(He,{group:s.group}),e.createElement(X.C,{label:"Namespace / Group",className:a.rightSideDetails},s.namespace.name," / ",s.group.name),(0,G.Pc)(s.rulerRule)&&e.createElement(at,{rule:s.rulerRule.grafana_alert}))),e.createElement("div",null,e.createElement(Ge.M,{rule:s,pagination:{itemsPerPage:N.gN}}))),e.createElement(m.U,{label:"Query & Results",isOpen:l,onToggle:c,loading:f&&nt(f),collapsible:!0,className:a.collapse},(0,G.Pc)(s.rulerRule)&&!F&&e.createElement(Oe,{condition:s.rulerRule.grafana_alert.condition,queries:v,evalDataByQuery:f,evalTimeRanges:x,onTimeRangeChange:_}),!(0,G.Pc)(s.rulerRule)&&!F&&f&&Object.keys(f).length>0&&e.createElement("div",{className:a.queries},v.map(y=>e.createElement(oe,{key:y.refId,refId:y.refId,model:y.model,dataSource:Object.values(b.v.datasources).find(h=>h.uid===y.datasourceUid),queryData:f[y.refId],relativeTimeRange:y.relativeTimeRange,evalTimeRange:x[y.refId],onEvalTimeRangeChange:h=>_(y.refId,h),isAlertCondition:!1}))),!F&&!B&&e.createElement(O.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 at({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(E.h,{name:"copy",onClick:l}))}function nt(t){return!!Object.values(t).find(a=>a.state===V.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)};
    `,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)};
    `,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)};
    `}),st=(0,T.Pf)(pe,{style:"page"})},51981:(te,U,n)=>{n.d(U,{q:()=>e});var r=n(68404),P=n(82002);const e=({actions:w,children:L,fallback:V=!0})=>w.some(b=>P.Vt.hasAccess(b,V))?r.createElement(r.Fragment,null,L):null},28104:(te,U,n)=>{n.d(U,{$:()=>V,l:()=>b});var r=n(52423),P=n(68404),e=n(72648),w=n(79396);const L={icon:"bell",id:"alert-rule-view",breadcrumbs:[{title:"Alert rules",url:"alerting/list"}]};function V(C){const{wrapInContent:$=!0,children:S,title:z}=C,m=(0,e.wW)(p);return P.createElement(w.T,{pageNav:{...L,text:z},navId:"alert-list"},P.createElement(w.T.Contents,null,P.createElement("div",{className:m.content},$?P.createElement(b,{...C}):S)))}function b({children:C,padding:$=2}){const S=(0,e.wW)(O($));return P.createElement("div",{className:S.wrapper},C)}const p=C=>({content:r.css`
      max-width: ${C.breakpoints.values.xxl}px;
    `}),O=C=>$=>({wrapper:r.css`
      background: ${$.colors.background.primary};
      border: 1px solid ${$.colors.border.weak};
      border-radius: ${$.shape.borderRadius()};
      padding: ${$.spacing(C)};
    `})},76277:(te,U,n)=>{n.d(U,{H:()=>C,X:()=>$});var r=n(68404),P=n(22350),e=n(81168),w=n(72004),L=n(46818),V=n(60048),b=n(79662),p=n(61627),O=n(69945);function C(m,E){const T=S(E),N=(0,p.Zo)(E),j=(0,r.useMemo)(()=>{if(!(!m||!E||N.length===0))for(const R of N)for(const W of R.groups)for(const I of W.rules){const K=V.Yd(E,I);if(V.Dg(K,m))return I}},[m,E,N]);return{...T,result:j}}function $(m,E){const T=S(E),N=(0,p.Zo)(E),j=(0,r.useMemo)(()=>{if(!m||!E||N.length===0)return[];const R=[];for(const W of N)for(const I of W.groups)for(const K of I.rules)K.name===m&&R.push(K);return R},[m,E,N]);return{...T,result:j}}function S(m){const E=(0,e.useDispatch)(),T=(0,O._)(I=>I.promRules),N=z(m,T),j=(0,O._)(I=>I.rulerRules),R=z(m,j),{loading:W}=(0,P.Z)(async()=>{m&&await E((0,w.dn)({rulesSourceName:m}))},[E,m]);return{loading:W,error:N.error??(0,b.m$)(R)?void 0:R.error,dispatched:N.dispatched&&R.dispatched}}function z(m,E){if(!m)return L.oq;const T=E[m];return T||L.oq}}}]);

//# sourceMappingURL=AlertingRule.022aaad9e55ad414cd5a.js.map