12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7494],{49005:(e,t,a)=>{a.r(t),a.d(t,{plugin:()=>Gt});var n=a(43215),r=a(36636),s=a(68404),i=a(69783),o=a(53772);const l=(0,o.PH)("init"),u=(0,o.PH)("time-range-changed"),c=(0,o.PH)("queries-changed"),m=(0,o.PH)("query-changed"),p=(0,o.PH)("segment-value-changed"),d=(0,o.PH)("add-new-tag"),h={init:l,timeRangeChanged:u,queriesChanged:c,queryChanged:m,segmentValueChanged:p,tagChanged:(0,o.PH)("tag-changed"),addNewTag:d,unpause:(0,o.PH)("unpause"),addFunction:(0,o.PH)("add-function"),removeFunction:(0,o.PH)("remove-function"),moveFunction:(0,o.PH)("move-function"),updateFunctionParam:(0,o.PH)("change-function-param"),updateQuery:(0,o.PH)("update-query"),runQuery:(0,o.PH)("run-current-query"),toggleEditorMode:(0,o.PH)("toggle-editor")};var g=a(20002),f=a(7166),y=a(90923),v=a(82897),x=a(30034);function b(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const S=[170,170,181,181,186,186,192,214,216,246,248,705,710,721,736,740,748,748,750,750,880,884,886,887,890,893,902,902,904,906,908,908,910,929,931,1013,1015,1153,1162,1319,1329,1366,1369,1369,1377,1415,1488,1514,1520,1522,1568,1610,1646,1647,1649,1747,1749,1749,1765,1766,1774,1775,1786,1788,1791,1791,1808,1808,1810,1839,1869,1957,1969,1969,1994,2026,2036,2037,2042,2042,2048,2069,2074,2074,2084,2084,2088,2088,2112,2136,2308,2361,2365,2365,2384,2384,2392,2401,2417,2423,2425,2431,2437,2444,2447,2448,2451,2472,2474,2480,2482,2482,2486,2489,2493,2493,2510,2510,2524,2525,2527,2529,2544,2545,2565,2570,2575,2576,2579,2600,2602,2608,2610,2611,2613,2614,2616,2617,2649,2652,2654,2654,2674,2676,2693,2701,2703,2705,2707,2728,2730,2736,2738,2739,2741,2745,2749,2749,2768,2768,2784,2785,2821,2828,2831,2832,2835,2856,2858,2864,2866,2867,2869,2873,2877,2877,2908,2909,2911,2913,2929,2929,2947,2947,2949,2954,2958,2960,2962,2965,2969,2970,2972,2972,2974,2975,2979,2980,2984,2986,2990,3001,3024,3024,3077,3084,3086,3088,3090,3112,3114,3123,3125,3129,3133,3133,3160,3161,3168,3169,3205,3212,3214,3216,3218,3240,3242,3251,3253,3257,3261,3261,3294,3294,3296,3297,3313,3314,3333,3340,3342,3344,3346,3386,3389,3389,3406,3406,3424,3425,3450,3455,3461,3478,3482,3505,3507,3515,3517,3517,3520,3526,3585,3632,3634,3635,3648,3654,3713,3714,3716,3716,3719,3720,3722,3722,3725,3725,3732,3735,3737,3743,3745,3747,3749,3749,3751,3751,3754,3755,3757,3760,3762,3763,3773,3773,3776,3780,3782,3782,3804,3805,3840,3840,3904,3911,3913,3948,3976,3980,4096,4138,4159,4159,4176,4181,4186,4189,4193,4193,4197,4198,4206,4208,4213,4225,4238,4238,4256,4293,4304,4346,4348,4348,4352,4680,4682,4685,4688,4694,4696,4696,4698,4701,4704,4744,4746,4749,4752,4784,4786,4789,4792,4798,4800,4800,4802,4805,4808,4822,4824,4880,4882,4885,4888,4954,4992,5007,5024,5108,5121,5740,5743,5759,5761,5786,5792,5866,5870,5872,5888,5900,5902,5905,5920,5937,5952,5969,5984,5996,5998,6e3,6016,6067,6103,6103,6108,6108,6176,6263,6272,6312,6314,6314,6320,6389,6400,6428,6480,6509,6512,6516,6528,6571,6593,6599,6656,6678,6688,6740,6823,6823,6917,6963,6981,6987,7043,7072,7086,7087,7104,7141,7168,7203,7245,7247,7258,7293,7401,7404,7406,7409,7424,7615,7680,7957,7960,7965,7968,8005,8008,8013,8016,8023,8025,8025,8027,8027,8029,8029,8031,8061,8064,8116,8118,8124,8126,8126,8130,8132,8134,8140,8144,8147,8150,8155,8160,8172,8178,8180,8182,8188,8305,8305,8319,8319,8336,8348,8450,8450,8455,8455,8458,8467,8469,8469,8473,8477,8484,8484,8486,8486,8488,8488,8490,8493,8495,8505,8508,8511,8517,8521,8526,8526,8544,8584,11264,11310,11312,11358,11360,11492,11499,11502,11520,11557,11568,11621,11631,11631,11648,11670,11680,11686,11688,11694,11696,11702,11704,11710,11712,11718,11720,11726,11728,11734,11736,11742,11823,11823,12293,12295,12321,12329,12337,12341,12344,12348,12353,12438,12445,12447,12449,12538,12540,12543,12549,12589,12593,12686,12704,12730,12784,12799,13312,13312,19893,19893,19968,19968,40907,40907,40960,42124,42192,42237,42240,42508,42512,42527,42538,42539,42560,42606,42623,42647,42656,42735,42775,42783,42786,42888,42891,42894,42896,42897,42912,42921,43002,43009,43011,43013,43015,43018,43020,43042,43072,43123,43138,43187,43250,43255,43259,43259,43274,43301,43312,43334,43360,43388,43396,43442,43471,43471,43520,43560,43584,43586,43588,43595,43616,43638,43642,43642,43648,43695,43697,43697,43701,43702,43705,43709,43712,43712,43714,43714,43739,43741,43777,43782,43785,43790,43793,43798,43808,43814,43816,43822,43968,44002,44032,44032,55203,55203,55216,55238,55243,55291,63744,64045,64048,64109,64112,64217,64256,64262,64275,64279,64285,64285,64287,64296,64298,64310,64312,64316,64318,64318,64320,64321,64323,64324,64326,64433,64467,64829,64848,64911,64914,64967,65008,65019,65136,65140,65142,65276,65313,65338,65345,65370,65382,65470,65474,65479,65482,65487,65490,65495,65498,65500,65536,65547,65549,65574,65576,65594,65596,65597,65599,65613,65616,65629,65664,65786,65856,65908,66176,66204,66208,66256,66304,66334,66352,66378,66432,66461,66464,66499,66504,66511,66513,66517,66560,66717,67584,67589,67592,67592,67594,67637,67639,67640,67644,67644,67647,67669,67840,67861,67872,67897,68096,68096,68112,68115,68117,68119,68121,68147,68192,68220,68352,68405,68416,68437,68448,68466,68608,68680,69635,69687,69763,69807,73728,74606,74752,74850,77824,78894,92160,92728,110592,110593,119808,119892,119894,119964,119966,119967,119970,119970,119973,119974,119977,119980,119982,119993,119995,119995,119997,120003,120005,120069,120071,120074,120077,120084,120086,120092,120094,120121,120123,120126,120128,120132,120134,120134,120138,120144,120146,120485,120488,120512,120514,120538,120540,120570,120572,120596,120598,120628,120630,120654,120656,120686,120688,120712,120714,120744,120746,120770,120772,120779,131072,131072,173782,173782,173824,173824,177972,177972,177984,177984,178205,178205,194560,195101],j=[];for(let e=0;e<128;e++)j[e]=e>=48&&e<=57||36===e||126===e||124===e||e>=65&&e<=90||95===e||45===e||42===e||58===e||91===e||93===e||63===e||37===e||35===e||61===e||e>=97&&e<=122;const T=j;class k{constructor(e){b(this,"input",void 0),b(this,"char",void 0),b(this,"from",void 0),this.input=e,this.char=1,this.from=1}peek(e){return this.input.charAt(e||0)}skip(e){e=e||1,this.char+=e,this.input=this.input.slice(e)}tokenize(){const e=[];let t=this.next();for(;t;)e.push(t),t=this.next();return e}next(){if(this.from=this.char,/\s/.test(this.peek())){for(;/\s/.test(this.peek());)this.from+=1,this.skip();if(""===this.peek())return null}let e=this.scanStringLiteral();return e||(e=this.scanPunctuator()||this.scanNumericLiteral()||this.scanIdentifier()||this.scanTemplateSequence(),e?(this.skip(e.value.length),e):null)}scanTemplateSequence(){return"["===this.peek()&&"["===this.peek(1)?{type:"templateStart",value:"[[",pos:this.char}:"]"===this.peek()&&"]"===this.peek(1)?{type:"templateEnd",value:"[[",pos:this.char}:null}scanIdentifier(){let e,t,a="",n=0;function r(e){for(let t=0;t<S.length;){if(e<S[t++])return!1;if(e<=S[t++])return!0}return!1}function s(e){return/^[0-9a-fA-F]$/.test(e)}const i=(0,v.bind)((function(){if(n+=1,"u"!==this.peek(n))return null;const e=this.peek(n+1),t=this.peek(n+2),a=this.peek(n+3),i=this.peek(n+4);let o;return s(e)&&s(t)&&s(a)&&s(i)?(o=parseInt(e+t+a+i,16),r(o)?(n+=5,"\\u"+e+t+a+i):null):null}),this),o=(0,v.bind)((function(){const e=this.peek(n),t=e.charCodeAt(0);return"*"===e?(n+=1,e):92===t?i():t<128?j[t]?(n+=1,e):null:r(t)?(n+=1,e):null}),this),l=(0,v.bind)((function(){const e=this.peek(n),t=e.charCodeAt(0);return 92===t?i():t<128?T[t]?(n+=1,e):null:r(t)?(n+=1,e):null}),this);if(t=o(),null===t)return null;for(a=t;t=l(),null!==t;)a+=t;switch(a){case"true":case"false":e="bool";break;default:e="identifier"}return{type:e,value:a,pos:this.char}}scanNumericLiteral(){let e=0,t="";const a=this.input.length;let n,r=this.peek(e);function s(e){return/^[0-9]$/.test(e)}function i(e){return/^[0-7]$/.test(e)}function o(e){return"$"===e||"_"===e||"\\"===e||e>="a"&&e<="z"||e>="A"&&e<="Z"}if("-"===r&&(t+=r,e+=1,r=this.peek(e)),"."!==r&&!s(r))return null;if("."!==r){if(t+=this.peek(e),e+=1,r=this.peek(e),"0"===t){if("x"===r||"X"===r){for(e+=1,t+=r;e<a&&(r=this.peek(e),/^[0-9a-fA-F]$/.test(r));)t+=r,e+=1;return t.length<=2?{type:"number",value:t,isMalformed:!0,pos:this.char}:e<a&&(r=this.peek(e),o(r))?null:{type:"number",value:t,base:16,isMalformed:!1,pos:this.char}}if(i(r)){for(e+=1,t+=r,n=!1;e<a;){if(r=this.peek(e),s(r)&&(n=!0),!i(r)){if(!this.isPunctuator(r))return null;break}t+=r,e+=1}return e<a&&(r=this.peek(e),o(r))?null:{type:"number",value:t,base:8,isMalformed:n}}s(r)&&(e+=1,t+=r)}for(;e<a&&(r=this.peek(e),s(r));)t+=r,e+=1}if("."===r)for(t+=r,e+=1;e<a&&(r=this.peek(e),s(r));)t+=r,e+=1;if("e"===r||"E"===r){if(t+=r,e+=1,r=this.peek(e),"+"!==r&&"-"!==r||(t+=this.peek(e),e+=1),r=this.peek(e),!s(r))return null;for(t+=r,e+=1;e<a&&(r=this.peek(e),s(r));)t+=r,e+=1}return e<a&&(r=this.peek(e),!this.isPunctuator(r))?null:{type:"number",value:t,base:10,pos:this.char,isMalformed:!isFinite(+t)}}isPunctuator(e){switch(e){case".":case"(":case")":case",":case"{":case"}":return!0}return!1}scanPunctuator(){const e=this.peek();return this.isPunctuator(e)?{type:e,value:e,pos:this.char}:null}scanStringLiteral(){const e=this.peek();if('"'!==e&&"'"!==e)return null;let t="";for(this.skip();this.peek()!==e;){if(""===this.peek())return{type:"string",value:t,isUnclosed:!0,quote:e,pos:this.char};const a=1;t+=this.peek(),this.skip(a)}return this.skip(),{type:"string",value:t,isUnclosed:!1,quote:e,pos:this.char}}}function w(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}class P{constructor(e){w(this,"expression",void 0),w(this,"lexer",void 0),w(this,"tokens",void 0),w(this,"index",void 0),this.expression=e,this.lexer=new k(e),this.tokens=this.lexer.tokenize(),this.index=0}getAst(){return this.start()}start(){try{return this.functionCall()||this.metricExpression()}catch(e){return{type:"error",message:e.message,pos:e.pos}}}curlyBraceSegment(){if(this.match("identifier","{")||this.match("{")){let e="";for(;!this.match("")&&!this.match("}");)e+=this.consumeToken().value;return this.match("}")||this.errorMark("Expected closing '}'"),e+=this.consumeToken().value,this.match("identifier")&&(e+=this.consumeToken().value),{type:"segment",value:e}}return null}metricSegment(){const e=this.curlyBraceSegment();if(e)return e;if(this.match("identifier")||this.match("number")){const e=this.consumeToken().value.split(".");return 2===e.length&&(this.tokens.splice(this.index,0,{type:"."}),this.tokens.splice(this.index+1,0,{type:"number",value:e[1]})),{type:"segment",value:e[0]}}this.match("templateStart")||this.errorMark("Expected metric identifier"),this.consumeToken(),this.match("identifier")||this.errorMark("Expected identifier after templateStart");const t={type:"template",value:this.consumeToken().value};return this.match("templateEnd")||this.errorMark("Expected templateEnd"),this.consumeToken(),t}metricExpression(){if(!(this.match("templateStart")||this.match("identifier")||this.match("number")||this.match("{")))return null;const e={type:"metric",segments:[]};for(e.segments.push(this.metricSegment());this.match(".");){this.consumeToken();const t=this.metricSegment();t||this.errorMark("Expected metric identifier"),e.segments.push(t)}return e}functionCall(){if(!this.match("identifier","("))return null;const e={type:"function",name:this.consumeToken().value};return this.consumeToken(),e.params=this.functionParameters(),this.match(")")||this.errorMark("Expected closing parenthesis"),this.consumeToken(),e}boolExpression(){return this.match("bool")?{type:"bool",value:"true"===this.consumeToken().value}:null}functionParameters(){if(this.match(")")||this.match(""))return[];const e=this.functionCall()||this.numericLiteral()||this.seriesRefExpression()||this.boolExpression()||this.metricExpression()||this.stringLiteral();return this.match(",")?(this.consumeToken(),[e].concat(this.functionParameters())):[e]}seriesRefExpression(){if(!this.match("identifier"))return null;if(!this.tokens[this.index].value.match(/\#[A-Z]/))return null;return{type:"series-ref",value:this.consumeToken().value}}numericLiteral(){return this.match("number")?{type:"number",value:parseFloat(this.consumeToken().value)}:null}stringLiteral(){if(!this.match("string"))return null;const e=this.consumeToken();if(e.isUnclosed)throw{message:"Unclosed string parameter",pos:e.pos};return{type:"string",value:e.value}}errorMark(e){const t=this.tokens[this.index];throw{message:e+" instead found "+(t?t.type:"end of string"),pos:t?t.pos:this.lexer.char}}consumeToken(){return this.index++,this.tokens[this.index-1]}matchToken(e,t){const a=this.tokens[this.index+t];return void 0===a&&""===e||a&&a.type===e}match(e,t){return this.matchToken(e,0)&&(!t||this.matchToken(t,1))}}function C(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}class M{constructor(e,t,a,n){C(this,"datasource",void 0),C(this,"target",void 0),C(this,"functions",[]),C(this,"segments",[]),C(this,"tags",[]),C(this,"error",void 0),C(this,"seriesByTagUsed",!1),C(this,"checkOtherSegmentsIndex",0),C(this,"removeTagValue",void 0),C(this,"templateSrv",void 0),C(this,"scopedVars",void 0),this.datasource=e,this.target=t,this.templateSrv=a,this.scopedVars=n,this.parseTarget(),this.removeTagValue="-- remove tag --"}parseTarget(){if(this.functions=[],this.segments=[],this.tags=[],this.seriesByTagUsed=!1,this.error=null,this.target.textEditor)return;const e=new P(this.target.target).getAst();if(null!==e){if("error"===e.type)return this.error=e.message+" at position: "+e.pos,void(this.target.textEditor=!0);try{this.parseTargetRecursive(e,null)}catch(e){console.error("error parsing target:",e.message),this.error=e.message,this.target.textEditor=!0}this.checkOtherSegmentsIndex=this.segments.length-1}else this.checkOtherSegmentsIndex=0}getSegmentPathUpTo(e){const t=this.segments.slice(0,e);return(0,v.reduce)(t,((e,t)=>e?e+"."+t.value:t.value),"")}parseTargetRecursive(e,t){if(null===e)return null;switch(e.type){case"function":const a=this.datasource.createFuncInstance(e.name,{withDefaultParams:!1});(0,v.each)(e.params,(e=>{this.parseTargetRecursive(e,a)})),a.updateText(),this.functions.push(a),"seriesByTag"!==a.def.name||this.seriesByTagUsed||(this.seriesByTagUsed=!0,a.hidden=!0,this.tags=this.splitSeriesByTagParams(a));break;case"series-ref":this.segments.length>0||this.getSeriesByTagFuncIndex()>=0?this.addFunctionParameter(t,e.value):this.segments.push(e);break;case"bool":case"string":case"number":this.addFunctionParameter(t,e.value);break;case"metric":this.segments.length||this.tags.length?this.addFunctionParameter(t,(0,v.join)((0,v.map)(e.segments,"value"),".")):this.segments=e.segments}}updateSegmentValue(e,t){this.segments[t].value=e.value}addSelectMetricSegment(){this.segments.push({value:"select metric"})}addFunction(e){this.functions.push(e)}addFunctionParameter(e,t){if(e.params.length>=e.def.params.length&&!(0,v.get)((0,v.last)(e.def.params),"multiple",!1))throw{message:"too many parameters for function "+e.def.name};e.params.push(t)}removeFunction(e){this.functions=(0,v.without)(this.functions,e)}moveFunction(e,t){const a=this.functions.indexOf(e);(0,x.R)(this.functions,a,a+t)}updateModelTarget(e){const t=(e,t)=>t.render(e,(e=>this.templateSrv.replace(e,this.scopedVars)));if(!this.target.textEditor){const e=this.getSegmentPathUpTo(this.segments.length).replace(/\.?select metric$/,"");this.target.target=(0,v.reduce)(this.functions,t,e)}this.updateRenderedTarget(this.target,e);for(const t of e||[])t.refId!==this.target.refId&&this.updateRenderedTarget(t,e);this.functions.forEach((e=>e.added=!1))}updateRenderedTarget(e,t){const a=(0,v.keyBy)(t,"refId");delete a[e.refId];const n=/\#([A-Z])/g;let r=e.target;for((0,v.each)(a,((e,t)=>{!function(e,t){let a=0;(0,v.each)(e,((e,r)=>{if(r!==t){const t=n.exec(e.target),r=t&&t.length?t.length-1:0;a+=r}})),e[t].refCount=a}(a,t)}));r.match(n);){const e=r.replace(n,((e,t)=>{const n=a[t];return n?(0===n.refCount&&delete a[t],n.refCount--,n.target):e}));if(e===r)break;r=e}delete e.targetFull,e.target!==r&&(e.targetFull=r)}splitSeriesByTagParams(e){const t=/([^\!=~]+)(\!?=~?)(.*)/;return(0,v.flatten)((0,v.map)(e.params,(e=>{const a=t.exec(e);if(a){const e=a.slice(1);if(3===e.length)return{key:e[0],operator:e[1],value:e[2]}}return[]})))}getSeriesByTagFuncIndex(){return(0,v.findIndex)(this.functions,(e=>"seriesByTag"===e.def.name))}getSeriesByTagFunc(){const e=this.getSeriesByTagFuncIndex();return e>=0?this.functions[e]:void 0}addTag(e){const t=q(e);this.getSeriesByTagFunc().params.push(t),this.tags.push(e)}removeTag(e){this.getSeriesByTagFunc().params.splice(e,1),this.tags.splice(e,1)}updateTag(e,t){if(this.error=null,e.key===this.removeTagValue)return this.removeTag(t),void(0===this.tags.length&&(this.removeFunction(this.getSeriesByTagFunc()),this.checkOtherSegmentsIndex=0,this.seriesByTagUsed=!1));this.getSeriesByTagFunc().params[t]=q(e),this.tags[t]=e}renderTagExpressions(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1;return(0,v.compact)((0,v.map)(this.tags,((t,a)=>a!==e?t.key+t.operator+t.value:void 0)))}}function q(e){return e.key+e.operator+e.value}M.$inject=["datasource","target","templateSrv","scopedVars"];var F=a(58257),I=a(49842),D=a(56340);const E=["=","!=","=~","!=~"],N="tag: ";async function A(e){e.queryModel.parseTarget(),await O(e)}async function O(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.segments=(0,v.clone)(e.queryModel.segments);const a=e.queryModel.checkOtherSegmentsIndex||0;await B(e,a,t)}function R(e){e.queryModel.addSelectMetricSegment(),e.segments.push({value:"select metric",fake:!0})}async function B(e,t){let a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(1===e.queryModel.segments.length&&"series-ref"===e.queryModel.segments[0].type)return;if(0===t)return void R(e);const n=e.queryModel.getSegmentPathUpTo(t+1);if(""!==n)try{const r=await e.datasource.metricFindQuery(n);0===r.length?""!==n&&a&&(e.queryModel.segments=e.queryModel.segments.splice(0,t),e.segments=e.segments.splice(0,t),R(e)):r[0].expandable&&(e.segments.length===t?R(e):await B(e,t+1))}catch(t){L(e,t)}}function $(e){e.queryModel.segments=[],e.segments=[]}function _(e){if(e.queryModel.error)return;const t=e.queryModel.target.target;e.queryModel.updateModelTarget((e.queries||[]).filter((e=>"target"in e&&"string"==typeof e.target))),e.queryModel.target.target===t||e.paused||e.refresh()}function L(e,t){return e.metricAutoCompleteErrorShown||(e.metricAutoCompleteErrorShown=!0,(0,D.WI)((0,I.$l)((0,F.t_)(`Fetching metrics failed: ${t.message}.`)))),e}function V(e,t){return e.tagsAutoCompleteErrorShown||(e.tagsAutoCompleteErrorShown=!0,(0,D.WI)((0,I.$l)((0,F.t_)(`Fetching tags failed: ${t.message}.`)))),e}const G=async(e,t)=>{if(t=Object.assign({},t),h.init.match(e)){const a=e.payload;a.target.target=a.target.target||"",await a.datasource.waitForFuncDefsLoaded(),t=Object.assign({},t,a,{queryModel:new M(a.datasource,a.target,(0,y.getTemplateSrv)()),supportsTags:a.datasource.supportsTags,paused:!1,removeTagValue:"-- remove tag --",funcDefs:a.datasource.funcDefs,queries:a.queries}),await O(t,!1)}if(h.timeRangeChanged.match(e)&&(t.range=e.payload),h.queriesChanged.match(e)&&(t.queries=e.payload,_(t)),h.queryChanged.match(e)&&(t.target.target=e.payload.target||"",await A(t),_(t)),h.segmentValueChanged.match(e)){const{segment:a,index:n}=e.payload;let r;if(r="string"==typeof a?{value:a,expandable:!0,fake:!1}:a,t.error=null,t.segments[n]=r,t.queryModel.updateSegmentValue(r,n),t.queryModel.functions.length>0&&t.queryModel.functions[0].def.fake&&(t.queryModel.functions=[]),"tag"===r.type){const e=r.value.replace(N,"");return function(e){e.paused=!0}(t),await async function(e,t){const a=e.datasource.createFuncInstance("seriesByTag",{withDefaultParams:!1}),n=`${t}=`;a.params=[n],e.queryModel.addFunction(a),a.added=!0,$(e),_(e),await A(e)}(t,e),t}r.expandable?await B(t,n+1):function(e,t){e.segments=e.segments.splice(0,t),e.queryModel.segments=e.queryModel.segments.splice(0,t)}(t,n+1),_(t)}if(h.tagChanged.match(e)){const{tag:a,index:n}=e.payload;t.queryModel.updateTag(a,n),_(t),0===t.queryModel.tags.length&&(await B(t,0),t.paused=!1)}if(h.addNewTag.match(e)){const a={key:e.payload.segment.value,operator:"=",value:""};t.queryModel.addTag(a),_(t)}if(h.unpause.match(e)&&(t.paused=!1,t.refresh()),h.addFunction.match(e)){const a=t.datasource.createFuncInstance(e.payload.name,{withDefaultParams:!0});a.added=!0,t.queryModel.addFunction(a),function(e,t){if("aliasByNode"===t.def.name)for(let a=0;a<e.segments.length;a++)if(e.segments[a].value.indexOf("*")>=0)return t.params[0]=a,t.added=!1,void _(e)}(t,a),1===t.segments.length&&t.segments[0].fake&&$(t),!a.params.length&&a.added&&_(t),"seriesByTag"===a.def.name&&await A(t)}if(h.removeFunction.match(e)&&(t.queryModel.removeFunction(e.payload.func),_(t)),h.moveFunction.match(e)){const{func:a,offset:n}=e.payload;t.queryModel.moveFunction(a,n),_(t)}if(h.updateFunctionParam.match(e)){const{func:a,index:n,value:r}=e.payload;a.updateParam(r,n),_(t)}return h.updateQuery.match(e)&&(t.target.target=e.payload.query,_(t)),h.runQuery.match(e)&&t.refresh(),h.toggleEditorMode.match(e)&&(t.target.textEditor=!t.target.textEditor,await A(t)),Object.assign({},t)};var z=a(45916);const H=(0,s.createContext)({}),U=(0,s.createContext)({}),W=()=>(0,s.useContext)(H),Q=e=>{let{datasource:t,onRunQuery:a,onChange:n,query:r,queries:i,range:o,children:l}=e;const[u,c]=(0,s.useState)(),[m,p]=(0,s.useState)(!1),d=(0,s.useMemo)((()=>(e=>{let t={};return async a=>{t=await G(a,t),e(t)}})((e=>{c(e)}))),[]),y=(0,g.Z)(o);return(0,s.useEffect)((()=>{(null==y?void 0:y.raw)!==(null==o?void 0:o.raw)&&d(h.timeRangeChanged(o))}),[d,o,y]),(0,s.useEffect)((()=>{u&&d(h.queriesChanged(i))}),[d,i]),(0,s.useEffect)((()=>{var e;u&&(null===(e=u.target)||void 0===e?void 0:e.target)!==r.target&&d(h.queryChanged(r))}),[d,r]),(0,s.useEffect)((()=>{m&&u&&(p(!1),n(Object.assign({},r,{target:u.target.target})),a())}),[m,n,a,r]),u?(0,z.jsx)(U.Provider,{value:u,children:(0,z.jsx)(H.Provider,{value:d,children:l})}):(d(h.init({target:r,datasource:t,range:o,templateSrv:(0,f.J)(),queries:i||[],refresh:()=>{p(!0)}})),null)};function Z(e){return e.map((e=>({value:e,label:e})))}function J(e){return e.map((e=>({label:e.value,value:e})))}function K(e,t,a){var n,r;return{name:e.name,value:(null==a?void 0:a.toString())||"",optional:!!e.optional||t,multiple:!!e.multiple,options:null!==(n=null===(r=e.options)||void 0===r?void 0:r.map((e=>({value:e.toString(),label:e.toString()}))))&&void 0!==n?n:[]}}function X(e){let{funcDefs:t}=e;const a=W(),[n,o]=(0,s.useState)(void 0),l=(0,i.useStyles2)(Y),u=(0,s.useMemo)((()=>function(e){const t={};return(0,v.forEach)(e,(e=>{e.category&&(t[e.category]||(t[e.category]={label:e.category,value:e.category,options:[]}),t[e.category].options.push({label:e.name,value:e.name}))})),(0,v.sortBy)(t,"label")}(t)),[t]);return(0,s.useEffect)((()=>{void 0!==(null==n?void 0:n.value)&&(a(h.addFunction({name:n.value})),o(void 0))}),[n,a]),(0,z.jsx)(i.Segment,{Component:(0,z.jsx)(i.Button,{icon:"plus",variant:"secondary",className:(0,r.cx)(l.button),"aria-label":"Add new function"}),options:u,onChange:o,inputMinWidth:150})}function Y(e){return{button:r.css`
- margin-right: ${e.spacing(.5)};
- `}}var ee;const te=s.lazy((async()=>{const{default:e}=await a.e(495).then(a.t.bind(a,53458,23));return{default(t){var a;return(0,z.jsx)("div",{dangerouslySetInnerHTML:{__html:e(null!==(a=t.description)&&void 0!==a?a:"")}})}}})),ae=e=>{if(e.description){let t=(0,z.jsx)(s.Suspense,{fallback:ee||(ee=(0,z.jsx)("span",{children:"Loading description..."})),children:(0,z.jsx)(te,{description:e.description})});return(0,z.jsx)(i.Tooltip,{content:t,placement:"bottom-end",children:(0,z.jsx)(i.Icon,{className:e.description?void 0:"pointer",name:"question-circle"})})}return(0,z.jsx)(i.Icon,{className:"pointer",name:"question-circle",onClick:()=>{window.open("http://graphite.readthedocs.org/en/latest/functions.html#graphite.render.functions."+e.name,"_blank")}})},ne=e=>{const{func:t,onMoveLeft:a,onMoveRight:n,onRemove:r}=e;return(0,z.jsxs)("div",{style:{display:"flex",width:"60px",justifyContent:"space-between"},children:[(0,z.jsx)(i.Icon,{name:"arrow-left",onClick:()=>a(t)}),(0,z.jsx)(ae,{name:t.def.name,description:t.def.description}),(0,z.jsx)(i.Icon,{name:"times",onClick:()=>r(t)}),(0,z.jsx)(i.Icon,{name:"arrow-right",onClick:()=>n(t)})]})};var re,se;const ie=["onMoveLeft","onMoveRight","func"];const oe=e=>({icon:r.css`
- margin-right: ${e.spacing(.5)};
- `,label:(0,r.css)({fontWeight:e.typography.fontWeightMedium,fontSize:e.typography.bodySmall.fontSize,cursor:"pointer",display:"inline-block"})}),le=e=>{let{onMoveLeft:t,onMoveRight:a,func:n}=e,r=function(e,t){if(null==e)return{};var a,n,r={},s=Object.keys(e);for(n=0;n<s.length;n++)a=s[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,ie);const s=(0,i.useStyles2)(oe);return(0,z.jsxs)(z.Fragment,{children:[n.def.unknown&&(0,z.jsx)(i.Tooltip,{content:re||(re=(0,z.jsx)(ue,{})),placement:"bottom",interactive:!0,children:(0,z.jsx)(i.Icon,{"data-testid":"warning-icon",name:"exclamation-triangle",size:"xs",className:s.icon})}),(0,z.jsx)(i.Tooltip,{content:e=>{let{updatePopperPosition:s}=e;return(0,z.jsx)(ne,Object.assign({},r,{func:n,onMoveLeft:()=>{t(n),s()},onMoveRight:()=>{a(n),s()}}))},placement:"top",interactive:!0,children:(0,z.jsx)("span",{className:s.label,children:n.def.name})})]})},ue=s.memo((()=>se||(se=(0,z.jsxs)("span",{children:["This function is not supported. Check your function for typos and"," ",(0,z.jsx)("a",{target:"_blank",className:"external-link",rel:"noreferrer noopener",href:"https://graphite.readthedocs.io/en/latest/functions.html",children:"read the docs"})," ","to see whether you need to upgrade your data source’s version to make this function available."]}))));function ce(e){var t;let{editableParam:a,onChange:n,onExpandedChange:r,autofocus:s}=e;const o=(0,i.useStyles2)(me);return(null===(t=a.options)||void 0===t?void 0:t.length)>0?(0,z.jsx)(i.Segment,{autofocus:s,value:a.value,inputPlaceholder:a.name,className:o.segment,options:a.options,placeholder:" +"+a.name,onChange:e=>{n(e.value||"")},onExpandedChange:r,inputMinWidth:150,allowCustomValue:!0,allowEmptyValue:!0}):(0,z.jsx)(i.SegmentInput,{autofocus:s,className:o.input,value:a.value||"",placeholder:" +"+a.name,inputPlaceholder:a.name,onChange:e=>{n(e.toString())},onExpandedChange:r,style:{height:"25px",paddingTop:"2px",marginTop:"2px",paddingLeft:"4px",minWidth:"100px"}})}ue.displayName="FunctionEditorTooltipContent";const me=e=>({segment:(0,r.css)({margin:0,padding:0}),input:r.css`
- margin: 0;
- padding: 0;
- input {
- height: 25px;
- },
- `});function pe(e){let{func:t}=e;const a=W(),n=(0,i.useStyles2)(de),[o,l]=(0,s.useState)(!1),[u,c]=(0,s.useState)(!1);let m=function(e){var t;const a=e.def.params.map(((t,a)=>K(t,!1,e.params[a])));for(;a.length<e.params.length;){const t=e.def.params[e.def.params.length-1],n=e.params[a.length];a.push(K(t,!0,n))}if(a.length&&a[a.length-1].value&&null!==(t=a[a.length-1])&&void 0!==t&&t.multiple){const t=e.def.params[e.def.params.length-1];a.push(K(t,!0,""))}return a}(t);return m=m.filter(((e,a)=>a<t.def.params.length&&!e.optional||t.added||e.value||u||o)),(0,z.jsx)("div",{className:(0,r.cx)(n.container,{[n.error]:t.def.unknown}),onMouseOver:()=>l(!0),onMouseLeave:()=>l(!1),children:(0,z.jsxs)(i.HorizontalGroup,{spacing:"none",children:[(0,z.jsx)(le,{func:t,onMoveLeft:()=>{a(h.moveFunction({func:t,offset:-1}))},onMoveRight:()=>{a(h.moveFunction({func:t,offset:1}))},onRemove:()=>{a(h.removeFunction({func:t}))}}),(0,z.jsx)(i.InlineLabel,{className:n.label,children:"("}),m.map(((e,n)=>(0,z.jsxs)(s.Fragment,{children:[(0,z.jsx)(ce,{autofocus:0===n&&t.added,editableParam:e,onChange:r=>{(""!==r||e.optional)&&a(h.updateFunctionParam({func:t,index:n,value:r})),c(!1),l(!1)},onExpandedChange:c}),n!==m.length-1?",":""]},n))),(0,z.jsx)(i.InlineLabel,{className:n.label,children:")"})]})})}const de=e=>({container:(0,r.css)({backgroundColor:e.colors.background.secondary,borderRadius:e.shape.borderRadius(),marginRight:e.spacing(.5),padding:`0 ${e.spacing(1)}`,height:`${e.v1.spacing.formInputHeight}px`}),error:r.css`
- border: 1px solid ${e.colors.error.main};
- `,label:(0,r.css)({padding:0,margin:0}),button:(0,r.css)({padding:e.spacing(.5)})});function he(e){let{functions:t=[],funcDefs:a}=e;return(0,z.jsxs)(i.SegmentSection,{label:"Functions",fill:!0,children:[t.map(((e,t)=>!e.hidden&&(0,z.jsx)(pe,{func:e},t))),(0,z.jsx)(X,{funcDefs:a})]})}function ge(e){let{rawQuery:t}=e;const a=W(),n=(0,s.useCallback)((e=>{a(h.updateQuery({query:e}))}),[a]),r=(0,s.useCallback)((()=>{a(h.runQuery())}),[a]);return(0,z.jsx)(i.QueryField,{query:t,onChange:n,onBlur:r,onRunQuery:r,placeholder:"Enter a Graphite query (run with Shift+Enter)",portalOrigin:"graphite"})}const fe=5e3;async function ye(e,t,a){let n=a.length>0?"*"+a+"*":"*";t>0&&(n=e.queryModel.getSegmentPathUpTo(t)+"."+n);const r={range:e.range,requestId:"get-alt-segments"};try{const s=await e.datasource.metricFindQuery(n,r),i=(0,v.map)(s,(e=>({value:e.text,expandable:e.expandable})));return t>0&&0===i.length?i:(0===t&&(0,v.eachRight)(e.queries,(t=>{t.refId!==e.queryModel.target.refId&&i.unshift({type:"series-ref",value:"#"+t.refId,expandable:!1})})),(0,v.eachRight)(e.templateSrv.getVariables(),(e=>{i.unshift({type:"template",value:"$"+e.name,expandable:!0})})),i.unshift({value:"*",expandable:!0}),i.splice(fe),e.supportsTags&&0===t?(function(e){(0,v.remove)(e,(e=>"_tagged"===e.value))}(i),await async function(e,t,a){let n=await xe(e,t);return n=(0,v.map)(n,(e=>(e.value=N+e.value,e))),a.concat(...n)}(e,a,i)):i)}catch(t){L(e,t)}return[]}async function ve(e,t,a){return Z(await async function(e,t,a){try{const n=e.queryModel.renderTagExpressions(t),r=await e.datasource.getTagsAutoComplete(n,a,{range:e.range,limit:fe}),s=(0,v.map)(r,"text");return s.splice(0,0,e.removeTagValue),s}catch(t){V(e,t)}return[]}(e,t,a))}async function xe(e,t){let a;try{const n=e.queryModel.renderTagExpressions(),r=await e.datasource.getTagsAutoComplete(n,t,{range:e.range,limit:fe});a=(0,v.map)(r,(e=>({value:e.text,type:"tag",expandable:!1})))}catch(t){a=[],V(e,t)}return a}async function be(e,t,a,n){return Z(await async function(e,t,a,n){const r=e.queryModel.renderTagExpressions(a),s=t.key,i=await e.datasource.getTagValuesAutoComplete(r,s,n,{limit:fe}),o=(0,v.map)(i,"text");return(0,v.eachRight)(e.templateSrv.getVariables(),(e=>{o.push("${"+e.name+":regex}")})),o}(e,t,a,n))}function Se(e){let{metricIndex:t,segment:a,state:n}=e;const r=W(),o=(0,s.useCallback)((e=>async function(e,t,a){return J(await ye(e,t,a))}(n,t,e||"")),[n,t]),l=(0,s.useMemo)((()=>(0,v.debounce)(o,200,{leading:!0})),[o]),u=(0,s.useCallback)((e=>{r(h.segmentValueChanged({segment:e.value,index:t}))}),[r,t]),c=(0,s.useMemo)((()=>(0,v.debounce)(u,100)),[u]);return(0,z.jsx)(i.SegmentAsync,{value:a.value,inputMinWidth:150,allowCustomValue:!0,loadOptions:l,reloadOptionsOnChange:!0,onChange:c})}function je(e){let{segments:t=[],state:a}=e;return(0,z.jsx)(z.Fragment,{children:t.map(((e,t)=>(0,z.jsx)(Se,{segment:e,metricIndex:t,state:a},t)))})}function Te(){const e=W(),t=(0,s.useCallback)((()=>{e(h.unpause())}),[e]);return(0,z.jsx)(i.Button,{icon:"play",onClick:t,type:"button",variant:"secondary","aria-label":"Unpause query"})}function ke(e){let{tag:t,tagIndex:a,state:n}=e;const r=W(),o=(0,s.useCallback)((e=>ve(n,a,e||"")),[n,a]),l=(0,s.useMemo)((()=>(0,v.debounce)(o,200,{leading:!0})),[o]),u=(0,s.useCallback)((e=>be(n,t,a,e||"")),[n,a,t]),c=(0,s.useMemo)((()=>(0,v.debounce)(u,200,{leading:!0})),[u]);return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i.SegmentAsync,{inputMinWidth:150,value:t.key,loadOptions:l,reloadOptionsOnChange:!0,onChange:e=>{r(h.tagChanged({tag:Object.assign({},t,{key:e.value}),index:a}))},allowCustomValue:!0}),(0,z.jsx)(i.Segment,{inputMinWidth:50,value:t.operator,options:Z(E),onChange:e=>{r(h.tagChanged({tag:Object.assign({},t,{operator:e.value}),index:a}))}}),(0,z.jsx)(i.SegmentAsync,{inputMinWidth:150,value:t.value,loadOptions:c,reloadOptionsOnChange:!0,onChange:e=>{r(h.tagChanged({tag:Object.assign({},t,{value:e.value}),index:a}))},allowCustomValue:!0})]})}var we,Pe;function Ce(e){let{tags:t,state:a}=e;const n=W(),r=(0,i.useStyles2)(Me),o=(0,s.useCallback)((e=>async function(e,t){return J(await xe(e,t))}(a,e||"")),[a]),l=(0,s.useMemo)((()=>(0,v.debounce)(o,200,{leading:!0})),[o]);return(0,z.jsxs)(z.Fragment,{children:[t.map(((e,t)=>(0,z.jsx)(ke,{tagIndex:t,tag:e,state:a},t))),t.length&&(0,z.jsx)(i.SegmentAsync,{inputMinWidth:150,onChange:e=>{n(h.addNewTag({segment:e.value}))},loadOptions:l,reloadOptionsOnChange:!0,Component:(0,z.jsx)(i.Button,{icon:"plus",variant:"secondary",className:r.button,"aria-label":"Add new tag"})}),a.paused&&(we||(we=(0,z.jsx)(Te,{})))]})}function Me(e){return{button:r.css`
- margin-right: ${e.spacing(.5)};
- `}}function qe(e){var t,a;let{state:n}=e;const r=null!==(t=n.queryModel)&&void 0!==t&&t.seriesByTagUsed?(0,z.jsx)(Ce,{tags:null===(a=n.queryModel)||void 0===a?void 0:a.tags,state:n}):(0,z.jsx)(je,{segments:n.segments,state:n});return(0,z.jsx)(i.SegmentSection,{label:"Series",fill:!0,children:r})}function Fe(){var e,t,a;const n=W(),r=(0,s.useContext)(U),o=(0,i.useStyles2)(Ie);return(0,z.jsxs)("div",{className:o.container,children:[(0,z.jsxs)("div",{className:o.visualEditor,children:[(null===(e=r.target)||void 0===e?void 0:e.textEditor)&&(0,z.jsx)(ge,{rawQuery:r.target.target}),!(null!==(t=r.target)&&void 0!==t&&t.textEditor)&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(qe,{state:r}),(0,z.jsx)(he,{functions:null===(a=r.queryModel)||void 0===a?void 0:a.functions,funcDefs:r.funcDefs})]})]}),(0,z.jsx)(i.Button,{className:o.toggleButton,icon:"pen",variant:"secondary","aria-label":"Toggle editor mode",onClick:()=>{n(h.toggleEditorMode())}})]})}function Ie(e){return{container:r.css`
- display: flex;
- `,visualEditor:r.css`
- flex-grow: 1;
- `,toggleButton:r.css`
- margin-left: ${e.spacing(.5)};
- `}}var De,Ee,Ne,Ae,Oe,Re=a(78837);function Be(e){if(e)return parseInt(e,10)}function $e(e){if(e)return"true"===e||"false"!==e&&parseInt(e,10)}function _e(e){for(const a of e){const e=a["archive-read"];if(e>0){var t;return{text:`Data is rolled up, aggregated over ${Ve(a["schema-retentions"])[e].interval} using ${(null!==(t=a["consolidator-normfetch"])&&void 0!==t?t:"").replace("Consolidator","")} function`,severity:"info",inspect:"meta"}}}return null}function Le(e){for(const a of e){const e=a["aggnum-rc"];if(e>0){var t;return{text:`Data is runtime consolidated, ${e} datapoints combined using ${(null!==(t=a["consolidator-rc"])&&void 0!==t?t:"").replace("Consolidator","")} function`,severity:"info",inspect:"meta"}}}return null}function Ve(e){return e?e.split(",").map((e=>{const t=e.split(":");return{interval:t[0],retention:t[1],chunkspan:t[2],numchunks:Be(t[3]),ready:$e(t[4])}})):[]}class Ge extends s.PureComponent{renderMeta(e,t){var a;const s=ze(),i=Ve(e["schema-retentions"]),o=_e([e]),l=Le([e]),u=(null!==(a=e["consolidator-normfetch"])&&void 0!==a?a:"").replace("Consolidator",""),c=i.reduce(((e,t)=>e+(t.retention?n.rangeUtil.intervalToSeconds(t.retention):0)),0);return(0,z.jsxs)("div",{className:s.metaItem,children:[(0,z.jsxs)("div",{className:s.metaItemHeader,children:["Schema: ",e["schema-name"],(0,z.jsxs)("div",{className:"small muted",children:["Series count: ",e.count]})]}),(0,z.jsxs)("div",{className:s.metaItemBody,children:[(0,z.jsxs)("div",{className:s.step,children:[(0,z.jsx)("div",{className:s.stepHeading,children:"Step 1: Fetch"}),(0,z.jsx)("div",{className:s.stepDescription,children:"First data is fetched, either from raw data archive or a rollup archive"}),o&&(0,z.jsx)("p",{children:o.text}),!o&&(De||(De=(0,z.jsx)("p",{children:"No rollup archive was used"}))),(0,z.jsx)("div",{children:i.map(((t,a)=>{const i=(t.retention?n.rangeUtil.intervalToSeconds(t.retention):0)/c*100,o=a===e["archive-read"];return(0,z.jsxs)("div",{className:s.bucket,children:[(0,z.jsx)("div",{className:s.bucketInterval,children:t.interval}),(0,z.jsx)("div",{className:(0,r.cx)(s.bucketRetention,{[s.bucketRetentionActive]:o}),style:{flexGrow:i}}),(0,z.jsx)("div",{style:{flexGrow:100-i},children:t.retention})]},t.retention)}))})]}),(0,z.jsxs)("div",{className:s.step,children:[(0,z.jsx)("div",{className:s.stepHeading,children:"Step 2: Normalization"}),(0,z.jsx)("div",{className:s.stepDescription,children:"Normalization happens when series with different intervals between points are combined."}),e["aggnum-norm"]>1&&(0,z.jsxs)("p",{children:["Normalization did occur using ",u]}),1===e["aggnum-norm"]&&(Ee||(Ee=(0,z.jsx)("p",{children:"No normalization was needed"})))]}),(0,z.jsxs)("div",{className:s.step,children:[(0,z.jsx)("div",{className:s.stepHeading,children:"Step 3: Runtime consolidation"}),(0,z.jsx)("div",{className:s.stepDescription,children:"If there are too many data points at this point Metrictank will consolidate them down to below max data points (set in queries tab)."}),l&&(0,z.jsx)("p",{children:l.text}),!l&&(Ne||(Ne=(0,z.jsx)("p",{children:"No runtime consolidation"})))]})]})]},t)}render(){const{data:e}=this.props,t={};for(const a of e)if(a.meta&&a.meta.custom)for(const e of a.meta.custom.seriesMetaList){const a=`${JSON.stringify(e)}`;t[a]?t[a].count+=e.count:t[a]=e}return 0===Object.keys(t).length?Ae||(Ae=(0,z.jsx)("div",{children:"No response meta data"})):(0,z.jsxs)("div",{children:[Oe||(Oe=(0,z.jsx)("h2",{className:"page-heading",children:"Metrictank Lineage"})),Object.keys(t).map((e=>this.renderMeta(t[e],e)))]})}}const ze=(0,i.stylesFactory)((()=>{const{theme:e}=Re.vc,t=e.isDark?e.palette.gray25:e.palette.gray85,a=e.isDark?e.palette.dark1:e.palette.white,n=e.isDark?e.palette.gray15:e.palette.gray85;return{metaItem:r.css`
- background: ${a};
- border: 1px solid ${t};
- margin-bottom: ${e.spacing.md};
- `,metaItemHeader:r.css`
- background: ${n};
- padding: ${e.spacing.xs} ${e.spacing.md};
- font-size: ${e.typography.size.md};
- display: flex;
- justify-content: space-between;
- `,metaItemBody:r.css`
- padding: ${e.spacing.md};
- `,stepHeading:r.css`
- font-size: ${e.typography.size.md};
- `,stepDescription:r.css`
- font-size: ${e.typography.size.sm};
- color: ${e.colors.textWeak};
- margin-bottom: ${e.spacing.sm};
- `,step:r.css`
- margin-bottom: ${e.spacing.lg};
- &:last-child {
- margin-bottom: 0;
- }
- `,bucket:r.css`
- display: flex;
- margin-bottom: ${e.spacing.sm};
- border-radius: ${e.border.radius.md};
- `,bucketInterval:r.css`
- flex-grow: 0;
- width: 60px;
- `,bucketRetention:r.css`
- background: linear-gradient(0deg, ${e.palette.blue85}, ${e.palette.blue95});
- text-align: center;
- color: ${e.palette.white};
- margin-right: ${e.spacing.md};
- border-radius: ${e.border.radius.md};
- `,bucketRetentionActive:r.css`
- background: linear-gradient(0deg, ${e.palette.greenBase}, ${e.palette.greenShade});
- `}}));var He=a(17421);let Ue;!function(e){e.Default="default",e.Metrictank="metrictank"}(Ue||(Ue={}));const We=["0.9","1.0","1.1"],Qe=(0,v.last)(We);var Ze,Je,Ke,Xe,Ye,et,tt;function at(e){return(0,z.jsxs)(i.Alert,{severity:"info",title:"How to map Graphite metrics to labels?",onRemove:e.onDismiss,children:[Ze||(Ze=(0,z.jsx)("p",{children:"Mappings are currently supported only between Graphite and Loki queries."})),Je||(Je=(0,z.jsx)("p",{children:"When you switch your data source from Graphite to Loki, your queries are mapped according to the mappings defined in the example below. To define a mapping, write the full path of the metric and replace nodes you want to map to label with the label name in parentheses. The value of the label is extracted from your Graphite query when you switch data sources."})),Ke||(Ke=(0,z.jsx)("p",{children:"All tags are automatically mapped to labels regardless of the mapping configuration. Graphite matching patterns (using {}) are converted to Loki's regular expressions matching patterns. When you use functions in your queries, the metrics, and tags are extracted to match them with defined mappings."})),Xe||(Xe=(0,z.jsxs)("p",{children:["Example: for a mapping = ",(0,z.jsx)("code",{children:"servers.(cluster).(server).*"}),":"]})),Ye||(Ye=(0,z.jsxs)("table",{children:[(0,z.jsx)("thead",{children:(0,z.jsxs)("tr",{children:[(0,z.jsx)("th",{children:"Graphite query"}),(0,z.jsx)("th",{children:"Mapped to Loki query"})]})}),(0,z.jsxs)("tbody",{children:[(0,z.jsxs)("tr",{children:[(0,z.jsx)("td",{children:(0,z.jsxs)("code",{children:["alias(servers.",(0,z.jsx)("u",{children:"west"}),".",(0,z.jsx)("u",{children:"001"}),".cpu,1,2)"]})}),(0,z.jsx)("td",{children:(0,z.jsxs)("code",{children:['{cluster="',(0,z.jsx)("u",{children:"west"}),'", server="',(0,z.jsx)("u",{children:"001"}),'"}']})})]}),(0,z.jsxs)("tr",{children:[(0,z.jsx)("td",{children:(0,z.jsxs)("code",{children:["alias(servers.*.",(0,z.jsx)("u",{children:"{001,002}"}),".*,1,2)"]})}),(0,z.jsx)("td",{children:(0,z.jsxs)("code",{children:['{server=~"',(0,z.jsx)("u",{children:"(001|002)"}),'"}']})})]}),(0,z.jsxs)("tr",{children:[(0,z.jsx)("td",{children:(0,z.jsx)("code",{children:"interpolate(seriesByTag('foo=bar', 'server=002'), inf))"})}),(0,z.jsx)("td",{children:(0,z.jsx)("code",{children:'{foo="bar", server="002"}'})})]})]})]}))]})}const nt=e=>{const[t,a]=(0,s.useState)(e.mappings||[]);return(0,z.jsxs)("div",{children:[et||(et=(0,z.jsx)("h3",{className:"page-heading",children:"Label mappings"})),!e.showHelp&&(0,z.jsx)("p",{children:(0,z.jsx)(i.Button,{fill:"text",onClick:e.onRestoreHelp,children:"Learn how label mappings work"})}),e.showHelp&&(0,z.jsx)(at,{onDismiss:e.onDismiss}),(0,z.jsxs)("div",{className:"gf-form-group",children:[t.map(((n,r)=>(0,z.jsxs)(i.InlineFieldRow,{children:[(0,z.jsx)(i.InlineField,{label:`Mapping (${r+1})`,children:(0,z.jsx)(i.Input,{width:50,onChange:e=>{let n=t.concat();n[r]=e.target.value,a(n)},onBlur:()=>{e.onChange(t)},placeholder:"e.g. test.metric.(labelName).*",value:n})}),(0,z.jsx)(i.Button,{type:"button","aria-label":"Remove header",variant:"secondary",size:"xs",onClick:n=>{let s=t.concat();s.splice(r,1),a(s),e.onChange(s)},children:tt||(tt=(0,z.jsx)(i.Icon,{name:"trash-alt"}))})]},r))),(0,z.jsx)(i.Button,{variant:"secondary",icon:"plus",type:"button",onClick:()=>{a([...t,""])},children:"Add label mapping"})]})]})};function rt(e){return{matchers:e.split(".").map((e=>e.startsWith("(")&&e.endsWith(")")?{value:"*",labelName:e.slice(1,-1)}:{value:e}))}}function st(e){return e.matchers.map((e=>e.labelName?`(${e.labelName})`:`${e.value}`)).join(".")}var it,ot,lt,ut;const{Select:ct,Switch:mt}=i.LegacyForms,pt="grafana.datasources.graphite.config.showMappingsHelp",dt=We.map((e=>({label:`${e}.x`,value:e}))),ht=Object.entries(Ue).map((e=>{let[t,a]=e;return{label:t,value:a}}));class gt extends s.PureComponent{constructor(e){var t,a,n;super(e),n=()=>it||(it=(0,z.jsxs)("p",{children:["There are different types of Graphite compatible backends. Here you can specify the type you are using. If you are using"," ",(0,z.jsx)("a",{href:"https://github.com/grafana/metrictank",className:"pointer",target:"_blank",rel:"noreferrer",children:"Metrictank"})," ","then select that here. This will enable Metrictank specific features like query processing meta data. Metrictank is a multi-tenant timeseries engine for Graphite and friends."]})),(a="renderTypeHelp")in(t=this)?Object.defineProperty(t,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[a]=n,this.state={showMappingsHelp:He.Z.getObject(pt,!0)}}componentDidMount(){(0,n.updateDatasourcePluginJsonDataOption)(this.props,"graphiteVersion",this.currentGraphiteVersion)}render(){var e,t;const{options:a,onOptionsChange:r}=this.props,s=dt.find((e=>e.value===this.currentGraphiteVersion));return(0,z.jsxs)(z.Fragment,{children:["direct"===a.access&&(ot||(ot=(0,z.jsx)(i.Alert,{title:"Deprecation Notice",severity:"warning",children:"This data source uses browser access mode. This mode is deprecated and will be removed in the future. Please use server access mode instead."}))),(0,z.jsx)(i.DataSourceHttpSettings,{defaultUrl:"http://localhost:8080",dataSourceConfig:a,onChange:r}),lt||(lt=(0,z.jsx)("h3",{className:"page-heading",children:"Graphite details"})),(0,z.jsxs)("div",{className:"gf-form-group",children:[(0,z.jsx)("div",{className:"gf-form-inline",children:(0,z.jsxs)("div",{className:"gf-form",children:[ut||(ut=(0,z.jsx)(i.InlineFormLabel,{tooltip:"This option controls what functions are available in the Graphite query editor.",children:"Version"})),(0,z.jsx)(ct,{"aria-label":"Graphite version",value:s,options:dt,width:8,onChange:(0,n.onUpdateDatasourceJsonDataOptionSelect)(this.props,"graphiteVersion")})]})}),(0,z.jsx)("div",{className:"gf-form-inline",children:(0,z.jsxs)("div",{className:"gf-form",children:[(0,z.jsx)(i.InlineFormLabel,{tooltip:this.renderTypeHelp,children:"Type"}),(0,z.jsx)(ct,{"aria-label":"Graphite backend type",options:ht,value:ht.find((e=>e.value===a.jsonData.graphiteType)),width:8,onChange:(0,n.onUpdateDatasourceJsonDataOptionSelect)(this.props,"graphiteType")})]})}),a.jsonData.graphiteType===Ue.Metrictank&&(0,z.jsx)("div",{className:"gf-form-inline",children:(0,z.jsx)("div",{className:"gf-form",children:(0,z.jsx)(mt,{label:"Rollup indicator",labelClass:"width-10",tooltip:"Shows up as an info icon in panel headers when data is aggregated",checked:!!a.jsonData.rollupIndicatorEnabled,onChange:(0,n.onUpdateDatasourceJsonDataOptionChecked)(this.props,"rollupIndicatorEnabled")})})})]}),(0,z.jsx)(nt,{mappings:((null===(e=a.jsonData.importConfiguration)||void 0===e||null===(t=e.loki)||void 0===t?void 0:t.mappings)||[]).map(st),showHelp:this.state.showMappingsHelp,onDismiss:()=>{this.setState({showMappingsHelp:!1}),He.Z.setObject(pt,!1)},onRestoreHelp:()=>{this.setState({showMappingsHelp:!0}),He.Z.setObject(pt,!0)},onChange:e=>{r(Object.assign({},a,{jsonData:Object.assign({},a.jsonData,{importConfiguration:Object.assign({},a.jsonData.importConfiguration,{loki:{mappings:e.map(rt)}})})}))}})]})}get currentGraphiteVersion(){return this.props.options.jsonData.graphiteVersion||Qe}}var ft=a(2937),yt=a(58788),vt=a(26702),xt=a(6639),bt=a(10010),St=a(76913);function jt(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const Tt=/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;class kt{constructor(e){jt(this,"major",void 0),jt(this,"minor",void 0),jt(this,"patch",void 0),jt(this,"meta",void 0),this.major=0,this.minor=0,this.patch=0,this.meta="";const t=Tt.exec(e);t&&(this.major=Number(t[1]),this.minor=Number(t[2]||0),this.patch=Number(t[3]||0),this.meta=t[4])}isGtOrEq(e){const t=new kt(e);for(let e=0;e<this.comparable.length;++e){if(this.comparable[e]>t.comparable[e])return!0;if(this.comparable[e]<t.comparable[e])return!1}return!0}isValid(){return(0,v.isNumber)(this.major)}get comparable(){return[this.major,this.minor,this.patch]}}function wt(e,t){return new kt(e).isGtOrEq(t)}var Pt=a(5970);function Ct(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const Mt={};function qt(e){e.params=e.params||[],e.defaultParams=e.defaultParams||[],Mt[e.name]=e,e.shortName&&(Mt[e.shortName]=e)}const Ft=[{name:"other",type:"value_or_series",optional:!0,multiple:!0}];function It(e,t){return!e.version||wt(t,e.version)}qt({name:"scaleToSeconds",category:"Transform",params:[{name:"seconds",type:"int"}],defaultParams:[1]}),qt({name:"perSecond",category:"Transform",params:[{name:"max value",type:"int",optional:!0}],defaultParams:[]}),qt({name:"holtWintersForecast",category:"Calculate"}),qt({name:"holtWintersConfidenceBands",category:"Calculate",params:[{name:"delta",type:"int"}],defaultParams:[3]}),qt({name:"holtWintersAberration",category:"Calculate",params:[{name:"delta",type:"int"}],defaultParams:[3]}),qt({name:"nPercentile",category:"Calculate",params:[{name:"Nth percentile",type:"int"}],defaultParams:[95]}),qt({name:"diffSeries",params:Ft,defaultParams:["#A"],category:"Combine"}),qt({name:"stddevSeries",params:Ft,defaultParams:[""],category:"Combine"}),qt({name:"divideSeries",params:Ft,defaultParams:["#A"],category:"Combine"}),qt({name:"multiplySeries",params:Ft,defaultParams:["#A"],category:"Combine"}),qt({name:"asPercent",params:Ft,defaultParams:["#A"],category:"Combine"}),qt({name:"group",params:Ft,defaultParams:["#A","#B"],category:"Combine"}),qt({name:"sumSeries",shortName:"sum",category:"Combine",params:Ft,defaultParams:[""]}),qt({name:"averageSeries",shortName:"avg",category:"Combine",params:Ft,defaultParams:[""]}),qt({name:"rangeOfSeries",category:"Combine"}),qt({name:"percentileOfSeries",category:"Combine",params:[{name:"n",type:"int"},{name:"interpolate",type:"boolean",options:["true","false"]}],defaultParams:[95,"false"]}),qt({name:"sumSeriesWithWildcards",category:"Combine",params:[{name:"node",type:"int",multiple:!0}],defaultParams:[3]}),qt({name:"maxSeries",shortName:"max",category:"Combine"}),qt({name:"minSeries",shortName:"min",category:"Combine"}),qt({name:"averageSeriesWithWildcards",category:"Combine",params:[{name:"node",type:"int",multiple:!0}],defaultParams:[3]}),qt({name:"alias",category:"Alias",params:[{name:"alias",type:"string"}],defaultParams:["alias"]}),qt({name:"aliasSub",category:"Alias",params:[{name:"search",type:"string"},{name:"replace",type:"string"}],defaultParams:["","\\1"]}),qt({name:"consolidateBy",category:"Special",params:[{name:"function",type:"string",options:["sum","average","min","max"]}],defaultParams:["max"]}),qt({name:"cumulative",category:"Special",params:[],defaultParams:[]}),qt({name:"groupByNode",category:"Combine",params:[{name:"node",type:"int",options:[0,1,2,3,4,5,6,7,8,9,10,12]},{name:"function",type:"string",options:["sum","avg","maxSeries"]}],defaultParams:[3,"sum"]}),qt({name:"aliasByNode",category:"Alias",params:[{name:"node",type:"int",options:[0,1,2,3,4,5,6,7,8,9,10,12],multiple:!0}],defaultParams:[3]}),qt({name:"substr",category:"Special",params:[{name:"start",type:"int",options:[-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,12]},{name:"stop",type:"int",options:[-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,12]}],defaultParams:[0,0]}),qt({name:"sortByName",category:"Sorting",params:[{name:"natural",type:"boolean",options:["true","false"],optional:!0}],defaultParams:["false"]}),qt({name:"sortByMaxima",category:"Sorting"}),qt({name:"sortByMinima",category:"Sorting"}),qt({name:"sortByTotal",category:"Sorting"}),qt({name:"aliasByMetric",category:"Alias"}),qt({name:"randomWalk",fake:!0,category:"Special",params:[{name:"name",type:"string"}],defaultParams:["randomWalk"]}),qt({name:"countSeries",category:"Combine"}),qt({name:"constantLine",category:"Special",params:[{name:"value",type:"int"}],defaultParams:[10]}),qt({name:"cactiStyle",category:"Special"}),qt({name:"keepLastValue",category:"Transform",params:[{name:"n",type:"int"}],defaultParams:[100]}),qt({name:"changed",category:"Special",params:[],defaultParams:[]}),qt({name:"scale",category:"Transform",params:[{name:"factor",type:"int"}],defaultParams:[1]}),qt({name:"offset",category:"Transform",params:[{name:"amount",type:"int"}],defaultParams:[10]}),qt({name:"transformNull",category:"Transform",params:[{name:"amount",type:"int"}],defaultParams:[0]}),qt({name:"integral",category:"Transform"}),qt({name:"derivative",category:"Transform"}),qt({name:"nonNegativeDerivative",category:"Transform",params:[{name:"max value or 0",type:"int",optional:!0}],defaultParams:[""]}),qt({name:"timeShift",category:"Transform",params:[{name:"amount",type:"select",options:["1h","6h","12h","1d","2d","7d","14d","30d"]}],defaultParams:["1d"]}),qt({name:"timeStack",category:"Transform",params:[{name:"timeShiftUnit",type:"select",options:["1h","6h","12h","1d","2d","7d","14d","30d"]},{name:"timeShiftStart",type:"int"},{name:"timeShiftEnd",type:"int"}],defaultParams:["1d",0,7]}),qt({name:"summarize",category:"Transform",params:[{name:"interval",type:"string"},{name:"func",type:"select",options:["sum","avg","min","max","last"]},{name:"alignToFrom",type:"boolean",optional:!0,options:["false","true"]}],defaultParams:["1h","sum","false"]}),qt({name:"smartSummarize",category:"Transform",params:[{name:"interval",type:"string"},{name:"func",type:"select",options:["sum","avg","min","max","last"]}],defaultParams:["1h","sum"]}),qt({name:"absolute",category:"Transform"}),qt({name:"hitcount",category:"Transform",params:[{name:"interval",type:"string"}],defaultParams:["10s"]}),qt({name:"log",category:"Transform",params:[{name:"base",type:"int"}],defaultParams:["10"]}),qt({name:"averageAbove",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[25]}),qt({name:"averageBelow",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[25]}),qt({name:"currentAbove",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[25]}),qt({name:"currentBelow",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[25]}),qt({name:"maximumAbove",category:"Filter Series",params:[{name:"value",type:"int"}],defaultParams:[0]}),qt({name:"maximumBelow",category:"Filter Series",params:[{name:"value",type:"int"}],defaultParams:[0]}),qt({name:"minimumAbove",category:"Filter Series",params:[{name:"value",type:"int"}],defaultParams:[0]}),qt({name:"minimumBelow",category:"Filter Series",params:[{name:"value",type:"int"}],defaultParams:[0]}),qt({name:"limit",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[5]}),qt({name:"mostDeviant",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[10]}),qt({name:"exclude",category:"Filter Series",params:[{name:"exclude",type:"string"}],defaultParams:["exclude"]}),qt({name:"highestCurrent",category:"Filter Series",params:[{name:"count",type:"int"}],defaultParams:[5]}),qt({name:"highestMax",category:"Filter Series",params:[{name:"count",type:"int"}],defaultParams:[5]}),qt({name:"lowestCurrent",category:"Filter Series",params:[{name:"count",type:"int"}],defaultParams:[5]}),qt({name:"movingAverage",category:"Calculate",params:[{name:"windowSize",type:"int_or_interval",options:["5","7","10","5min","10min","30min","1hour"]}],defaultParams:[10]}),qt({name:"movingMedian",category:"Calculate",params:[{name:"windowSize",type:"int_or_interval",options:["5","7","10","5min","10min","30min","1hour"]}],defaultParams:["5"]}),qt({name:"stdev",category:"Calculate",params:[{name:"n",type:"int"},{name:"tolerance",type:"int"}],defaultParams:[5,.1]}),qt({name:"highestAverage",category:"Filter Series",params:[{name:"count",type:"int"}],defaultParams:[5]}),qt({name:"lowestAverage",category:"Filter Series",params:[{name:"count",type:"int"}],defaultParams:[5]}),qt({name:"removeAbovePercentile",category:"Filter Data",params:[{name:"n",type:"int"}],defaultParams:[5]}),qt({name:"removeAboveValue",category:"Filter Data",params:[{name:"n",type:"int"}],defaultParams:[5]}),qt({name:"removeBelowPercentile",category:"Filter Data",params:[{name:"n",type:"int"}],defaultParams:[5]}),qt({name:"removeBelowValue",category:"Filter Data",params:[{name:"n",type:"int"}],defaultParams:[5]}),qt({name:"useSeriesAbove",category:"Filter Series",params:[{name:"value",type:"int"},{name:"search",type:"string"},{name:"replace",type:"string"}],defaultParams:[0,"search","replace"]}),qt({name:"aggregateLine",category:"Calculate",params:[{name:"func",type:"select",options:["sum","avg","min","max","last"]}],defaultParams:["avg"],version:"1.0"}),qt({name:"averageOutsidePercentile",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[95],version:"1.0"}),qt({name:"delay",category:"Transform",params:[{name:"steps",type:"int"}],defaultParams:[1],version:"1.0"}),qt({name:"exponentialMovingAverage",category:"Calculate",params:[{name:"windowSize",type:"int_or_interval",options:["5","7","10","5min","10min","30min","1hour"]}],defaultParams:[10],version:"1.0"}),qt({name:"fallbackSeries",category:"Special",params:[{name:"fallback",type:"string"}],defaultParams:["constantLine(0)"],version:"1.0"}),qt({name:"grep",category:"Filter Series",params:[{name:"grep",type:"string"}],defaultParams:["grep"],version:"1.0"}),qt({name:"groupByNodes",category:"Combine",params:[{name:"function",type:"string",options:["sum","avg","maxSeries"]},{name:"node",type:"int",options:[0,1,2,3,4,5,6,7,8,9,10,12],multiple:!0}],defaultParams:["sum",3],version:"1.0"}),qt({name:"integralByInterval",category:"Transform",params:[{name:"intervalUnit",type:"select",options:["1h","6h","12h","1d","2d","7d","14d","30d"]}],defaultParams:["1d"],version:"1.0"}),qt({name:"interpolate",category:"Transform",params:[{name:"limit",type:"int",optional:!0}],defaultParams:[],version:"1.0"}),qt({name:"invert",category:"Transform",version:"1.0"}),qt({name:"isNonNull",category:"Combine",version:"1.0"}),qt({name:"linearRegression",category:"Calculate",params:[{name:"startSourceAt",type:"select",options:["-1h","-6h","-12h","-1d","-2d","-7d","-14d","-30d"],optional:!0},{name:"endSourceAt",type:"select",options:["-1h","-6h","-12h","-1d","-2d","-7d","-14d","-30d"],optional:!0}],defaultParams:[],version:"1.0"}),qt({name:"mapSeries",shortName:"map",params:[{name:"node",type:"int"}],defaultParams:[3],category:"Combine",version:"1.0"}),qt({name:"movingMin",category:"Calculate",params:[{name:"windowSize",type:"int_or_interval",options:["5","7","10","5min","10min","30min","1hour"]}],defaultParams:[10],version:"1.0"}),qt({name:"movingMax",category:"Calculate",params:[{name:"windowSize",type:"int_or_interval",options:["5","7","10","5min","10min","30min","1hour"]}],defaultParams:[10],version:"1.0"}),qt({name:"movingSum",category:"Calculate",params:[{name:"windowSize",type:"int_or_interval",options:["5","7","10","5min","10min","30min","1hour"]}],defaultParams:[10],version:"1.0"}),qt({name:"multiplySeriesWithWildcards",category:"Combine",params:[{name:"position",type:"int",options:[0,1,2,3,4,5,6,7,8,9,10,12],multiple:!0}],defaultParams:[2],version:"1.0"}),qt({name:"offsetToZero",category:"Transform",version:"1.0"}),qt({name:"pow",category:"Transform",params:[{name:"factor",type:"int"}],defaultParams:[10],version:"1.0"}),qt({name:"powSeries",category:"Transform",params:Ft,defaultParams:[""],version:"1.0"}),qt({name:"reduceSeries",shortName:"reduce",params:[{name:"function",type:"string",options:["asPercent","diffSeries","divideSeries"]},{name:"reduceNode",type:"int",options:[0,1,2,3,4,5,6,7,8,9,10,11,12,13]},{name:"reduceMatchers",type:"string",multiple:!0}],defaultParams:["asPercent",2,"used_bytes"],category:"Combine",version:"1.0"}),qt({name:"removeBetweenPercentile",category:"Filter Series",params:[{name:"n",type:"int"}],defaultParams:[95],version:"1.0"}),qt({name:"removeEmptySeries",category:"Filter Series",version:"1.0"}),qt({name:"squareRoot",category:"Transform",version:"1.0"}),qt({name:"timeSlice",category:"Transform",params:[{name:"startSliceAt",type:"select",options:["-1h","-6h","-12h","-1d","-2d","-7d","-14d","-30d"]},{name:"endSliceAt",type:"select",options:["-1h","-6h","-12h","-1d","-2d","-7d","-14d","-30d"],optional:!0}],defaultParams:["-1h"],version:"1.0"}),qt({name:"weightedAverage",category:"Combine",params:[{name:"other",type:"value_or_series",optional:!0},{name:"node",type:"int",options:[0,1,2,3,4,5,6,7,8,9,10,12]}],defaultParams:["#A",4],version:"1.0"}),qt({name:"seriesByTag",category:"Special",params:[{name:"tagExpression",type:"string",multiple:!0}],version:"1.1"}),qt({name:"groupByTags",category:"Combine",params:[{name:"function",type:"string",options:["sum","avg","maxSeries"]},{name:"tag",type:"string",multiple:!0}],defaultParams:["sum","tag"],version:"1.1"}),qt({name:"aliasByTags",category:"Alias",params:[{name:"tag",type:"string",multiple:!0}],defaultParams:["tag"],version:"1.1"});class Dt{constructor(e,t){Ct(this,"def",void 0),Ct(this,"params",void 0),Ct(this,"text",void 0),Ct(this,"hidden",void 0),this.def=e,this.params=[],t&&t.withDefaultParams&&e.defaultParams&&(this.params=e.defaultParams.slice(0)),this.updateText()}render(e,t){const a=this.def.name+"(",n=(0,v.map)(this.params,((e,a)=>{let n;if(a<this.def.params.length?n=this.def.params[a].type:(0,v.get)((0,v.last)(this.def.params),"multiple")&&(n=(0,v.get)((0,v.last)(this.def.params),"type")),(0,v.includes)(["value_or_series","boolean","int","float","node","int_or_infinity"],n))return e;const r=(0,v.isString)(e)?t(e):e;return(0,v.includes)(["int_or_interval","node_or_tag"],n)&&(0,v.isFinite)(+r)?(0,v.toString)(e):"'"+e+"'"}));for(;""===n[n.length-1];)n.pop();return e&&n.unshift(e),a+n.join(", ")+")"}_hasMultipleParamsInString(e,t){return-1!==e.indexOf(",")&&(!(!this.def.params[t+1]||!this.def.params[t+1].optional)||!!(t+1>=this.def.params.length&&(0,v.get)((0,v.last)(this.def.params),"multiple")))}updateParam(e,t){this._hasMultipleParamsInString(e,t)?(0,v.each)(e.split(","),((e,a)=>{this.updateParam(e.trim(),t+a)})):(""===e&&(t>=this.def.params.length||this.def.params[t].optional)?this.params.splice(t,1):this.params[t]=e,this.updateText())}updateText(){if(0===this.params.length)return void(this.text=this.def.name+"()");let e=this.def.name+"(";e+=this.params.join(", "),e+=")",this.text=e}}function Et(e,t){return(t||Mt)[e]?(t||Mt)[e]:{name:e,params:[{name:"",type:"",multiple:!0}],defaultParams:[""],unknown:!0}}const Nt={createFuncInstance:function(e,t,a){return(0,v.isString)(e)&&(e=Et(e,a)),new Dt(e,t)},getFuncDef:Et,getFuncDefs:function(e,t){const a={};return(0,v.forEach)(t||Mt,(t=>{It(t,e)&&(a[t.name]=(0,v.assign)({},t,{params:(0,v.filter)(t.params,(t=>It(t,e)))}))})),a},parseFuncDefs:function(e){const t={};return(0,v.forEach)(e||{},((e,a)=>{if("Graph"===e.group)return;let n=e.description;n&&(n=n.replace(/:py:func:`(.+)( <[^>]*>)?`/g,"``$1``").replace(/.. seealso:: /g,"See also: ").replace(/.. code-block *:: *none/g,".. code-block::"));const r={name:e.name,description:n,category:e.group,params:[],defaultParams:[],fake:!1};/^seriesLists?$/.test((0,v.get)(e,"params[0].type",""))?e.params[0].multiple?e.params[0].required=!1:e.params.shift():r.fake=!0,(0,v.forEach)(e.params,(e=>{const t={name:e.name,type:"string",optional:!e.required,multiple:!!e.multiple,options:void 0};void 0!==e.default?e.default===1/0?r.defaultParams.push("inf"):r.defaultParams.push((0,v.toString)(e.default)):e.suggestions?r.defaultParams.push((0,v.toString)(e.suggestions[0])):r.defaultParams.push(""),"boolean"===e.type?(t.type="boolean",t.options=["true","false"]):"integer"===e.type?t.type="int":"float"===e.type?t.type="float":"node"===e.type?(t.type="node",t.options=["0","1","2","3","4","5","6","7","8","9","10","11","12"]):"nodeOrTag"===e.type?(t.type="node_or_tag",t.options=["name","0","1","2","3","4","5","6","7","8","9","10","11","12"]):"intOrInterval"===e.type?t.type="int_or_interval":"seriesList"===e.type?t.type="value_or_series":"intOrInf"===e.type&&(t.type="int_or_infinity"),e.options?t.options=(0,v.map)(e.options,v.toString):e.suggestions&&(t.options=(0,v.map)(e.suggestions,v.toString)),r.params.push(t)})),t[a]=r})),t}};function At(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const Ot={"=":n.AbstractLabelOperator.Equal,"!=":n.AbstractLabelOperator.NotEqual,"=~":n.AbstractLabelOperator.EqualRegEx,"!=~":n.AbstractLabelOperator.NotEqualRegEx};class Rt extends n.DataSourceApi{constructor(e){var t,a;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,f.J)();super(e),At(this,"basicAuth",void 0),At(this,"url",void 0),At(this,"name",void 0),At(this,"graphiteVersion",void 0),At(this,"supportsTags",void 0),At(this,"isMetricTank",void 0),At(this,"rollupIndicatorEnabled",void 0),At(this,"cacheTimeout",void 0),At(this,"withCredentials",void 0),At(this,"funcDefs",null),At(this,"funcDefsPromise",null),At(this,"_seriesRefLetters",void 0),At(this,"metricMappings",void 0),At(this,"convertResponseToDataFrames",(e=>{const t=[];if(!e||!e.data)return{data:t};const a=e.data.series||e.data;if(!(0,v.isArray)(a))throw{message:"Missing series in result",data:e};for(let r=0;r<a.length;r++){const s=a[r];s.title=s.target;for(let e=0;e<s.datapoints.length;e++)s.datapoints[e][1]*=1e3;const i=(0,n.toDataFrame)(s);if(s.meta){if(i.meta={custom:{requestMetaList:e.data.meta,seriesMetaList:s.meta}},this.rollupIndicatorEnabled){const e=_e(s.meta),t=Le(s.meta);e?i.meta.notices=[e]:t&&(i.meta.notices=[t])}0===r&&e.data.meta.stats&&(i.meta.stats=this.getRequestStats(e.data.meta))}t.push(i)}return{data:t}})),this.templateSrv=r,this.basicAuth=e.basicAuth,this.url=e.url,this.name=e.name,this.graphiteVersion=e.jsonData.graphiteVersion||Qe,this.metricMappings=(null===(t=e.jsonData.importConfiguration)||void 0===t||null===(a=t.loki)||void 0===a?void 0:a.mappings)||[],this.isMetricTank=e.jsonData.graphiteType===Ue.Metrictank,this.supportsTags=wt(this.graphiteVersion,"1.1"),this.cacheTimeout=e.cacheTimeout,this.rollupIndicatorEnabled=e.jsonData.rollupIndicatorEnabled,this.withCredentials=e.withCredentials,this.funcDefs=null,this.funcDefsPromise=null,this._seriesRefLetters="ABCDEFGHIJKLMNOPQRSTUVWXYZ"}getQueryOptionsInfo(){return{maxDataPoints:!0,cacheTimeout:!0,links:[{text:"Help",url:"http://docs.grafana.org/features/datasources/graphite/#using-graphite-in-grafana"}]}}getImportQueryConfiguration(){return{loki:{mappings:this.metricMappings}}}async exportToAbstractQueries(e){return e.map((e=>this.exportToAbstractQuery(e)))}exportToAbstractQuery(e){const t=new M(this,Object.assign({},e,{target:e.target||"",textEditor:!1}),(0,f.J)());t.parseTarget();let a=[];const r=this.getImportQueryConfiguration().loki;if(t.seriesByTagUsed)t.tags.forEach((e=>{a.push({name:e.key,operator:Ot[e.operator],value:e.value})}));else{const e=t.segments.map((e=>e.value));let s=r.mappings.filter((t=>t.matchers.length<=e.length));for(let t of s){t.matchers.concat().every(((t,r)=>{if(t.labelName){let i=e[r];if("*"===i)return!0;const o=(s=i).includes("*")||s.includes("{")?"^"+s.replace(/\*/g,".*").replace(/\{/g,"(").replace(/}/g,")").replace(/,/g,"|"):s;return a.push({name:t.labelName,operator:o!==i?n.AbstractLabelOperator.EqualRegEx:n.AbstractLabelOperator.Equal,value:o}),!0}var s;return e[r]===t.value||"*"===t.value}))}}return{refId:e.refId,labelMatchers:a}}query(e){const t={from:this.translateTime(e.range.raw.from,!1,e.timezone),until:this.translateTime(e.range.raw.to,!0,e.timezone),targets:e.targets,format:e.format,cacheTimeout:e.cacheTimeout||this.cacheTimeout,maxDataPoints:e.maxDataPoints},a=this.buildGraphiteParams(t,e.scopedVars);if(0===a.length)return(0,ft.of)({data:[]});this.isMetricTank&&a.push("meta=true");const n={method:"POST",url:"/render",data:a.join("&"),headers:{"Content-Type":"application/x-www-form-urlencoded"}};return this.addTracingHeaders(n,e),e.panelId&&(n.requestId=this.name+".panelId."+e.panelId),this.doGraphiteRequest(n).pipe((0,bt.U)(this.convertResponseToDataFrames))}addTracingHeaders(e,t){!this.url.match(/^http/)&&(t.dashboardId&&(e.headers["X-Dashboard-Id"]=t.dashboardId),t.panelId&&(e.headers["X-Panel-Id"]=t.panelId))}getRequestStats(e){const t=[];for(const a in e.stats){let n;a.endsWith(".ms")&&(n="ms"),t.push({displayName:a,value:e.stats[a],unit:n})}return t}parseTags(e){let t=[];return t=e.split(","),1===t.length&&(t=e.split(" "),""===t[0]&&(t=[])),t}interpolateVariablesInQueries(e,t){let a=e;return e&&e.length>0&&(a=e.map((e=>{var a;return Object.assign({},e,{datasource:this.getRef(),target:this.templateSrv.replace(null!==(a=e.target)&&void 0!==a?a:"",t)})}))),a}annotationQuery(e){if(e.annotation.target){const t=this.templateSrv.replace(e.annotation.target,{},"glob"),a={range:e.range,targets:[{target:t}],format:"json",maxDataPoints:100};return(0,yt.n)(this.query(a).pipe((0,bt.U)((t=>{const a=[];for(let n=0;n<t.data.length;n++){const r=t.data[n];for(let t=0;t<r.length;t++){const n=r.fields[0].values.get(t);r.fields[1].values.get(t)&&a.push({annotation:e.annotation,time:n,title:r.name})}}return a}))))}{const t=this.templateSrv.replace(e.annotation.tags);return this.events({range:e.range,tags:t}).then((t=>{const a=[];if(!(0,v.isArray)(t.data))return console.error(`Unable to get annotations from ${t.url}.`),[];for(let n=0;n<t.data.length;n++){const r=t.data[n];let s=r.tags;(0,v.isString)(r.tags)&&(s=this.parseTags(r.tags)),a.push({annotation:e.annotation,time:1e3*r.when,title:r.what,tags:s,text:r.data})}return a}))}}events(e){try{let t="";return e.tags&&(t="&tags="+e.tags),(0,yt.n)(this.doGraphiteRequest({method:"GET",url:"/events/get_data?from="+this.translateTime(e.range.raw.from,!1,e.timezone)+"&until="+this.translateTime(e.range.raw.to,!0,e.timezone)+t}))}catch(e){return Promise.reject(e)}}targetContainsTemplate(e){var t;return this.templateSrv.containsTemplate(null!==(t=e.target)&&void 0!==t?t:"")}translateTime(e,t,a){if((0,v.isString)(e)){if("now"===e)return"now";if(e.indexOf("now-")>=0&&-1===e.indexOf("/"))return e=(e=(e=e.substring(3)).replace("m","min")).replace("M","mon");e=n.dateMath.parse(e,t,a)}return t?e.get("s")&&e.add(1,"s"):!1===t&&e.get("s")&&e.subtract(1,"s"),e.unix()}metricFindQuery(e,t){const a=t||{};let n=this.templateSrv.replace(e,(0,Pt._6)({query:e,wildcardChar:"",options:t})),r=n.match(/^tag_values\((.*)\)$/),s=r?r[1].split(",").filter((e=>!!e)):void 0;if(s)return a.limit=1e4,this.getTagValuesAutoComplete(s.slice(1),s[0],void 0,a);if(r=n.match(/^tags\((.*)\)$/),s=r?r[1].split(",").filter((e=>!!e)):void 0,s)return a.limit=1e4,this.getTagsAutoComplete(s,void 0,a);let i,o=e.match(/^expand\((.*)\)$/);return e=o?o[1]:e,n=this.templateSrv.replace(e,(0,Pt._6)({query:e,wildcardChar:"*",options:t})),a.range&&(i={from:this.translateTime(a.range.from,!1,a.timezone),until:this.translateTime(a.range.to,!0,a.timezone)}),o?this.requestMetricExpand(n,a.requestId,i):this.requestMetricFind(n,a.requestId,i)}requestMetricFind(e,t,a){const n={method:"POST",url:"/metrics/find",params:{},data:`query=${e}`,headers:{"Content-Type":"application/x-www-form-urlencoded"},requestId:t};return a&&(n.params.from=a.from,n.params.until=a.until),(0,yt.n)(this.doGraphiteRequest(n).pipe((0,bt.U)((e=>(0,v.map)(e.data,(e=>({text:e.text,expandable:!!e.expandable})))))))}requestMetricExpand(e,t,a){const n={method:"GET",url:"/metrics/expand",params:{query:e},headers:{"Content-Type":"application/x-www-form-urlencoded"},requestId:t};return a&&(n.params.from=a.from,n.params.until=a.until),(0,yt.n)(this.doGraphiteRequest(n).pipe((0,bt.U)((e=>(0,v.map)(e.data.results,(e=>({text:e,expandable:!1})))))))}getTags(e){const t=e||{},a={method:"GET",url:"/tags",requestId:t.requestId};return t.range&&(a.params.from=this.translateTime(t.range.from,!1,t.timezone),a.params.until=this.translateTime(t.range.to,!0,t.timezone)),(0,yt.n)(this.doGraphiteRequest(a).pipe((0,bt.U)((e=>(0,v.map)(e.data,(e=>({text:e.tag,id:e.id})))))))}getTagValues(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t={method:"GET",url:"/tags/"+this.templateSrv.replace(e.key),requestId:e.requestId};return e.range&&(t.params.from=this.translateTime(e.range.from,!1,e.timezone),t.params.until=this.translateTime(e.range.to,!0,e.timezone)),(0,yt.n)(this.doGraphiteRequest(t).pipe((0,bt.U)((e=>e.data&&e.data.values?(0,v.map)(e.data.values,(e=>({text:e.value,id:e.id}))):[]))))}getTagsAutoComplete(e,t,a){const n=a||{},r={method:"GET",url:"/tags/autoComplete/tags",params:{expr:(0,v.map)(e,(e=>this.templateSrv.replace((e||"").trim())))},requestId:n.requestId};return t&&(r.params.tagPrefix=t),n.limit&&(r.params.limit=n.limit),n.range&&(r.params.from=this.translateTime(n.range.from,!1,n.timezone),r.params.until=this.translateTime(n.range.to,!0,n.timezone)),(0,yt.n)(this.doGraphiteRequest(r).pipe(Bt()))}getTagValuesAutoComplete(e,t,a,n){const r=n||{},s={method:"GET",url:"/tags/autoComplete/values",params:{expr:(0,v.map)(e,(e=>this.templateSrv.replace((e||"").trim()))),tag:this.templateSrv.replace((t||"").trim())},requestId:r.requestId};return a&&(s.params.valuePrefix=a),r.limit&&(s.params.limit=r.limit),r.range&&(s.params.from=this.translateTime(r.range.from,!1,r.timezone),s.params.until=this.translateTime(r.range.to,!0,r.timezone)),(0,yt.n)(this.doGraphiteRequest(s).pipe(Bt()))}getVersion(e){const t={method:"GET",url:"/version",requestId:(e||{}).requestId};return(0,yt.n)(this.doGraphiteRequest(t).pipe((0,bt.U)((e=>{if(e.data){return new kt(e.data).isValid()?e.data:""}return""})),(0,St.K)((()=>(0,ft.of)("")))))}createFuncInstance(e,t){return Nt.createFuncInstance(e,t,this.funcDefs)}getFuncDef(e){return Nt.getFuncDef(e,this.funcDefs)}waitForFuncDefsLoaded(){return this.getFuncDefs()}getFuncDefs(){if(null!==this.funcDefsPromise)return this.funcDefsPromise;if(!wt(this.graphiteVersion,"1.1"))return this.funcDefs=Nt.getFuncDefs(this.graphiteVersion),this.funcDefsPromise=Promise.resolve(this.funcDefs),this.funcDefsPromise;return(0,yt.n)(this.doGraphiteRequest({method:"GET",url:"/functions",responseType:"text"}).pipe((0,bt.U)((e=>{const t=JSON.parse(e.data.replace(/"default": ?Infinity/g,'"default": 1e9999'));return this.funcDefs=Nt.parseFuncDefs(t),this.funcDefs})),(0,St.K)((e=>(console.error("Fetching graphite functions error",e),this.funcDefs=Nt.getFuncDefs(this.graphiteVersion),(0,ft.of)(this.funcDefs))))))}testDatasource(){return(0,yt.n)(this.query({panelId:3,rangeRaw:{from:"now-1h",to:"now"},range:{raw:{from:"now-1h",to:"now"}},targets:[{target:"constantLine(100)"}],maxDataPoints:300})).then((()=>({status:"success",message:"Data source is working"})))}doGraphiteRequest(e){return(this.basicAuth||this.withCredentials)&&(e.withCredentials=!0),this.basicAuth&&(e.headers=e.headers||{},e.headers.Authorization=this.basicAuth),e.url=this.url+e.url,e.inspect={type:"graphite"},(0,y.getBackendSrv)().fetch(e).pipe((0,St.K)((e=>(0,vt._)(function(e){var t,a;if(e&&500===e.status&&null!==(t=e.data)&&void 0!==t&&null!==(a=t.message)&&void 0!==a&&a.startsWith("<body")){const t=(0,v.last)(e.data.message.replace(/(<([^>]+)>)/gi,"").trim().split(/\n/)).replace(/u?&#[^;]+;/g,"");e.data.message=`Graphite encountered an unexpected error while handling your request. ${t}`}return e}(e)))))}buildGraphiteParams(e,t){const a=["from","until","rawData","format","maxDataPoints","cacheTimeout"],n=[],r={};let s,i,o;const l=/\#([A-Z])/g,u=/'(\d+)m'/gi;let c=!1;function m(e){return e.replace("m","min").replace("M","mon")}for(e.format="json",o=0;o<e.targets.length;o++)s=e.targets[o],s.target&&(s.refId||(s.refId=this._seriesRefLetters[o]),i=this.templateSrv.replace(s.target,t),i=i.replace(u,m),r[s.refId]=i);function p(e,t){return r[t]||e}for(o=0;o<e.targets.length;o++)s=e.targets[o],s.target&&(i=r[s.refId],i=i.replace(l,p),r[s.refId]=i,s.hide||(c=!0,n.push("target="+encodeURIComponent(i))));return(0,v.each)(e,((e,t)=>{-1!==(0,v.indexOf)(a,t)&&e&&n.push(t+"="+encodeURIComponent(e))})),c?n:[]}}function Bt(){return(0,xt.z)((0,bt.U)((e=>e.data?(0,v.map)(e.data,(e=>({text:e}))):[])))}class $t{}var _t,Lt,Vt;Vt="partials/annotations.editor.html",(Lt="templateUrl")in(_t=$t)?Object.defineProperty(_t,Lt,{value:Vt,enumerable:!0,configurable:!0,writable:!0}):_t[Lt]=Vt;const Gt=new n.DataSourcePlugin(Rt).setQueryEditor((function(e){let{datasource:t,onRunQuery:a,onChange:n,query:r,range:s,queries:i}=e;return(0,z.jsx)(Q,{datasource:t,onRunQuery:a,onChange:n,query:r,queries:i,range:s,children:Pe||(Pe=(0,z.jsx)(Fe,{}))})})).setConfigEditor(gt).setMetadataInspector(Ge).setAnnotationQueryCtrl($t)},20002:(e,t,a)=>{a.d(t,{Z:()=>r});var n=a(68404);function r(e){var t=(0,n.useRef)();return(0,n.useEffect)((function(){t.current=e})),t.current}}}]);
- //# sourceMappingURL=graphitePlugin.03dad8816dcd2ba68863.js.map
|