text: (window.webpackJsonp=window.webpackJsonp||[]).push([[33],{EnIS:function(e,t,r){"use strict";r.r(t);var n=r("Obii"),i=r("KHwQ"),a=r.n(i),o=r("LvDl"),s=r.n(o),l=r("wEtz"),u=[{text:"Count",value:"count",requiresField:!1},{text:"Average",value:"avg",requiresField:!0,supportsInlineScript:!0,supportsMissing:!0},{text:"Sum",value:"sum",requiresField:!0,supportsInlineScript:!0,supportsMissing:!0},{text:"Max",value:"max",requiresField:!0,supportsInlineScript:!0,supportsMissing:!0},{text:"Min",value:"min",requiresField:!0,supportsInlineScript:!0,supportsMissing:!0},{text:"Extended Stats",value:"extended_stats",requiresField:!0,supportsMissing:!0,supportsInlineScript:!0},{text:"Percentiles",value:"percentiles",requiresField:!0,supportsMissing:!0,supportsInlineScript:!0},{text:"Unique Count",value:"cardinality",requiresField:!0,supportsMissing:!0},{text:"Moving Average",value:"moving_avg",requiresField:!1,isPipelineAgg:!0,minVersion:2},{text:"Derivative",value:"derivative",requiresField:!1,isPipelineAgg:!0,minVersion:2},{text:"Bucket Script",value:"bucket_script",requiresField:!1,isPipelineAgg:!0,supportsMultipleBucketPaths:!0,minVersion:2},{text:"Raw Document",value:"raw_document",requiresField:!1},{text:"Logs",value:"logs",requiresField:!1}],c=[{text:"Terms",value:"terms",requiresField:!0},{text:"Filters",value:"filters"},{text:"Geo Hash Grid",value:"geohash_grid",requiresField:!0},{text:"Date Histogram",value:"date_histogram",requiresField:!0},{text:"Histogram",value:"histogram",requiresField:!0}],g=[{text:"Doc Count",value:"_count"},{text:"Term value",value:"_term"}],f=[{text:"Top",value:"desc"},{text:"Bottom",value:"asc"}],d=[{text:"No limit",value:"0"},{text:"1",value:"1"},{text:"2",value:"2"},{text:"3",value:"3"},{text:"5",value:"5"},{text:"10",value:"10"},{text:"15",value:"15"},{text:"20",value:"20"}],p=[{text:"Avg",value:"avg"},{text:"Min",value:"min"},{text:"Max",value:"max"},{text:"Sum",value:"sum"},{text:"Count",value:"count"},{text:"Std Dev",value:"std_deviation"},{text:"Std Dev Upper",value:"std_deviation_bounds_upper"},{text:"Std Dev Lower",value:"std_deviation_bounds_lower"}],v=[{text:"auto",value:"auto"},{text:"10s",value:"10s"},{text:"1m",value:"1m"},{text:"5m",value:"5m"},{text:"10m",value:"10m"},{text:"20m",value:"20m"},{text:"1h",value:"1h"},{text:"1d",value:"1d"}],m=[{text:"Simple",value:"simple"},{text:"Linear",value:"linear"},{text:"Exponentially Weighted",value:"ewma"},{text:"Holt Linear",value:"holt"},{text:"Holt Winters",value:"holt_winters"}],h={moving_avg:[{text:"window",default:5},{text:"model",default:"simple"},{text:"predict",default:void 0},{text:"minimize",default:!1}],derivative:[{text:"unit",default:void 0}],bucket_script:[]},y={simple:[],linear:[],ewma:[{text:"Alpha",value:"alpha",default:void 0}],holt:[{text:"Alpha",value:"alpha",default:void 0},{text:"Beta",value:"beta",default:void 0}],holt_winters:[{text:"Alpha",value:"alpha",default:void 0},{text:"Beta",value:"beta",default:void 0},{text:"Gamma",value:"gamma",default:void 0},{text:"Period",value:"period",default:void 0},{text:"Pad",value:"pad",default:void 0,isCheckbox:!0}]};function b(e){return s.a.filter(u,(function(t){return!t.minVersion||t.minVersion<=e}))}function O(e){if(e){var t=h[e];return null!=t}return!1}function x(e){return!!e&&void 0!==u.find((function(t){return t.value===e&&t.supportsMultipleBucketPaths}))}function _(e,t){var r=[];return t?(s.a.each(y[e],(function(e){e.isCheckbox||r.push(e)})),r):y[e]}function w(e){var t=s.a.find(u,{value:e.type});return t.requiresField||O(e.type)?t.text+" "+e.field:t.text}var k=function(e,t){return s.a.find(e,{id:t})};function j(e,t){return e&&e.metrics&&e.metrics.some((function(e){return e.type===t}))}var S=r("iZOS");function F(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?F(Object(r),!0).forEach((function(t){P(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):F(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function q(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var C=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.targets=t,this.response=r,this.targets=t,this.response=r}var t,r,i;return t=e,(r=[{key:"processMetrics",value:function(e,t,r,n){var i,a,o,s,l,u;for(a=0;a<t.metrics.length;a++)if(!(i=t.metrics[a]).hide)switch(i.type){case"count":for(s={datapoints:[],metric:"count",props:n},o=0;o<e.buckets.length;o++)u=(l=e.buckets[o]).doc_count,s.datapoints.push([u,l.key]);r.push(s);break;case"percentiles":if(0===e.buckets.length)break;var c=e.buckets[0][i.id].values;for(var g in c){for(s={datapoints:[],metric:"p"+g,props:n,field:i.field},o=0;o<e.buckets.length;o++){var f=(l=e.buckets[o])[i.id].values;s.datapoints.push([f[g],l.key])}r.push(s)}break;case"extended_stats":for(var d in i.meta)if(i.meta[d]){for(s={datapoints:[],metric:d,props:n,field:i.field},o=0;o<e.buckets.length;o++){var p=(l=e.buckets[o])[i.id];p.std_deviation_bounds_upper=p.std_deviation_bounds.upper,p.std_deviation_bounds_lower=p.std_deviation_bounds.lower,s.datapoints.push([p[d],l.key])}r.push(s)}break;default:for(s={datapoints:[],metric:i.type,field:i.field,metricId:i.id,props:n},o=0;o<e.buckets.length;o++)void 0!==(u=(l=e.buckets[o])[i.id])&&(u.normalized_value?s.datapoints.push([u.normalized_value,l.key]):s.datapoints.push([u.value,l.key]));r.push(s)}}},{key:"processAggregationDocs",value:function(e,t,r,n,i){if(0===n.columns.length){var a=!0,o=!1,l=void 0;try{for(var u,c=s.a.keys(i)[Symbol.iterator]();!(a=(u=c.next()).done);a=!0){var g=u.value;n.addColumn({text:g,filterable:!0})}}catch(e){o=!0,l=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw l}}n.addColumn({text:t.field,filterable:!0})}var f=function(e,t,r){n.addColumn({text:t}),e.push(r)},d=!0,p=!1,v=void 0;try{for(var m,h=e.buckets[Symbol.iterator]();!(d=(m=h.next()).done);d=!0){var y=m.value,b=[],O=!0,x=!1,_=void 0;try{for(var w,k=s.a.values(i)[Symbol.iterator]();!(O=(w=k.next()).done);O=!0){var j=w.value;b.push(j)}}catch(e){x=!0,_=e}finally{try{O||null==k.return||k.return()}finally{if(x)throw _}}b.push(y.key);var S=!0,F=!1,E=void 0;try{for(var P,q=r.metrics[Symbol.iterator]();!(S=(P=q.next()).done);S=!0){var C=P.value;switch(C.type){case"count":f(b,this.getMetricName(C.type),y.doc_count);break;case"extended_stats":for(var D in C.meta)if(C.meta[D]){var A=y[C.id];A.std_deviation_bounds_upper=A.std_deviation_bounds.upper,A.std_deviation_bounds_lower=A.std_deviation_bounds.lower,f(b,this.getMetricName(D),A[D])}break;case"percentiles":var T=y[C.id].values;for(var M in T)f(b,"p".concat(M," ").concat(C.field),T[M]);break;default:var L=this.getMetricName(C.type);s.a.filter(r.metrics,{type:C.type}).length>1&&(L+=" "+C.field),f(b,L,y[C.id].value)}}}catch(e){F=!0,E=e}finally{try{S||null==q.return||q.return()}finally{if(F)throw E}}n.rows.push(b)}}catch(e){p=!0,v=e}finally{try{d||null==h.return||h.return()}finally{if(p)throw v}}}},{key:"processBuckets",value:function(e,t,r,n,i,a){var o,l,u,c,g=t.bucketAggs.length-1;for(c in e)if(l=s.a.find(t.bucketAggs,{id:c}),u=e[c],l)if(a===g)"date_histogram"===l.type?this.processMetrics(u,t,r,i):this.processAggregationDocs(u,l,t,n,i);else for(var f in u.buckets)o=u.buckets[f],i=s.a.clone(i),void 0!==o.key?i[l.field]=o.key:i.filter=f,o.key_as_string&&(i[l.field]=o.key_as_string),this.processBuckets(o,t,r,n,i,a+1)}},{key:"getMetricName",value:function(e){var t=s.a.find(u,{value:e});return t||(t=s.a.find(p,{value:e})),t?t.text:e}},{key:"getSeriesName",value:function(e,t,r){var n=this.getMetricName(e.metric);if(t.alias)return t.alias.replace(/\{\{([\s\S]+?)\}\}/g,(function(t,r,i){var a=r||i;return 0===a.indexOf("term ")?e.props[a.substring(5)]:void 0!==e.props[a]?e.props[a]:"metric"===a?n:"field"===a?e.field||"":t}));if(e.field&&O(e.metric))if(e.metric&&x(e.metric)){var i=s.a.find(t.metrics,{id:e.metricId});if(i&&i.settings.script){n=i.settings.script;var a=!0,o=!1,l=void 0;try{for(var u,c=i.pipelineVariables[Symbol.iterator]();!(a=(u=c.next()).done);a=!0){var g=u.value,f=s.a.find(t.metrics,{id:g.pipelineAgg});f&&(n=n.replace("params."+g.name,w(f)))}}catch(e){o=!0,l=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw l}}}else n="Unset"}else{var d=s.a.find(t.metrics,{id:e.field});d?n+=" "+w(d):n="Unset"}else e.field&&(n+=" "+e.field);if(0===s.a.keys(e.props).length)return n;var p="";for(var v in e.props)p+=e.props[v]+" ";return 1===r?p.trim():p.trim()+" "+n}},{key:"nameSeries",value:function(e,t){for(var r=s.a.uniq(s.a.map(e,"metric")).length,n=0;n<e.length;n++){var i=e[n];i.target=this.getSeriesName(i,t,r)}}},{key:"processHits",value:function(e,t){var r,n,i,a,o={target:"docs",type:"docs",datapoints:[],total:"number"==typeof e.total?e.total:e.total.value,filterable:!0};for(a=0;a<e.hits.length;a++){if(i={_id:(n=e.hits[a])._id,_type:n._type,_index:n._index},n._source)for(r in n._source)i[r]=n._source[r];for(r in n.fields)i[r]=n.fields[r];o.datapoints.push(i)}t.push(o)}},{key:"trimDatapoints",value:function(e,t){var r=s.a.find(t.bucketAggs,{type:"date_histogram"});if(r&&r.settings&&r.settings.trimEdges){var n=r.settings.trimEdges;for(var i in e){var a=e[i];a.datapoints.length>2*n&&(a.datapoints=a.datapoints.slice(n,a.datapoints.length-n))}}}},{key:"getErrorFromElasticResponse",value:function(e,t){var r={};return r.data=JSON.stringify(t,null,4),t.root_cause&&t.root_cause.length>0&&t.root_cause[0].reason?r.message=t.root_cause[0].reason:r.message=t.reason||"Unkown elastic error response",e.$$config&&(r.config=e.$$config),r}},{key:"getTimeSeries",value:function(){for(var e=[],t=0;t<this.response.responses.length;t++){var r=this.response.responses[t];if(r.error)throw this.getErrorFromElasticResponse(this.response,r.error);if(r.hits&&r.hits.hits.length>0&&this.processHits(r.hits,e),r.aggregations){var n=r.aggregations,i=this.targets[t],a=[],o=new S.a;this.processBuckets(n,i,a,o,{},0),this.trimDatapoints(a,i),this.nameSeries(a,i);for(var s=0;s<a.length;s++)e.push(a[s]);o.rows.length>0&&e.push(o)}}return{data:e}}},{key:"getLogs",value:function(e,t){for(var r=[],i=0;i<this.response.responses.length;i++){var a=this.response.responses[i];if(a.error)throw this.getErrorFromElasticResponse(this.response,a.error);var o=D(a.hits.hits),s=o.propNames,l=o.docs;if(l.length>0){var u=A(s,this.targets[0].timeField,e,t),c=!0,g=!1,f=void 0;try{for(var d,p=l[Symbol.iterator]();!(c=(d=p.next()).done);c=!0){var v=d.value;t&&(v.level=v[t]),u.add(v)}}catch(e){g=!0,f=e}finally{try{c||null==p.return||p.return()}finally{if(g)throw f}}r.push(u)}if(a.aggregations){var m=a.aggregations,h=this.targets[i],y=[],b=new S.a;this.processBuckets(m,h,y,b,{},0),this.trimDatapoints(y,h),this.nameSeries(y,h);for(var O=0;O<y.length;O++){var x=Object(n.toDataFrame)(y[O]);r.push(x)}}}return{data:r}}}])&&q(t.prototype,r),i&&q(t,i),e}(),D=function(e){var t=[],r=[],n=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){for(var u=o.value,c=u._source?Object(l.default)(u._source,null):{},g=E({_id:u._id,_type:u._type,_index:u._index,_source:E({},c)},c),f=0,d=Object.keys(g);f<d.length;f++){var p=d[f];-1===r.indexOf(p)&&r.push(p)}t.push(g)}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r.sort(),{docs:t,propNames:r}},A=function(e,t,r,i){var a=new n.MutableDataFrame({fields:[]});a.addField({name:t,type:n.FieldType.time}),r?a.addField({name:r,type:n.FieldType.string}).parse=function(e){return e||""}:a.addField({name:"_source",type:n.FieldType.string}).parse=function(e){return JSON.stringify(e,null,2)},i&&(a.addField({name:"level",type:n.FieldType.string}).parse=function(e){return e||""});var o=a.fields.map((function(e){return e.name})),s=!0,l=!1,u=void 0;try{for(var c,g=e[Symbol.iterator]();!(s=(c=g.next()).done);s=!0){var f=c.value;o.includes(f)||(a.addField({name:f,type:n.FieldType.string}).parse=function(e){return e||""})}}catch(e){l=!0,u=e}finally{try{s||null==g.return||g.return()}finally{if(l)throw u}}return a};function T(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var M={Hourly:{startOf:"hour",amount:"hours"},Daily:{startOf:"day",amount:"days"},Weekly:{startOf:"isoWeek",amount:"weeks"},Monthly:{startOf:"month",amount:"months"},Yearly:{startOf:"year",amount:"years"}},L=function(){function e(t,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.pattern=t,this.interval=r}var t,r,i;return t=e,(r=[{key:"getIndexForToday",value:function(){return this.interval?Object(n.toUtc)().format(this.pattern):this.pattern}},{key:"getIndexList",value:function(e,t){if(!this.interval)return this.pattern;for(var r=M[this.interval],i=Object(n.dateTime)(e).utc().startOf(r.startOf),a=Object(n.dateTime)(t).utc().startOf(r.startOf).valueOf(),o=[];i.valueOf()<=a;)o.push(i.format(this.pattern)),i.add(1,r.amount);return o}}])&&T(t.prototype,r),i&&T(t,i),e}();function V(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function I(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var Q=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.timeField=t.timeField,this.esVersion=t.esVersion}var t,r,n;return t=e,(r=[{key:"getRangeFilter",value:function(){var e={};return e[this.timeField]={gte:"$timeFrom",lte:"$timeTo",format:"epoch_millis"},e}},{key:"buildTermsAgg",value:function(e,t,r){var n,i,a;if(t.terms={field:e.field},!e.settings)return t;if(t.terms.size=0===parseInt(e.settings.size,10)?500:parseInt(e.settings.size,10),void 0!==e.settings.orderBy&&(t.terms.order={},"_term"===e.settings.orderBy&&this.esVersion>=60?t.terms.order._key=e.settings.order:t.terms.order[e.settings.orderBy]=e.settings.order,n=parseInt(e.settings.orderBy,10),!isNaN(n)))for(a=0;a<r.metrics.length;a++)if((i=r.metrics[a]).id===e.settings.orderBy){t.aggs={},t.aggs[i.id]={},t.aggs[i.id][i.type]={field:i.field};break}return void 0!==e.settings.min_doc_count&&(t.terms.min_doc_count=parseInt(e.settings.min_doc_count,10)),e.settings.missing&&(t.terms.missing=e.settings.missing),t}},{key:"getDateHistogramAgg",value:function(e){var t={},r=e.settings||{};return t.interval=r.interval,t.field=this.timeField,t.min_doc_count=r.min_doc_count||0,t.extended_bounds={min:"$timeFrom",max:"$timeTo"},t.format="epoch_millis",""!==r.offset&&(t.offset=r.offset),"auto"===t.interval&&(t.interval="$__interval"),r.missing&&(t.missing=r.missing),t}},{key:"getHistogramAgg",value:function(e){var t={},r=e.settings||{};return t.interval=r.interval,t.field=e.field,t.min_doc_count=r.min_doc_count||0,r.missing&&(t.missing=r.missing),t}},{key:"getFiltersAgg",value:function(e){for(var t={},r=0;r<e.settings.filters.length;r++){var n=e.settings.filters[r].query,i=e.settings.filters[r].label;t[i=""===i||void 0===i?n:i]={query_string:{query:n,analyze_wildcard:!0}}}return t}},{key:"documentQuery",value:function(e,t){return e.size=t,e.sort={},e.sort[this.timeField]={order:"desc",unmapped_type:"boolean"},this.esVersion<5&&(e.fields=["*","_source"]),e.script_fields={},e}},{key:"addAdhocFilters",value:function(e,t){var r,n,i,a;if(t)for(r=0;r<t.length;r++)switch((i={})[(n=t[r]).key]=n.value,(a={})[n.key]={query:n.value},n.operator){case"=":e.query.bool.must||(e.query.bool.must=[]),e.query.bool.must.push({match_phrase:a});break;case"!=":e.query.bool.must_not||(e.query.bool.must_not=[]),e.query.bool.must_not.push({match_phrase:a});break;case"<":i[n.key]={lt:n.value},e.query.bool.filter.push({range:i});break;case">":i[n.key]={gt:n.value},e.query.bool.filter.push({range:i});break;case"=~":e.query.bool.filter.push({regexp:i});break;case"!~":e.query.bool.filter.push({bool:{must_not:{regexp:i}}})}}},{key:"build",value:function(e,t,r){var n,i,a,o,s;e.metrics=e.metrics||[{type:"count",id:"1"}],e.bucketAggs=e.bucketAggs||[{type:"date_histogram",id:"2",settings:{interval:"auto"}}],e.timeField=this.timeField;var l={size:0,query:{bool:{filter:[{range:this.getRangeFilter()},{query_string:{analyze_wildcard:!0,query:r}}]}}};if(this.addAdhocFilters(l,t),0===e.bucketAggs.length){if(!(s=e.metrics[0])||"raw_document"!==s.type)throw{message:"Invalid query"};var u=s.settings&&s.settings.size||500;return this.documentQuery(l,u)}for(o=l,n=0;n<e.bucketAggs.length;n++){var c=e.bucketAggs[n],g={};switch(c.type){case"date_histogram":g.date_histogram=this.getDateHistogramAgg(c);break;case"histogram":g.histogram=this.getHistogramAgg(c);break;case"filters":g.filters={filters:this.getFiltersAgg(c)};break;case"terms":this.buildTermsAgg(c,g,e);break;case"geohash_grid":g.geohash_grid={field:c.field,precision:c.settings.precision}}o.aggs=o.aggs||{},o.aggs[c.id]=g,o=g}for(o.aggs={},n=0;n<e.metrics.length;n++)if("count"!==(s=e.metrics[n]).type){var f={},d=null;if(O(s.type))if(x(s.type)){if(!s.pipelineVariables)continue;for(d={buckets_path:{}},i=0;i<s.pipelineVariables.length;i++)if((a=s.pipelineVariables[i]).name&&a.pipelineAgg&&/^\d*$/.test(a.pipelineAgg)){var p=k(e.metrics,a.pipelineAgg);p&&("count"===p.type?d.buckets_path[a.name]="_count":d.buckets_path[a.name]=a.pipelineAgg)}}else{if(!s.pipelineAgg||!/^\d*$/.test(s.pipelineAgg))continue;var v=k(e.metrics,s.pipelineAgg);v&&(d="count"===v.type?{buckets_path:"_count"}:{buckets_path:s.pipelineAgg})}else d={field:s.field};for(var m in s.settings)s.settings.hasOwnProperty(m)&&null!==s.settings[m]&&(d[m]=s.settings[m]);f[s.type]=d,o.aggs[s.id]=f}return l}},{key:"getTermsQuery",value:function(e){var t={size:0,query:{bool:{filter:[{range:this.getRangeFilter()}]}}};e.query&&t.query.bool.filter.push({query_string:{analyze_wildcard:!0,query:e.query}});var r=500;e.size&&(r=e.size),t.aggs={1:{terms:{field:e.field,size:r,order:{}}}};var n=e.orderBy,i=void 0===n?"key":n,a=e.order,o=void 0===a?"doc_count"===i?"desc":"asc":a;if(["asc","desc"].indexOf(o)<0)throw{message:"Invalid query sort order ".concat(o)};switch(i){case"key":case"term":var s=this.esVersion>=60?"_key":"_term";t.aggs[1].terms.order[s]=o;break;case"doc_count":t.aggs[1].terms.order._count=o;break;default:throw{message:"Invalid query sort type ".concat(i)}}return t}},{key:"getLogsQuery",value:function(e,t,r){var n={size:0,query:{bool:{filter:[{range:this.getRangeFilter()}]}}};return this.addAdhocFilters(n,t),e.query&&n.query.bool.filter.push({query_string:{analyze_wildcard:!0,query:r}}),function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?V(Object(r),!0).forEach((function(t){I(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},n=this.documentQuery(n,500),{aggs:this.build(e,null,r).aggs})}}])&&$(t.prototype,r),n&&$(t,n),e}(),N=r("t8hP");function R(e){return(R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function z(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function B(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function U(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function W(e,t,r,n,i,a,o){try{var s=e[a](o),l=s.value}catch(e){return void r(e)}s.done?t(l):Promise.resolve(l).then(n,i)}function H(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function Y(e,t){return!t||"object"!==R(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function J(e){return(J=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function G(e,t){return(G=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var K=function(e){function t(e,r,n){var i;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(i=Y(this,J(t).call(this,e))).templateSrv=r,i.timeSrv=n,i.basicAuth=e.basicAuth,i.withCredentials=e.withCredentials,i.url=e.url,i.name=e.name,i.index=e.database;var a=e.jsonData||{};return i.timeField=a.timeField,i.esVersion=a.esVersion,i.indexPattern=new L(i.index,a.interval),i.interval=a.timeInterval,i.maxConcurrentShardRequests=a.maxConcurrentShardRequests,i.queryBuilder=new Q({timeField:i.timeField,esVersion:i.esVersion}),i.logMessageField=a.logMessageField||"",i.logLevelField=a.logLevelField||"",i.dataLinks=a.dataLinks||[],""===i.logMessageField&&(i.logMessageField=null),""===i.logLevelField&&(i.logLevelField=null),i}var r,i,o,l,u;return t.$inject=["instanceSettings","templateSrv","timeSrv"],function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&G(e,t)}(t,e),r=t,(i=[{key:"request",value:function(e,t,r){var n={url:this.url+"/"+t,method:e,data:r};return(this.basicAuth||this.withCredentials)&&(n.withCredentials=!0),this.basicAuth&&(n.headers={Authorization:this.basicAuth}),Object(N.getBackendSrv)().datasourceRequest(n)}},{key:"get",value:function(e){var t=this.timeSrv.timeRange(),r=this.indexPattern.getIndexList(t.from.valueOf(),t.to.valueOf());return s.a.isArray(r)&&r.length?this.requestAllIndices(r,e).then((function(e){return e.data.$$config=e.config,e.data})):this.request("GET",this.indexPattern.getIndexForToday()+e).then((function(e){return e.data.$$config=e.config,e.data}))}},{key:"requestAllIndices",value:(l=regeneratorRuntime.mark((function e(t,r){var n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=7,i=t.length,a=0;case 3:if(!(a<Math.min(i,n))){e.next=17;break}return e.prev=4,e.next=7,this.request("GET",t[i-a-1]+r);case 7:return e.abrupt("return",e.sent);case 10:if(e.prev=10,e.t0=e.catch(4),404===e.t0.status&&a!==n-1){e.next=14;break}throw e.t0;case 14:a++,e.next=3;break;case 17:case"end":return e.stop()}}),e,this,[[4,10]])})),u=function(){var e=this,t=arguments;return new Promise((function(r,n){var i=l.apply(e,t);function a(e){W(i,r,n,a,o,"next",e)}function o(e){W(i,r,n,a,o,"throw",e)}a(void 0)}))},function(e,t){return u.apply(this,arguments)})},{key:"post",value:function(e,t){return this.request("POST",e,t).then((function(e){return e.data.$$config=e.config,e.data})).catch((function(e){if(e.data&&e.data.error)throw{message:"Elasticsearch error: "+e.data.error.reason,error:e.data.error};throw e}))}},{key:"annotationQuery",value:function(e){var t=e.annotation,r=t.timeField||"@timestamp",i=t.timeEndField||null,o=t.query||"*",l=t.tagsField||"tags",u=t.textField||null,c=[],g={};if(g[r]={from:e.range.from.valueOf(),to:e.range.to.valueOf(),format:"epoch_millis"},c.push({range:g}),i){var f={};f[i]={from:e.range.from.valueOf(),to:e.range.to.valueOf(),format:"epoch_millis"},c.push({range:f})}var d={query:{bool:{filter:[{bool:{should:c,minimum_should_match:1}},{query_string:{query:this.templateSrv.replace(o,{},"lucene")}}]}},size:1e4};this.esVersion<5&&(d.fields=[r,"_source"]);var p={search_type:"query_then_fetch",ignore_unavailable:!0};t.index?p.index=t.index:p.index=this.indexPattern.getIndexList(e.range.from,e.range.to);var v=a.a.toJson(p)+"\n"+a.a.toJson(d)+"\n";return this.post("_msearch",v).then((function(e){for(var a=[],o=e.responses[0].hits.hits,c=function(e,t){if(t){for(var r=t.split("."),n=e,i=0;i<r.length;i++)if(!(n=n[r[i]]))return console.log("could not find field in annotation: ",t),"";return n}},g=0;g<o.length;g++){var f=o[g]._source,d=c(f,r);if(void 0!==o[g].fields){var p=o[g].fields;(s.a.isString(p[r])||s.a.isNumber(p[r]))&&(d=p[r])}var v={annotation:t,time:Object(n.toUtc)(d).valueOf(),text:c(f,u),tags:c(f,l)};if(i){var m=c(f,i);m&&(v.timeEnd=Object(n.toUtc)(m).valueOf())}if(t.titleField){var h=c(f,t.titleField);h&&(v.text=h+"\n"+v.text)}"string"==typeof v.tags&&(v.tags=v.tags.split(",")),a.push(v)}return a}))}},{key:"interpolateVariablesInQueries",value:function(e,t){var r=this,n=e;return e&&e.length>0&&(n=e.map((function(e){return function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?B(Object(r),!0).forEach((function(t){U(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):B(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},e,{datasource:r.name,query:r.templateSrv.replace(e.query,t,"lucene")})}))),n}},{key:"testDatasource",value:function(){var e=this;return this.getFields({type:"date"}).then((function(t){return s.a.find(t,{text:e.timeField})?{status:"success",message:"Index OK. Time field name OK."}:{status:"error",message:"No date field named "+e.timeField+" found"}}),(function(e){if(console.log(e),e.data&&e.data.error){var t=a.a.toJson(e.data.error);return e.data.error.reason&&(t=e.data.error.reason),{status:"error",message:t}}return{status:"error",message:e.status}}))}},{key:"getQueryHeader",value:function(e,t,r){var n={search_type:e,ignore_unavailable:!0,index:this.indexPattern.getIndexList(t,r)};return this.esVersion>=56&&this.esVersion<70&&(n.max_concurrent_shard_requests=this.maxConcurrentShardRequests),a.a.toJson(n)}},{key:"query",value:function(e){var t=this,r="",n=s.a.cloneDeep(e.targets),i=[],o=this.templateSrv.getAdhocFilters(this.name),l=!0,u=!1,c=void 0;try{for(var g,f=n[Symbol.iterator]();!(l=(g=f.next()).done);l=!0){var d=g.value;if(!d.hide){var p=this.templateSrv.replace(d.query,e.scopedVars,"lucene");p&&""!==p||(p="*");var v=void 0;d.isLogsQuery||j(d,"logs")?(d.bucketAggs=[{type:"date_histogram",id:"2",settings:{interval:"auto"}}],d.metrics=[{type:"count",id:"1"}],d.isLogsQuery=!0,v=this.queryBuilder.getLogsQuery(d,o,p)):(d.alias&&(d.alias=this.templateSrv.replace(d.alias,e.scopedVars,"lucene")),v=this.queryBuilder.build(d,o,p));var m=a.a.toJson(v),h=0===v.size&&this.esVersion<5?"count":"query_then_fetch";r+=this.getQueryHeader(h,e.range.from,e.range.to)+"\n",r+=m+"\n",i.push(d)}}}catch(e){u=!0,c=e}finally{try{l||null==f.return||f.return()}finally{if(u)throw c}}if(0===i.length)return Promise.resolve({data:[]});r=(r=r.replace(/"\$timeFrom"/g,e.range.from.valueOf().toString())).replace(/"\$timeTo"/g,e.range.to.valueOf().toString()),r=this.templateSrv.replace(r,e.scopedVars);var y=this.getMultiSearchUrl();return this.post(y,r).then((function(e){var r=new C(i,e);if(i.some((function(e){return e.isLogsQuery}))){var n=r.getLogs(t.logMessageField,t.logLevelField),a=!0,o=!1,s=void 0;try{for(var l,u=n.data[Symbol.iterator]();!(a=(l=u.next()).done);a=!0){var c=l.value;t.enhanceDataFrame(c)}}catch(e){o=!0,s=e}finally{try{a||null==u.return||u.return()}finally{if(o)throw s}}return n}return r.getTimeSeries()}))}},{key:"getFields",value:function(e){var t=this.esVersion;return this.get("/_mapping").then((function(r){var n={float:"number",double:"number",integer:"number",long:"number",date:"date",string:"string",text:"string",scaled_float:"number",nested:"nested"};function i(e,t,r){return"_"!==t[0]&&(!r.type||r.type===e.type||r.type===n[e.type])}var a=[],o={};function l(t){for(var r in t){var n=t[r];if(s.a.isObject(n.properties)&&(a.push(r),l(n.properties)),s.a.isObject(n.fields)&&(a.push(r),l(n.fields)),s.a.isString(n.type)){var u=a.concat(r).join(".");i(n,r,e)&&(o[u]={text:u,type:n.type})}}a.pop()}for(var u in r){var c=r[u];if(c&&c.mappings){var g=c.mappings;if(t<70)for(var f in g)l(g[f].properties);else l(g.properties)}}return s.a.map(o,(function(e){return e}))}))}},{key:"getTerms",value:function(e){var t=this.timeSrv.timeRange(),r=this.esVersion>=5?"query_then_fetch":"count",n=this.getQueryHeader(r,t.from,t.to),i=a.a.toJson(this.queryBuilder.getTermsQuery(e));i=n+"\n"+(i=(i=i.replace(/\$timeFrom/g,t.from.valueOf().toString())).replace(/\$timeTo/g,t.to.valueOf().toString()))+"\n";var o=this.getMultiSearchUrl();return this.post(o,i).then((function(e){if(!e.responses[0].aggregations)return[];var t=e.responses[0].aggregations[1].buckets;return s.a.map(t,(function(e){return{text:e.key_as_string||e.key,value:e.key}}))}))}},{key:"getMultiSearchUrl",value:function(){return this.esVersion>=70&&this.maxConcurrentShardRequests?"_msearch?max_concurrent_shard_requests=".concat(this.maxConcurrentShardRequests):"_msearch"}},{key:"metricFindQuery",value:function(e){if(e=a.a.fromJson(e)){if("fields"===e.find)return e.field=this.templateSrv.replace(e.field,{},"lucene"),this.getFields(e);if("terms"===e.find)return e.field=this.templateSrv.replace(e.field,{},"lucene"),e.query=this.templateSrv.replace(e.query||"*",{},"lucene"),this.getTerms(e)}return Promise.resolve([])}},{key:"getTagKeys",value:function(){return this.getFields({})}},{key:"getTagValues",value:function(e){return this.getTerms({field:e.key,query:"*"})}},{key:"targetContainsTemplate",value:function(e){if(this.templateSrv.variableExists(e.query)||this.templateSrv.variableExists(e.alias))return!0;var t=!0,r=!1,n=void 0;try{for(var i,a=e.bucketAggs[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;if(this.templateSrv.variableExists(o.field)||this.objectContainsTemplate(o.settings))return!0}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}var s=!0,l=!1,u=void 0;try{for(var c,g=e.metrics[Symbol.iterator]();!(s=(c=g.next()).done);s=!0){var f=c.value;if(this.templateSrv.variableExists(f.field)||this.objectContainsTemplate(f.settings)||this.objectContainsTemplate(f.meta))return!0}}catch(e){l=!0,u=e}finally{try{s||null==g.return||g.return()}finally{if(l)throw u}}return!1}},{key:"enhanceDataFrame",value:function(e){var t=this;if(this.dataLinks.length){var r=!0,n=!1,i=void 0;try{for(var a,o=function(){var e=a.value,r=t.dataLinks.find((function(t){return e.name&&e.name.match(t.field)}));r&&(e.config=e.config||{},e.config.links=[].concat(z(e.config.links||[]),[{url:r.url,title:""}]))},s=e.fields[Symbol.iterator]();!(r=(a=s.next()).done);r=!0)o()}catch(e){n=!0,i=e}finally{try{r||null==s.return||s.return()}finally{if(n)throw i}}}}},{key:"isPrimitive",value:function(e){return null==e||!!["string","number","boolean"].some((function(e){return e===R(!0)}))}},{key:"objectContainsTemplate",value:function(e){if(!e)return!1;for(var t=0,r=Object.keys(e);t<r.length;t++){var n=r[t];if(this.isPrimitive(e[n])){if(this.templateSrv.variableExists(e[n]))return!0}else if(Array.isArray(e[n])){var i=!0,a=!1,o=void 0;try{for(var s,l=e[n][Symbol.iterator]();!(i=(s=l.next()).done);i=!0){var u=s.value;if(this.objectContainsTemplate(u))return!0}}catch(e){a=!0,o=e}finally{try{i||null==l.return||l.return()}finally{if(a)throw o}}}else if(this.objectContainsTemplate(e[n]))return!0}return!1}}])&&H(r.prototype,i),o&&H(r,o),t}(n.DataSourceApi),X=r("txxJ"),Z=r("GQ3c");var ee=function e(t,r,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var i=t.target.bucketAggs;t.orderByOptions=[],t.getBucketAggTypes=function(){return c},t.getOrderOptions=function(){return f},t.getSizeOptions=function(){return d},n.onAppEvent(Z.CoreEvents.elasticQueryUpdated,(function(){t.validateModel()}),t),t.init=function(){t.agg=i[t.index],t.validateModel()},t.onChangeInternal=function(){t.onChange()},t.onTypeChanged=function(){switch(t.agg.settings={},t.showOptions=!1,t.agg.type){case"date_histogram":case"histogram":case"terms":delete t.agg.query,t.agg.field="select field";break;case"filters":delete t.agg.field,t.agg.query="*";break;case"geohash_grid":t.agg.settings.precision=3}t.validateModel(),t.onChange()},t.validateModel=function(){t.index=s.a.indexOf(i,t.agg),t.isFirst=0===t.index,t.bucketAggCount=i.length;var e,r="",n=t.agg.settings||{};switch(t.agg.type){case"terms":n.order=n.order||"desc",n.size=n.size||"10",n.min_doc_count=n.min_doc_count||1,n.orderBy=n.orderBy||"_term","0"!==n.size&&(e=n.order,r=s.a.find(f,{value:e}).text+" "+n.size+", "),n.min_doc_count>0&&(r+="Min Doc Count: "+n.min_doc_count+", "),r+="Order by: "+function(e,t){var r=s.a.find(g,{value:e});if(r)return r.text;var n=s.a.find(t.metrics,{id:e});return n?w(n):"metric not found"}(n.orderBy,t.target),"0"===n.size&&(r+=" ("+n.order+")");break;case"filters":n.filters=n.filters||[{query:"*"}],(r=s.a.reduce(n.filters,(function(e,t,r){return e+="Q"+(r+1)+"  = "+t.query+" "}),"")).length>50&&(r=r.substr(0,50)+"..."),r="Filter Queries ("+n.filters.length+")";break;case"date_histogram":n.interval=n.interval||"auto",n.min_doc_count=n.min_doc_count||0,t.agg.field=t.target.timeField,r="Interval: "+n.interval,n.min_doc_count>0&&(r+=", Min Doc Count: "+n.min_doc_count),(void 0===n.trimEdges||n.trimEdges<0)&&(n.trimEdges=0),n.trimEdges&&n.trimEdges>0&&(r+=", Trim edges: "+n.trimEdges);break;case"histogram":n.interval=n.interval||1e3,n.min_doc_count=s.a.defaultTo(n.min_doc_count,1),r="Interval: "+n.interval,n.min_doc_count>0&&(r+=", Min Doc Count: "+n.min_doc_count);break;case"geohash_grid":n.precision=Math.max(Math.min(n.precision,7),1),r="Precision: "+n.precision}return t.settingsLinkText=r,t.agg.settings=n,!0},t.addFiltersQuery=function(){t.agg.settings.filters.push({query:"*"})},t.removeFiltersQuery=function(e){t.agg.settings.filters=s.a.without(t.agg.settings.filters,e)},t.toggleOptions=function(){t.showOptions=!t.showOptions},t.getOrderByOptions=function(){return e=t.target,r=[],s.a.each(e.metrics,(function(e){"count"!==e.type&&r.push({text:w(e),value:e.id})})),g.concat(r);var e,r},t.getFieldsInternal=function(){return"date_histogram"===t.agg.type?t.getFields({$fieldType:"date"}):t.getFields()},t.getIntervalOptions=function(){return Promise.resolve(r.transformToSegments(!0,"interval")(v))},t.addBucketAgg=function(){var e=i[i.length-1],r=i.length-1;e&&"date_histogram"===e.type&&(r-=1);var n=s.a.reduce(t.target.bucketAggs.concat(t.target.metrics),(function(e,t){return parseInt(t.id,10)>e?parseInt(t.id,10):e}),0);i.splice(r,0,{type:"terms",field:"select field",id:(n+1).toString(),fake:!0}),t.onChange()},t.removeBucketAgg=function(){i.splice(t.index,1),t.onChange()},t.init()};ee.$inject=["$scope","uiSegmentSrv","$rootScope"],ee.$inject=["$scope","uiSegmentSrv","$rootScope"],X.c.directive("elasticBucketAgg",(function(){return{templateUrl:"public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html",controller:ee,restrict:"E",scope:{target:"=",index:"=",onChange:"&",getFields:"&"}}}));var te=function e(t,r,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var i=t.target.metrics;t.metricAggTypes=b(t.esVersion),t.extendedStats=p,t.pipelineAggOptions=[],t.modelSettingsValues={},t.init=function(){t.agg=i[t.index],t.validateModel(),t.updatePipelineAggOptions()},t.updatePipelineAggOptions=function(){var e,r;t.pipelineAggOptions=(e=t.target,r=[],s.a.each(e.metrics,(function(e){O(e.type)||r.push({text:w(e),value:e.id})})),r)},n.onAppEvent(Z.CoreEvents.elasticQueryUpdated,(function(){t.index=s.a.indexOf(i,t.agg),t.updatePipelineAggOptions(),t.validateModel()}),t),t.validateModel=function(){if(t.isFirst=0===t.index,t.isSingle=1===i.length,t.settingsLinkText="",t.variablesLinkText="",t.aggDef=s.a.find(t.metricAggTypes,{value:t.agg.type}),O(t.agg.type)){x(t.agg.type)?(t.variablesLinkText="Options",t.agg.settings.script&&(t.variablesLinkText="Script: "+t.agg.settings.script.replace(new RegExp("params.","g"),""))):(t.agg.pipelineAgg=t.agg.pipelineAgg||"select metric",t.agg.field=t.agg.pipelineAgg);var e=O((r=t.agg).type)?h[r.type]:[];e.length>0&&(s.a.each(e,(function(e){t.agg.settings[e.text]=t.agg.settings[e.text]||e.default})),t.settingsLinkText="Options")}else t.agg.field||(t.agg.field="select field");var r;switch(t.agg.type){case"cardinality":var n=t.agg.settings.precision_threshold||"";t.settingsLinkText="Precision threshold: "+n;break;case"percentiles":t.agg.settings.percents=t.agg.settings.percents||[25,50,75,95,99],t.settingsLinkText="Values: "+t.agg.settings.percents.join(",");break;case"extended_stats":0===s.a.keys(t.agg.meta).length&&(t.agg.meta.std_deviation_bounds_lower=!0,t.agg.meta.std_deviation_bounds_upper=!0);var a=s.a.reduce(t.agg.meta,(function(e,r,n){if(r){var i=s.a.find(t.extendedStats,{value:n});e.push(i.text)}return e}),[]);t.settingsLinkText="Stats: "+a.join(", ");break;case"moving_avg":t.movingAvgModelTypes=m,t.modelSettings=_(t.agg.settings.model,!0),t.updateMovingAvgModelSettings();break;case"raw_document":t.agg.settings.size=t.agg.settings.size||500,t.settingsLinkText="Size: "+t.agg.settings.size,t.target.metrics.splice(0,t.target.metrics.length,t.agg),t.target.bucketAggs=[]}if(t.aggDef.supportsInlineScript){var o=t.agg.inlineScript;o?t.agg.settings.script={inline:o}:delete t.agg.settings.script,""===t.settingsLinkText&&(t.settingsLinkText="Options")}},t.toggleOptions=function(){t.showOptions=!t.showOptions,t.updatePipelineAggOptions()},t.toggleVariables=function(){t.showVariables=!t.showVariables},t.onChangeInternal=function(){t.onChange()},t.updateMovingAvgModelSettings=function(){for(var e=[],r=_(t.agg.settings.model,!1),n=0;n<r.length;n++)e.push(r[n].value);for(var i in t.agg.settings.settings)null!==t.agg.settings.settings[i]&&-1!==e.indexOf(i)||delete t.agg.settings.settings[i]},t.onChangeClearInternal=function(){delete t.agg.settings.minimize,t.onChange()},t.onTypeChange=function(){t.agg.settings={},t.agg.meta={},t.showOptions=!1,0===t.target.bucketAggs.length&&"raw_document"!==t.agg.type&&(t.target.bucketAggs=[{type:"date_histogram",id:"2",settings:{interval:"auto"}}]),t.showVariables=x(t.agg.type),t.updatePipelineAggOptions(),t.onChange()},t.getFieldsInternal=function(){return"cardinality"===t.agg.type?t.getFields():t.getFields({$fieldType:"number"})},t.addMetricAgg=function(){var e=i.length,r=s.a.reduce(t.target.bucketAggs.concat(t.target.metrics),(function(e,t){return parseInt(t.id,10)>e?parseInt(t.id,10):e}),0);i.splice(e,0,{type:"count",field:"select field",id:(r+1).toString()}),t.onChange()},t.removeMetricAgg=function(){i.splice(t.index,1),t.onChange()},t.toggleShowMetric=function(){t.agg.hide=!t.agg.hide,t.agg.hide||delete t.agg.hide,t.onChange()},t.init()};te.$inject=["$scope","uiSegmentSrv","$rootScope"],te.$inject=["$scope","uiSegmentSrv","$rootScope"],X.c.directive("elasticMetricAgg",(function(){return{templateUrl:"public/app/plugins/datasource/elasticsearch/partials/metric_agg.html",controller:te,restrict:"E",scope:{target:"=",index:"=",onChange:"&",getFields:"&",esVersion:"="}}}));var re=function(e){return{name:"var"+e,pipelineAgg:"select metric"}},ne=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t.variables=t.variables||[re(1)],t.onChangeInternal=function(){t.onChange()},t.add=function(){t.variables.push(re(t.variables.length+1)),t.onChange()},t.remove=function(e){t.variables.splice(e,1),t.onChange()}};function ie(e){return(ie="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ae(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function oe(e,t){return!t||"object"!==ie(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function se(e){return(se=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function le(e,t){return(le=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}ne.$inject=["$scope"],ne.$inject=["$scope"],X.c.directive("elasticPipelineVariables",(function(){return{templateUrl:"public/app/plugins/datasource/elasticsearch/partials/pipeline_variables.html",controller:"ElasticPipelineVariablesCtrl",restrict:"E",scope:{onChange:"&",variables:"=",options:"="}}})),X.c.controller("ElasticPipelineVariablesCtrl",ne);var ue=function(e){function t(e,r,n,i){var a;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(a=oe(this,se(t).call(this,e,r))).$rootScope=n,a.uiSegmentSrv=i,a.esVersion=a.datasource.esVersion,a.target=a.target||{},a.target.metrics=a.target.metrics||[{type:"count",id:"1"}],a.target.bucketAggs=a.target.bucketAggs||[{type:"date_histogram",id:"2",settings:{interval:"auto"}}],0===a.target.bucketAggs.length){var o=a.target.metrics[0];o&&"raw_document"===o.type||(a.target.bucketAggs=[{type:"date_histogram",id:"2",settings:{interval:"auto"}}]),a.refresh()}return a.queryUpdated(),a}var r,n,i;return t.$inject=["$scope","$injector","$rootScope","uiSegmentSrv"],function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&le(e,t)}(t,e),r=t,(n=[{key:"getFields",value:function(e){var t=a.a.toJson({find:"fields",type:e});return this.datasource.metricFindQuery(t).then(this.uiSegmentSrv.transformToSegments(!1)).catch(this.handleQueryError.bind(this))}},{key:"queryUpdated",value:function(){var e=a.a.toJson(this.datasource.queryBuilder.build(this.target),!0);this.rawQueryOld&&e!==this.rawQueryOld&&this.refresh(),this.rawQueryOld=e,this.$rootScope.appEvent(Z.CoreEvents.elasticQueryUpdated)}},{key:"getCollapsedText",value:function(){var e=this.target.metrics,t=this.target.bucketAggs,r=b(this.esVersion),n=c,i="";return this.target.query&&(i+="Query: "+this.target.query+", "),i+="Metrics: ",s.a.each(e,(function(e,t){var n=s.a.find(r,{value:e.type});i+=n.text+"(",n.requiresField&&(i+=e.field),n.supportsMultipleBucketPaths&&(i+=e.settings.script.replace(new RegExp("params.","g"),"")),i+="), "})),s.a.each(t,(function(e,t){0===t&&(i+=" Group by: ");var r=s.a.find(n,{value:e.type});i+=r.text+"(",r.requiresField&&(i+=e.field),i+="), "})),this.target.alias&&(i+="Alias: "+this.target.alias),i}},{key:"handleQueryError",value:function(e){return this.error=e.message||"Failed to issue metric query",[]}}])&&ae(r.prototype,n),i&&ae(r,i),t}(r("LzXI").QueryCtrl);ue.templateUrl="partials/query.editor.html";var ce=r("q1tI"),ge=r.n(ce),fe=r("kDLi");function de(e){return(de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function pe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function ve(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function me(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function he(e,t){return!t||"object"!==de(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function ye(e){return(ye=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function be(e,t){return(be=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var Oe=function(e){function t(e,r){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=he(this,ye(t).call(this,e,r))).onChangeQuery=function(e,t){var r=n.props,i=r.query,a=r.onChange,o=r.onRunQuery;a&&(a(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?pe(Object(r),!0).forEach((function(t){ve(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):pe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},i,{query:e,isLogsQuery:!0})),t&&o&&o())},n.plugins=[Object(fe.SlatePrism)({onlyIn:function(e){return"code_block"===e.type},getSyntax:function(e){return"lucene"}})],n.state={syntaxLoaded:!1},n}var r,n,i;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&be(e,t)}(t,e),r=t,(n=[{key:"componentDidMount",value:function(){this.props.query.isLogsQuery||this.onChangeQuery("",!0)}},{key:"componentWillUnmount",value:function(){}},{key:"componentDidUpdate",value:function(e){this.props.query.isLogsQuery||this.onChangeQuery("",!0)}},{key:"render",value:function(){var e=this.props.query,t=this.state.syntaxLoaded;return ge.a.createElement(ge.a.Fragment,null,ge.a.createElement("div",{className:"gf-form-inline gf-form-inline--nowrap"},ge.a.createElement("div",{className:"gf-form gf-form--grow flex-shrink-1"},ge.a.createElement(fe.QueryField,{additionalPlugins:this.plugins,query:e.query,onChange:this.onChangeQuery,onRunQuery:this.props.onRunQuery,placeholder:"Enter a Lucene query",portalOrigin:"elasticsearch",syntaxLoaded:t}))))}}])&&me(r.prototype,n),i&&me(r,i),t}(ge.a.PureComponent);function xe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _e(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?xe(Object(r),!0).forEach((function(t){we(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):xe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function we(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var ke=[{label:"No pattern",value:"none"},{label:"Hourly",value:"Hourly",example:"[logstash-]YYYY.MM.DD.HH"},{label:"Daily",value:"Daily",example:"[logstash-]YYYY.MM.DD"},{label:"Weekly",value:"Weekly",example:"[logstash-]GGGG.WW"},{label:"Monthly",value:"Monthly",example:"[logstash-]YYYY.MM"},{label:"Yearly",value:"Yearly",example:"[logstash-]YYYY"}],je=[{label:"2.x",value:2},{label:"5.x",value:5},{label:"5.6+",value:56},{label:"6.0+",value:60},{label:"7.0+",value:70}],Se=function(e){var t=e.value,r=e.onChange;return ge.a.createElement(ge.a.Fragment,null,ge.a.createElement("h3",{className:"page-heading"},"Elasticsearch details"),ge.a.createElement("div",{className:"gf-form-group"},ge.a.createElement("div",{className:"gf-form-inline"},ge.a.createElement("div",{className:"gf-form max-width-25"},ge.a.createElement(fe.FormField,{labelWidth:10,inputWidth:15,label:"Index name",value:t.database||"",onChange:Fe("database",t,r),placeholder:"es-index-name",required:!0})),ge.a.createElement("div",{className:"gf-form width-14"},ge.a.createElement(fe.FormField,{labelWidth:10,label:"Pattern",inputEl:ge.a.createElement(fe.Select,{options:ke,onChange:Pe(t,r),value:ke.find((function(e){return e.value===(void 0===t.jsonData.interval?"none":t.jsonData.interval)}))})}))),ge.a.createElement("div",{className:"gf-form max-width-25"},ge.a.createElement(fe.FormField,{labelWidth:10,inputWidth:15,label:"Time field name",value:t.jsonData.timeField||"",onChange:Ee("timeField",t,r),required:!0})),ge.a.createElement("div",{className:"gf-form"},ge.a.createElement("span",{className:"gf-form-select-wrapper"},ge.a.createElement(fe.FormField,{labelWidth:10,label:"Version",inputEl:ge.a.createElement(fe.Select,{options:je,onChange:function(e){var n=function(e,t){if(5===e&&t<70)return 256;if(256===e&&t>=70)return 5;return e||qe(t)}(t.jsonData.maxConcurrentShardRequests,e.value);r(_e({},t,{jsonData:_e({},t.jsonData,{esVersion:e.value,maxConcurrentShardRequests:n})}))},value:je.find((function(e){return e.value===t.jsonData.esVersion}))})}))),t.jsonData.esVersion>=56&&ge.a.createElement("div",{className:"gf-form max-width-30"},ge.a.createElement(fe.FormField,{"aria-label":"Max concurrent Shard Requests input",labelWidth:15,label:"Max concurrent Shard Requests",value:t.jsonData.maxConcurrentShardRequests||"",onChange:Ee("maxConcurrentShardRequests",t,r)})),ge.a.createElement("div",{className:"gf-form-inline"},ge.a.createElement("div",{className:"gf-form"},ge.a.createElement(fe.FormField,{labelWidth:10,label:"Min time interval",inputEl:ge.a.createElement(fe.Input,{className:"width-6",value:t.jsonData.timeInterval||"",onChange:Ee("timeInterval",t,r),placeholder:"10s",validationEvents:we({},fe.EventsWithValidation.onBlur,[Object(fe.regexValidation)(/^\d+(ms|[Mwdhmsy])$/,"Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s")])}),tooltip:ge.a.createElement(ge.a.Fragment,null,"A lower limit for the auto group by time interval. Recommended to be set to write frequency, for example ",ge.a.createElement("code",null,"1m")," if your data is written every minute.")})))))},Fe=function(e,t,r){return function(n){r(_e({},t,we({},e,n.currentTarget.value)))}},Ee=function(e,t,r){return function(n){r(_e({},t,{jsonData:_e({},t.jsonData,we({},e,n.currentTarget.value))}))}},Pe=function(e,t){return function(r){var n=e.database,i="none"===r.value?void 0:r.value;if(!n||0===n.length||n.startsWith("[logstash-]")){var a="";if(void 0!==i){var o=ke.find((function(e){return e.value===i}));o&&(a=o.example)}t(_e({},e,{database:a,jsonData:_e({},e.jsonData,{interval:i})}))}else t(_e({},e,{jsonData:_e({},e.jsonData,{interval:i})}))}};function qe(e){return e>=70?5:256}function Ce(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function De(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var Ae=function(e){var t=e.value,r=e.onChange,n=function(e){return function(n){r(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Ce(Object(r),!0).forEach((function(t){De(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Ce(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},t,De({},e,n.currentTarget.value)))}};return ge.a.createElement(ge.a.Fragment,null,ge.a.createElement("h3",{className:"page-heading"},"Logs"),ge.a.createElement("div",{className:"gf-form-group"},ge.a.createElement("div",{className:"gf-form max-width-30"},ge.a.createElement(fe.FormField,{labelWidth:11,label:"Message field name",value:t.logMessageField,onChange:n("logMessageField"),placeholder:"_source"})),ge.a.createElement("div",{className:"gf-form max-width-30"},ge.a.createElement(fe.FormField,{labelWidth:11,label:"Level field name",value:t.logLevelField,onChange:n("logLevelField")}))))},Te=r("kDDq");function Me(){var e=Re(["\n          width: 100%;\n        "]);return Me=function(){return e},e}function Le(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Ve(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Le(Object(r),!0).forEach((function(t){Ie(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Le(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function Ie(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $e(){var e=Re(["\n    flex: 3;\n  "]);return $e=function(){return e},e}function Qe(){var e=Re(["\n    flex: 2;\n  "]);return Qe=function(){return e},e}function Ne(){var e=Re(["\n    display: flex;\n  "]);return Ne=function(){return e},e}function Re(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}var ze=Object(fe.stylesFactory)((function(){return{firstRow:Object(Te.css)(Ne()),nameField:Object(Te.css)(Qe()),regexField:Object(Te.css)($e())}})),Be=function(e){var t,r=e.value,n=e.onChange,i=e.onDelete,a=e.suggestions,o=e.className,s=ze();return ge.a.createElement("div",{className:o},ge.a.createElement("div",{className:s.firstRow},ge.a.createElement(fe.FormField,{className:s.nameField,labelWidth:6,inputWidth:null,label:"Field",type:"text",value:r.field,tooltip:"Can be exact field name or a regex pattern that will match on the field name.",onChange:(t="field",function(e){n(Ve({},r,Ie({},t,e.currentTarget.value)))})}),ge.a.createElement(fe.Button,{variant:"inverse",title:"Remove field",icon:"fa fa-times",onClick:function(e){e.preventDefault(),i()}})),ge.a.createElement(fe.FormField,{label:"URL",labelWidth:6,inputEl:ge.a.createElement(fe.DataLinkInput,{placeholder:"http://example.com/${__value.raw}",value:r.url||"",onChange:function(e){return n(Ve({},r,{url:e}))},suggestions:a}),className:Object(Te.css)(Me())}))};function Ue(){var e=Je(["\n              margin-right: 10px;\n            "]);return Ue=function(){return e},e}function We(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function He(){var e=Je(["\n    margin-bottom: ",";\n  "]);return He=function(){return e},e}function Ye(){var e=Je(["\n    padding-bottom: ",";\n    color: ",";\n  "]);return Ye=function(){return e},e}function Je(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}var Ge=Object(fe.stylesFactory)((function(e){return{infoText:Object(Te.css)(Ye(),e.spacing.md,e.colors.textWeak),dataLink:Object(Te.css)(He(),e.spacing.sm)}})),Ke=function(e){var t=e.value,r=e.onChange,i=Object(fe.useTheme)(),a=Ge(i);return ge.a.createElement(ge.a.Fragment,null,ge.a.createElement("h3",{className:"page-heading"},"Data links"),ge.a.createElement("div",{className:a.infoText},"Add links to existing fields. Links will be shown in log row details next to the field value."),ge.a.createElement("div",{className:"gf-form-group"},t&&t.map((function(e,i){return ge.a.createElement(Be,{className:a.dataLink,key:i,value:e,onChange:function(e){var n=We(t);n.splice(i,1,e),r(n)},onDelete:function(){var e=We(t);e.splice(i,1),r(e)},suggestions:[{value:fe.DataLinkBuiltInVars.valueRaw,label:"Raw value",documentation:"Raw value of the field",origin:n.VariableOrigin.Value}]})})),ge.a.createElement("div",null,ge.a.createElement(fe.Button,{variant:"inverse",className:Object(Te.css)(Ue()),icon:"fa fa-plus",onClick:function(e){e.preventDefault();var n=[].concat(We(t||[]),[{field:"",url:""}]);r(n)}},"Add"))))};function Xe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Ze(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Xe(Object(r),!0).forEach((function(t){et(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Xe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function et(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,"plugin",(function(){return rt}));var tt=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)};tt.templateUrl="partials/annotations.editor.html";var rt=new n.DataSourcePlugin(K).setQueryCtrl(ue).setConfigEditor((function(e){var t=e.options,r=e.onOptionsChange;return Object(ce.useEffect)((function(){var e=t.jsonData.esVersion||5;r(Ze({},t,{jsonData:Ze({},t.jsonData,{timeField:t.jsonData.timeField||"@timestamp",esVersion:e,maxConcurrentShardRequests:t.jsonData.maxConcurrentShardRequests||qe(e),logMessageField:t.jsonData.logMessageField||"",logLevelField:t.jsonData.logLevelField||""})}))}),[]),ge.a.createElement(ge.a.Fragment,null,ge.a.createElement(fe.DataSourceHttpSettings,{defaultUrl:"http://localhost:9200",dataSourceConfig:t,showAccessOptions:!0,onChange:r}),ge.a.createElement(Se,{value:t,onChange:r}),ge.a.createElement(Ae,{value:t.jsonData,onChange:function(e){return r(Ze({},t,{jsonData:e}))}}),ge.a.createElement(Ke,{value:t.jsonData.dataLinks,onChange:function(e){r(Ze({},t,{jsonData:Ze({},t.jsonData,{dataLinks:e})}))}}))})).setExploreLogsQueryField(Oe).setAnnotationQueryCtrl(tt)}}]);
  //# sourceMappingURL=elasticsearchPlugin.5c3edd1990e1c7cf41f1.js.map