/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.observability_bundle_jsonpfunction=window.observability_bundle_jsonpfunction||[]).push([[7],{102:function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));const a="/internal/rac/alerts"},123:function(e,t,r){"use strict";r(104);var a=r(102);r.d(t,"a",(function(){return a.a}))},134:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a=r(2),i=!1,o={};t.default=function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n=0||(i[r]=e[r]);return i}(t,["children"]),n=e(o),s=i,c=0;c{const r=s.a.duration(s()(t).diff(s()(e))),a=s()().toISOString(),i=r.asMinutes()<160?s.a.duration(20,"minutes").asMilliseconds():r.asMilliseconds()/8;return{from:s()(e).subtract(i,"millisecond").toISOString(),to:t&&s()(t).add(i,"millisecond").isBefore(a)?s()(t).add(i,"millisecond").toISOString():a}};r(123),r(74);var v=r(41),y=r(137);const E=(e,t="")=>{const r=a.i18n.translate("xpack.observability.threshold.rule.alerting.noDataFormattedValue",{defaultMessage:"[NO DATA]"}),i=t.endsWith(".pct")?Object(y.a)("percent"):Object(y.a)("highPrecision");return null==e?r:i(e)},O=e=>{const t=e.metric?`(${e.metric})`:"";return e.aggType+t+e.comparator+e.threshold.join(",")};var T=r(135),j=r(133);function S({chartProps:{theme:e,baseTheme:t},comparator:r,id:i,threshold:o,title:l,value:s,valueFormatter:u}){const d=Object(c.useEuiBackgroundColor)("danger");return n.a.createElement(c.EuiPanel,{paddingSize:"none",style:{height:"100%",overflow:"hidden",position:"relative",minWidth:"100%"},hasShadow:!1,"data-test-subj":`thresholdRule-${o}-${s}`},n.a.createElement(m.Chart,null,n.a.createElement(m.Settings,{theme:e,baseTheme:t}),n.a.createElement(m.Metric,{id:i,data:[[{title:l,extra:n.a.createElement("span",null,a.i18n.translate("xpack.observability.threshold.rule.thresholdExtraTitle",{values:{comparator:r,threshold:u(o)},defaultMessage:"Alert when {comparator} {threshold}"})),color:d,value:s,valueFormatter:u,icon:({width:e,height:t,color:r})=>n.a.createElement(c.EuiIcon,{width:e,height:t,color:r,type:"alert"})}]]})))}var k=r(51),x=r.n(k),A=r(0),M=r(8),w=r(134),F=r.n(w),P=r(49),R=r(47);const[_,D]=F()((()=>({metricThresholdPrefill:(()=>{const[e,t]=Object(o.useState)({groupBy:void 0,filterQuery:void 0,metrics:[]}),{groupBy:r,filterQuery:a,metrics:i}=e;return{groupBy:r,filterQuery:a,metrics:i,setPrefillOptions(r){Object(M.isEqual)(r,e)||t(r)}}})()})));var B=r(160),C=r.n(B),I=r(58),N=r.n(I);const L=({from:e,to:t})=>{const{services:r}=Object(v.a)();return[Object(o.useCallback)((()=>{const a=r.data.query.timefilter.timefilter;return a.isTimeTouched()?a.getTime():{from:e,to:t}}),[r.data.query.timefilter.timefilter,e,t]),r.data.query.timefilter.timefilter.setTime]},Q=A.intersection([P.b,A.partial({rate:A.boolean,color:A.keyof(Object.fromEntries(Object(M.values)(R.a).map((e=>[e,null])))),label:A.string})]);let q,z;!function(e){e.line="line",e.area="area",e.bar="bar"}(q||(q={})),function(e){e.fromZero="fromZero",e.auto="auto"}(z||(z={})),A.type({yAxisMode:A.keyof(Object.fromEntries(Object(M.values)(z).map((e=>[e,null])))),type:A.keyof(Object.fromEntries(Object(M.values)(q).map((e=>[e,null])))),stack:A.boolean});const V=A.type({aggregation:A.string,metrics:A.array(Q)}),$=A.partial({limit:A.number,groupBy:A.union([A.string,A.array(A.string)]),filterQuery:A.string,source:A.string,forceInterval:A.boolean,dropLastBucket:A.boolean}),U=(A.intersection([V,$]),A.type({fromTimestamp:A.number,toTimestamp:A.number,interval:A.string,timeFieldName:A.string}),A.type({from:A.string,to:A.string,interval:A.string}),{from:"now-1h",to:"now",interval:">=10s"}),W={type:q.line,yAxisMode:z.fromZero,stack:!1},Y={aggregation:"avg",metrics:[{aggregation:"avg",field:"system.cpu.total.norm.pct",color:R.a.color0},{aggregation:"avg",field:"kubernetes.pod.cpu.usage.node.pct",color:R.a.color1},{aggregation:"avg",field:"docker.cpu.total.pct",color:R.a.color2}],source:"default"};function H(e,t){const r=localStorage.getItem(e),[a,i]=Object(o.useState)(function(e,t){if(!e)return t;try{return JSON.parse(e)}catch(e){return t}}(r,t));return Object(o.useEffect)((()=>{localStorage.setItem(e,JSON.stringify(a))}),[e,a]),[a,i]}const Z=({from:e,to:t})=>({fromTimestamp:x.a.parse(e).valueOf(),toTimestamp:x.a.parse(t,{roundUp:!0}).valueOf(),interval:U.interval}),[G,J]=F()((()=>{const e={from:"now-1h",to:"now"},[t]=L(e),{from:r,to:a}=t(),[i,n]=H("MetricsExplorerOptions",Y),[l,s]=Object(o.useState)({from:r,to:a,interval:U.interval}),[c,u]=Object(o.useState)({...Z({from:r,to:a}),timeFieldName:"@timestamp"});((e,t,r)=>{const{services:a}=Object(v.a)(),[i,n]=L(e);N()((()=>{e.from===t.from&&e.to===t.to||n({from:t.from,to:t.to})})),C()((()=>{n({from:t.from,to:t.to})}),[t.from,t.to,n]),Object(o.useEffect)((()=>{const e=a.data.query.timefilter.timefilter.getTimeUpdate$().subscribe((()=>{r}));return()=>e.unsubscribe()}),[i,r,a.data.query.timefilter.timefilter])})(e,{from:l.from,to:l.to});const[m,d]=H("MetricsExplorerChartOptions",W),[f,p]=Object(o.useState)(!1),{metricThresholdPrefill:h}=D(),g=Object(o.useMemo)((()=>h),[h]);return Object(o.useEffect)((()=>{if(g){const{setPrefillOptions:e}=g,{metrics:t,groupBy:r,filterQuery:a}=i;e({metrics:t,groupBy:r,filterQuery:a})}}),[i,g]),{defaultViewState:{options:Y,chartOptions:W,currentTimerange:l},options:i,chartOptions:m,setChartOptions:d,timeRange:l,isAutoReloading:f,setOptions:n,setTimeRange:s,startAutoReload:()=>p(!0),stopAutoReload:()=>p(!1),timestamps:c,setTimestamps:u}})),X="YYYY-MM-DD HH:mm",K="alert_start_annotation",ee="alert_time_range_annotation";function te({alert:e,rule:t,ruleLink:r,setAlertSummaryFields:l}){const{uiSettings:m,charts:d}=Object(v.a)().services,{euiTheme:f}=Object(c.useEuiTheme)(),h=Object(o.useMemo)((()=>({fields:[],title:"unknown-index"})),[]),y={theme:d.theme.useChartsTheme(),baseTheme:d.theme.useChartsBaseTheme()},k=b(e.fields[u.R],e.fields[u.e]),x=e.fields[u.e]?s()(e.fields[u.e]).valueOf():void 0,A=[n.a.createElement(p,{alertStart:e.start,color:f.colors.danger,dateFormat:m.get("dateFormat")||X,id:K,key:K}),n.a.createElement(g,{alertStart:e.start,alertEnd:x,color:f.colors.danger,id:ee,key:ee})];return Object(o.useEffect)((()=>{l([{label:a.i18n.translate("xpack.observability.threshold.rule.alertDetailsAppSection.summaryField.rule",{defaultMessage:"Rule"}),value:n.a.createElement(c.EuiLink,{"data-test-subj":"thresholdRuleAlertDetailsAppSectionRuleLink",href:r},t.name)}])}),[e,t,r,l]),t.params.criteria?n.a.createElement(c.EuiFlexGroup,{direction:"column","data-test-subj":"thresholdRuleAppSection"},t.params.criteria.map(((r,o)=>n.a.createElement(c.EuiFlexItem,{key:O(r)},n.a.createElement(c.EuiPanel,{hasBorder:!0,hasShadow:!1},n.a.createElement(c.EuiTitle,{size:"xs"},n.a.createElement("h4",null,r.aggType.toUpperCase()," ","metric"in r?r.metric:void 0)),n.a.createElement(c.EuiText,{size:"s",color:"subdued"},n.a.createElement(i.FormattedMessage,{id:"xpack.observability.threshold.rule.alertDetailsAppSection.criterion.subtitle",defaultMessage:"Last {lookback} {timeLabel}",values:{lookback:r.timeSize,timeLabel:j.d[r.timeUnit]}})),n.a.createElement(c.EuiSpacer,{size:"s"}),n.a.createElement(c.EuiFlexGroup,null,n.a.createElement(c.EuiFlexItem,{style:{minHeight:150,minWidth:160},grow:1},n.a.createElement(S,{chartProps:y,id:`threshold-${O(r)}`,threshold:r.threshold[0],value:e.fields[u.h][o],valueFormatter:e=>E(e,"metric"in r?r.metric:void 0),title:a.i18n.translate("xpack.observability.threshold.rule.alertDetailsAppSection.thresholdTitle",{defaultMessage:"Threshold breached"}),comparator:r.comparator})),n.a.createElement(c.EuiFlexItem,{grow:5},n.a.createElement(T.a,{annotations:A,chartType:q.line,derivedIndexPattern:h,expression:r,filterQuery:t.params.filterQuery,groupBy:t.params.groupBy,hideTitle:!0,timeRange:k})))))))):null}}}]);