"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4679],{55476:(e,t,s)=>{s.r(t),s.d(t,{RuleViewer:()=>oe,default:()=>de});var r=s(77813),n=s(76687),a=s(91597),i=s(77212),l=s(27668),o=s(35562),c=s(42384),u=s(7053),d=s(55312),h=s(39756),f=s(56998),g=s(51397),p=s(56921),m=s(11676),x=s(94528),j=s(78391),v=s(14647),b=s(65677),y=s(53185),w=s(85994),S=s(2343),R=s(53620),C=s(67273),$=s(68964),q=s(99117),I=s(46852),N=s(352),k=s(73285),O=s(58124),T=s(96680),M=s(52010);const U=["refId"];var Q;function z(e){var t;const s=(0,l.l4)(),r=(0,l.wW)(D),{data:a,query:i,onChangeQuery:c}=e,u=(0,I.j)(i.model)?k.Fe:k.GC,[h,f]=(0,n.useState)(u),g=(0,S.F)().getInstanceSettings(i.datasourceUid),p=i.relativeTimeRange,[m,x]=(0,n.useState)({frameIndex:0,showHeader:!0}),j=(0,n.useCallback)((e=>{const t=(0,y.CQ)().unix()-e.unix();if(p){const e=p.from-p.to;c(Object.assign({},i,{relativeTimeRange:{from:t+e,to:t}}))}}),[c,i,p]),v=(0,n.useCallback)((e=>0===e?(0,y.CQ)():(0,y.CQ)().subtract(e,"seconds")),[]);return a?g?(0,M.jsx)("div",{className:r.content,children:(0,M.jsx)(b.Z,{children:e=>{let{width:n,height:l}=e;return(0,M.jsxs)("div",{style:{width:n,height:l},children:[(0,M.jsxs)("div",{className:r.header,children:[(0,M.jsxs)("div",{children:[`Query ${i.refId}`,(0,M.jsxs)("span",{className:r.dataSource,children:["(",g.name,")"]})]}),(0,M.jsxs)("div",{className:r.actions,children:[!(0,I.j)(i.model)&&p?(0,M.jsx)(q.x,{date:v(p.to),onChange:j,maxDate:new Date}):null,t||(t=(0,M.jsx)(T.j,{onChange:f,value:h,size:"md"})),(0,M.jsx)(O.q,{actions:[N.bW.DataSourcesExplore],children:!(0,I.j)(i.model)&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("div",{className:r.spacing}),(0,M.jsx)(d.Qj,{size:"md",variant:"secondary",icon:"compass",target:"_blank",href:G(g,i),children:"View in Explore"})]})})]})]}),(0,M.jsx)(R.$,{height:l-4*s.spacing.gridSize,width:n,data:a,pluginId:h,title:"",onOptionsChange:x,options:m})]})}})}):(0,M.jsxs)("div",{className:r.content,children:[Q||(Q=(0,M.jsx)(o.b,{title:"Could not find datasource for query"})),(0,M.jsx)($.p,{width:"100%",height:"250px",language:"json",showLineNumbers:!1,showMiniMap:!1,value:JSON.stringify(i,null,"\t"),readOnly:!0})]}):null}function G(e,t){const{name:s}=e,r=function(e,t){if(null==e)return{};var s,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)s=a[r],t.indexOf(s)>=0||(n[s]=e[s]);return n}(t.model,U),n=Object.assign({},r,{datasource:s});return w.Cj.renderUrl(`${C.v.appSubUrl}/explore`,{left:JSON.stringify(["now-1h","now",s,n])})}const D=e=>({content:r.css`
      width: 100%;
      height: 250px;
    `,header:r.css`
      height: ${e.spacing(4)};
      display: flex;
      align-items: center;
      justify-content: space-between;
      white-space: nowrap;
    `,refId:r.css`
      font-weight: ${e.typography.fontWeightMedium};
      color: ${e.colors.text.link};
      overflow: hidden;
    `,dataSource:r.css`
      margin-left: ${e.spacing(1)};
      font-style: italic;
      color: ${e.colors.text.secondary};
    `,actions:r.css`
      display: flex;
      align-items: center;
    `,spacing:r.css`
      padding: ${e.spacing(0,1,0,0)};
    `,errorMessage:r.css`
      white-space: pre-wrap;
    `});var F=s(75520),P=s(2291),W=s(26160),E=s(72578);const A=e=>{var t;let{group:s}=e;const r=null!==(t=s.source_tenants)&&void 0!==t?t:[];return(0,M.jsx)(x.C,{label:"Tenant sources",children:(0,M.jsx)(M.Fragment,{children:r.map((e=>(0,M.jsx)("div",{children:e},e)))})})};var L=s(15738),_=s(52238),J=s(24045),V=s(70434),Z=s(62605),B=s(47536),H=s(11126),K=s(18077);function X(e){if(!e)return[];const{namespace:t,rulerRule:s}=e,{rulesSource:r}=t;if((0,H.HY)(r)&&(0,K.Pc)(s))return s.grafana_alert.data;if((0,H.jq)(r)){const t=function(e,t){const s="A";switch(e.type){case"prometheus":return{refId:s,expr:t.query};case"loki":return{refId:s,expr:t.query};default:throw new Error(`Query for datasource type ${e.type} is currently not supported by cloud alert rules.`)}}(r,e);return[(n=t,a=r.uid,{refId:n.refId,datasourceUid:a,queryType:"",model:n,relativeTimeRange:{from:360,to:0}})]}var n,a;return[]}var Y,ee,te,se,re,ne=s(42673);const ae="Could not find data source for rule",ie="Could not view rule",le="Alerting / View rule";function oe(e){let{match:t}=e;const s=(0,l.wW)(ue),{id:r}=t.params,i=ne.OA(r,!0),{loading:g,error:b,result:y}=(0,Z.H)(i,null==i?void 0:i.ruleSourceName),w=(0,n.useMemo)((()=>new B.v),[]),S=(0,a.Z)(w.get()),R=(0,n.useMemo)((()=>X(y)),[y]),[C,$]=(0,n.useState)([]),{allDataSourcesAvailable:q}=(0,V.S)(R),I=(0,n.useCallback)((()=>{C.length>0&&q&&w.run(C)}),[C,w,q]);(0,n.useEffect)((()=>{$(R)}),[R]),(0,n.useEffect)((()=>{q&&I()}),[I,q]),(0,n.useEffect)((()=>()=>w.destroy()),[w]);const N=(0,n.useCallback)((e=>{$((t=>t.map((t=>t.refId===e.refId?e:t))))}),[]);if(null==i||!i.ruleSourceName)return(0,M.jsx)(v.$,{title:le,children:(0,M.jsx)(o.b,{title:ie,children:(0,M.jsx)("details",{className:s.errorMessage,children:ae})})});const k=(0,H.o_)(i.ruleSourceName);if(g)return Y||(Y=(0,M.jsx)(v.$,{title:le,children:(0,M.jsx)(c.u,{text:"Loading rule..."})}));var O;if(b||!k)return(0,M.jsx)(v.$,{title:le,children:(0,M.jsx)(o.b,{title:ie,children:(0,M.jsxs)("details",{className:s.errorMessage,children:[null!==(O=null==b?void 0:b.message)&&void 0!==O?O:ae,ee||(ee=(0,M.jsx)("br",{})),!(null==b||!b.stack)&&b.stack]})})});if(!y)return te||(te=(0,M.jsx)(v.$,{title:le,children:(0,M.jsx)("span",{children:"Rule could not be found."})}));const T=Object.entries(y.annotations).filter((e=>{let[t,s]=e;return!!s.trim()})),U=(0,K.Jq)(y.group),Q=(0,K.Pc)(y.rulerRule)&&Boolean(y.rulerRule.grafana_alert.provenance);return(0,M.jsxs)(v.$,{wrapInContent:!1,title:le,children:[U&&(se||(se=(0,M.jsx)(o.b,{severity:"info",title:"This rule is part of a federated rule group.",children:(0,M.jsxs)(u.wc,{children:["Federated rule groups are currently an experimental feature.",(0,M.jsx)(d.zx,{fill:"text",icon:"book",children:(0,M.jsx)("a",{href:"https://grafana.com/docs/metrics-enterprise/latest/tenant-management/tenant-federation/#cross-tenant-alerting-and-recording-rule-federation",children:"Read documentation"})})]})}))),Q&&(0,M.jsx)(j.Xq,{resource:j.Uv.AlertRule}),(0,M.jsxs)(v.l,{children:[(0,M.jsxs)("div",{children:[(0,M.jsxs)("h4",{children:[re||(re=(0,M.jsx)(h.J,{name:"bell",size:"lg"}))," ",y.name]}),(0,M.jsx)(J.p,{rule:y,isCreating:!1,isDeleting:!1}),(0,M.jsx)(F.f,{rule:y,rulesSource:k})]}),(0,M.jsxs)("div",{className:s.details,children:[(0,M.jsxs)("div",{className:s.leftSide,children:[y.promRule&&(0,M.jsx)(x.C,{label:"Health",horizontal:!0,children:(0,M.jsx)(_.V,{rule:y.promRule})}),!!y.labels&&!!Object.keys(y.labels).length&&(0,M.jsx)(x.C,{label:"Labels",horizontal:!0,children:(0,M.jsx)(m.s,{labels:y.labels})}),(0,M.jsx)(E.C,{rulesSource:k,rule:y,annotations:T}),(0,M.jsx)(P.J,{annotations:T})]}),(0,M.jsxs)("div",{className:s.rightSide,children:[(0,M.jsx)(W.C,{rule:y,rulesSource:k}),U&&(0,M.jsx)(A,{group:y.group}),(0,M.jsx)(x.C,{label:"Namespace / Group",children:`${y.namespace.name} / ${y.group.name}`})]})]}),(0,M.jsx)("div",{children:(0,M.jsx)(L.M,{rule:y,pagination:{itemsPerPage:p.gN}})})]}),!U&&S&&Object.keys(S).length>0&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("div",{className:s.queriesTitle,children:["Query results ",(0,M.jsx)(f.T,{loading:ce(S),onCancel:()=>w.cancel()})]}),(0,M.jsx)(v.l,{padding:0,children:(0,M.jsx)("div",{className:s.queries,children:C.map((e=>(0,M.jsx)("div",{className:s.query,children:(0,M.jsx)(z,{query:e,data:S&&S[e.refId],onChangeQuery:N})},e.refId)))})})]}),!U&&!q&&(0,M.jsx)(o.b,{title:"Query not available",severity:"warning",className:s.queryWarning,children:"Cannot display the query preview. Some of the data sources used in the queries are not available."})]})}function ce(e){return!!Object.values(e).find((e=>e.state===i.Gu.Loading))}const ue=e=>({errorMessage:r.css`
      white-space: pre-wrap;
    `,queries:r.css`
      height: 100%;
      width: 100%;
    `,queriesTitle:r.css`
      padding: ${e.spacing(2,.5)};
      font-size: ${e.typography.h5.fontSize};
      font-weight: ${e.typography.fontWeightBold};
      font-family: ${e.typography.h5.fontFamily};
    `,query:r.css`
      border-bottom: 1px solid ${e.colors.border.medium};
      padding: ${e.spacing(2)};
    `,queryWarning:r.css`
      margin: ${e.spacing(4,0)};
    `,details:r.css`
      display: flex;
      flex-direction: row;
    `,leftSide:r.css`
      flex: 1;
    `,rightSide:r.css`
      padding-left: 90px;
      width: 300px;
    `}),de=(0,g.Pf)(oe,{style:"page"})},58124:(e,t,s)=>{s.d(t,{q:()=>a});s(76687);var r=s(69369),n=s(52010);const a=e=>{let{actions:t,children:s,fallback:a=!0}=e;return t.some((e=>r.Vt.hasAccess(e,a)))?(0,n.jsx)(n.Fragment,{children:s}):null}},96680:(e,t,s)=>{s.d(t,{j:()=>o});var r=s(76687),n=s(67273),a=s(81377),i=s(73285),l=s(52010);function o(e){const{value:t,onChange:s,size:o="md"}=e,c=(0,r.useMemo)((()=>Object.values(n.v.panels).reduce(((e,t)=>(function(e){switch(e){case i.GC:case i.Fe:case i.Kd:return!0;default:return!1}}(t.id)&&e.push({value:t.id,label:t.name,imgUrl:t.info.logos.small}),e)),[])),[]);return(0,l.jsx)(a.S,{options:c,value:t,onChange:s,size:o})}},14647:(e,t,s)=>{s.d(t,{$:()=>c,l:()=>u});var r=s(77813),n=(s(76687),s(49622)),a=s(27668),i=s(21733),l=s(28781),o=s(52010);function c(e){const{wrapInContent:t=!0,children:s,title:r}=e,c=(0,a.wW)(d);return(0,o.jsxs)(l.T,{children:[(0,o.jsx)(i.X,{title:r,pageIcon:"bell",onGoBack:()=>n.E1.push("/alerting/list")}),(0,o.jsx)("div",{className:c.content,children:t?(0,o.jsx)(u,Object.assign({},e)):s})]})}function u(e){let{children:t,padding:s=2}=e;const r=(0,a.wW)(h(s));return(0,o.jsx)("div",{className:r.wrapper,children:t})}const d=e=>({content:r.css`
      margin: ${e.spacing(0,2,2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}),h=e=>t=>({wrapper:r.css`
      background: ${t.colors.background.primary};
      border: 1px solid ${t.colors.border.weak};
      border-radius: ${t.shape.borderRadius()};
      padding: ${t.spacing(e)};
    `})},70434:(e,t,s)=>{s.d(t,{S:()=>a});var r=s(76687),n=s(2343);function a(e){return{allDataSourcesAvailable:(0,r.useMemo)((()=>e.every((e=>Boolean((0,n.F)().getInstanceSettings(e.datasourceUid))))),[e])}}},62605:(e,t,s)=>{s.d(t,{H:()=>h,X:()=>f});var r=s(76687),n=s(68021),a=s(352),i=s(68175),l=s(27121),o=s(42673),c=s(18077),u=s(63373),d=s(7566);function h(e,t){const s=g(t),n=(0,u.Zo)(t),a=(0,r.useMemo)((()=>{if(e&&t&&0!==n.length)for(const s of n)for(const r of s.groups)for(const s of r.rules){const r=o.Yd(t,s);if(o.Dg(r,e))return s}}),[e,t,n]);return Object.assign({},s,{result:a})}function f(e,t){const s=g(t),n=(0,u.Zo)(t),a=(0,r.useMemo)((()=>{if(!e||!t||0===n.length)return[];const s=[];for(const t of n)for(const r of t.groups)for(const t of r.rules)t.name===e&&s.push(t);return s}),[e,t,n]);return Object.assign({},s,{result:a})}function g(e){var t;const s=(0,a.I0)(),r=(0,d._)((e=>e.promRules)),l=p(e,r),o=(0,d._)((e=>e.rulerRules)),u=p(e,o),{loading:h}=(0,n.Z)((async()=>{e&&await s((0,i.dn)({rulesSourceName:e}))}),[s,e]);return{loading:h,error:(null!==(t=l.error)&&void 0!==t?t:(0,c.m$)(u))?void 0:u.error,dispatched:l.dispatched&&u.dispatched}}function p(e,t){if(!e)return l.oq;const s=t[e];return s||l.oq}},47536:(e,t,s)=>{s.d(t,{v:()=>N});var r=s(46844),n=s(98800),a=s(95481),i=s(11316),l=s(20709),o=s(816),c=s(77212),u=s(37),d=s(31757),h=s(61997),f=s(29117),g=s(2343),p=s(92572),m=s(75477),x=s(46852),j=s(97416),v=s(36724),b=s(9046),y=s(90411);const w={from:21600,to:0},S=(e,t)=>{switch(e.type){case y.Us.classic:return R(e);case y.Us.math:return $(e,t);case y.Us.resample:case y.Us.reduce:return q(e)}},R=e=>{var t;return null===(t=e.conditions)||void 0===t?void 0:t.map((e=>e.query.params[0]))},C=(e,t)=>{let s=[],r=[w.to];for(const n of e){const e=t.find((e=>e.refId===n));e&&e.relativeTimeRange&&(s.push(e.relativeTimeRange.from),r.push(e.relativeTimeRange.to))}return{from:s,to:r}},$=(e,t)=>t.filter((t=>{var s;return"query"===t.queryType&&(null===(s=e.expression)||void 0===s?void 0:s.includes(t.refId))})).map((e=>e.refId)),q=e=>e.expression?[e.expression]:void 0;function I(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}class N{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:(0,m.i)(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,g.F)();I(this,"subject",void 0),I(this,"subscription",void 0),I(this,"lastResult",void 0),this.backendSrv=e,this.dataSourceSrv=t,this.subject=new r.t(1),this.lastResult={}}get(){return this.subject.asObservable()}async run(e){if(0===e.length){const t=O(e,c.Gu.Done);return this.subject.next(t)}for(const t of e)if(!(0,x.j)(t.model)){const s=await this.dataSourceSrv.get(t.datasourceUid);if(s.filterQuery&&!s.filterQuery(t.model)){const t=O(e,c.Gu.Done);return this.subject.next(t)}}this.subscription=k(this.backendSrv,e).subscribe({next:e=>{const t=Q(e,((e,t)=>{const s=this.lastResult[e],r=(0,b.zR)(t,s);return(0,v.C)(r,s)}));this.lastResult=t,this.subject.next(this.lastResult)},error:e=>{this.lastResult=U(this.lastResult,e),this.subject.next(this.lastResult)}})}cancel(){if(!this.subscription)return;this.subscription.unsubscribe();let e=!1;const t=Q(this.lastResult,((t,s)=>(s.state===c.Gu.Loading&&(e=!0),Object.assign({},s,{state:c.Gu.Done}))));e&&this.subject.next(t)}destroy(){this.subject&&this.subject.complete(),this.cancel()}}const k=(e,t)=>{const s=O(t,c.Gu.Loading),r={data:{data:t},url:"/api/v1/eval",method:"POST",requestId:(0,o.Z)()};return(0,u.x)({whileLoading:s,source:e.fetch(r).pipe(M(s),(0,a.K)((e=>(0,n.of)(U(s,e)))),(0,j.V)(e,r.requestId),(0,i.B)())})},O=(e,t)=>e.reduce(((s,r)=>(s[r.refId]={state:t,series:[],timeRange:T(r,e)},s)),{}),T=(e,t)=>{if((0,x.j)(e.model)){const s=((e,t)=>{const s=S(e,t);if(!s)return w;const{from:r,to:n}=C(s,t);return r.length||n.length?{from:Math.max(...r),to:Math.min(...n)}:w})(e.model,t);return d.relativeToTimeRange(s)}return e.relativeTimeRange?d.relativeToTimeRange(e.relativeTimeRange):(console.warn(`Query with refId: ${e.refId} did not have any relative time range, using default.`),(0,h.JK)())},M=e=>(0,l.U)((t=>{const{data:s}=t,r={};for(const[t,n]of Object.entries(s.results))r[t]={timeRange:e[t].timeRange,state:c.Gu.Done,series:n.frames.map(f.vP)};return r})),U=(e,t)=>{const s=(0,p.P)(t);return Q(e,((e,t)=>Object.assign({},t,{state:c.Gu.Error,error:s})))},Q=(e,t)=>{const s={};for(const[r,n]of Object.entries(e))s[r]=t(r,n);return s}},46852:(e,t,s)=>{s.d(t,{j:()=>a});var r=s(60849),n=s(90411);const a=e=>{if(!e)return!1;if((0,r.Pr)(e.datasource))return!0;const t=e;return"string"==typeof t.type&&Object.values(n.Us).includes(t.type)}}}]);
//# sourceMappingURL=AlertingRule.0bfdee2c8593a7f52947.js.map