/*! 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([[2],{114:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.pipeable=t.pipe=void 0;var r=n(112);t.pipe=r.pipe;t.pipeable=function(e){var t={};return function(e){return"function"==typeof e.map}(e)&&(t.map=function(t){return function(n){return e.map(n,t)}}),function(e){return"function"==typeof e.contramap}(e)&&(t.contramap=function(t){return function(n){return e.contramap(n,t)}}),function(e){return"function"==typeof e.mapWithIndex}(e)&&(t.mapWithIndex=function(t){return function(n){return e.mapWithIndex(n,t)}}),function(e){return"function"==typeof e.ap}(e)&&(t.ap=function(t){return function(n){return e.ap(n,t)}},t.apFirst=function(t){return function(n){return e.ap(e.map(n,(function(e){return function(){return e}})),t)}},t.apSecond=function(t){return function(n){return e.ap(e.map(n,(function(){return function(e){return e}})),t)}}),function(e){return"function"==typeof e.chain}(e)&&(t.chain=function(t){return function(n){return e.chain(n,t)}},t.chainFirst=function(t){return function(n){return e.chain(n,(function(n){return e.map(t(n),(function(){return n}))}))}},t.flatten=function(t){return e.chain(t,r.identity)}),function(e){return"function"==typeof e.bimap}(e)&&(t.bimap=function(t,n){return function(r){return e.bimap(r,t,n)}},t.mapLeft=function(t){return function(n){return e.mapLeft(n,t)}}),function(e){return"function"==typeof e.extend}(e)&&(t.extend=function(t){return function(n){return e.extend(n,t)}},t.duplicate=function(t){return e.extend(t,r.identity)}),function(e){return"function"==typeof e.reduce}(e)&&(t.reduce=function(t,n){return function(r){return e.reduce(r,t,n)}},t.foldMap=function(t){var n=e.foldMap(t);return function(e){return function(t){return n(t,e)}}},t.reduceRight=function(t,n){return function(r){return e.reduceRight(r,t,n)}}),function(e){return"function"==typeof e.reduceWithIndex}(e)&&(t.reduceWithIndex=function(t,n){return function(r){return e.reduceWithIndex(r,t,n)}},t.foldMapWithIndex=function(t){var n=e.foldMapWithIndex(t);return function(e){return function(t){return n(t,e)}}},t.reduceRightWithIndex=function(t,n){return function(r){return e.reduceRightWithIndex(r,t,n)}}),function(e){return"function"==typeof e.alt}(e)&&(t.alt=function(t){return function(n){return e.alt(n,t)}}),function(e){return"function"==typeof e.compact}(e)&&(t.compact=e.compact,t.separate=e.separate),function(e){return"function"==typeof e.filter}(e)&&(t.filter=function(t){return function(n){return e.filter(n,t)}},t.filterMap=function(t){return function(n){return e.filterMap(n,t)}},t.partition=function(t){return function(n){return e.partition(n,t)}},t.partitionMap=function(t){return function(n){return e.partitionMap(n,t)}}),function(e){return"function"==typeof e.filterWithIndex}(e)&&(t.filterWithIndex=function(t){return function(n){return e.filterWithIndex(n,t)}},t.filterMapWithIndex=function(t){return function(n){return e.filterMapWithIndex(n,t)}},t.partitionWithIndex=function(t){return function(n){return e.partitionWithIndex(n,t)}},t.partitionMapWithIndex=function(t){return function(n){return e.partitionMapWithIndex(n,t)}}),function(e){return"function"==typeof e.promap}(e)&&(t.promap=function(t,n){return function(r){return e.promap(r,t,n)}}),function(e){return"function"==typeof e.compose}(e)&&(t.compose=function(t){return function(n){return e.compose(n,t)}}),function(e){return"function"==typeof e.throwError}(e)&&(t.fromOption=function(t){return function(n){return"None"===n._tag?e.throwError(t()):e.of(n.value)}},t.fromEither=function(t){return"Left"===t._tag?e.throwError(t.left):e.of(t.right)},t.fromPredicate=function(t,n){return function(r){return t(r)?e.of(r):e.throwError(n(r))}},t.filterOrElse=function(t,n){return function(r){return e.chain(r,(function(r){return t(r)?e.of(r):e.throwError(n(r))}))}}),t}},116:function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));const r=e=>Number(e).toLocaleString("en",{maximumFractionDigits:1})},117:function(e,t,n){"use strict";n.d(t,"c",(function(){return i})),n.d(t,"e",(function(){return a})),n.d(t,"d",(function(){return o})),n.d(t,"a",(function(){return c})),n.d(t,"b",(function(){return u}));var r=n(1);const i=r.i18n.translate("xpack.observability.threshold.rule.alertFlyout.customEquationEditor.equationHelpMessage",{defaultMessage:"Supports basic math equations, valid charaters are: A-Z, +, -, /, *, (, ), ?, !, &, :, |, >, <, ="}),a=r.i18n.translate("xpack.observability.threshold.rule.alertFlyout.customEquationEditor.labelLabel",{defaultMessage:"Label (optional)"}),o=r.i18n.translate("xpack.observability.threshold.rule.alertFlyout.customEquationEditor.labelHelpMessage",{defaultMessage:"Custom label will show on the alert chart and in reason"}),c=r.i18n.translate("xpack.observability.threshold.rule.alertFlyout.customEquation",{defaultMessage:"Custom equation"}),u=r.i18n.translate("xpack.observability.threshold.rule.alertFlyout.customEquationEditor.deleteRowButton",{defaultMessage:"Delete"})},133:function(e,t,n){"use strict";n.d(t,"d",(function(){return l})),n.d(t,"e",(function(){return f})),n.d(t,"a",(function(){return m})),n.d(t,"c",(function(){return p})),n.d(t,"b",(function(){return b}));var r=n(2),i=n.n(r),a=n(75),o=n(1),c=n(11),u=n(42),s=(n(8),n(116));const l={s:o.i18n.translate("xpack.observability.threshold.rule..timeLabels.seconds",{defaultMessage:"seconds"}),m:o.i18n.translate("xpack.observability.threshold.rule..timeLabels.minutes",{defaultMessage:"minutes"}),h:o.i18n.translate("xpack.observability.threshold.rule..timeLabels.hours",{defaultMessage:"hours"}),d:o.i18n.translate("xpack.observability.threshold.rule..timeLabels.days",{defaultMessage:"days"})},f=(s.a,e=>e?a.DARK_THEME:a.LIGHT_THEME),d=({children:e})=>i.a.createElement("div",{style:{width:"100%",height:150,display:"flex",justifyContent:"center",alignItems:"center"}},e),m=({children:e})=>i.a.createElement("div",{style:{width:"100%",height:150}},e);function p(){return i.a.createElement(d,null,i.a.createElement(c.EuiText,{color:"subdued","data-test-subj":"thresholdRuleNoChartData"},i.a.createElement(u.FormattedMessage,{id:"xpack.observability.threshold.rule..charts.noDataMessage",defaultMessage:"No chart data available"})))}function b(){return i.a.createElement(d,null,i.a.createElement(c.EuiText,{color:"subdued","data-test-subj":"thresholdRuleLoadingData"},i.a.createElement(c.EuiLoadingChart,{size:"m"})))}},135:function(e,t,n){"use strict";n.d(t,"a",(function(){return Y}));var r=n(2),i=n.n(r),a=n(75),o=n(11),c=n(42),u=n(88),s=n(50),l=n(8),f=n(9),d=n.n(f),m=n(41),p=n(47),b=n(37),h=n(23),g=n.n(h),y=n(137);const v=e=>{if("custom"===(null==e?void 0:e.aggregation))return e=>g()(e).format("0.[0000]");if(e&&e.field){const t=(e=>{if(e&&e.field){const t=Object(l.last)(e.field.split(/\./));if("pct"===t)return b.c.percent;if("bytes"===t&&"rate"===e.aggregation)return b.c.bits;if("bytes"===t)return b.c.bytes}return b.c.number})(e);return t===b.c.bits&&"rate"===e.aggregation?Object(y.a)(b.c.bits,"{{value}}/s"):Object(y.a)(t)}return Object(y.a)(b.c.number)};var E=n(51),x=n.n(E),T=n(74),O=n(14),j=n(49),w=n(25);const M=(e,t,n=!0)=>{try{return e?JSON.stringify(Object(w.toElasticsearchQuery)(Object(w.fromKueryExpression)(e),t)):""}catch(e){if(n)return"";throw e}};var k=n(100),L=n(112),S=n(114),A=n(0);const I=([e,...t])=>{if(void 0===e)return[];if(e.type instanceof A.IntersectionType){const[,...e]=t;return I(e)}if(e.type instanceof A.UnionType){const[,...n]=t;return[e.key,...I(n)]}return[e.key,...I(t)]},N=e=>new Error(e),F=(e,t=N)=>n=>Object(S.pipe)(e.decode(n),Object(k.fold)((e=>t=>{throw e((e=>`Failed to validate: \n${e.map((e=>` ${(e=>{var t;return null!==(t=e.message)&&void 0!==t?t:`in ${I(e.context).join("/")}: ${JSON.stringify(e.value)} does not match expected type ${(({context:e})=>{var t,n,r;return null!==(t=null===(n=e[e.length-1])||void 0===n||null===(r=n.type)||void 0===r?void 0:r.name)&&void 0!==t?t:"unknown"})(e)}`})(e)}`)).join("\n")}`)(t))})(t),L.identity)),$={},D=(e,t,n,i,a=$,o="@timestamp")=>{const{timeSize:c,timeUnit:u}=e||{timeSize:1,timeUnit:"m"};return function(e,t,{fromTimestamp:n,toTimestamp:r,interval:i,timeFieldName:a},o=!0){const{http:c}=Object(O.useKibana)().services,{isLoading:u,data:s,error:l,refetch:f,fetchNextPage:d}=Object(T.useInfiniteQuery)({queryKey:["metricExplorer",e,n,r,t.title],queryFn:async({signal:o,pageParam:u={afterKey:null}})=>{if(!n||!r)throw new Error("Unable to parse timerange");if(!c)throw new Error("HTTP service is unavailable");if(!t.title)throw new Error("Data view is unavailable");const{afterKey:s}=u,l=await c.post("/api/infra/metrics_explorer",{method:"POST",body:JSON.stringify({forceInterval:e.forceInterval,dropLastBucket:null==e.dropLastBucket||e.dropLastBucket,metrics:"count"===e.aggregation?[{aggregation:"count"}]:e.metrics,groupBy:e.groupBy,afterKey:s,limit:e.limit,indexPattern:t.title,filterQuery:e.filterQuery&&M(e.filterQuery,t)||void 0,timerange:{interval:i,timeFieldName:a,from:n,to:r}}),signal:o});return F(j.c)(l)},getNextPageParam:e=>e.pageInfo,enabled:o&&!!n&&!!r&&!!c&&!!t.title,refetchOnWindowFocus:!1});return{data:s,error:l,fetchNextPage:d,isLoading:u,refetch:f}}(Object(r.useMemo)((()=>{var t,r;return{limit:1,forceInterval:!0,dropLastBucket:!1,groupBy:i,filterQuery:n,metrics:["custom"===e.aggType?{aggregation:"custom",custom_metrics:null!==(t=null==e||null===(r=e.customMetrics)||void 0===r?void 0:r.map(W))&&void 0!==t?t:[],equation:e.equation}:{field:e.metric,aggregation:e.aggType}],aggregation:e.aggType||"avg"}}),[e.aggType,e.equation,e.metric,JSON.stringify(e.customMetrics),n,i]),t,Object(r.useMemo)((()=>{var e,t;const n=null!==(e=a.from)&&void 0!==e?e:`now-${20*(c||1)}${u}`,r=null!==(t=a.to)&&void 0!==t?t:"now",i=x.a.parse(n).valueOf(),s=x.a.parse(r,{roundUp:!0}).valueOf();return{interval:`>=${c||1}${u}`,fromTimestamp:i,toTimestamp:s,timeFieldName:o}}),[a.from,a.to,c,u,o]))},W=e=>"count"===e.aggType?{name:e.name,aggregation:"count",filter:e.filter}:{name:e.name,aggregation:e.aggType,field:e.field};var B=n(133);const _=.3;function R({threshold:e,sortedThresholds:t,comparator:n,color:r,id:o,firstTimestamp:c,lastTimestamp:u,domain:s}){if(!n||!e)return null;const f=[b.b.GT,b.b.GT_OR_EQ].includes(n),d=[b.b.LT,b.b.LT_OR_EQ].includes(n);return i.a.createElement(i.a.Fragment,null,i.a.createElement(a.LineAnnotation,{id:`${o}-thresholds`,domainType:a.AnnotationDomainType.YDomain,"data-test-subj":"threshold-line",dataValues:t.map((e=>({dataValue:e}))),style:{line:{strokeWidth:2,stroke:Object(p.b)(r),opacity:1}}}),2===t.length&&n===b.b.BETWEEN?i.a.createElement(i.a.Fragment,null,i.a.createElement(a.RectAnnotation,{id:`${o}-lower-threshold`,"data-test-subj":"between-rect",style:{fill:Object(p.b)(r),opacity:_},dataValues:[{coordinates:{x0:c,x1:u,y0:Object(l.first)(e),y1:Object(l.last)(e)}}]})):null,2===t.length&&n===b.b.OUTSIDE_RANGE?i.a.createElement(i.a.Fragment,null,i.a.createElement(a.RectAnnotation,{id:`${o}-lower-threshold`,"data-test-subj":"outside-range-lower-rect",style:{fill:Object(p.b)(r),opacity:_},dataValues:[{coordinates:{x0:c,x1:u,y0:s.min,y1:Object(l.first)(e)}}]}),i.a.createElement(a.RectAnnotation,{id:`${o}-upper-threshold`,"data-test-subj":"outside-range-upper-rect",style:{fill:Object(p.b)(r),opacity:_},dataValues:[{coordinates:{x0:c,x1:u,y0:Object(l.last)(e),y1:s.max}}]})):null,d&&null!=Object(l.first)(e)?i.a.createElement(a.RectAnnotation,{id:`${o}-upper-threshold`,"data-test-subj":"below-rect",style:{fill:Object(p.b)(r),opacity:_},dataValues:[{coordinates:{x0:c,x1:u,y0:s.min,y1:Object(l.first)(e)}}]}):null,f&&null!=Object(l.first)(e)?i.a.createElement(a.RectAnnotation,{id:`${o}-upper-threshold`,"data-test-subj":"above-rect",style:{fill:Object(p.b)(r),opacity:_},dataValues:[{coordinates:{x0:c,x1:u,y0:Object(l.first)(e),y1:s.max}}]}):null)}var P=n(117);const q=(e,t)=>`metric_${t}`,U=e=>{const t=Object(l.min)(e);return Object(l.isNumber)(t)&&Number.isFinite(t)?t:void 0},C=e=>{const t=Object(l.max)(e);return Object(l.isNumber)(t)&&Number.isFinite(t)?t:void 0},G=(e,t,n=!1)=>{const r=e.rows.reduce(((e,r)=>{const i=t.map(((e,t)=>r[q(e,t)]||null)).filter((e=>Object(l.isNumber)(e))),a=U(i),o=n?1.1*Object(l.sum)(i):C(i);return e.concat([a||null,o||null])}),[]).filter((e=>Object(l.isNumber)(e)));return{min:U(r)||0,max:C(r)||0}};var Q=n(30),K=n.n(Q);function z(){const[e]=Object(O.useUiSetting$)(s.UI_SETTINGS.DATEFORMAT_TZ);return e&&"Browser"!==e?e:K.a.tz.guess()}const H=e=>e.label?e.label:`${e.aggregation}(${e.field||""})`;function V(e){return b.d.bar===e.type?i.a.createElement(J,e):i.a.createElement(Z,e)}function Z({metric:e,id:t,series:n,type:r,stack:o,opacity:c}){const u=z(),s=e.color&&Object(p.b)(e.color)||Object(p.b)(p.a.color0),l=Array.isArray(t)?t.map((t=>q(e,t))).slice(t.length-1,t.length):[q(e,t)],f=Array.isArray(t)&&t.length>1?t.map((t=>q(e,t))).slice(0,1):void 0,d=`series-${n.id}-${l.join("-")}`,m={line:{strokeWidth:2,visible:!0},area:{opacity:c||.5,visible:r===b.d.area}};return i.a.createElement(a.AreaSeries,{id:d,key:d,name:H(e),xScaleType:a.ScaleType.Time,yScaleType:a.ScaleType.Linear,xAccessor:"timestamp",yAccessors:l,y0Accessors:f,data:n.rows,stackAccessors:o?["timestamp"]:void 0,areaSeriesStyle:m,color:s,timeZone:u})}function J({metric:e,id:t,series:n,stack:r}){const o=z(),c=e.color&&Object(p.b)(e.color)||Object(p.b)(p.a.color0),u=Array.isArray(t)?t.map((t=>q(e,t))).slice(t.length-1,t.length):[q(e,t)],s=`series-${n.id}-${u.join("-")}`,l={rectBorder:{stroke:c,strokeWidth:1,visible:!0},rect:{opacity:1}};return i.a.createElement(a.BarSeries,{id:s,key:s,name:H(e),xScaleType:a.ScaleType.Time,yScaleType:a.ScaleType.Linear,xAccessor:"timestamp",yAccessors:u,data:n.rows,stackAccessors:r?["timestamp"]:void 0,barSeriesStyle:l,color:c,timeZone:o})}function Y({expression:e,derivedIndexPattern:t,annotations:n,chartType:f=b.d.bar,filterQuery:h,groupBy:g,hideTitle:y=!1,timeRange:E,timeFieldName:x}){var T,O;const{charts:j,uiSettings:w}=Object(m.a)().services,{isLoading:M,data:k}=D(e,t,h,g,E,x),L=Object(r.useRef)(null),S=Object(u.useActiveCursor)(j.activeCursor,L,{isDateHistogram:!0});if(M)return i.a.createElement(B.b,null);if(!k)return i.a.createElement(B.c,null);const A=(null==w?void 0:w.get("theme:darkMode"))||!1,I=Object(l.first)(Object(l.first)(k.pages).series);if(!I||!I.rows||0===I.rows.length)return i.a.createElement(B.c,null);const N=Object(l.first)(I.rows).timestamp,F=Object(l.last)(I.rows).timestamp,$={field:e.metric,aggregation:e.aggType,color:p.a.color0};"custom"===$.aggregation&&($.label=e.label||P.a);const W=null==N||null==F?e=>`${e}`:Object(a.niceTimeFormatter)([N,F]),_=e.threshold.slice().sort(),U=null!==(T=null===(O=e.warningThreshold)||void 0===O?void 0:O.slice().sort())&&void 0!==T?T:[],C=[..._,...U].sort(),Q={...I,rows:I.rows.map((e=>{const t={...e};return C.forEach(((e,n)=>{t[q($,`threshold_${n}`)]=e})),t}))},K=G(Q,[$],!1),z={max:1.1*Math.max(K.max,Object(l.last)(C)||K.max),min:.9*Math.min(K.min,Object(l.first)(C)||K.min)};z.min===Object(l.first)(e.threshold)&&(z.min=.9*z.min);const{timeSize:H,timeUnit:Z}=e,J=B.d[Z];return i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,null,i.a.createElement(a.Chart,{ref:L},i.a.createElement(V,{type:f,metric:$,id:"0",series:Q,stack:!1}),i.a.createElement(R,{comparator:e.comparator,threshold:e.threshold,sortedThresholds:_,color:p.a.color1,id:"critical",firstTimestamp:N,lastTimestamp:F,domain:z}),e.warningComparator&&e.warningThreshold&&i.a.createElement(R,{comparator:e.warningComparator,threshold:e.warningThreshold,sortedThresholds:U,color:p.a.color5,id:"warning",firstTimestamp:N,lastTimestamp:F,domain:z}),n,i.a.createElement(a.Axis,{id:"timestamp",position:a.Position.Bottom,showOverlappingTicks:!0,tickFormat:W}),i.a.createElement(a.Axis,{id:"values",position:a.Position.Left,tickFormat:v($),domain:z}),i.a.createElement(a.Tooltip,{headerFormatter:({value:e})=>d()(e).format(w.get(s.UI_SETTINGS.DATE_FORMAT))}),i.a.createElement(a.Settings,{onPointerUpdate:S,externalPointerEvents:{tooltip:{visible:!0}},theme:Object(B.e)(A)}))),!y&&i.a.createElement("div",{style:{textAlign:"center"}},"ALL"!==Q.id?i.a.createElement(o.EuiText,{size:"xs",color:"subdued"},i.a.createElement(c.FormattedMessage,{id:"xpack.observability.threshold.rule.alerts.dataTimeRangeLabelWithGrouping",defaultMessage:"Last {lookback} {timeLabel} of data for {id}",values:{id:Q.id,timeLabel:J,lookback:20*H}})):i.a.createElement(o.EuiText,{size:"xs",color:"subdued"},i.a.createElement(c.FormattedMessage,{id:"xpack.observability.threshold.rule.alerts.dataTimeRangeLabel",defaultMessage:"Last {lookback} {timeLabel}",values:{timeLabel:J,lookback:20*H}}))))}},137:function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var r=n(116);let i;!function(e){e.bytesDecimal="bytesDecimal",e.bitsDecimal="bitsDecimal",e.abbreviatedNumber="abbreviatedNumber"}(i||(i={}));const a={[i.bytesDecimal]:["B","kB","MB","GB","TB","PB","EB","ZB","YB"],[i.bitsDecimal]:["bit","kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],[i.abbreviatedNumber]:["","K","M","B","T"]},o={[i.bytesDecimal]:1e3,[i.bitsDecimal]:1e3,[i.abbreviatedNumber]:1e3},c=e=>t=>{const n=a[e],c=o[e],u=e===i.bitsDecimal?8*t:t,s=Math.min(Math.floor(Math.log(Math.abs(u))/Math.log(c)),n.length-1);return s<0?`${Object(r.a)(u)} ${n[0]}`:`${Object(r.a)(u/Math.pow(c,s))} ${n[s]}`},u={number:r.a,abbreviatedNumber:c(i.abbreviatedNumber),bytes:c(i.bytesDecimal),bits:c(i.bitsDecimal),percent:e=>`${Object(r.a)(100*e)}%`,highPrecision:e=>Number(e).toLocaleString("en",{maximumFractionDigits:5})},s=(e,t="{{value}}")=>n=>{if(null==n)return"";const r=(0,u[e])(Number(n));return t.replace(/{{value}}/g,r)}}}]);