"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1343],{44243:(e,t,r)=>{r.d(t,{x:()=>s});var n=r(76687),a=r(352),i=r(77829);function s(e){const t=(0,a.I0)(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)((()=>()=>{t((0,i.e)({cleanupAction:r.current}))}),[t])}},66783:(e,t,r)=>{r.d(t,{R:()=>o});r(76687);var n,a=r(67273),i=r(35562),s=r(52010);const o=()=>(0,s.jsxs)(i.b,{severity:"warning",title:"Global evalutation interval limit exceeded",children:["A minimum evaluation interval of ",(0,s.jsx)("strong",{children:a.v.unifiedAlerting.minInterval})," has been configured in Grafana.",n||(n=(0,s.jsx)("br",{})),"Please contact the administrator to configure a lower interval."]})},49765:(e,t,r)=>{r.d(t,{wO:()=>F,MD:()=>S});var n=r(77813),a=r(76687),i=r(84734),s=r(27668),o=r(45550),l=r(97770),c=r(9120),d=r(60521),u=r(93507),g=r(95513),v=r(2437),h=r(66783),p=r(62533),f=r(23697),x=r(52010);const m=["includeNoData","includeError"];const w=[{value:f.g0.Alerting,label:"Alerting"},{value:f.g0.NoData,label:"No Data"},{value:f.g0.OK,label:"OK"},{value:f.g0.Error,label:"Error"}],b=e=>{let{includeNoData:t,includeError:r}=e,n=function(e,t){if(null==e)return{};var r,n,a={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,m);const i=(0,a.useMemo)((()=>t?r?w:w.filter((e=>e.value!==f.g0.Error)):w.filter((e=>e.value!==f.g0.NoData))),[t,r]);return(0,x.jsx)(p.Ph,Object.assign({options:i},n))};var j=r(97999),y=r(50454);const $=["onChange","ref"],N=["onChange","ref"];var E,C;function O(e,t){if(null==e)return{};var r,n,a={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}const S={required:{value:!0,message:"Required."},validate:e=>{try{const t=(0,g.nd)(e);return t<1e4?"Cannot be less than 10 seconds.":t%1e4==0||"Must be a multiple of 10 seconds."}catch(e){return e instanceof Error?e.message:"Failed to parse duration"}}},F=()=>{var e,t,r;const n=(0,s.wW)(k),[p,f]=(0,a.useState)(!1),{register:m,formState:{errors:w},watch:F}=(0,i.Gc)(),{exceedsLimit:A}=(0,u.f)(F("evaluateEvery")),D="eval-every-input",G="eval-for-input";return(0,x.jsxs)(y.z,{stepNo:2,title:"Alert evaluation behavior",children:[(0,x.jsx)(o.g,{label:"Evaluate",description:"Evaluation interval applies to every rule within a group. It can overwrite the interval of an existing alert rule.",children:(0,x.jsxs)("div",{className:n.flexRow,children:[(0,x.jsx)(l.W,{htmlFor:D,width:16,tooltip:"How often the alert will be evaluated to see if it fires",children:"Evaluate every"}),(0,x.jsx)(o.g,{className:n.inlineField,error:null===(e=w.evaluateEvery)||void 0===e?void 0:e.message,invalid:!!w.evaluateEvery,validationMessageHorizontalOverflow:!0,children:(0,x.jsx)(c.I,Object.assign({id:D,width:8},m("evaluateEvery",S)))}),(0,x.jsx)(l.W,{htmlFor:G,width:7,tooltip:'Once condition is breached, alert will go into pending state. If it is pending for longer than the "for" value, it will become a firing alert.',children:"for"}),(0,x.jsx)(o.g,{className:n.inlineField,error:null===(t=w.evaluateFor)||void 0===t?void 0:t.message,invalid:!(null===(r=w.evaluateFor)||void 0===r||!r.message),validationMessageHorizontalOverflow:!0,children:(0,x.jsx)(c.I,Object.assign({id:G,width:8},m("evaluateFor",(I=F("evaluateEvery"),{required:{value:!0,message:"Required."},validate:e=>{if("0"===e)return!0;try{const t=(0,g.nd)(e);if(0===t)return!0;try{return t>=(0,g.nd)(I)||"For duration must be greater than or equal to the evaluation interval."}catch(e){return!0}}catch(e){return e instanceof Error?e.message:"Failed to parse duration"}}}))))})]})}),A&&(E||(E=(0,x.jsx)(h.R,{}))),(0,x.jsx)(v.U,{isCollapsed:!p,onToggle:e=>f(!e),text:"Configure no data and error handling",className:n.collapseToggle}),p&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(o.g,{htmlFor:"no-data-state-input",label:"Alert state if no data or all values are null",children:(0,x.jsx)(d.g,{render:e=>{let{field:{onChange:t}}=e,r=O(e.field,$);return(0,x.jsx)(b,Object.assign({},r,{inputId:"no-data-state-input",width:42,includeNoData:!0,includeError:!1,onChange:e=>t(null==e?void 0:e.value)}))},name:"noDataState"})}),(0,x.jsx)(o.g,{htmlFor:"exec-err-state-input",label:"Alert state if execution error or timeout",children:(0,x.jsx)(d.g,{render:e=>{let{field:{onChange:t}}=e,r=O(e.field,N);return(0,x.jsx)(b,Object.assign({},r,{inputId:"exec-err-state-input",width:42,includeNoData:!1,includeError:!0,onChange:e=>t(null==e?void 0:e.value)}))},name:"execErrState"})})]}),C||(C=(0,x.jsx)(j.Y,{}))]});var I},k=e=>({inlineField:n.css`
    margin-bottom: 0;
  `,flexRow:n.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
  `,collapseToggle:n.css`
    margin: ${e.spacing(2,0,2,-1)};
  `,globalLimitValue:n.css`
    font-weight: ${e.typography.fontWeightBold};
  `})},97999:(e,t,r)=>{r.d(t,{Y:()=>L,u:()=>W});var n=r(77813),a=r(76687),i=r(84734),s=r(49458),o=r(13467),l=r(84738),c=r(77212),d=r(2343),u=r(27668),g=r(7053),v=r(55312),h=r(35562),p=r(98800),f=r(20709),x=r(95481),m=r(11316),w=r(37),b=r(29117),j=r(61997),y=r(5205),$=r(92572);var N=r(17558),E=r(11126);function C(e,t,r){return(0,w.x)({whileLoading:O(r),source:(0,y.i)().fetch({method:"POST",url:`/api/v1/rule/test/${t}`,data:e}).pipe((0,f.U)((e=>{let{data:t}=e;return O(r,{state:c.Gu.Done,series:t.instances.map(b.vP)})})),(0,x.K)((e=>(0,p.of)(O(r,{state:c.Gu.Error,error:(0,$.P)(e)})))),(0,m.B)())})}function O(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{ruleType:e,data:Object.assign({state:c.Gu.Loading,series:[],timeRange:(0,j.JK)()},t)}}var S,F,k=r(70434),A=r(65677),D=r(40840),G=r(53620),I=r(98277),q=r(27121),R=r(52010);function z(e){const{preview:t}=e,r=(0,u.wW)(M),n={defaults:{},overrides:[{matcher:{id:D.mi.byName,options:"Info"},properties:[{id:"custom.displayMode",value:I.h2.JSONView}]}]};if(!t)return null;const{data:a,ruleType:i}=t;return a.state===c.Gu.Loading?(0,R.jsx)("div",{className:r.container,children:S||(S=(0,R.jsx)("span",{children:"Loading preview..."}))}):a.state===c.Gu.Error?(0,R.jsx)("div",{className:r.container,children:a.error?(0,q.kk)(a.error):"Failed to preview alert rule"}):(0,R.jsxs)("div",{className:r.container,children:[(0,R.jsxs)("span",{children:["Preview based on the result of running the query, for this moment."," ",i===N.$.grafana?"Configuration for `no data` and `error handling` is not applied.":null]}),(0,R.jsx)("div",{className:r.table,children:(0,R.jsx)(A.Z,{children:e=>{let{width:t,height:r}=e;return(0,R.jsx)("div",{style:{width:`${t}px`,height:`${r}px`},children:(0,R.jsx)(G.$,{title:"",width:t,height:r,pluginId:"table",data:a,fieldConfig:n})})}})})]})}function M(e){return{container:n.css`
      margin: ${e.spacing(2)} 0;
    `,table:n.css`
      flex: 1 1 auto;
      height: 135px;
      margin-top: ${e.spacing(2)};
      border: 1px solid ${e.colors.border.medium};
      border-radius: ${e.shape.borderRadius(1)};
    `}}const P=["type","dataSourceName","condition","queries","expression"];function L(){const e=(0,u.wW)(T),[t,r]=W(),{watch:n}=(0,i.Gc)(),[a,s,o]=n(["type","condition","queries"]),{allDataSourcesAvailable:l}=(0,k.S)(o);if(a===N.$.cloudRecording||a===N.$.cloudAlerting)return null;const c=Boolean(s)&&l;return(0,R.jsxs)("div",{className:e.container,children:[(0,R.jsxs)(g.Lh,{children:[l&&(0,R.jsx)(v.zx,{disabled:!c,type:"button",variant:"primary",onClick:r,children:"Preview alerts"}),!l&&(F||(F=(0,R.jsx)(h.b,{title:"Preview is not available",severity:"warning",children:"Cannot display the query preview. Some of the data sources used in the queries are not available."})))]}),(0,R.jsx)(z,{preview:t})]})}function W(){const[e,t]=(0,a.useState)(),{getValues:r}=(0,i.Gc)(),n=(0,s.Z)();return[e,(0,a.useCallback)((()=>{const e=function(e){const[t,r,n,a,i]=e,s=(0,d.F)().getInstanceSettings(r);if(!s)throw new Error(`Cannot find data source settings for ${r}`);switch(t){case N.$.cloudAlerting:return{dataSourceUid:s.uid,dataSourceName:r,expr:i};case N.$.grafana:return{grafana_condition:{condition:n,data:a,now:(0,l.lf)(Date.now())}};default:throw new Error(`Alert type ${t} not supported by preview.`)}}(r(P));(function(e){if(function(e){return"expr"in e}(e))return C(e,e.dataSourceUid,N.$.cloudAlerting);if(function(e){return"grafana_condition"in e}(e))return C(e,E.GC,N.$.grafana);throw new Error("unsupported preview rule request")})(e).pipe((0,o.o)((e=>!function(e){switch(e.data.state){case c.Gu.Done:case c.Gu.Error:return!0;default:return!1}}(e)),!0)).subscribe((e=>{n()&&t(e)}))}),[r,n])]}function T(e){return{container:n.css`
      margin-top: ${e.spacing(2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}}},50454:(e,t,r)=>{r.d(t,{z:()=>o});var n=r(77813),a=(r(76687),r(27668)),i=r(72660),s=r(52010);const o=e=>{let{title:t,stepNo:r,children:n,description:o}=e;const c=(0,a.wW)(l);return(0,s.jsxs)("div",{className:c.parent,children:[(0,s.jsx)("div",{children:(0,s.jsx)("span",{className:c.stepNo,children:r})}),(0,s.jsx)("div",{className:c.content,children:(0,s.jsxs)(i.C,{label:t,className:c.fieldset,children:[o&&(0,s.jsx)("p",{className:c.description,children:o}),n]})})]})},l=e=>({fieldset:n.css`
    legend {
      font-size: 16px;
      padding-top: ${e.spacing(.5)};
    }
  `,parent:n.css`
    display: flex;
    flex-direction: row;
    max-width: ${e.breakpoints.values.xl};
    & + & {
      margin-top: ${e.spacing(4)};
    }
  `,description:n.css`
    margin-top: -${e.spacing(2)};
    color: ${e.colors.text.secondary};
  `,stepNo:n.css`
    display: inline-block;
    width: ${e.spacing(4)};
    height: ${e.spacing(4)};
    line-height: ${e.spacing(4)};
    border-radius: ${e.spacing(4)};
    text-align: center;
    color: ${e.colors.text.maxContrast};
    background-color: ${e.colors.background.canvas};
    font-size: ${e.typography.size.lg};
    margin-right: ${e.spacing(2)};
  `,content:n.css`
    flex: 1;
  `})},70434:(e,t,r)=>{r.d(t,{S:()=>i});var n=r(76687),a=r(2343);function i(e){return{allDataSourcesAvailable:(0,n.useMemo)((()=>e.every((e=>Boolean((0,a.F)().getInstanceSettings(e.datasourceUid))))),[e])}}},98090:(e,t,r)=>{r.d(t,{B:()=>i});var n=r(76687),a=r(72721);function i(){return(0,n.useMemo)((()=>(0,a.Rv)()),[])}}}]);
//# sourceMappingURL=1343.0bd505924d51bdb55494.js.map