"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9168],{16905:(e,n,t)=>{t.d(n,{F:()=>c});var r,a,s,l=t(36636),o=(t(68404),t(90747)),i=t(69783),u=t(45916);const c=e=>{let{className:n,onFilterChange:t,defaultQueryString:l,queryString:c}=e;const p=(0,i.useStyles2)(d),m=r||(r=(0,u.jsx)(i.Icon,{name:"search"}));return(0,u.jsxs)("div",{className:n,children:[(0,u.jsx)(i.Label,{children:(0,u.jsxs)(o.Stack,{gap:.5,children:[a||(a=(0,u.jsx)("span",{children:"Search by label"})),(0,u.jsx)(i.Tooltip,{content:s||(s=(0,u.jsxs)("div",{children:["Filter alerts using label querying, ex:",(0,u.jsx)("pre",{children:'{severity="critical", instance=~"cluster-us-.+"}'})]})),children:(0,u.jsx)(i.Icon,{className:p.icon,name:"info-circle",size:"sm"})})]})}),(0,u.jsx)(i.Input,{placeholder:"Search",defaultValue:l,value:c,onChange:e=>{const n=e.target;t(n.value)},"data-testid":"search-query-input",prefix:m,className:p.inputWidth})]})},d=e=>({icon:l.css`
    margin-right: ${e.spacing(.5)};
  `,inputWidth:l.css`
    width: 340px;
    flex-grow: 0;
  `})},83039:(e,n,t)=>{t.d(n,{f:()=>F});var r=t(36636),a=t(68404),s=t(18745),l=t(42326),o=t(43215),i=t(90923),u=t(69783),c=t(58257),d=t(61959),p=t(58170),m=t(78567),h=t(82897),g=t(83809),x=t(33899);var f,v=t(23906),j=t(9019),b=t(69357),y=t(45916);const S=e=>{let{alertId:n}=e;const{loading:t,error:r,result:l=[]}=function(e){const n=(0,s.useDispatch)(),t=(0,x._)((e=>e.managedAlertStateHistory));return(0,a.useEffect)((()=>{n((0,g.Ms)(e))}),[n,e]),t}(n);if(t&&!r)return f||(f=(0,y.jsx)(u.LoadingPlaceholder,{text:"Loading history..."}));if(r&&!t)return(0,y.jsx)(u.Alert,{title:"Failed to fetch alert state history",children:r.message});const o=[{id:"state",label:"State",size:"max-content",renderCell:R},{id:"value",label:"",size:"auto",renderCell:w},{id:"timestamp",label:"Time",size:"max-content",renderCell:C}],i=l.reduce(((e,n,t)=>(e.push({id:String(n.id),state:n.newState,text:n.text,data:n.data,timestamp:n.updated}),function(e,n){const t=n[e],r=n[e+1];if(!r)return!1;return r.newState===t.prevState}(t,l)||e.push({id:(0,h.uniqueId)(),state:n.prevState}),e)),[]).map((e=>({id:e.id,data:e})));return(0,y.jsx)(j.t,{cols:o,items:i})};function w(e){var n,t;const r=null!==(n=null===(t=e.data.data)||void 0===t?void 0:t.evalMatches)&&void 0!==n?n:[];return(0,y.jsxs)(y.Fragment,{children:[e.data.text,(0,y.jsx)(k,{children:r.map((e=>(0,y.jsx)(v.i,{labelKey:e.metric,value:String(e.value)},e.metric)))})]})}function R(e){return(0,y.jsx)(b.l,{state:e.data.state})}function C(e){return(0,y.jsx)("div",{className:_,children:e.data.timestamp&&(0,y.jsx)("span",{children:(0,o.dateTimeFormat)(e.data.timestamp)})})}const k=e=>{let{children:n}=e;const{wrapper:t}=(0,u.useStyles)(q);return(0,y.jsx)("div",{className:t,children:n})},_=r.css`
  display: flex;
  align-items: flex-end;
  flex-direction: column;
