(window.webpackJsonp=window.webpackJsonp||[]).push([[18],{DmTC:function(e,t,r){"use strict";r.r(t);var n=r("q1tI"),s="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;var a=function(e,t){var r=Object(n.useState)(t),a=r[0],c=r[1];return s((function(){var t=e.subscribe(c);return function(){return t.unsubscribe()}}),[e]),a},c=r("vF1F"),i=r("Obii"),o=r("kDLi"),l=r("P0IT"),u=r("gg9e"),d=r("Jzaf"),j=r("IpGs");function b(e){if(!e)return[];const{namespace:t,rulerRule:r}=e,{rulesSource:n}=t;if(Object(d.k)(n)&&Object(j.j)(r))return r.grafana_alert.data;if(Object(d.j)(n)){const t=function(e,t){switch(e.type){case"prometheus":return{refId:"A",expr:t.query};case"loki":return{refId:"A",expr:t.query};default:throw new Error(`Query for datasource type ${e.type} is currently not supported by cloud alert rules.`)}}(n,e);return[{refId:t.refId,datasourceUid:n.uid,queryType:"",model:t,relativeTimeRange:{from:360,to:0}}]}return[]}var f=r("xVL3"),h=r("dVib"),p=r("7G0q"),g=r("t8hP"),O=r("p8f7"),m=r("jYz7"),v=r("mfno"),x=r("d6cI"),y=r("nKUr");const w=["refId"];var S;function I(){return(I=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function R(e){var t;const r=Object(o.useTheme2)(),s=Object(o.useStyles2)(q),{data:a,query:c}=e,i=Object(O.a)(c.model)?x.i:x.j,[l,u]=Object(n.useState)(i),d=Object(g.getDataSourceSrv)().getInstanceSettings(c.datasourceUid),[j,b]=Object(n.useState)({frameIndex:0,showHeader:!0});return a?d?Object(y.jsx)("div",{className:s.content,children:Object(y.jsx)(m.a,{children:({width:e,height:n})=>Object(y.jsxs)("div",{style:{width:e,height:n},children:[Object(y.jsxs)("div",{className:s.header,children:[Object(y.jsxs)("div",{children:["Query "+c.refId,Object(y.jsxs)("span",{className:s.dataSource,children:["(",d.name,")"]})]}),Object(y.jsxs)("div",{className:s.actions,children:[t||(t=Object(y.jsx)(v.a,{onChange:u,value:l,size:"sm"})),!Object(O.a)(c.model)&&Object(y.jsxs)(y.Fragment,{children:[Object(y.jsx)("div",{className:s.spacing}),Object(y.jsx)(o.LinkButton,{size:"sm",variant:"secondary",icon:"compass",target:"_blank",href:L(d,c),children:"View in Explore"})]})]})]}),Object(y.jsx)(g.PanelRenderer,{height:n-4*r.spacing.gridSize,width:e,data:a,pluginId:l,title:"",onOptionsChange:b,options:j})]})})}):Object(y.jsxs)("div",{className:s.content,children:[S||(S=Object(y.jsx)(o.Alert,{title:"Could not find datasource for query"})),Object(y.jsx)(o.CodeEditor,{width:"100%",height:"250px",language:"json",showLineNumbers:!1,showMiniMap:!1,value:JSON.stringify(c,null,"\t"),readOnly:!0})]}):null}function L(e,t){const{name:r}=e,n=I({},function(e,t){if(null==e)return{};var r,n,s={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(s[r]=e[r]);return s}(t.model,w),{datasource:r});return i.urlUtil.renderUrl("/explore",{left:JSON.stringify(["now-1h","now",r,n])})}const q=e=>({content:c.css`
      width: 100%;
      height: 250px;
    `,header:c.css`
      height: ${e.spacing(4)};
      display: flex;
      align-items: center;
      justify-content: space-between;
      white-space: nowrap;
    `,refId:c.css`
      font-weight: ${e.typography.fontWeightMedium};
      color: ${e.colors.text.link};
      overflow: hidden;
    `,dataSource:c.css`
      margin-left: ${e.spacing(1)};
      font-style: italic;
      color: ${e.colors.text.secondary};
    `,actions:c.css`
      display: flex;
      align-items: center;
    `,spacing:c.css`
      padding: ${e.spacing(0,1,0,0)};
    `,errorMessage:c.css`
      white-space: pre-wrap;
    `});var k,N,$,C,T=r("cLaa"),P=r("epYg"),M=r("vmN6"),z=r("rBL+"),D=r("CBrm"),E=r("CBn2"),F=r("yZbJ"),U=r("K3Xr");r.d(t,"RuleViewer",(function(){return G}));const B="Alerting / View rule";function G({match:e}){const t=Object(o.useStyles2)(A),{id:r,sourceName:s}=e.params,c=U.g(r,!0),{loading:i,error:j,result:g}=Object(u.a)(c,s),O=Object(n.useMemo)(()=>new l.a,[]),m=a(O.get()),v=Object(n.useMemo)(()=>b(g),[g]),x=Object(n.useCallback)(()=>{v.length>0&&O.run(v)},[v,O]);if(Object(n.useEffect)(()=>{x()},[x]),Object(n.useEffect)(()=>()=>O.destroy(),[O]),!s)return Object(y.jsx)(z.a,{title:B,children:Object(y.jsx)(o.Alert,{title:"Could not view rule",children:Object(y.jsx)("details",{className:t.errorMessage,children:"Could not find data source for rule"})})});const w=Object(d.h)(s);if(i)return k||(k=Object(y.jsx)(z.a,{title:B,children:Object(y.jsx)(o.LoadingPlaceholder,{text:"Loading rule..."})}));var S;if(j||!w)return Object(y.jsx)(z.a,{title:B,children:Object(y.jsx)(o.Alert,{title:"Could not view rule",children:Object(y.jsxs)("details",{className:t.errorMessage,children:[null!==(S=null==j?void 0:j.message)&&void 0!==S?S:"Could not find data source for rule",N||(N=Object(y.jsx)("br",{})),!(null==j||!j.stack)&&j.stack]})})});if(!g)return $||($=Object(y.jsx)(z.a,{title:B,children:Object(y.jsx)("span",{children:"Rule could not be found."})}));const I=Object.entries(g.annotations).filter(([e,t])=>!!t.trim());return Object(y.jsxs)(z.a,{wrapInContent:!1,title:B,children:[Object(y.jsxs)(z.b,{children:[Object(y.jsxs)("div",{children:[Object(y.jsxs)("h4",{children:[C||(C=Object(y.jsx)(o.Icon,{name:"bell",size:"lg"}))," ",g.name]}),Object(y.jsx)(f.a,{rule:g,isCreating:!1,isDeleting:!1}),Object(y.jsx)(T.a,{rule:g,rulesSource:w})]}),Object(y.jsxs)("div",{className:t.details,children:[Object(y.jsxs)("div",{className:t.leftSide,children:[g.promRule&&Object(y.jsx)(h.a,{label:"Health",horizontal:!0,children:Object(y.jsx)(p.a,{rule:g.promRule})}),!!g.labels&&!!Object.keys(g.labels).length&&Object(y.jsx)(h.a,{label:"Labels",horizontal:!0,children:Object(y.jsx)(D.a,{labels:g.labels})}),Object(y.jsx)(E.a,{rulesSource:w,rule:g,annotations:I}),Object(y.jsx)(F.a,{annotations:I})]}),Object(y.jsxs)("div",{className:t.rightSide,children:[Object(y.jsx)(M.a,{rule:g,rulesSource:w}),Object(y.jsx)(h.a,{label:"Namespace / Group",children:`${g.namespace.name} / ${g.group.name}`})]})]}),Object(y.jsx)("div",{children:Object(y.jsx)(P.a,{promRule:g.promRule})})]}),m&&Object.keys(m).length>0&&Object(y.jsxs)(y.Fragment,{children:[Object(y.jsxs)("div",{className:t.queriesTitle,children:["Query results ",Object(y.jsx)(o.PanelChromeLoadingIndicator,{loading:J(m),onCancel:()=>O.cancel()})]}),Object(y.jsx)(z.b,{padding:0,children:Object(y.jsx)("div",{className:t.queries,children:v.map(e=>Object(y.jsx)("div",{className:t.query,children:Object(y.jsx)(R,{query:e,data:m&&m[e.refId]})},e.refId))})})]})]})}function J(e){return!!Object.values(e).find(e=>e.state===i.LoadingState.Loading)}const A=e=>({errorMessage:c.css`
      white-space: pre-wrap;
    `,queries:c.css`
      height: 100%;
      width: 100%;
    `,queriesTitle:c.css`
      padding: ${e.spacing(2,.5)};
      font-size: ${e.typography.h5.fontSize};
      font-weight: ${e.typography.fontWeightBold};
      font-family: ${e.typography.h5.fontFamily};
    `,query:c.css`
      border-bottom: 1px solid ${e.colors.border.medium};
      padding: ${e.spacing(2)};
    `,details:c.css`
      display: flex;
      flex-direction: row;
    `,leftSide:c.css`
      flex: 1;
    `,rightSide:c.css`
      padding-left: 90px;
      width: 300px;
    `});t.default=Object(o.withErrorBoundary)(G,{style:"page"})},P0IT:function(e,t,r){"use strict";var n=r("S5bw"),s=r("F/XL"),a=r("9Z1F"),c=r("S1nX"),i=r("67Y/"),o=r("7Cbv"),l=r("Obii"),u=r("t8hP"),d=r("NXk7"),j=r("tCoL"),b=r("yhyZ");const f={from:21600,to:0},h=(e,t)=>{switch(e.type){case b.a.classic:return p(e);case b.a.math:return O(e,t);case b.a.resample:case b.a.reduce:return m(e)}},p=e=>{var t;return null===(t=e.conditions)||void 0===t?void 0:t.map(e=>e.query.params[0])},g=(e,t)=>{let r=[],n=[f.to];for(const s of e){const e=t.find(e=>e.refId===s);e&&e.relativeTimeRange&&(r.push(e.relativeTimeRange.from),n.push(e.relativeTimeRange.to))}return{from:r,to:n}},O=(e,t)=>t.filter(t=>{var r;return"query"===t.queryType&&(null===(r=e.expression)||void 0===r?void 0:r.includes(t.refId))}).map(e=>e.refId),m=e=>e.expression?[e.expression]:void 0;var v=r("p8f7"),x=r("65gb"),y=r("w/qm");function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function S(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,"a",(function(){return I}));class I{constructor(e=Object(d.c)()){S(this,"subject",void 0),S(this,"subscription",void 0),S(this,"lastResult",void 0),this.backendSrv=e,this.subject=new n.a(1),this.lastResult={}}get(){return this.subject.asObservable()}run(e){if(0===e.length){const t=L(e,l.LoadingState.Done);return this.subject.next(t)}this.subscription=R(this.backendSrv,e).subscribe({next:e=>{const t=$(e,(e,t)=>{const r=this.lastResult[e],n=Object(j.b)(t,r);return Object(x.a)(n,r)});this.lastResult=t,this.subject.next(this.lastResult)},error:e=>{this.lastResult=N(this.lastResult,e),this.subject.next(this.lastResult)}})}cancel(){if(!this.subscription)return;this.subscription.unsubscribe();let e=!1;const t=$(this.lastResult,(t,r)=>(r.state===l.LoadingState.Loading&&(e=!0),w({},r,{state:l.LoadingState.Done})));e&&this.subject.next(t)}destroy(){this.subject&&this.subject.complete(),this.cancel()}}const R=(e,t)=>{const r=L(t,l.LoadingState.Loading),n={data:{data:t},url:"/api/v1/eval",method:"POST",requestId:Object(o.a)()};return Object(l.withLoadingIndicator)({whileLoading:r,source:e.fetch(n).pipe(k(r),Object(a.a)(e=>Object(s.a)(N(r,e))),Object(y.a)(e,n.requestId),Object(c.a)())})},L=(e,t)=>e.reduce((r,n)=>(r[n.refId]={state:t,series:[],timeRange:q(n,e)},r),{}),q=(e,t)=>{if(Object(v.a)(e.model)){const r=((e,t)=>{const r=h(e,t);if(!r)return f;const{from:n,to:s}=g(r,t);return n.length||s.length?{from:Math.max(...n),to:Math.min(...s)}:f})(e.model,t);return l.rangeUtil.relativeToTimeRange(r)}return e.relativeTimeRange?l.rangeUtil.relativeToTimeRange(e.relativeTimeRange):(console.warn(`Query with refId: ${e.refId} did not have any relative time range, using default.`),Object(l.getDefaultTimeRange)())},k=e=>Object(i.a)(t=>{const{data:r}=t,n={};for(const[t,s]of Object.entries(r.results))n[t]={timeRange:e[t].timeRange,state:l.LoadingState.Done,series:s.frames.map(l.dataFrameFromJSON)};return n}),N=(e,t)=>{const r=Object(u.toDataQueryError)(t);return $(e,(e,t)=>w({},t,{state:l.LoadingState.Error,error:r}))},$=(e,t)=>{const r={};for(const[n,s]of Object.entries(e))r[n]=t(n,s);return r}},gg9e:function(e,t,r){"use strict";r.d(t,"a",(function(){return j})),r.d(t,"b",(function(){return b}));var n=r("q1tI"),s=r("/MKj"),a=r("fXZ9"),c=r("O6qV"),i=r("w+lj"),o=r("4Yfp"),l=r("K3Xr"),u=r("IpGs");function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function j(e,t){const r=f(t),s=Object(c.a)(t);return d({},r,{result:Object(n.useMemo)(()=>{if(e&&t&&0!==s.length)for(const r of s)for(const n of r.groups)for(const r of n.rules){const n=l.b(t,r);if(l.a(n,e))return r}},[e,t,s])})}function b(e,t){const r=f(t),s=Object(c.a)(t);return d({},r,{result:Object(n.useMemo)(()=>{if(!e||!t||0===s.length)return[];const r=[];for(const t of s)for(const n of t.groups)for(const t of n.rules)t.name===e&&r.push(t);return r},[e,t,s])})}function f(e){var t;const r=Object(s.useDispatch)(),a=Object(i.a)(e=>e.promRules),c=h(e,a),l=Object(i.a)(e=>e.rulerRules),d=h(e,l);return Object(n.useEffect)(()=>{e&&(r(Object(o.q)(e)),r(Object(o.r)(e)))},[r,e]),{loading:c.loading||d.loading,error:(null!==(t=c.error)&&void 0!==t?t:Object(u.n)(d))?void 0:d.error,dispatched:c.dispatched&&d.dispatched}}function h(e,t){if(!e)return a.c;const r=t[e];return r||a.c}},mfno:function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r("t8hP"),s=r("kDLi"),a=r("q1tI"),c=r("d6cI"),i=r("nKUr");function o(e){const{value:t,onChange:r,size:o="md"}=e,l=Object(a.useMemo)(()=>Object.values(n.config.panels).reduce((e,t)=>(function(e){switch(e){case c.j:case c.i:case c.h:return!0;default:return!1}}(t.id)&&e.push({value:t.id,label:t.name,imgUrl:t.info.logos.small}),e),[]),[]);return Object(i.jsx)(s.RadioButtonGroup,{options:l,value:t,onChange:r,size:o})}},p8f7:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r("exx3"),s=r("yhyZ");const a=e=>{if(!e)return!1;if(e.datasource===n.a)return!0;const t=e;return"string"==typeof t.type&&Object.values(s.a).includes(t.type)}},"rBL+":function(e,t,r){"use strict";r.d(t,"a",(function(){return l})),r.d(t,"b",(function(){return u}));r("q1tI");var n=r("vF1F"),s=r("t8hP"),a=r("kDLi"),c=r("ZGyg"),i=r("nKUr");function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function l(e){const{wrapInContent:t=!0,children:r,title:n}=e,l=Object(a.useStyles2)(d);return Object(i.jsxs)(c.a,{children:[Object(i.jsx)(a.PageToolbar,{title:n,pageIcon:"bell",onGoBack:()=>s.locationService.push("/alerting/list")}),Object(i.jsx)("div",{className:l.content,children:t?Object(i.jsx)(u,o({},e)):r})]})}function u({children:e,padding:t=2}){const r=Object(a.useStyles2)(j(t));return Object(i.jsx)("div",{className:r.wrapper,children:e})}const d=e=>({content:n.css`
      margin: ${e.spacing(0,2,2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}),j=e=>t=>({wrapper:n.css`
      background: ${t.colors.background.primary};
      border: 1px solid ${t.colors.border.weak};
      border-radius: ${t.shape.borderRadius()};
      padding: ${t.spacing(e)};
    `})}}]);
//# sourceMappingURL=AlertingRule.d7cfb4e56c8be9229275.js.map