"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4679],{"./public/app/features/alerting/unified/RuleViewer.tsx":(e,s,t)=>{t.r(s),t.d(s,{RuleViewer:()=>B,default:()=>V});var r=t("./node_modules/react/index.js"),n=t("./node_modules/react-use/esm/useObservable.js"),a=t("./node_modules/@emotion/css/dist/emotion-css.esm.js"),i=t("./packages/grafana-data/src/index.ts"),o=t("./packages/grafana-ui/src/index.ts"),u=t("./public/app/features/alerting/unified/state/AlertingQueryRunner.ts"),l=t("./public/app/features/alerting/unified/hooks/useCombinedRule.ts"),c=t("./public/app/features/alerting/unified/utils/datasource.ts"),d=t("./public/app/features/alerting/unified/utils/rules.ts");function p(e){if(!e)return[];const{namespace:s,rulerRule:t}=e,{rulesSource:r}=s;if((0,c.HY)(r)&&(0,d.Pc)(t))return t.grafana_alert.data;if((0,c.jq)(r)){const s=function(e,s){const t="A";switch(e.type){case"prometheus":return{refId:t,expr:s.query};case"loki":return{refId:t,expr:s.query};default:throw new Error(`Query for datasource type ${e.type} is currently not supported by cloud alert rules.`)}}(r,e);return[{refId:s.refId,datasourceUid:r.uid,queryType:"",model:s,relativeTimeRange:{from:360,to:0}}]}return[]}var f=t("./public/app/features/alerting/unified/components/rules/RuleState.tsx"),g=t("./public/app/features/alerting/unified/components/DetailsField.tsx"),m=t("./public/app/features/alerting/unified/components/rules/RuleHealth.tsx"),h=t("./packages/grafana-runtime/src/index.ts"),x=t("./public/app/features/expressions/guards.ts"),b=t("./node_modules/react-virtualized-auto-sizer/dist/index.esm.js"),j=t("./public/app/features/alerting/unified/components/PanelPluginsButtonGroup.tsx"),v=t("./public/app/features/alerting/unified/utils/constants.ts"),y=t("./node_modules/react/jsx-runtime.js");const w=["refId"];var R;function S(e){var s;const t=(0,o.useTheme2)(),n=(0,o.useStyles2)(C),{data:a,query:u,onChangeQuery:l}=e,c=(0,x.j)(u.model)?v.Fe:v.GC,[d,p]=(0,r.useState)(c),f=(0,h.getDataSourceSrv)().getInstanceSettings(u.datasourceUid),g=u.relativeTimeRange,[m,w]=(0,r.useState)({frameIndex:0,showHeader:!0}),S=(0,r.useCallback)((e=>{const s=(0,i.dateTime)().unix()-e.unix();if(g){const e=g.from-g.to;l(Object.assign({},u,{relativeTimeRange:{from:s+e,to:s}}))}}),[l,u,g]),$=(0,r.useCallback)((e=>0===e?(0,i.dateTime)():(0,i.dateTime)().subtract(e,"seconds")),[]);return a?f?(0,y.jsx)("div",{className:n.content,children:(0,y.jsx)(b.Z,{children:({width:e,height:r})=>(0,y.jsxs)("div",{style:{width:e,height:r},children:[(0,y.jsxs)("div",{className:n.header,children:[(0,y.jsxs)("div",{children:[`Query ${u.refId}`,(0,y.jsxs)("span",{className:n.dataSource,children:["(",f.name,")"]})]}),(0,y.jsxs)("div",{className:n.actions,children:[!(0,x.j)(u.model)&&g?(0,y.jsx)(o.DateTimePicker,{date:$(g.to),onChange:S,maxDate:new Date}):null,s||(s=(0,y.jsx)(j.j,{onChange:p,value:d,size:"md"})),!(0,x.j)(u.model)&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:n.spacing}),(0,y.jsx)(o.LinkButton,{size:"md",variant:"secondary",icon:"compass",target:"_blank",href:k(f,u),children:"View in Explore"})]})]})]}),(0,y.jsx)(h.PanelRenderer,{height:r-4*t.spacing.gridSize,width:e,data:a,pluginId:d,title:"",onOptionsChange:w,options:m})]})})}):(0,y.jsxs)("div",{className:n.content,children:[R||(R=(0,y.jsx)(o.Alert,{title:"Could not find datasource for query"})),(0,y.jsx)(o.CodeEditor,{width:"100%",height:"250px",language:"json",showLineNumbers:!1,showMiniMap:!1,value:JSON.stringify(u,null,"\t"),readOnly:!0})]}):null}function k(e,s){const{name:t}=e,r=function(e,s){if(null==e)return{};var t,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],s.indexOf(t)>=0||(n[t]=e[t]);return n}(s.model,w),n=Object.assign({},r,{datasource:t});return i.urlUtil.renderUrl(`${h.config.appSubUrl}/explore`,{left:JSON.stringify(["now-1h","now",t,n])})}const C=e=>({content:a.css`
      width: 100%;
      height: 250px;
    `,header:a.css`
      height: ${e.spacing(4)};
      display: flex;
      align-items: center;
      justify-content: space-between;
      white-space: nowrap;
    `,refId:a.css`
      font-weight: ${e.typography.fontWeightMedium};
      color: ${e.colors.text.link};
      overflow: hidden;
    `,dataSource:a.css`
      margin-left: ${e.spacing(1)};
      font-style: italic;
      color: ${e.colors.text.secondary};
    `,actions:a.css`
      display: flex;
      align-items: center;
    `,spacing:a.css`
      padding: ${e.spacing(0,1,0,0)};
    `,errorMessage:a.css`
      white-space: pre-wrap;
    `});var $,I,O,_,T=t("./public/app/features/alerting/unified/components/rules/RuleDetailsActionButtons.tsx"),q=t("./public/app/features/alerting/unified/components/rules/RuleDetailsMatchingInstances.tsx"),N=t("./public/app/features/alerting/unified/components/rules/RuleDetailsDataSources.tsx"),L=t("./public/app/features/alerting/unified/components/rule-viewer/RuleViewerLayout.tsx"),D=t("./public/app/features/alerting/unified/components/AlertLabels.tsx"),M=t("./public/app/features/alerting/unified/components/rules/RuleDetailsExpression.tsx"),U=t("./public/app/features/alerting/unified/components/rules/RuleDetailsAnnotations.tsx"),E=t("./public/app/features/alerting/unified/utils/rule-id.ts");const P="Could not find data source for rule",z="Could not view rule",A="Alerting / View rule";function B({match:e}){const s=(0,o.useStyles2)(F),{id:t,sourceName:a}=e.params,i=E.OA(t,!0),{loading:d,error:h,result:x}=(0,l.H)(i,a),b=(0,r.useMemo)((()=>new u.v),[]),j=(0,n.Z)(b.get()),v=(0,r.useMemo)((()=>p(x)),[x]),[w,R]=(0,r.useState)([]),k=(0,r.useCallback)((()=>{w.length>0&&b.run(w)}),[w,b]);(0,r.useEffect)((()=>{R(v)}),[v]),(0,r.useEffect)((()=>{k()}),[k]),(0,r.useEffect)((()=>()=>b.destroy()),[b]);const C=(0,r.useCallback)((e=>{R((s=>s.map((s=>s.refId===e.refId?e:s))))}),[]);if(!a)return(0,y.jsx)(L.$,{title:A,children:(0,y.jsx)(o.Alert,{title:z,children:(0,y.jsx)("details",{className:s.errorMessage,children:P})})});const B=(0,c.o_)(a);if(d)return $||($=(0,y.jsx)(L.$,{title:A,children:(0,y.jsx)(o.LoadingPlaceholder,{text:"Loading rule..."})}));var V;if(h||!B)return(0,y.jsx)(L.$,{title:A,children:(0,y.jsx)(o.Alert,{title:z,children:(0,y.jsxs)("details",{className:s.errorMessage,children:[null!==(V=null==h?void 0:h.message)&&void 0!==V?V:P,I||(I=(0,y.jsx)("br",{})),!(null==h||!h.stack)&&h.stack]})})});if(!x)return O||(O=(0,y.jsx)(L.$,{title:A,children:(0,y.jsx)("span",{children:"Rule could not be found."})}));const G=Object.entries(x.annotations).filter((([e,s])=>!!s.trim()));return(0,y.jsxs)(L.$,{wrapInContent:!1,title:A,children:[(0,y.jsxs)(L.l,{children:[(0,y.jsxs)("div",{children:[(0,y.jsxs)("h4",{children:[_||(_=(0,y.jsx)(o.Icon,{name:"bell",size:"lg"}))," ",x.name]}),(0,y.jsx)(f.p,{rule:x,isCreating:!1,isDeleting:!1}),(0,y.jsx)(T.f,{rule:x,rulesSource:B})]}),(0,y.jsxs)("div",{className:s.details,children:[(0,y.jsxs)("div",{className:s.leftSide,children:[x.promRule&&(0,y.jsx)(g.C,{label:"Health",horizontal:!0,children:(0,y.jsx)(m.V,{rule:x.promRule})}),!!x.labels&&!!Object.keys(x.labels).length&&(0,y.jsx)(g.C,{label:"Labels",horizontal:!0,children:(0,y.jsx)(D.s,{labels:x.labels})}),(0,y.jsx)(M.C,{rulesSource:B,rule:x,annotations:G}),(0,y.jsx)(U.J,{annotations:G})]}),(0,y.jsxs)("div",{className:s.rightSide,children:[(0,y.jsx)(N.C,{rule:x,rulesSource:B}),(0,y.jsx)(g.C,{label:"Namespace / Group",children:`${x.namespace.name} / ${x.group.name}`})]})]}),(0,y.jsx)("div",{children:(0,y.jsx)(q.M,{promRule:x.promRule})})]}),j&&Object.keys(j).length>0&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:s.queriesTitle,children:["Query results ",(0,y.jsx)(o.PanelChromeLoadingIndicator,{loading:Q(j),onCancel:()=>b.cancel()})]}),(0,y.jsx)(L.l,{padding:0,children:(0,y.jsx)("div",{className:s.queries,children:w.map((e=>(0,y.jsx)("div",{className:s.query,children:(0,y.jsx)(S,{query:e,data:j&&j[e.refId],onChangeQuery:C})},e.refId)))})})]})]})}function Q(e){return!!Object.values(e).find((e=>e.state===i.LoadingState.Loading))}const F=e=>({errorMessage:a.css`
      white-space: pre-wrap;
    `,queries:a.css`
      height: 100%;
      width: 100%;
    `,queriesTitle:a.css`
      padding: ${e.spacing(2,.5)};
      font-size: ${e.typography.h5.fontSize};
      font-weight: ${e.typography.fontWeightBold};
      font-family: ${e.typography.h5.fontFamily};
    `,query:a.css`
      border-bottom: 1px solid ${e.colors.border.medium};
      padding: ${e.spacing(2)};
    `,details:a.css`
      display: flex;
      flex-direction: row;
    `,leftSide:a.css`
      flex: 1;
    `,rightSide:a.css`
      padding-left: 90px;
      width: 300px;
    `}),V=(0,o.withErrorBoundary)(B,{style:"page"})},"./public/app/features/alerting/unified/components/PanelPluginsButtonGroup.tsx":(e,s,t)=>{t.d(s,{j:()=>u});var r=t("./packages/grafana-runtime/src/index.ts"),n=t("./packages/grafana-ui/src/index.ts"),a=t("./node_modules/react/index.js"),i=t("./public/app/features/alerting/unified/utils/constants.ts"),o=t("./node_modules/react/jsx-runtime.js");function u(e){const{value:s,onChange:t,size:u="md"}=e,l=(0,a.useMemo)((()=>Object.values(r.config.panels).reduce(((e,s)=>(function(e){switch(e){case i.GC:case i.Fe:case i.Kd:return!0;default:return!1}}(s.id)&&e.push({value:s.id,label:s.name,imgUrl:s.info.logos.small}),e)),[])),[]);return(0,o.jsx)(n.RadioButtonGroup,{options:l,value:s,onChange:t,size:u})}},"./public/app/features/alerting/unified/components/rule-viewer/RuleViewerLayout.tsx":(e,s,t)=>{t.d(s,{$:()=>u,l:()=>l});t("./node_modules/react/index.js");var r=t("./node_modules/@emotion/css/dist/emotion-css.esm.js"),n=t("./packages/grafana-runtime/src/index.ts"),a=t("./packages/grafana-ui/src/index.ts"),i=t("./public/app/core/components/Page/Page.tsx"),o=t("./node_modules/react/jsx-runtime.js");function u(e){const{wrapInContent:s=!0,children:t,title:r}=e,u=(0,a.useStyles2)(c);return(0,o.jsxs)(i.T,{children:[(0,o.jsx)(a.PageToolbar,{title:r,pageIcon:"bell",onGoBack:()=>n.locationService.push("/alerting/list")}),(0,o.jsx)("div",{className:u.content,children:s?(0,o.jsx)(l,Object.assign({},e)):t})]})}function l({children:e,padding:s=2}){const t=(0,a.useStyles2)(d(s));return(0,o.jsx)("div",{className:t.wrapper,children:e})}const c=e=>({content:r.css`
      margin: ${e.spacing(0,2,2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}),d=e=>s=>({wrapper:r.css`
      background: ${s.colors.background.primary};
      border: 1px solid ${s.colors.border.weak};
      border-radius: ${s.shape.borderRadius()};
      padding: ${s.spacing(e)};
    `})},"./public/app/features/alerting/unified/hooks/useCombinedRule.ts":(e,s,t)=>{t.d(s,{H:()=>d,X:()=>p});var r=t("./node_modules/react/index.js"),n=t("./node_modules/react-redux/es/index.js"),a=t("./public/app/features/alerting/unified/utils/redux.ts"),i=t("./public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts"),o=t("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),u=t("./public/app/features/alerting/unified/state/actions.ts"),l=t("./public/app/features/alerting/unified/utils/rule-id.ts"),c=t("./public/app/features/alerting/unified/utils/rules.ts");function d(e,s){const t=f(s),n=(0,i.Z)(s),a=(0,r.useMemo)((()=>{if(e&&s&&0!==n.length)for(const t of n)for(const r of t.groups)for(const t of r.rules){const r=l.Yd(s,t);if(l.Dg(r,e))return t}}),[e,s,n]);return Object.assign({},t,{result:a})}function p(e,s){const t=f(s),n=(0,i.Z)(s),a=(0,r.useMemo)((()=>{if(!e||!s||0===n.length)return[];const t=[];for(const s of n)for(const r of s.groups)for(const s of r.rules)s.name===e&&t.push(s);return t}),[e,s,n]);return Object.assign({},t,{result:a})}function f(e){var s;const t=(0,n.useDispatch)(),a=(0,o._)((e=>e.promRules)),i=g(e,a),l=(0,o._)((e=>e.rulerRules)),d=g(e,l);return(0,r.useEffect)((()=>{e&&(t((0,u.y6)(e)),t((0,u.UR)(e)))}),[t,e]),{loading:i.loading||d.loading,error:(null!==(s=i.error)&&void 0!==s?s:(0,c.m$)(d))?void 0:d.error,dispatched:i.dispatched&&d.dispatched}}function g(e,s){if(!e)return a.oq;const t=s[e];return t||a.oq}},"./public/app/features/alerting/unified/state/AlertingQueryRunner.ts":(e,s,t)=>{t.d(s,{v:()=>S});var r=t("./node_modules/rxjs/dist/esm5/internal/ReplaySubject.js"),n=t("./node_modules/rxjs/dist/esm5/internal/observable/of.js"),a=t("./node_modules/rxjs/dist/esm5/internal/operators/catchError.js"),i=t("./node_modules/rxjs/dist/esm5/internal/operators/share.js"),o=t("./node_modules/rxjs/dist/esm5/internal/operators/map.js"),u=t("./node_modules/uuid/dist/esm-browser/v4.js"),l=t("./packages/grafana-data/src/index.ts"),c=t("./packages/grafana-runtime/src/index.ts"),d=t("./public/app/core/services/backend_srv.ts"),p=t("./public/app/features/query/state/runRequest.ts"),f=t("./public/app/features/expressions/types.ts");const g={from:21600,to:0},m=(e,s)=>{switch(e.type){case f.Us.classic:return h(e);case f.Us.math:return b(e,s);case f.Us.resample:case f.Us.reduce:return j(e)}},h=e=>{var s;return null===(s=e.conditions)||void 0===s?void 0:s.map((e=>e.query.params[0]))},x=(e,s)=>{let t=[],r=[g.to];for(const n of e){const e=s.find((e=>e.refId===n));e&&e.relativeTimeRange&&(t.push(e.relativeTimeRange.from),r.push(e.relativeTimeRange.to))}return{from:t,to:r}},b=(e,s)=>s.filter((s=>{var t;return"query"===s.queryType&&(null===(t=e.expression)||void 0===t?void 0:t.includes(s.refId))})).map((e=>e.refId)),j=e=>e.expression?[e.expression]:void 0;var v=t("./public/app/features/expressions/guards.ts"),y=t("./public/app/features/query/state/processing/revision.ts"),w=t("./public/app/features/query/state/processing/canceler.ts");function R(e,s,t){return s in e?Object.defineProperty(e,s,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[s]=t,e}class S{constructor(e=(0,d.i)()){R(this,"subject",void 0),R(this,"subscription",void 0),R(this,"lastResult",void 0),this.backendSrv=e,this.subject=new r.t(1),this.lastResult={}}get(){return this.subject.asObservable()}run(e){if(0===e.length){const s=C(e,l.LoadingState.Done);return this.subject.next(s)}this.subscription=k(this.backendSrv,e).subscribe({next:e=>{const s=_(e,((e,s)=>{const t=this.lastResult[e],r=(0,p.zR)(s,t);return(0,y.C)(r,t)}));this.lastResult=s,this.subject.next(this.lastResult)},error:e=>{this.lastResult=O(this.lastResult,e),this.subject.next(this.lastResult)}})}cancel(){if(!this.subscription)return;this.subscription.unsubscribe();let e=!1;const s=_(this.lastResult,((s,t)=>(t.state===l.LoadingState.Loading&&(e=!0),Object.assign({},t,{state:l.LoadingState.Done}))));e&&this.subject.next(s)}destroy(){this.subject&&this.subject.complete(),this.cancel()}}const k=(e,s)=>{const t=C(s,l.LoadingState.Loading),r={data:{data:s},url:"/api/v1/eval",method:"POST",requestId:(0,u.Z)()};return(0,l.withLoadingIndicator)({whileLoading:t,source:e.fetch(r).pipe(I(t),(0,a.K)((e=>(0,n.of)(O(t,e)))),(0,w.V)(e,r.requestId),(0,i.B)())})},C=(e,s)=>e.reduce(((t,r)=>(t[r.refId]={state:s,series:[],timeRange:$(r,e)},t)),{}),$=(e,s)=>{if((0,v.j)(e.model)){const t=((e,s)=>{const t=m(e,s);if(!t)return g;const{from:r,to:n}=x(t,s);return r.length||n.length?{from:Math.max(...r),to:Math.min(...n)}:g})(e.model,s);return l.rangeUtil.relativeToTimeRange(t)}return e.relativeTimeRange?l.rangeUtil.relativeToTimeRange(e.relativeTimeRange):(console.warn(`Query with refId: ${e.refId} did not have any relative time range, using default.`),(0,l.getDefaultTimeRange)())},I=e=>(0,o.U)((s=>{const{data:t}=s,r={};for(const[s,n]of Object.entries(t.results))r[s]={timeRange:e[s].timeRange,state:l.LoadingState.Done,series:n.frames.map(l.dataFrameFromJSON)};return r})),O=(e,s)=>{const t=(0,c.toDataQueryError)(s);return _(e,((e,s)=>Object.assign({},s,{state:l.LoadingState.Error,error:t})))},_=(e,s)=>{const t={};for(const[r,n]of Object.entries(e))t[r]=s(r,n);return t}},"./public/app/features/expressions/guards.ts":(e,s,t)=>{t.d(s,{j:()=>a});var r=t("./public/app/features/expressions/ExpressionDatasource.ts"),n=t("./public/app/features/expressions/types.ts");const a=e=>{if(!e)return!1;if(e.datasource===r.DB)return!0;const s=e;return"string"==typeof s.type&&Object.values(n.Us).includes(s.type)}},"./node_modules/react-use/esm/useObservable.js":(e,s,t)=>{t.d(s,{Z:()=>a});var r=t("./node_modules/react/index.js"),n=t("./node_modules/react-use/esm/useIsomorphicLayoutEffect.js");const a=function(e,s){var t=(0,r.useState)(s),a=t[0],i=t[1];return(0,n.Z)((function(){var s=e.subscribe(i);return function(){return s.unsubscribe()}}),[e]),a}}}]);
//# sourceMappingURL=AlertingRule.8128b05ac04b15cbf98d.js.map