`,q=e=>({wrapper:r.css`
    & > * {
      margin-right: ${e.spacing.xs};
    }
  `});var N,$,z=t(82139),E=t(85464),M=t(19462),I=t(39357),U=t(59940),D=t(86647);const F=e=>{var n,t;let{rule:r,rulesSource:h}=e;const x=(0,s.useDispatch)(),f=(0,l.TH)(),v=(0,c.iG)(),j=(0,u.useStyles2)(L),{namespace:b,group:w,rulerRule:R}=r,[C,k]=(0,a.useState)(),_=function(e){if(!e)return!1;return null!=e.grafana_alert}(r.rulerRule)&&null!==(n=r.rulerRule.grafana_alert.id)&&void 0!==n?n:"",{StateHistoryModal:q,showStateHistoryModal:F}=function(e){var n;const[t,r]=(0,a.useState)(!1);return{StateHistoryModal:(0,a.useMemo)((()=>(0,y.jsx)(u.Modal,{isOpen:t,onDismiss:()=>r(!1),closeOnBackdropClick:!0,closeOnEscape:!0,title:"State history",children:n||(n=(0,y.jsx)(S,{alertId:e}))})),[e,t]),showStateHistoryModal:()=>r(!0),hideStateHistoryModal:()=>r(!1)}}(_),V=(0,M.HY)(h)?h:null===(t=(0,z.Xy)(h.jsonData.alertmanagerUid))||void 0===t?void 0:t.name,B=(0,M.EG)(h),H=d.Vt.hasPermission(p.bW.DataSourcesExplore),O=[],G=[],A=(0,D.Jq)(w),{isEditable:P,isRemovable:T}=(0,m.M)(B,R),W=f.pathname+f.search,Z=f.pathname.endsWith("/view");const J=()=>{if(C&&C.rulerRule){const e=U.Zk((0,M.EG)(C.namespace.rulesSource),C.namespace.name,C.group.name,C.rulerRule);x((0,g.hS)(e,{navigateTo:Z?"/alerting/list":void 0})),k(void 0)}},Y=()=>{if((0,M.jq)(h)){const{appUrl:e,appSubUrl:n}=i.config;return`${""!==n?`${e}${n}/`:i.config.appUrl}alerting/${`${encodeURIComponent(h.name)}/${encodeURIComponent(r.name)}`}/find`}return window.location.href.split("?")[0]};if((0,M.jq)(h)&&H&&!A&&O.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"primary",icon:"chart-line",target:"__blank",href:(0,I.mH)(h.name,r.query),children:"See graph"},"explore")),r.annotations[E.q6.runbookURL]&&O.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"primary",icon:"book",target:"__blank",href:r.annotations[E.q6.runbookURL],children:"View runbook"},"runbook")),r.annotations[E.q6.dashboardUID]){const e=r.annotations[E.q6.dashboardUID];if(e){O.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}`,children:"Go to dashboard"},"dashboard"));const n=r.annotations[E.q6.panelID];n&&O.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}?viewPanel=${encodeURIComponent(n)}`,children:"Go to panel"},"panel"))}}if(V&&d.Vt.hasAccess(p.bW.AlertingInstanceCreate,d.Vt.isEditor)&&O.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",icon:"bell-slash",target:"__blank",href:(0,I.Vv)(V,r),children:"Silence"},"silence")),_&&O.push((0,y.jsxs)(a.Fragment,{children:[(0,y.jsx)(u.Button,{className:j.button,size:"xs",icon:"history",onClick:()=>F(),children:"Show state history"}),q]},"history")),Z||G.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"secondary",icon:"eye",href:(0,I.V2)(h,r,W),children:"View"},"view")),P&&R&&!A){const e=(0,M.EG)(h),n=U.Zk(e,b.name,w.name,R),t=o.urlUtil.renderUrl(`${i.config.appSubUrl}/alerting/${encodeURIComponent(U.$V(n))}/edit`,{returnTo:W});Z&&G.push((0,y.jsx)(u.ClipboardButton,{onClipboardCopy:()=>{v.success("URL copied!")},onClipboardError:e=>{v.error("Error while copying URL",e)},className:j.button,size:"sm",getText:Y,children:"Copy link to rule"},"copy")),G.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"secondary",icon:"pen",href:t,children:"Edit"},"edit"))}return T&&R&&!A&&G.push((0,y.jsx)(u.Button,{className:j.button,size:"xs",type:"button",variant:"secondary",icon:"trash-alt",onClick:()=>k(r),children:"Delete"},"delete")),O.length||G.length?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:j.wrapper,children:[(0,y.jsx)(u.HorizontalGroup,{width:"auto",children:O.length?O:N||(N=(0,y.jsx)("div",{}))}),(0,y.jsx)(u.HorizontalGroup,{width:"auto",children:G.length?G:$||($=(0,y.jsx)("div",{}))})]}),!!C&&(0,y.jsx)(u.ConfirmModal,{isOpen:!0,title:"Delete rule",body:"Deleting this rule will permanently remove it from your alert rule list. Are you sure you want to delete this rule?",confirmText:"Yes, delete",icon:"exclamation-triangle",onConfirm:J,onDismiss:()=>k(void 0)})]}):null};const L=e=>({wrapper:r.css`
    padding: ${e.spacing(2)} 0;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
    border-bottom: solid 1px ${e.colors.border.medium};
  `,button:r.css`
    height: 24px;
    margin-top: ${e.spacing(1)};
    font-size: ${e.typography.size.sm};
  `})},97292:(e,n,t)=>{t.d(n,{J:()=>o});var r=t(36636),a=(t(68404),t(69783)),s=t(212),l=t(45916);function o(e){const{annotations:n}=e,t=(0,a.useStyles2)(i);return 0===n.length?null:(0,l.jsx)("div",{className:t.annotations,children:n.map((e=>{let[n,t]=e;return(0,l.jsx)(s.a,{annotationKey:n,value:t},n)}))})}const i=()=>({annotations:r.css`
    margin-top: 46px;
  `})},79842:(e,n,t)=>{t.d(n,{C:()=>p});var r=t(36636),a=t(68404),s=t(90923),l=t(69783),o=t(24036),i=t(19462),u=t(86647),c=t(52510),d=t(45916);function p(e){const{rulesSource:n,rule:t}=e,r=(0,l.useStyles2)(m),p=(0,a.useMemo)((()=>{if((0,i.jq)(n))return[{name:n.name,icon:n.meta.info.logos.small}];if((0,u.Pc)(t.rulerRule)){const{data:e}=t.rulerRule.grafana_alert,n=e.reduce(((e,n)=>{const t=(0,s.getDataSourceSrv)().getInstanceSettings(n.datasourceUid);return t&&t.uid!==o.Yq?(e[t.name]={name:t.name,icon:t.meta.info.logos.small},e):e}),{});return Object.values(n)}return[]}),[t,n]);return 0===p.length?null:(0,d.jsx)(c.C,{label:"Data source",children:p.map(((e,n)=>{let{name:t,icon:a}=e;return(0,d.jsxs)("div",{children:[a&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("img",{alt:`${t} datasource logo`,className:r.dataSourceIcon,src:a})," "]}),t]},t)}))})}function m(e){const n=e.spacing(2);return{dataSourceIcon:r.css`
      width: ${n};
      height: ${n};
    `}}},85351:(e,n,t)=>{t.d(n,{C:()=>f});var r=t(36636),a=t(68404),s=t(19462),l=t(52510),o=t(50539),i=t(86377),u=t(69783),c=t(17245),d=t(53454),p=t(1481),m=t(45916);const h=e=>{let{language:n,expr:t}=e;const r=(0,a.useMemo)((()=>[(0,u.SlatePrism)({onlyIn:e=>"code_block"===e.type,getSyntax:()=>n},Object.assign({},o.languages,{[n]:"logql"===n?c.ZP:d.ZP}))]),[n]),s=(0,a.useMemo)((()=>(0,u.makeValue)(t)),[t]);return(0,m.jsx)(i.ML,{plugins:r,value:s,readOnly:!0})},g=e=>{let{expression:n,rulesSource:t}=e;const a=(0,u.useStyles)(x);return(0,m.jsx)(p.t,{className:(0,r.cx)(a.well,"slate-query-field"),children:(0,s.jq)(t)?(0,m.jsx)(h,{expr:n,language:t.type===s.ye.Loki?"logql":"promql"}):n})},x=e=>({well:r.css`
    font-family: ${e.typography.fontFamily.monospace};
  `});function f(e){const{annotations:n,rulesSource:t,rule:a}=e,o=v();return(0,s.jq)(t)?(0,m.jsx)(l.C,{label:"Expression",horizontal:!0,className:(0,r.cx)({[o.exprRow]:!!n.length}),children:(0,m.jsx)(g,{expression:a.query,rulesSource:t})}):null}const v=()=>({exprRow:r.css`
    margin-bottom: 46px;
  `})},12135:(e,n,t)=>{t.d(n,{M:()=>f});var r,a=t(36636),s=t(68404),l=t(69783),o=t(16905),i=t(51542),u=t(45916);const c=e=>{let{className:n,onStateFilterChange:t,stateFilter:a}=e;const s=Object.values(i.bj).map((e=>({label:e,value:e})));return(0,u.jsxs)("div",{className:n,children:[r||(r=(0,u.jsx)(l.Label,{children:"State"})),(0,u.jsx)(l.RadioButtonGroup,{options:s,value:a,onChange:t,onClick:e=>{e===a&&t(void 0)}})]})};var d=t(82139),p=t(39357),m=t(40206),h=t(86647),g=t(52510),x=t(9290);function f(e){const{promRule:n}=e,[t,r]=(0,s.useState)(),[f,j]=(0,s.useState)(),[b]=(0,s.useState)(Math.floor(100*Math.random())),y=`queryString-${b}`,S=(0,l.useStyles)(v),w=(0,s.useMemo)((()=>{var e;return(0,h.x_)(n)&&null!==(e=n.alerts)&&void 0!==e&&e.length?function(e,n,t){let r=[...t];if(e){const n=(0,d.Zh)(e||"");r=r.filter((e=>{let{labels:t}=e;return(0,d.eD)(t,n)}))}n&&(r=r.filter((e=>(0,i.ED)(e.state)===n)));return r}(t,f,(0,p.Zl)(m.As.Importance,n.alerts)):[]}),[n,f,t]);return(0,h.x_)(n)?(0,u.jsxs)(g.C,{label:"Matching instances",horizontal:!0,children:[(0,u.jsx)("div",{className:(0,a.cx)(S.flexRow,S.spaceBetween),children:(0,u.jsxs)("div",{className:S.flexRow,children:[(0,u.jsx)(o.F,{className:S.rowChild,defaultQueryString:t,onFilterChange:e=>r(e)},y),(0,u.jsx)(c,{className:S.rowChild,stateFilter:f,onStateFilterChange:j})]})}),(0,u.jsx)(x.o,{instances:w})]}):null}const v=e=>({flexRow:a.css`
      display: flex;
      flex-direction: row;
      align-items: flex-end;
      width: 100%;
      flex-wrap: wrap;
      margin-bottom: ${e.spacing.sm};
    `,spaceBetween:a.css`
      justify-content: space-between;
    `,rowChild:a.css`
      margin-right: ${e.spacing.sm};
    `})},82434:(e,n,t)=>{t.d(n,{V:()=>i});var r,a,s=t(36636),l=(t(68404),t(69783)),o=t(45916);const i=e=>{let{rule:n}=e;const t=(0,l.useStyles2)(u);return"err"===n.health||"error"===n.health?(0,o.jsx)(l.Tooltip,{theme:"error",content:n.lastError||"No error message provided.",children:(0,o.jsxs)("div",{className:t.warn,children:[r||(r=(0,o.jsx)(l.Icon,{name:"exclamation-triangle"})),a||(a=(0,o.jsx)("span",{children:"error"}))]})}):(0,o.jsx)(o.Fragment,{children:n.health})},u=e=>({warn:s.css`
    display: inline-flex;
    flex-direction: row;
    color: ${e.colors.warning.text};
    & > * + * {
      margin-left: ${e.spacing(1)};
    }
  `})},18181:(e,n,t)=>{t.d(n,{p:()=>m});var r,a,s=t(36636),l=t(68404),o=t(43215),i=t(69783),u=t(51542),c=t(86647),d=t(69357),p=t(45916);const m=e=>{let{rule:n,isDeleting:t,isCreating:s}=e;const m=(0,i.useStyles2)(h),{promRule:g}=n,x=(0,l.useMemo)((()=>{var e;if(g&&(0,c.x_)(g)&&null!==(e=g.alerts)&&void 0!==e&&e.length&&g.state!==u.x_.Inactive){const e=(0,c.ub)(g);if(e)return(0,p.jsxs)("span",{title:String(e),className:m.for,children:["for"," ",(0,o.intervalToAbbreviatedDurationString)({start:e,end:new Date},!1)]})}return null}),[g,m]);return t?r||(r=(0,p.jsxs)(i.HorizontalGroup,{align:"flex-start",children:[(0,p.jsx)(i.Spinner,{}),"deleting"]})):s?a||(a=(0,p.jsxs)(i.HorizontalGroup,{align:"flex-start",children:[" ",(0,p.jsx)(i.Spinner,{}),"creating"]})):g&&(0,c.x_)(g)?(0,p.jsxs)(i.HorizontalGroup,{align:"flex-start",children:[(0,p.jsx)(d.l,{state:g.state}),x]}):g&&(0,c.OP)(g)?(0,p.jsx)(p.Fragment,{children:"Recording rule"}):(0,p.jsx)(p.Fragment,{children:"n/a"})},h=e=>({for:s.css`
    font-size: ${e.typography.bodySmall.fontSize};
    color: ${e.colors.text.secondary};
    white-space: nowrap;
    padding-top: 2px;
  `})},75678:(e,n,t)=>{t.d(n,{Kd:()=>i,Zo:()=>o});var r=t(68404),a=t(19462),s=t(86647),l=t(33899);function o(e){const n=(0,l._)((e=>e.promRules)),t=(0,l._)((e=>e.rulerRules)),o=(0,r.useRef)({}),i=(0,r.useMemo)((()=>{if(e){const n=(0,a.o_)(e);if(!n)throw new Error(`Unknown rules source: ${e}`);return[n]}return(0,a.h_)()}),[e]);return(0,r.useMemo)((()=>i.map((e=>{var r,l;const i=(0,a.jq)(e)?e.name:e,c=null===(r=n[i])||void 0===r?void 0:r.result,d=null===(l=t[i])||void 0===l?void 0:l.result,p=o.current[i];if(p&&p.promRules===c&&p.rulerRules===d)return p.result;const m={};Object.entries(d||{}).forEach((n=>{let[t,r]=n;const a={rulesSource:e,name:t,groups:[]};m[t]=a,function(e,n){e.groups=n.map((n=>{const t={name:n.name,interval:n.interval,source_tenants:n.source_tenants,rules:[]};return t.rules=n.rules.map((n=>function(e,n,t){return(0,s.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:n,group:t}:(0,s.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:n,group:t}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:n,group:t}}(n,e,t))),t}))}(a,r)})),null==c||c.forEach((n=>{let{name:t,groups:r}=n;!function(e,n){n.forEach((n=>{var t;let r=e.groups.find((e=>e.name===n.name));r||(r={name:n.name,rules:[]},e.groups.push(r)),(null!==(t=n.rules)&&void 0!==t?t:[]).forEach((n=>{const t=function(e,n,t){var r;if((0,a.HY)(t))return n.rules.find((n=>n.name===e.name));return null!==(r=n.rules.find((n=>!n.promRule&&u(n,e,!0))))&&void 0!==r?r:n.rules.find((n=>!n.promRule&&u(n,e,!1)))}(n,r,e.rulesSource);t?t.promRule=n:r.rules.push(function(e,n,t){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,s.x_)(e)&&e.annotations||{},promRule:e,namespace:n,group:t}}(n,e,r))}))}))}(m[t]=m[t]||{rulesSource:e,name:t,groups:[]},r)}));const h=Object.values(m);return o.current[i]={promRules:c,rulerRules:d,result:h},h})).flat()),[n,t,i])}function i(e){return e.map((e=>{const n=Object.assign({},e,{groups:[]});var t;return n.groups.push({name:"default",rules:(t=e.groups.flatMap((e=>e.rules)),t.sort(((e,n)=>e.name.localeCompare(n.name))))}),n}))}function u(e,n){let t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===n.name&&JSON.stringify([t?c(e.query):"",e.labels,e.annotations])===JSON.stringify([t?c(n.query):"",n.labels||{},(0,s.x_)(n)&&n.annotations||{}])}function c(e){return e.length>1&&"("===e[0]&&")"===e[e.length-1]&&(e=e.slice(1,-1)),(e=e.replace(/\s|\n/g,"")).split("").sort().join("")}},13309:(e,n,t)=>{t.d(n,{W:()=>i});var r=t(68404),a=t(18745),s=t(83809),l=t(8455),o=t(33899);function i(e){const n=(0,a.useDispatch)(),t=(0,o._)((e=>e.folders));if((0,r.useEffect)((()=>{e&&n((0,s.sw)(e))}),[n,e]),e){const n=t[e]||l.oq;return{folder:n.result,loading:n.loading}}return{loading:!1}}},78567:(e,n,t)=>{t.d(n,{M:()=>i});var r=t(61959),a=t(82969),s=t(86647),l=t(13309),o=t(33899);function i(e,n){var t,i,u;const c=(0,o._)((e=>e.dataSources)),d=n&&(0,s.Pc)(n)?n.grafana_alert.namespace_uid:void 0,p=(0,a.Bz)(e),{folder:m,loading:h}=(0,l.W)(d);if(!n)return{isEditable:!1,isRemovable:!1,loading:!1};if((0,s.Pc)(n)){var g,x;if(!d)throw new Error(`Rule ${n.grafana_alert.title} does not have a folder uid, cannot determine if it is editable.`);return{isEditable:r.Vt.hasAccess(p.update,null!==(g=null==m?void 0:m.canSave)&&void 0!==g&&g),isRemovable:r.Vt.hasAccess(p.delete,null!==(x=null==m?void 0:m.canSave)&&void 0!==x&&x),loading:h}}const f=Boolean(null===(t=c[e])||void 0===t||null===(i=t.result)||void 0===i?void 0:i.rulerConfig);return{isEditable:r.Vt.hasAccess(p.update,r.Vt.isEditor)&&f,isRemovable:r.Vt.hasAccess(p.delete,r.Vt.isEditor)&&f,loading:null===(u=c[e])||void 0===u?void 0:u.loading}}}}]);
//# sourceMappingURL=9168.813c58a562dbfd304dbd.js.map