"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9168],{16905:(e,t,n)=>{n.d(t,{F:()=>c});var r,a,s,l=n(36636),o=(n(68404),n(90747)),i=n(69783),u=n(45916);const c=e=>{let{className:t,onFilterChange:n,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:t,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 t=e.target;n(t.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,t,n)=>{n.d(t,{f:()=>D});var r=n(36636),a=n(68404),s=n(18745),l=n(42326),o=n(43215),i=n(90923),u=n(69783),c=n(58257),d=n(61959),p=n(58170),m=n(78567),h=n(82897),g=n(83809),x=n(33899);var f,v=n(23906),j=n(9019),b=n(69357),y=n(45916);const S=e=>{let{alertId:t}=e;const{loading:n,error:r,result:l=[]}=function(e){const t=(0,s.useDispatch)(),n=(0,x._)((e=>e.managedAlertStateHistory));return(0,a.useEffect)((()=>{t((0,g.Ms)(e))}),[t,e]),n}(t);if(n&&!r)return f||(f=(0,y.jsx)(u.LoadingPlaceholder,{text:"Loading history..."}));if(r&&!n)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,t,n)=>(e.push({id:String(t.id),state:t.newState,text:t.text,data:t.data,timestamp:t.updated}),function(e,t){const n=t[e],r=t[e+1];if(!r)return!1;return r.newState===n.prevState}(n,l)||e.push({id:(0,h.uniqueId)(),state:t.prevState}),e)),[]).map((e=>({id:e.id,data:e})));return(0,y.jsx)(j.t,{cols:o,items:i})};function w(e){var t,n;const r=null!==(t=null===(n=e.data.data)||void 0===n?void 0:n.evalMatches)&&void 0!==t?t:[];return(0,y.jsxs)(y.Fragment,{children:[e.data.text,(0,y.jsx)(_,{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:k,children:e.data.timestamp&&(0,y.jsx)("span",{children:(0,o.dateTimeFormat)(e.data.timestamp)})})}const _=e=>{let{children:t}=e;const{wrapper:n}=(0,u.useStyles)(q);return(0,y.jsx)("div",{className:n,children:t})},k=r.css` display: flex; align-items: flex-end; flex-direction: column; `,q=e=>({wrapper:r.css` & > * { margin-right: ${e.spacing.xs}; } `});var N,$,z=n(82139),E=n(85464),M=n(19462),I=n(39357),U=n(59940),F=n(86647);const D=e=>{var t,n;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,_]=(0,a.useState)(),k=function(e){if(!e)return!1;return null!=e.grafana_alert}(r.rulerRule)&&null!==(t=r.rulerRule.grafana_alert.id)&&void 0!==t?t:"",{StateHistoryModal:q,showStateHistoryModal:D}=function(e){var t;const[n,r]=(0,a.useState)(!1);return{StateHistoryModal:(0,a.useMemo)((()=>(0,y.jsx)(u.Modal,{isOpen:n,onDismiss:()=>r(!1),closeOnBackdropClick:!0,closeOnEscape:!0,title:"State history",children:t||(t=(0,y.jsx)(S,{alertId:e}))})),[e,n]),showStateHistoryModal:()=>r(!0),hideStateHistoryModal:()=>r(!1)}}(k),V=(0,M.HY)(h)?h:null===(n=(0,z.Xy)(h.jsonData.alertmanagerUid))||void 0===n?void 0:n.name,B=(0,M.EG)(h),H=d.Vt.hasPermission(p.bW.DataSourcesExplore),G=[],O=[],T=(0,F.Jq)(w),{isEditable:A,isRemovable:P}=(0,m.M)(B,R),W=f.pathname+f.search,Z=f.pathname.endsWith("/view");const Y=()=>{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})),_(void 0)}},J=()=>{if((0,M.jq)(h)){const{appUrl:e,appSubUrl:t}=i.config;return`${""!==t?`${e}${t}/`:i.config.appUrl}alerting/${`${encodeURIComponent(h.name)}/${encodeURIComponent(r.name)}`}/find`}return window.location.href.split("?")[0]};if((0,M.jq)(h)&&H&&!T&&G.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]&&G.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"primary",icon:"book",target:"__blank",href:o.textUtil.sanitizeUrl(r.annotations[E.q6.runbookURL]),children:"View runbook"},"runbook")),r.annotations[E.q6.dashboardUID]){const e=r.annotations[E.q6.dashboardUID];if(e){G.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 t=r.annotations[E.q6.panelID];t&&G.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}?viewPanel=${encodeURIComponent(t)}`,children:"Go to panel"},"panel"))}}if(V&&d.Vt.hasAccess(p.bW.AlertingInstanceCreate,d.Vt.isEditor)&&G.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")),k&&G.push((0,y.jsxs)(a.Fragment,{children:[(0,y.jsx)(u.Button,{className:j.button,size:"xs",icon:"history",onClick:()=>D(),children:"Show state history"}),q]},"history")),Z||O.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")),A&&R&&!T){const e=(0,M.EG)(h),t=U.Zk(e,b.name,w.name,R),n=o.urlUtil.renderUrl(`${i.config.appSubUrl}/alerting/${encodeURIComponent(U.$V(t))}/edit`,{returnTo:W});Z&&O.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:J,children:"Copy link to rule"},"copy")),O.push((0,y.jsx)(u.LinkButton,{className:j.button,size:"xs",variant:"secondary",icon:"pen",href:n,children:"Edit"},"edit"))}return P&&R&&!T&&O.push((0,y.jsx)(u.Button,{className:j.button,size:"xs",type:"button",variant:"secondary",icon:"trash-alt",onClick:()=>_(r),children:"Delete"},"delete")),G.length||O.length?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:j.wrapper,children:[(0,y.jsx)(u.HorizontalGroup,{width:"auto",children:G.length?G:N||(N=(0,y.jsx)("div",{}))}),(0,y.jsx)(u.HorizontalGroup,{width:"auto",children:O.length?O:$||($=(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:Y,onDismiss:()=>_(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,t,n)=>{n.d(t,{J:()=>o});var r=n(36636),a=(n(68404),n(69783)),s=n(212),l=n(45916);function o(e){const{annotations:t}=e,n=(0,a.useStyles2)(i);return 0===t.length?null:(0,l.jsx)("div",{className:n.annotations,children:t.map((e=>{let[t,n]=e;return(0,l.jsx)(s.a,{annotationKey:t,value:n},t)}))})}const i=()=>({annotations:r.css` margin-top: 46px; `})},79842:(e,t,n)=>{n.d(t,{C:()=>p});var r=n(36636),a=n(68404),s=n(90923),l=n(69783),o=n(24036),i=n(19462),u=n(86647),c=n(52510),d=n(45916);function p(e){const{rulesSource:t,rule:n}=e,r=(0,l.useStyles2)(m),p=(0,a.useMemo)((()=>{if((0,i.jq)(t))return[{name:t.name,icon:t.meta.info.logos.small}];if((0,u.Pc)(n.rulerRule)){const{data:e}=n.rulerRule.grafana_alert,t=e.reduce(((e,t)=>{const n=(0,s.getDataSourceSrv)().getInstanceSettings(t.datasourceUid);return n&&n.uid!==o.Yq?(e[n.name]={name:n.name,icon:n.meta.info.logos.small},e):e}),{});return Object.values(t)}return[]}),[n,t]);return 0===p.length?null:(0,d.jsx)(c.C,{label:"Data source",children:p.map(((e,t)=>{let{name:n,icon:a}=e;return(0,d.jsxs)("div",{children:[a&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("img",{alt:`${n} datasource logo`,className:r.dataSourceIcon,src:a})," "]}),n]},n)}))})}function m(e){const t=e.spacing(2);return{dataSourceIcon:r.css` width: ${t}; height: ${t}; `}}},85351:(e,t,n)=>{n.d(t,{C:()=>f});var r=n(36636),a=n(68404),s=n(19462),l=n(52510),o=n(50539),i=n(86377),u=n(69783),c=n(17245),d=n(53454),p=n(1481),m=n(45916);const h=e=>{let{language:t,expr:n}=e;const r=(0,a.useMemo)((()=>[(0,u.SlatePrism)({onlyIn:e=>"code_block"===e.type,getSyntax:()=>t},Object.assign({},o.languages,{[t]:"logql"===t?c.ZP:d.ZP}))]),[t]),s=(0,a.useMemo)((()=>(0,u.makeValue)(n)),[n]);return(0,m.jsx)(i.ML,{plugins:r,value:s,readOnly:!0})},g=e=>{let{expression:t,rulesSource:n}=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)(n)?(0,m.jsx)(h,{expr:t,language:n.type===s.ye.Loki?"logql":"promql"}):t})},x=e=>({well:r.css` font-family: ${e.typography.fontFamily.monospace}; `});function f(e){const{annotations:t,rulesSource:n,rule:a}=e,o=v();return(0,s.jq)(n)?(0,m.jsx)(l.C,{label:"Expression",horizontal:!0,className:(0,r.cx)({[o.exprRow]:!!t.length}),children:(0,m.jsx)(g,{expression:a.query,rulesSource:n})}):null}const v=()=>({exprRow:r.css` margin-bottom: 46px; `})},12135:(e,t,n)=>{n.d(t,{M:()=>y});var r,a=n(36636),s=n(68404),l=n(69783),o=n(16905),i=n(82897),u=n(51542),c=n(45916);const d=Object.values(u.bj).map((e=>({label:e,value:e}))),p=[u.x_.Firing,u.x_.Pending].map((e=>({label:(0,i.capitalize)(e),value:e}))),m=e=>{let{className:t,onStateFilterChange:n,stateFilter:a,filterType:o}=e;const i=(0,s.useMemo)((()=>"grafana"===o?d:p),[o]);return(0,c.jsxs)("div",{className:t,"data-testid":"alert-instance-state-filter",children:[r||(r=(0,c.jsx)(l.Label,{children:"State"})),(0,c.jsx)(l.RadioButtonGroup,{options:i,value:a,onChange:n,onClick:e=>{e===a&&n(void 0)}})]})};var h=n(82139),g=n(39357),x=n(40206),f=n(19462),v=n(86647),j=n(52510),b=n(9290);function y(e){const{rule:{promRule:t,namespace:n}}=e,[r,i]=(0,s.useState)(),[d,p]=(0,s.useState)(),[y]=(0,s.useState)(Math.floor(100*Math.random())),w=`queryString-${y}`,R=(0,l.useStyles)(S),C=(0,f.HY)(n.rulesSource)?f.GC:"prometheus",_=(0,s.useMemo)((()=>{var e;return(0,v.x_)(t)&&null!==(e=t.alerts)&&void 0!==e&&e.length?function(e,t,n){let r=[...n];if(e){const t=(0,h.Zh)(e||"");r=r.filter((e=>{let{labels:n}=e;return(0,h.eD)(n,t)}))}t&&(r=r.filter((e=>(0,u.ED)(e.state)===t)));return r}(r,d,(0,g.Zl)(x.As.Importance,t.alerts)):[]}),[t,d,r]);return(0,v.x_)(t)?(0,c.jsxs)(j.C,{label:"Matching instances",horizontal:!0,children:[(0,c.jsx)("div",{className:(0,a.cx)(R.flexRow,R.spaceBetween),children:(0,c.jsxs)("div",{className:R.flexRow,children:[(0,c.jsx)(o.F,{className:R.rowChild,defaultQueryString:r,onFilterChange:e=>i(e)},w),(0,c.jsx)(m,{className:R.rowChild,filterType:C,stateFilter:d,onStateFilterChange:p})]})}),(0,c.jsx)(b.o,{instances:_})]}):null}const S=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,t,n)=>{n.d(t,{V:()=>i});var r,a,s=n(36636),l=(n(68404),n(69783)),o=n(45916);const i=e=>{let{rule:t}=e;const n=(0,l.useStyles2)(u);return"err"===t.health||"error"===t.health?(0,o.jsx)(l.Tooltip,{theme:"error",content:t.lastError||"No error message provided.",children:(0,o.jsxs)("div",{className:n.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:t.health})},u=e=>({warn:s.css` display: inline-flex; flex-direction: row; color: ${e.colors.warning.text}; & > * + * { margin-left: ${e.spacing(1)}; } `})},18181:(e,t,n)=>{n.d(t,{p:()=>m});var r,a,s=n(36636),l=n(68404),o=n(43215),i=n(69783),u=n(51542),c=n(86647),d=n(69357),p=n(45916);const m=e=>{let{rule:t,isDeleting:n,isCreating:s}=e;const m=(0,i.useStyles2)(h),{promRule:g}=t,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 n?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,t,n)=>{n.d(t,{Kd:()=>i,Zo:()=>o});var r=n(68404),a=n(19462),s=n(86647),l=n(33899);function o(e){const t=(0,l._)((e=>e.promRules)),n=(0,l._)((e=>e.rulerRules)),o=(0,r.useRef)({}),i=(0,r.useMemo)((()=>{if(e){const t=(0,a.o_)(e);if(!t)throw new Error(`Unknown rules source: ${e}`);return[t]}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=t[i])||void 0===r?void 0:r.result,d=null===(l=n[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((t=>{let[n,r]=t;const a={rulesSource:e,name:n,groups:[]};m[n]=a,function(e,t){e.groups=t.map((t=>{const n={name:t.name,interval:t.interval,source_tenants:t.source_tenants,rules:[]};return n.rules=t.rules.map((t=>function(e,t,n){return(0,s.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:n}:(0,s.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:t,group:n}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:n}}(t,e,n))),n}))}(a,r)})),null==c||c.forEach((t=>{let{name:n,groups:r}=t;!function(e,t){t.forEach((t=>{var n;let r=e.groups.find((e=>e.name===t.name));r||(r={name:t.name,rules:[]},e.groups.push(r)),(null!==(n=t.rules)&&void 0!==n?n:[]).forEach((t=>{const n=function(e,t,n){var r;if((0,a.HY)(n))return t.rules.find((t=>t.name===e.name));return null!==(r=t.rules.find((t=>!t.promRule&&u(t,e,!0))))&&void 0!==r?r:t.rules.find((t=>!t.promRule&&u(t,e,!1)))}(t,r,e.rulesSource);n?n.promRule=t:r.rules.push(function(e,t,n){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,s.x_)(e)&&e.annotations||{},promRule:e,namespace:t,group:n}}(t,e,r))}))}))}(m[n]=m[n]||{rulesSource:e,name:n,groups:[]},r)}));const h=Object.values(m);return o.current[i]={promRules:c,rulerRules:d,result:h},h})).flat()),[t,n,i])}function i(e){return e.map((e=>{const t=Object.assign({},e,{groups:[]});var n;return t.groups.push({name:"default",rules:(n=e.groups.flatMap((e=>e.rules)),n.sort(((e,t)=>e.name.localeCompare(t.name))))}),t}))}function u(e,t){let n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===t.name&&JSON.stringify([n?c(e.query):"",e.labels,e.annotations])===JSON.stringify([n?c(t.query):"",t.labels||{},(0,s.x_)(t)&&t.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,t,n)=>{n.d(t,{W:()=>i});var r=n(68404),a=n(18745),s=n(83809),l=n(8455),o=n(33899);function i(e){const t=(0,a.useDispatch)(),n=(0,o._)((e=>e.folders));if((0,r.useEffect)((()=>{e&&t((0,s.sw)(e))}),[t,e]),e){const t=n[e]||l.oq;return{folder:t.result,loading:t.loading}}return{loading:!1}}},78567:(e,t,n)=>{n.d(t,{M:()=>i});var r=n(61959),a=n(82969),s=n(86647),l=n(13309),o=n(33899);function i(e,t){var n,i,u;const c=(0,o._)((e=>e.dataSources)),d=t&&(0,s.Pc)(t)?t.grafana_alert.namespace_uid:void 0,p=(0,a.Bz)(e),{folder:m,loading:h}=(0,l.W)(d);if(!t)return{isEditable:!1,isRemovable:!1,loading:!1};if((0,s.Pc)(t)){var g,x;if(!d)throw new Error(`Rule ${t.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===(n=c[e])||void 0===n||null===(i=n.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.ef33458a94f37200941b.js.map