diff --git a/app/vmselect/vmui/asset-manifest.json b/app/vmselect/vmui/asset-manifest.json index 3b827eeff..b1d52c0d0 100644 --- a/app/vmselect/vmui/asset-manifest.json +++ b/app/vmselect/vmui/asset-manifest.json @@ -1,13 +1,13 @@ { "files": { - "main.css": "./static/css/main.d871147a.css", - "main.js": "./static/js/main.621c4b4d.js", + "main.css": "./static/css/main.d781989c.css", + "main.js": "./static/js/main.68e2aae8.js", "static/js/685.f772060c.chunk.js": "./static/js/685.f772060c.chunk.js", "static/media/MetricsQL.md": "./static/media/MetricsQL.a00044c91d9781cf8557.md", "index.html": "./index.html" }, "entrypoints": [ - "static/css/main.d871147a.css", - "static/js/main.621c4b4d.js" + "static/css/main.d781989c.css", + "static/js/main.68e2aae8.js" ] } \ No newline at end of file diff --git a/app/vmselect/vmui/index.html b/app/vmselect/vmui/index.html index c886e92f8..0dd3f5db0 100644 --- a/app/vmselect/vmui/index.html +++ b/app/vmselect/vmui/index.html @@ -1 +1 @@ -
'+(a?i:si(i,!0))+"
\n":""+(a?i:si(i,!0))+"
\n"}blockquote(e){let{tokens:t}=e;const n=this.parser.parse(t);return"\n".concat(n,"\n")}html(e){let{text:t}=e;return t}heading(e){let{tokens:t,depth:n}=e;return"
".concat(this.parser.parseInline(t),"
\n")}table(e){let t="",n="";for(let a=0;a".concat(t,"
")}br(e){return"An error occurred:
"+si(n.message+"",!0)+"";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function ol(e,t){return al.parse(e,t)}ol.options=ol.setOptions=function(e){return al.setOptions(e),ol.defaults=al.defaults,ti(ol.defaults),ol},ol.getDefaults=Xo,ol.defaults=ei,ol.use=function(){return al.use(...arguments),ol.defaults=al.defaults,ti(ol.defaults),ol},ol.walkTokens=function(e,t){return al.walkTokens(e,t)},ol.parseInline=al.parseInline,ol.Parser=nl,ol.parser=nl.parse,ol.Renderer=el,ol.TextRenderer=tl,ol.Lexer=Xi,ol.lexer=Xi.lex,ol.Tokenizer=vi,ol.Hooks=rl,ol.parse=ol;ol.options,ol.setOptions,ol.use,ol.walkTokens,ol.parseInline,nl.parse,Xi.lex;const il=n.p+"static/media/MetricsQL.a00044c91d9781cf8557.md",ll=e=>{const t='$1 target="_blank" class="'.concat("vm-link vm-link_colored",'" $2').concat("https://docs.victoriametrics.com/MetricsQL.html","#");return e.replace(/({let t="";return Array.from(e).map((e=>{var n;const r="h3"===e.tagName.toLowerCase();return t=r?null!==(n=e.textContent)&&void 0!==n?n:"":t,r?null:((e,t)=>{var n;const r=null!==(n=t.textContent)&&void 0!==n?n:"",a=(e=>{const t=[];let n=e.nextElementSibling;for(;n&&"p"===n.tagName.toLowerCase();)n&&t.push(n),n=n.nextElementSibling;return t})(t).map((e=>{var t;return null!==(t=e.outerHTML)&&void 0!==t?t:""})).join("\n");return{type:e,value:r,description:ll(a),icon:Nt(gr,{})}})(t,e)})).filter(Boolean)},cl=()=>{const{metricsQLFunctions:e}=Cn(),t=En();return(0,r.useEffect)((()=>{e.length||(async()=>{try{const e=await fetch(il),n=(e=>{const t=document.createElement("div");t.innerHTML=ol(e);const n=t.querySelectorAll("".concat("h3",", ").concat("h4"));return sl(n)})(await e.text());t({type:"SET_METRICSQL_FUNCTIONS",payload:n})}catch(Pp){console.error("Error fetching or processing the MetricsQL.md file:",Pp)}})()}),[]),e},ul=e=>{let{value:t,anchorEl:n,caretPosition:a,hasHelperText:i,onSelect:l,onFoundOptions:s}=e;const[c,u]=(0,r.useState)({top:0,left:0}),d=cl(),h=(0,r.useMemo)((()=>{if(a[0]!==a[1])return{beforeCursor:t,afterCursor:""};return{beforeCursor:t.substring(0,a[0]),afterCursor:t.substring(a[1])}}),[t,a]),m=(0,r.useMemo)((()=>{const e=h.beforeCursor.split(/\s(or|and|unless|default|ifnot|if|group_left|group_right)\s|}|\+|\|-|\*|\/|\^/i);return e[e.length-1]}),[h]),p=(0,r.useMemo)((()=>{const e=[...m.matchAll(/\w+\((?
\n This table returns a list of metrics with the highest cardinality.\n The cardinality of a metric is the number of time series associated with that metric,\n where each time series is defined as a unique combination of key-value label pairs.\n
\n\n When looking to reduce the number of active series in your data source,\n you can start by inspecting individual metrics with high cardinality\n (i.e. that have lots of active time series associated with them),\n since that single metric contributes a large fraction of the series that make up your total series count.\n
",seriesCountByLabelName:"\n\n This table returns a list of the labels with the highest number of series.\n
\n\n Use this table to identify labels that are storing dimensions with high cardinality\n (many different label values).\n
\n\n It is recommended to choose labels such that they have a finite set of values,\n since every unique combination of key-value label pairs creates a new time series\n and therefore can dramatically increase the number of time series in your system.\n
",seriesCountByFocusLabelValue:"\n\n This table returns a list of unique label values per selected label.\n
\n\n Use this table to identify label values that are storing per each selected series.\n
",labelValueCountByLabelName:"\n\n This table returns a list of labels with the highest number of the unique values.\n
\n ",seriesCountByLabelValuePair:"\n\n This table returns a list of the label values pairs with the highest number of series.\n
\n\n Use this table to identify unique label values pairs. This helps to identify same labels \n is applied to count timeseries in your system, since every unique combination of key-value label pairs \n creates a new time series and therefore can dramatically increase the number of time series in your system\n
"}}get tablesHeaders(){return{seriesCountByMetricName:hm,seriesCountByLabelName:mm,seriesCountByFocusLabelValue:pm,seriesCountByLabelValuePair:fm,labelValueCountByLabelName:vm}}totalSeries(e){return"labelValueCountByLabelName"===e?-1:arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.tsdbStatus.totalSeriesPrev:this.tsdbStatus.totalSeries}}const hm=[{id:"name",label:"Metric name"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of a metric to the total number of series"},{id:"action",label:""}],mm=[{id:"name",label:"Label name"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of the label to the total number of series"},{id:"action",label:""}],pm=[{id:"name",label:"Label value"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total"},{disablePadding:!1,id:"action",label:"",numeric:!1}],fm=[{id:"name",label:"Label=value pair"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total",info:"Shows the share of the label value pair to the total number of series"},{id:"action",label:""}],vm=[{id:"name",label:"Label name"},{id:"value",label:"Number of unique values"},{id:"action",label:""}],gm=()=>{const e=new dm,[t]=He(),n=t.get("match"),a=t.get("focusLabel"),i=+(t.get("topN")||10),l=t.get("date")||o()().tz().format(Ot),s=Qa(l),c=(0,r.useRef)(),{serverUrl:u}=Mt(),[d,h]=(0,r.useState)(!1),[m,p]=(0,r.useState)(),[f,v]=(0,r.useState)(e.defaultTSDBStatus),[g,y]=(0,r.useState)(!1),_=async e=>{const t=await fetch(e);if(t.ok)return await t.json();throw new Error("Request failed with status ".concat(t.status))},b=async t=>{if(!u)return;p(""),h(!0),v(e.defaultTSDBStatus);const r={...t,date:t.date,topN:0,match:"",focusLabel:""},a={...t,date:o()(t.date).subtract(1,"day").format(Ot)},i=[um(u,t),um(u,a)];s!==l&&(t.match||t.focusLabel)&&i.push(um(u,r));try{var d,m,g,y,b,w,k,x,S,C;const[e,t,r]=await Promise.all(i.map(_)),a={...t.data},{data:o}=r||c.current||e;c.current={data:o};const l={...e.data,totalSeries:(null===(d=e.data)||void 0===d?void 0:d.totalSeries)||(null===(m=e.data)||void 0===m||null===(g=m.headStats)||void 0===g?void 0:g.numSeries)||0,totalLabelValuePairs:(null===(y=e.data)||void 0===y?void 0:y.totalLabelValuePairs)||(null===(b=e.data)||void 0===b||null===(w=b.headStats)||void 0===w?void 0:w.numLabelValuePairs)||0,seriesCountByLabelName:(null===(k=e.data)||void 0===k?void 0:k.seriesCountByLabelName)||[],seriesCountByFocusLabelValue:(null===(x=e.data)||void 0===x?void 0:x.seriesCountByFocusLabelValue)||[],totalSeriesByAll:(null===o||void 0===o?void 0:o.totalSeries)||(null===o||void 0===o||null===(S=o.headStats)||void 0===S?void 0:S.numSeries)||f.totalSeriesByAll||0,totalSeriesPrev:(null===a||void 0===a?void 0:a.totalSeries)||(null===a||void 0===a||null===(C=a.headStats)||void 0===C?void 0:C.numSeries)||0},s=null===n||void 0===n?void 0:n.replace(/[{}"]/g,"");l.seriesCountByLabelValuePair=l.seriesCountByLabelValuePair.filter((e=>e.name!==s)),((e,t)=>{Object.keys(e).forEach((n=>{const r=n,a=e[r],o=t[r];Array.isArray(a)&&Array.isArray(o)&&a.forEach((e=>{var t;const n=null===(t=o.find((t=>t.name===e.name)))||void 0===t?void 0:t.value;e.diff=n?e.value-n:0,e.valuePrev=n||0}))}))})(l,a),v(l),h(!1)}catch(Pp){h(!1),Pp instanceof Error&&p("".concat(Pp.name,": ").concat(Pp.message))}};return(0,r.useEffect)((()=>{b({topN:i,match:n,date:l,focusLabel:a})}),[u,n,a,i,l]),(0,r.useEffect)((()=>{m&&(v(e.defaultTSDBStatus),h(!1))}),[m]),(0,r.useEffect)((()=>{const e=Je(u);y(!!e)}),[u]),e.tsdbStatusData=f,{isLoading:d,appConfigurator:e,error:m,isCluster:g}},ym={seriesCountByMetricName:e=>{let{query:t}=e;return _m("__name__",t)},seriesCountByLabelName:e=>{let{query:t}=e;return"{".concat(t,'!=""}')},seriesCountByFocusLabelValue:e=>{let{query:t,focusLabel:n}=e;return _m(n,t)},seriesCountByLabelValuePair:e=>{let{query:t}=e;const n=t.split("="),r=n[0],a=n.slice(1).join("=");return _m(r,a)},labelValueCountByLabelName:e=>{let{query:t,match:n}=e;return""===n?"{".concat(t,'!=""}'):"".concat(n.replace("}",""),", ").concat(t,'!=""}')}},_m=(e,t)=>e?"{"+e+"="+JSON.stringify(t)+"}":"",bm=e=>{var t;let{totalSeries:n=0,totalSeriesPrev:r=0,totalSeriesAll:a=0,seriesCountByMetricName:o=[],isPrometheus:i}=e;const{isMobile:l}=ea(),[s]=He(),c=s.get("match"),u=s.get("focusLabel"),d=/__name__/.test(c||""),h=(null===(t=o[0])||void 0===t?void 0:t.value)/a*100,m=n-r,p=Math.abs(m)/r*100,f=[{title:"Total series",value:n.toLocaleString("en-US"),dynamic:n&&r&&!i?"".concat(p.toFixed(2),"%"):"",display:!u,info:'The total number of active time series. \n A time series is uniquely identified by its name plus a set of its labels. \n For example, temperature{city="NY",country="US"} and temperature{city="SF",country="US"} \n are two distinct series, since they differ by the city label.'},{title:"Percentage from total",value:isNaN(h)?"-":"".concat(h.toFixed(2),"%"),display:d,info:"The share of these series in the total number of time series."}].filter((e=>e.display));return f.length?Nt("div",{className:Cr()({"vm-cardinality-totals":!0,"vm-cardinality-totals_mobile":l}),children:f.map((e=>{let{title:t,value:n,info:a,dynamic:o}=e;return Nt("div",{className:"vm-cardinality-totals-card",children:[Nt("h4",{className:"vm-cardinality-totals-card__title",children:[t,a&&Nt(_a,{title:Nt("p",{className:"vm-cardinality-totals-card__tooltip",children:a}),children:Nt("div",{className:"vm-cardinality-totals-card__info-icon",children:Nt(In,{})})})]}),Nt("span",{className:"vm-cardinality-totals-card__value",children:n}),!!o&&Nt(_a,{title:"in relation to the previous day: ".concat(r.toLocaleString("en-US")),children:Nt("span",{className:Cr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":m<0,"vm-dynamic-number_negative vm-dynamic-number_up":m>0}),children:o})})]},t)}))}):null},wm=(e,t)=>{const[n]=He(),a=n.get(t)?n.get(t):e,[o,i]=(0,r.useState)(a);return(0,r.useEffect)((()=>{a!==o&&i(a)}),[a]),[o,i]},km=e=>{let{isPrometheus:t,isCluster:n,...a}=e;const{isMobile:o}=ea(),[i]=He(),{setSearchParamsFromKeys:l}=ho(),s=i.get("tips")||"",[c,u]=wm("","match"),[d,h]=wm("","focusLabel"),[m,p]=wm(10,"topN"),f=(0,r.useMemo)((()=>m<0?"Number must be bigger than zero":""),[m]),v=()=>{l({match:c,topN:m,focusLabel:d})};return(0,r.useEffect)((()=>{const e=i.get("match"),t=+(i.get("topN")||10),n=i.get("focusLabel");e!==c&&u(e||""),t!==m&&p(t),n!==d&&h(n||"")}),[i]),Nt("div",{className:Cr()({"vm-cardinality-configurator":!0,"vm-cardinality-configurator_mobile":o,"vm-block":!0,"vm-block_mobile":o}),children:[Nt("div",{className:"vm-cardinality-configurator-controls",children:[Nt("div",{className:"vm-cardinality-configurator-controls__query",children:Nt(Wa,{label:"Time series selector",type:"string",value:c,onChange:u,onEnter:v})}),Nt("div",{className:"vm-cardinality-configurator-controls__item",children:Nt(Wa,{label:"Focus label",type:"text",value:d||"",onChange:h,onEnter:v,endIcon:Nt(_a,{title:Nt("div",{children:Nt("p",{children:"To identify values with the highest number of series for the selected label."})}),children:Nt(sr,{})})})}),Nt("div",{className:"vm-cardinality-configurator-controls__item vm-cardinality-configurator-controls__item_limit",children:Nt(Wa,{label:"Limit entries",type:"number",value:t?10:m,error:f,disabled:t,helperText:t?"not available for Prometheus":"",onChange:e=>{const t=+e;p(isNaN(t)?0:t)},onEnter:v})})]}),Nt("div",{className:"vm-cardinality-configurator-bottom",children:[Nt(bm,{isPrometheus:t,isCluster:n,...a}),n&&Nt("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Nt(Il,{href:"https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cardinality-explorer-statistic-inaccuracy",withIcon:!0,children:[Nt(ir,{}),"Statistic inaccuracy explanation"]})}),Nt("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Nt(Il,{href:"https://docs.victoriametrics.com/#cardinality-explorer",withIcon:!0,children:[Nt(ir,{}),"Documentation"]})}),Nt("div",{className:"vm-cardinality-configurator-bottom__execute",children:[Nt(_a,{title:s?"Hide tips":"Show tips",children:Nt(ma,{variant:"text",color:s?"warning":"gray",startIcon:Nt(hr,{}),onClick:()=>{const e=i.get("tips")||"";l({tips:e?"":"true"})},ariaLabel:"visibility tips"})}),Nt(ma,{variant:"text",startIcon:Nt(Pn,{}),onClick:()=>{l({match:"",focusLabel:""})},children:"Reset"}),Nt(ma,{startIcon:Nt(qn,{}),onClick:v,children:"Execute Query"})]})]})]})};function xm(e){const{order:t,orderBy:n,onRequestSort:r,headerCells:a}=e;return Nt("thead",{className:"vm-table-header vm-cardinality-panel-table__header",children:Nt("tr",{className:"vm-table__row vm-table__row_header",children:a.map((e=>{return Nt("th",{className:Cr()({"vm-table-cell vm-table-cell_header":!0,"vm-table-cell_sort":"action"!==e.id&&"percentage"!==e.id,"vm-table-cell_right":"action"===e.id}),onClick:(a=e.id,e=>{r(e,a)}),children:Nt("div",{className:"vm-table-cell__content",children:[e.info?Nt(_a,{title:e.info,children:[Nt("div",{className:"vm-metrics-content-header__tip-icon",children:Nt(In,{})}),e.label]}):Nt(Ct.FK,{children:e.label}),"action"!==e.id&&"percentage"!==e.id&&Nt("div",{className:Cr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":n===e.id,"vm-table__sort-icon_desc":"desc"===t&&n===e.id}),children:Nt(Hn,{})})]})},e.id);var a}))})})}const Sm=["date","timestamp","time"];function Cm(e,t,n){const r=e[n],a=t[n],i=Sm.includes("".concat(n))?o()("".concat(r)).unix():r,l=Sm.includes("".concat(n))?o()("".concat(a)).unix():a;return li?1:0}function Em(e,t){return"desc"===e?(e,n)=>Cm(e,n,t):(e,n)=>-Cm(e,n,t)}function Nm(e,t){const n=e.map(((e,t)=>[e,t]));return n.sort(((e,n)=>{const r=t(e[0],n[0]);return 0!==r?r:e[1]-n[1]})),n.map((e=>e[0]))}const Am=e=>{let{rows:t,headerCells:n,defaultSortColumn:a,tableCells:o}=e;const[i,l]=(0,r.useState)("desc"),[s,c]=(0,r.useState)(a),u=Nm(t,Em(i,s));return Nt("table",{className:"vm-table vm-cardinality-panel-table",children:[Nt(xm,{order:i,orderBy:s,onRequestSort:(e,t)=>{l(s===t&&"asc"===i?"desc":"asc"),c(t)},rowCount:t.length,headerCells:n}),Nt("tbody",{className:"vm-table-header",children:u.map((e=>Nt("tr",{className:"vm-table__row",children:o(e)},e.name)))})]})},Mm=e=>{let{row:t,totalSeries:n,totalSeriesPrev:r,onActionClick:a}=e;const o=n>0?t.value/n*100:-1,i=r>0?t.valuePrev/r*100:-1,l=[o,i].some((e=>-1===e)),s=o-i,c=l?"":"".concat(s.toFixed(2),"%"),u=()=>{a(t.name)};return Nt(Ct.FK,{children:[Nt("td",{className:"vm-table-cell",children:Nt("span",{className:"vm-link vm-link_colored",onClick:u,children:t.name})},t.name),Nt("td",{className:"vm-table-cell",children:[t.value,!!t.diff&&Nt(_a,{title:"in relation to the previous day: ".concat(t.valuePrev),children:Nt("span",{className:Cr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive":t.diff<0,"vm-dynamic-number_negative":t.diff>0}),children:["\xa0",t.diff>0?"+":"",t.diff]})})]},t.value),o>0&&Nt("td",{className:"vm-table-cell",children:Nt("div",{className:"vm-cardinality-panel-table__progress",children:[Nt(Fl,{value:o}),c&&Nt(_a,{title:"in relation to the previous day",children:Nt("span",{className:Cr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":s<0,"vm-dynamic-number_negative vm-dynamic-number_up":s>0}),children:c})})]})},t.progressValue),Nt("td",{className:"vm-table-cell vm-table-cell_right",children:Nt("div",{className:"vm-table-cell__content",children:Nt(_a,{title:"Filter by ".concat(t.name),children:Nt(ma,{variant:"text",size:"small",onClick:u,children:Nt(Yn,{})})})})},"action")]})},Tm=e=>{let{data:t}=e;const[n,a]=(0,r.useState)([]),[o,i]=(0,r.useState)([0,0]);return(0,r.useEffect)((()=>{const e=t.sort(((e,t)=>t.value-e.value)),n=(e=>{const t=e.map((e=>e.value)),n=Math.ceil(t[0]||1),r=n/9;return new Array(11).fill(n+r).map(((e,t)=>Math.round(e-r*t)))})(e);i(n),a(e.map((e=>({...e,percentage:e.value/n[0]*100}))))}),[t]),Nt("div",{className:"vm-simple-bar-chart",children:[Nt("div",{className:"vm-simple-bar-chart-y-axis",children:o.map((e=>Nt("div",{className:"vm-simple-bar-chart-y-axis__tick",children:e},e)))}),Nt("div",{className:"vm-simple-bar-chart-data",children:n.map((e=>{let{name:t,value:n,percentage:r}=e;return Nt(_a,{title:"".concat(t,": ").concat(n),placement:"top-center",children:Nt("div",{className:"vm-simple-bar-chart-data-item",style:{maxHeight:"".concat(r||0,"%")}})},"".concat(t,"_").concat(n))}))})]})},Lm=e=>{let{rows:t,tabs:n=[],chartContainer:a,totalSeries:o,totalSeriesPrev:i,onActionClick:l,sectionTitle:s,tip:c,tableHeaderCells:u,isPrometheus:d}=e;const{isMobile:h}=ea(),[m,p]=(0,r.useState)("table"),f=d&&!t.length,v=(0,r.useMemo)((()=>n.map(((e,t)=>({value:e,label:e,icon:Nt(0===t?Kn:Wn,{})})))),[n]);return Nt("div",{className:Cr()({"vm-metrics-content":!0,"vm-metrics-content_mobile":h,"vm-block":!0,"vm-block_mobile":h}),children:[Nt("div",{className:"vm-metrics-content-header vm-section-header",children:[Nt("h5",{className:Cr()({"vm-metrics-content-header__title":!0,"vm-section-header__title":!0,"vm-section-header__title_mobile":h}),children:[!h&&c&&Nt(_a,{title:Nt("p",{dangerouslySetInnerHTML:{__html:c},className:"vm-metrics-content-header__tip"}),children:Nt("div",{className:"vm-metrics-content-header__tip-icon",children:Nt(In,{})})}),s]}),Nt("div",{className:"vm-section-header__tabs",children:Nt(Tr,{activeItem:m,items:v,onChange:p})})]}),f&&Nt("div",{className:"vm-metrics-content-prom-data",children:[Nt("div",{className:"vm-metrics-content-prom-data__icon",children:Nt(In,{})}),Nt("h3",{className:"vm-metrics-content-prom-data__title",children:"Prometheus Data Limitation"}),Nt("p",{className:"vm-metrics-content-prom-data__text",children:["Due to missing data from your Prometheus source, some tables may appear empty.",Nt("br",{}),"This does not indicate an issue with your system or our tool."]})]}),!f&&"table"===m&&Nt("div",{ref:a,className:Cr()({"vm-metrics-content__table":!0,"vm-metrics-content__table_mobile":h}),children:Nt(Am,{rows:t,headerCells:u,defaultSortColumn:"value",tableCells:e=>Nt(Mm,{row:e,totalSeries:o,totalSeriesPrev:i,onActionClick:l})})}),!f&&"graph"===m&&Nt("div",{className:"vm-metrics-content__chart",children:Nt(Tm,{data:t.map((e=>{let{name:t,value:n}=e;return{name:t,value:n}}))})})]})},Om=e=>{let{title:t,children:n}=e;return Nt("div",{className:"vm-cardinality-tip",children:[Nt("div",{className:"vm-cardinality-tip-header",children:[Nt("div",{className:"vm-cardinality-tip-header__tip-icon",children:Nt(hr,{})}),Nt("h4",{className:"vm-cardinality-tip-header__title",children:t||"Tips"})]}),Nt("p",{className:"vm-cardinality-tip__description",children:n})]})},Pm=()=>Nt(Om,{title:"Metrics with a high number of series",children:Nt("ul",{children:[Nt("li",{children:["Identify and eliminate labels with frequently changed values to reduce their\xa0",Nt(Il,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-cardinality",children:"cardinality"}),"\xa0and\xa0",Nt(Il,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-churn-rate",children:"high churn rate"})]}),Nt("li",{children:["Find unused time series and\xa0",Nt(Il,{href:"https://docs.victoriametrics.com/relabeling.html",children:"drop entire metrics"})]}),Nt("li",{children:["Aggregate time series before they got ingested into the database via\xa0",Nt(Il,{href:"https://docs.victoriametrics.com/stream-aggregation.html",children:"streaming aggregation"})]})]})}),Im=()=>Nt(Om,{title:"Labels with a high number of unique values",children:Nt("ul",{children:[Nt("li",{children:"Decrease the number of unique label values to reduce cardinality"}),Nt("li",{children:["Drop the label entirely via\xa0",Nt(Il,{href:"https://docs.victoriametrics.com/relabeling.html",children:"relabeling"})]}),Nt("li",{children:"For volatile label values (such as URL path, user session, etc.) consider printing them to the log file instead of adding to time series"})]})}),Rm=()=>Nt(Om,{title:"Dashboard of a single metric",children:[Nt("p",{children:"This dashboard helps to understand the cardinality of a single metric."}),Nt("p",{children:"Each time series is a unique combination of key-value label pairs. Therefore a label key with many values can create a lot of time series for a particular metric. If you\u2019re trying to decrease the cardinality of a metric, start by looking at the labels with the highest number of values."}),Nt("p",{children:"Use the series selector at the top of the page to apply additional filters."})]}),Dm=()=>Nt(Om,{title:"Dashboard of a label",children:[Nt("p",{children:"This dashboard helps you understand the count of time series per label."}),Nt("p",{children:"Use the selector at the top of the page to pick a label name you\u2019d like to inspect. For the selected label name, you\u2019ll see the label values that have the highest number of series associated with them. So if you\u2019ve chosen `instance` as your label name, you may see that `657` time series have value \u201chost-1\u201d attached to them and `580` time series have value `host-2` attached to them."}),Nt("p",{children:"This can be helpful in allowing you to determine where the bulk of your time series are coming from. If the label \u201cinstance=host-1\u201d was applied to 657 series and the label \u201cinstance=host-2\u201d was only applied to 580 series, you\u2019d know, for example, that host-01 was responsible for sending the majority of the time series."})]}),zm=()=>{const{isMobile:e}=ea(),[t]=He(),{setSearchParamsFromKeys:n}=ho(),r=t.get("tips")||"",a=t.get("match")||"",o=t.get("focusLabel")||"",{isLoading:i,appConfigurator:l,error:s,isCluster:c}=gm(),{tsdbStatusData:u,getDefaultState:d,tablesHeaders:h,sectionsTips:m}=l,p=d(a,o);return Nt("div",{className:Cr()({"vm-cardinality-panel":!0,"vm-cardinality-panel_mobile":e}),children:[i&&Nt(xl,{message:"Please wait while cardinality stats is calculated. \n This may take some time if the db contains big number of time series."}),Nt(km,{isPrometheus:l.isPrometheusData,totalSeries:u.totalSeries,totalSeriesPrev:u.totalSeriesPrev,totalSeriesAll:u.totalSeriesByAll,totalLabelValuePairs:u.totalLabelValuePairs,seriesCountByMetricName:u.seriesCountByMetricName,isCluster:c}),r&&Nt("div",{className:"vm-cardinality-panel-tips",children:[!a&&!o&&Nt(Pm,{}),a&&!o&&Nt(Rm,{}),!a&&!o&&Nt(Im,{}),o&&Nt(Dm,{})]}),s&&Nt(na,{variant:"error",children:s}),l.keys(a,o).map((e=>{return Nt(Lm,{sectionTitle:l.sectionsTitles(o)[e],tip:m[e],rows:u[e],onActionClick:(t=e,e=>{const r={match:ym[t]({query:e,focusLabel:o,match:a})};"labelValueCountByLabelName"!==t&&"seriesCountByLabelName"!=t||(r.focusLabel=e),"seriesCountByFocusLabelValue"==t&&(r.focusLabel=""),n(r)}),tabs:p.tabs[e],chartContainer:p.containerRefs[e],totalSeriesPrev:l.totalSeries(e,!0),totalSeries:l.totalSeries(e),tableHeaderCells:h[e],isPrometheus:l.isPrometheusData},e);var t}))]})},Fm=e=>(["topByAvgDuration","topByCount","topBySumDuration"].forEach((t=>{const n=e[t];Array.isArray(n)&&n.forEach((e=>{const t=en(1e3*e.timeRangeSeconds);e.url=((e,t)=>{var n;const{query:r,timeRangeSeconds:a}=e,o=["g0.expr=".concat(encodeURIComponent(r))],i=null===(n=rn.find((e=>e.duration===t)))||void 0===n?void 0:n.id;return i&&o.push("g0.relative_time=".concat(i)),a&&o.push("g0.range_input=".concat(t)),"".concat(We.home,"?").concat(o.join("&"))})(e,t),e.timeRange=t}))})),e),jm=e=>{let{topN:t,maxLifetime:n}=e;const{serverUrl:a}=Mt(),{setSearchParamsFromKeys:o}=ho(),[i,l]=(0,r.useState)(null),[s,c]=(0,r.useState)(!1),[u,d]=(0,r.useState)(),h=(0,r.useMemo)((()=>((e,t,n)=>"".concat(e,"/api/v1/status/top_queries?topN=").concat(t||"","&maxLifetime=").concat(n||""))(a,t,n)),[a,t,n]);return{data:i,error:u,loading:s,fetch:async()=>{c(!0),o({topN:t,maxLifetime:n});try{const e=await fetch(h),t=await e.json();l(e.ok?Fm(t):null),d(String(t.error||""))}catch(Pp){Pp instanceof Error&&"AbortError"!==Pp.name&&d("".concat(Pp.name,": ").concat(Pp.message))}c(!1)}}},Hm=e=>{let{rows:t,columns:n,defaultOrderBy:a}=e;const o=gl(),[i,l]=(0,r.useState)(a||"count"),[s,c]=(0,r.useState)("desc"),u=(0,r.useMemo)((()=>Nm(t,Em(s,i))),[t,i,s]),d=e=>()=>{var t;t=e,c((e=>"asc"===e&&i===t?"desc":"asc")),l(t)},h=e=>{let{query:t}=e;return async()=>{await o(t,"Query has been copied")}};return Nt("table",{className:"vm-table",children:[Nt("thead",{className:"vm-table-header",children:Nt("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((e=>Nt("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:d(e.sortBy||e.key),children:Nt("div",{className:"vm-table-cell__content",children:[e.title||e.key,Nt("div",{className:Cr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":i===e.key,"vm-table__sort-icon_desc":"desc"===s&&i===e.key}),children:Nt(Hn,{})})]})},e.key))),Nt("th",{className:"vm-table-cell vm-table-cell_header"})," "]})}),Nt("tbody",{className:"vm-table-body",children:u.map(((e,t)=>Nt("tr",{className:"vm-table__row",children:[n.map((t=>Nt("td",{className:"vm-table-cell",children:e[t.key]||"-"},t.key))),Nt("td",{className:"vm-table-cell vm-table-cell_no-padding",children:Nt("div",{className:"vm-top-queries-panels__table-actions",children:[e.url&&Nt(_a,{title:"Execute query",children:Nt(Re,{to:e.url,target:"_blank",rel:"noreferrer","aria-disabled":!0,children:Nt(ma,{variant:"text",size:"small",startIcon:Nt(Yn,{}),ariaLabel:"execute query"})})}),Nt(_a,{title:"Copy query",children:Nt(ma,{variant:"text",size:"small",startIcon:Nt(rr,{}),onClick:h(e),ariaLabel:"copy query"})})]})})]},t)))})]})},$m=["table","JSON"].map(((e,t)=>({value:String(t),label:e,icon:Nt(0===t?Kn:Qn,{})}))),Vm=e=>{let{rows:t,title:n,columns:a,defaultOrderBy:o}=e;const{isMobile:i}=ea(),[l,s]=(0,r.useState)(0);return Nt("div",{className:Cr()({"vm-top-queries-panel":!0,"vm-block":!0,"vm-block_mobile":i}),children:[Nt("div",{className:Cr()({"vm-top-queries-panel-header":!0,"vm-section-header":!0,"vm-top-queries-panel-header_mobile":i}),children:[Nt("h5",{className:Cr()({"vm-section-header__title":!0,"vm-section-header__title_mobile":i}),children:n}),Nt("div",{className:"vm-section-header__tabs",children:Nt(Tr,{activeItem:String(l),items:$m,onChange:e=>{s(+e)}})})]}),Nt("div",{className:Cr()({"vm-top-queries-panel__table":!0,"vm-top-queries-panel__table_mobile":i}),children:[0===l&&Nt(Hm,{rows:t,columns:a,defaultOrderBy:o}),1===l&&Nt(Wh,{data:t})]})]})},Um=()=>{const{isMobile:e}=ea(),[t,n]=wm(10,"topN"),[a,i]=wm("10m","maxLifetime"),{data:l,error:s,loading:c,fetch:u}=jm({topN:t,maxLifetime:a}),d=(0,r.useMemo)((()=>{const e=a.trim().split(" ").reduce(((e,t)=>{const n=Kt(t);return n?{...e,...n}:{...e}}),{});return!!o().duration(e).asMilliseconds()}),[a]),h=(0,r.useMemo)((()=>!!t&&t<1),[t]),m=(0,r.useMemo)((()=>h?"Number must be bigger than zero":""),[h]),p=(0,r.useMemo)((()=>d?"":"Invalid duration value"),[d]),f=e=>{if(!l)return e;const t=l[e];return"number"===typeof t?qd(t,t,t):t||e},v=e=>{"Enter"===e.key&&u()};return(0,r.useEffect)((()=>{l&&(t||n(+l.topN),a||i(l.maxLifetime))}),[l]),(0,r.useEffect)((()=>(u(),window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)})),[]),Nt("div",{className:Cr()({"vm-top-queries":!0,"vm-top-queries_mobile":e}),children:[c&&Nt(xl,{containerStyles:{height:"500px"}}),Nt("div",{className:Cr()({"vm-top-queries-controls":!0,"vm-block":!0,"vm-block_mobile":e}),children:[Nt("div",{className:"vm-top-queries-controls-fields",children:[Nt("div",{className:"vm-top-queries-controls-fields__item",children:Nt(Wa,{label:"Max lifetime",value:a,error:p,helperText:"For example ".concat("30ms, 15s, 3d4h, 1y2w"),onChange:e=>{i(e)},onKeyDown:v})}),Nt("div",{className:"vm-top-queries-controls-fields__item",children:Nt(Wa,{label:"Number of returned queries",type:"number",value:t||"",error:m,onChange:e=>{n(+e)},onKeyDown:v})})]}),Nt("div",{className:Cr()({"vm-top-queries-controls-bottom":!0,"vm-top-queries-controls-bottom_mobile":e}),children:[Nt("div",{className:"vm-top-queries-controls-bottom__info",children:["VictoriaMetrics tracks the last\xa0",Nt(_a,{title:"search.queryStats.lastQueriesCount",children:Nt("b",{children:f("search.queryStats.lastQueriesCount")})}),"\xa0queries with durations at least\xa0",Nt(_a,{title:"search.queryStats.minQueryDuration",children:Nt("b",{children:f("search.queryStats.minQueryDuration")})})]}),Nt("div",{className:"vm-top-queries-controls-bottom__button",children:Nt(ma,{startIcon:Nt(qn,{}),onClick:u,children:"Execute"})})]})]}),s&&Nt(na,{variant:"error",children:s}),l&&Nt(Ct.FK,{children:Nt("div",{className:"vm-top-queries-panels",children:[Nt(Vm,{rows:l.topBySumDuration,title:"Queries with most summary time to execute",columns:[{key:"query"},{key:"sumDurationSeconds",title:"sum duration, sec"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}],defaultOrderBy:"sumDurationSeconds"}),Nt(Vm,{rows:l.topByAvgDuration,title:"Most heavy queries",columns:[{key:"query"},{key:"avgDurationSeconds",title:"avg duration, sec"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}],defaultOrderBy:"avgDurationSeconds"}),Nt(Vm,{rows:l.topByCount,title:"Most frequently executed queries",columns:[{key:"query"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}]})]})})]})},Bm={"color-primary":"#589DF6","color-secondary":"#316eca","color-error":"#e5534b","color-warning":"#c69026","color-info":"#539bf5","color-success":"#57ab5a","color-background-body":"#22272e","color-background-block":"#2d333b","color-background-tooltip":"rgba(22, 22, 22, 0.8)","color-text":"#cdd9e5","color-text-secondary":"#768390","color-text-disabled":"#636e7b","box-shadow":"rgba(0, 0, 0, 0.16) 1px 2px 6px","box-shadow-popper":"rgba(0, 0, 0, 0.2) 0px 2px 8px 0px","border-divider":"1px solid rgba(99, 110, 123, 0.5)","color-hover-black":"rgba(0, 0, 0, 0.12)","color-log-hits-bar-0":"rgba(255, 255, 255, 0.18)","color-log-hits-bar-1":"#FFB74D","color-log-hits-bar-2":"#81C784","color-log-hits-bar-3":"#64B5F6","color-log-hits-bar-4":"#E57373","color-log-hits-bar-5":"#8a62f0"},qm={"color-primary":"#3F51B5","color-secondary":"#E91E63","color-error":"#FD080E","color-warning":"#FF8308","color-info":"#03A9F4","color-success":"#4CAF50","color-background-body":"#FEFEFF","color-background-block":"#FFFFFF","color-background-tooltip":"rgba(80,80,80,0.9)","color-text":"#110f0f","color-text-secondary":"#706F6F","color-text-disabled":"#A09F9F","box-shadow":"rgba(0, 0, 0, 0.08) 1px 2px 6px","box-shadow-popper":"rgba(0, 0, 0, 0.1) 0px 2px 8px 0px","border-divider":"1px solid rgba(0, 0, 0, 0.15)","color-hover-black":"rgba(0, 0, 0, 0.06)","color-log-hits-bar-0":"rgba(0, 0, 0, 0.18)","color-log-hits-bar-1":"#FFB74D","color-log-hits-bar-2":"#81C784","color-log-hits-bar-3":"#64B5F6","color-log-hits-bar-4":"#E57373","color-log-hits-bar-5":"#8a62f0"},Ym=()=>{const[e,t]=(0,r.useState)(_t()),n=e=>{t(e.matches)};return(0,r.useEffect)((()=>{const e=window.matchMedia("(prefers-color-scheme: dark)");return e.addEventListener("change",n),()=>e.removeEventListener("change",n)}),[]),e},Wm=["primary","secondary","error","warning","info","success"],Km=e=>{let{onLoaded:t}=e;const n=Qe(),{palette:a={}}=Ke(),{theme:o}=Mt(),i=Ym(),l=Tt(),s=Mr(),[c,u]=(0,r.useState)({[ft.dark]:Bm,[ft.light]:qm,[ft.system]:_t()?Bm:qm}),d=()=>{const{innerWidth:e,innerHeight:t}=window,{clientWidth:n,clientHeight:r}=document.documentElement;yt("scrollbar-width","".concat(e-n,"px")),yt("scrollbar-height","".concat(t-r,"px")),yt("vh","".concat(.01*t,"px"))},h=()=>{Wm.forEach(((e,n)=>{const r=(e=>{let t=e.replace("#","").trim();if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6!==t.length)throw new Error("Invalid HEX color.");return(299*parseInt(t.slice(0,2),16)+587*parseInt(t.slice(2,4),16)+114*parseInt(t.slice(4,6),16))/1e3>=128?"#000000":"#FFFFFF"})(gt("color-".concat(e)));yt("".concat(e,"-text"),r),n===Wm.length-1&&(l({type:"SET_DARK_THEME"}),t(!0))}))},m=()=>{const e=et("THEME")||ft.system,t=c[e];Object.entries(t).forEach((e=>{let[t,n]=e;yt(t,n)})),h(),n&&(Wm.forEach((e=>{const t=a[e];t&&yt("color-".concat(e),t)})),h())};return(0,r.useEffect)((()=>{d(),m()}),[c]),(0,r.useEffect)(d,[s]),(0,r.useEffect)((()=>{const e=_t()?Bm:qm;c[ft.system]!==e?u((t=>({...t,[ft.system]:e}))):m()}),[o,i]),(0,r.useEffect)((()=>{n&&l({type:"SET_THEME",payload:ft.light})}),[]),null},Qm=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)(!1),o=(0,r.useRef)(document.body),i=e=>{e.preventDefault(),e.stopPropagation(),"dragenter"===e.type||"dragover"===e.type?a(!0):"dragleave"===e.type&&a(!1)};return Ar("dragenter",i,o),Ar("dragleave",i,o),Ar("dragover",i,o),Ar("drop",(e=>{var n;e.preventDefault(),e.stopPropagation(),a(!1),null!==e&&void 0!==e&&null!==(n=e.dataTransfer)&&void 0!==n&&n.files&&e.dataTransfer.files[0]&&(e=>{const n=Array.from(e||[]);t(n)})(e.dataTransfer.files)}),o),Ar("paste",(e=>{var n;const r=null===(n=e.clipboardData)||void 0===n?void 0:n.items;if(!r)return;const a=Array.from(r).filter((e=>"application/json"===e.type)).map((e=>e.getAsFile())).filter((e=>null!==e));t(a)}),o),{files:e,dragging:n}},Zm=e=>{let{onOpenModal:t,onChange:n}=e;return Nt("div",{className:"vm-upload-json-buttons",children:[Nt(ma,{variant:"outlined",onClick:t,children:"Paste JSON"}),Nt(ma,{children:["Upload Files",Nt("input",{id:"json",type:"file",accept:"application/json",multiple:!0,title:" ",onChange:n})]})]})},Gm=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)([]),o=(0,r.useMemo)((()=>!!e.length),[e]),{value:i,setTrue:l,setFalse:s}=fa(!1),c=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";a((n=>[{filename:t,text:": ".concat(e.message)},...n]))},u=(e,n)=>{try{const r=JSON.parse(e),a=r.trace||r;if(!a.duration_msec)return void c(new Error(pt.traceNotFound),n);const o=new Nl(a,n);t((e=>[o,...e]))}catch(Pp){Pp instanceof Error&&c(Pp,n)}},d=e=>{e.map((e=>{const t=new FileReader,n=(null===e||void 0===e?void 0:e.name)||"";t.onload=e=>{var t;const r=String(null===(t=e.target)||void 0===t?void 0:t.result);u(r,n)},t.readAsText(e)}))},h=e=>{a([]);const t=Array.from(e.target.files||[]);d(t),e.target.value=""},m=e=>()=>{(e=>{a((t=>t.filter(((t,n)=>n!==e))))})(e)},{files:p,dragging:f}=Qm();return(0,r.useEffect)((()=>{d(p)}),[p]),Nt("div",{className:"vm-trace-page",children:[Nt("div",{className:"vm-trace-page-header",children:[Nt("div",{className:"vm-trace-page-header-errors",children:n.map(((e,t)=>Nt("div",{className:"vm-trace-page-header-errors-item",children:[Nt(na,{variant:"error",children:[Nt("b",{className:"vm-trace-page-header-errors-item__filename",children:e.filename}),Nt("span",{children:e.text})]}),Nt(ma,{className:"vm-trace-page-header-errors-item__close",startIcon:Nt(On,{}),variant:"text",color:"error",onClick:m(t)})]},"".concat(e,"_").concat(t))))}),Nt("div",{children:o&&Nt(Zm,{onOpenModal:l,onChange:h})})]}),o&&Nt("div",{children:Nt(Vl,{jsonEditor:!0,traces:e,onDeleteClick:n=>{const r=e.filter((e=>e.idValue!==n.idValue));t([...r])}})}),!o&&Nt("div",{className:"vm-trace-page-preview",children:[Nt("p",{className:"vm-trace-page-preview__text",children:["Please, upload file with JSON response content.","\n","The file must contain tracing information in JSON format.","\n","In order to use tracing please refer to the doc:\xa0",Nt("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/#query-tracing",target:"_blank",rel:"help noreferrer",children:"https://docs.victoriametrics.com/#query-tracing"}),"\n","Tracing graph will be displayed after file upload.","\n","Attach files by dragging & dropping, selecting or pasting them."]}),Nt(Zm,{onOpenModal:l,onChange:h})]}),i&&Nt(ya,{title:"Paste JSON",onClose:s,children:Nt($l,{editable:!0,displayTitle:!0,defaultTile:"JSON ".concat(e.length+1),onClose:s,onUpload:u})}),f&&Nt("div",{className:"vm-trace-page__dropzone"})]})},Jm=e=>{const{serverUrl:t}=Mt(),{period:n}=fn(),[a,o]=(0,r.useState)([]),[i,l]=(0,r.useState)(!1),[s,c]=(0,r.useState)(),u=(0,r.useMemo)((()=>((e,t,n)=>{const r="{job=".concat(JSON.stringify(n),"}");return"".concat(e,"/api/v1/label/instance/values?match[]=").concat(encodeURIComponent(r),"&start=").concat(t.start,"&end=").concat(t.end)})(t,n,e)),[t,n,e]);return(0,r.useEffect)((()=>{if(!e)return;(async()=>{l(!0);try{const e=await fetch(u),t=await e.json(),n=t.data||[];o(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?c(void 0):c("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Pp){Pp instanceof Error&&c("".concat(Pp.name,": ").concat(Pp.message))}l(!1)})().catch(console.error)}),[u]),{instances:a,isLoading:i,error:s}},Xm=(e,t)=>{const{serverUrl:n}=Mt(),{period:a}=fn(),[o,i]=(0,r.useState)([]),[l,s]=(0,r.useState)(!1),[c,u]=(0,r.useState)(),d=(0,r.useMemo)((()=>((e,t,n,r)=>{const a=Object.entries({job:n,instance:r}).filter((e=>e[1])).map((e=>{let[t,n]=e;return"".concat(t,"=").concat(JSON.stringify(n))})).join(","),o="{".concat(a,"}");return"".concat(e,"/api/v1/label/__name__/values?match[]=").concat(encodeURIComponent(o),"&start=").concat(t.start,"&end=").concat(t.end)})(n,a,e,t)),[n,a,e,t]);return(0,r.useEffect)((()=>{if(!e)return;(async()=>{s(!0);try{const e=await fetch(d),t=await e.json(),n=t.data||[];i(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?u(void 0):u("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Pp){Pp instanceof Error&&u("".concat(Pp.name,": ").concat(Pp.message))}s(!1)})().catch(console.error)}),[d]),{names:o,isLoading:l,error:c}},ep=e=>{let{name:t,job:n,instance:a,rateEnabled:o,isBucket:i,height:l}=e;const{isMobile:s}=ea(),{customStep:c,yaxis:u}=Ur(),{period:d}=fn(),h=Br(),m=vn(),p=Zt(d.end-d.start),f=Qt(c),v=en(10*f*1e3),[g,y]=(0,r.useState)(!1),[_,b]=(0,r.useState)(!1),w=g&&c===p?v:c,k=(0,r.useMemo)((()=>{const e=Object.entries({job:n,instance:a}).filter((e=>e[1])).map((e=>{let[t,n]=e;return"".concat(t,"=").concat(JSON.stringify(n))}));e.push("__name__=".concat(JSON.stringify(t))),"node_cpu_seconds_total"==t&&e.push('mode!="idle"');const r="{".concat(e.join(","),"}");if(i)return"sum(rate(".concat(r,")) by (vmrange, le)");const l=o?"rollup_rate(".concat(r,")"):"rollup(".concat(r,")");return"\nwith (q = ".concat(l,') (\n alias(min(label_match(q, "rollup", "min")), "min"),\n alias(max(label_match(q, "rollup", "max")), "max"),\n alias(avg(label_match(q, "rollup", "avg")), "avg"),\n)')}),[t,n,a,o,i]),{isLoading:x,graphData:S,error:C,queryErrors:E,warning:N,isHistogram:A}=Ol({predefinedQuery:[k],visible:!0,customStep:w,showAllSeries:_});return(0,r.useEffect)((()=>{y(A)}),[A]),Nt("div",{className:Cr()({"vm-explore-metrics-graph":!0,"vm-explore-metrics-graph_mobile":s}),children:[x&&Nt(xl,{}),C&&Nt(na,{variant:"error",children:C}),E[0]&&Nt(na,{variant:"error",children:E[0]}),N&&Nt(Bl,{warning:N,query:[k],onChange:b}),S&&d&&Nt($h,{data:S,period:d,customStep:w,query:[k],yaxis:u,setYaxisLimits:e=>{h({type:"SET_YAXIS_LIMITS",payload:e})},setPeriod:e=>{let{from:t,to:n}=e;m({type:"SET_PERIOD",payload:{from:t,to:n}})},showLegend:!1,height:l,isHistogram:A})]})},tp=e=>{let{name:t,index:n,length:r,isBucket:a,rateEnabled:o,onChangeRate:i,onRemoveItem:l,onChangeOrder:s}=e;const{isMobile:c}=ea(),{value:u,setTrue:d,setFalse:h}=fa(!1),m=()=>{l(t)},p=()=>{s(t,n,n+1)},f=()=>{s(t,n,n-1)};return Nt("div",c?{className:"vm-explore-metrics-item-header vm-explore-metrics-item-header_mobile",children:[Nt("div",{className:"vm-explore-metrics-item-header__name",children:t}),Nt(ma,{variant:"text",size:"small",startIcon:Nt(ur,{}),onClick:d,ariaLabel:"open panel settings"}),u&&Nt(ya,{title:t,onClose:h,children:Nt("div",{className:"vm-explore-metrics-item-header-modal",children:[Nt("div",{className:"vm-explore-metrics-item-header-modal-order",children:[Nt(ma,{startIcon:Nt(Jn,{}),variant:"outlined",onClick:f,disabled:0===n,ariaLabel:"move graph up"}),Nt("p",{children:["position:",Nt("span",{className:"vm-explore-metrics-item-header-modal-order__index",children:["#",n+1]})]}),Nt(ma,{endIcon:Nt(Gn,{}),variant:"outlined",onClick:p,disabled:n===r-1,ariaLabel:"move graph down"})]}),!a&&Nt("div",{className:"vm-explore-metrics-item-header-modal__rate",children:[Nt(To,{label:Nt("span",{children:["enable ",Nt("code",{children:"rate()"})]}),value:o,onChange:i,fullWidth:!0}),Nt("p",{children:"calculates the average per-second speed of metrics change"})]}),Nt(ma,{startIcon:Nt(On,{}),color:"error",variant:"outlined",onClick:m,fullWidth:!0,children:"Remove graph"})]})})]}:{className:"vm-explore-metrics-item-header",children:[Nt("div",{className:"vm-explore-metrics-item-header-order",children:[Nt(_a,{title:"move graph up",children:Nt(ma,{className:"vm-explore-metrics-item-header-order__up",startIcon:Nt(jn,{}),variant:"text",color:"gray",size:"small",onClick:f,ariaLabel:"move graph up"})}),Nt("div",{className:"vm-explore-metrics-item-header__index",children:["#",n+1]}),Nt(_a,{title:"move graph down",children:Nt(ma,{className:"vm-explore-metrics-item-header-order__down",startIcon:Nt(jn,{}),variant:"text",color:"gray",size:"small",onClick:p,ariaLabel:"move graph down"})})]}),Nt("div",{className:"vm-explore-metrics-item-header__name",children:t}),!a&&Nt("div",{className:"vm-explore-metrics-item-header__rate",children:Nt(_a,{title:"calculates the average per-second speed of metric's change",children:Nt(To,{label:Nt("span",{children:["enable ",Nt("code",{children:"rate()"})]}),value:o,onChange:i})})}),Nt("div",{className:"vm-explore-metrics-item-header__close",children:Nt(_a,{title:"close graph",children:Nt(ma,{startIcon:Nt(On,{}),variant:"text",color:"gray",size:"small",onClick:m,ariaLabel:"close graph"})})})]})},np=e=>{let{name:t,job:n,instance:a,index:o,length:i,size:l,onRemoveItem:s,onChangeOrder:c}=e;const u=(0,r.useMemo)((()=>/_sum?|_total?|_count?/.test(t)),[t]),d=(0,r.useMemo)((()=>/_bucket?/.test(t)),[t]),[h,m]=(0,r.useState)(u),p=Mr(),f=(0,r.useMemo)(l.height,[l,p]);return(0,r.useEffect)((()=>{m(u)}),[n]),Nt("div",{className:"vm-explore-metrics-item vm-block vm-block_empty-padding",children:[Nt(tp,{name:t,index:o,length:i,isBucket:d,rateEnabled:h,size:l.id,onChangeRate:m,onRemoveItem:s,onChangeOrder:c}),Nt(ep,{name:t,job:n,instance:a,rateEnabled:h,isBucket:d,height:f},"".concat(t,"_").concat(n,"_").concat(a,"_").concat(h))]})},rp=e=>{let{values:t,onRemoveItem:n}=e;const{isMobile:r}=ea();return r?Nt("span",{className:"vm-select-input-content__counter",children:["selected ",t.length]}):Nt(Ct.FK,{children:t.map((e=>{return Nt("div",{className:"vm-select-input-content__selected",children:[Nt("span",{children:e}),Nt("div",{onClick:(t=e,e=>{n(t),e.stopPropagation()}),children:Nt(On,{})})]},e);var t}))})},ap=e=>{let{value:t,list:n,label:a,placeholder:o,noOptionsText:i,clearable:l=!1,searchable:s=!1,autofocus:c,disabled:u,onChange:d}=e;const{isDarkTheme:h}=Mt(),{isMobile:m}=ea(),[p,f]=(0,r.useState)(""),v=(0,r.useRef)(null),[g,y]=(0,r.useState)(null),[_,b]=(0,r.useState)(!1),w=(0,r.useRef)(null),k=Array.isArray(t),x=Array.isArray(t)?t:void 0,S=m&&k&&!(null===x||void 0===x||!x.length),C=(0,r.useMemo)((()=>_?p:Array.isArray(t)?"":t),[t,p,_,k]),E=(0,r.useMemo)((()=>_?p||"(.+)":""),[p,_]),N=()=>{w.current&&w.current.blur()},A=()=>{b(!1),N()},M=e=>{f(""),d(e),k||A(),k&&w.current&&w.current.focus()};return(0,r.useEffect)((()=>{f(""),_&&w.current&&w.current.focus(),_||N()}),[_,w]),(0,r.useEffect)((()=>{c&&w.current&&!m&&w.current.focus()}),[c,w]),Ar("keyup",(e=>{w.current!==e.target&&b(!1)})),ha(v,A,g),Nt("div",{className:Cr()({"vm-select":!0,"vm-select_dark":h,"vm-select_disabled":u}),children:[Nt("div",{className:"vm-select-input",onClick:e=>{e.target instanceof HTMLInputElement||u||b((e=>!e))},ref:v,children:[Nt("div",{className:"vm-select-input-content",children:[!(null===x||void 0===x||!x.length)&&Nt(rp,{values:x,onRemoveItem:M}),!S&&Nt("input",{value:C,type:"text",placeholder:o,onInput:e=>{f(e.target.value)},onFocus:()=>{u||b(!0)},onBlur:()=>{n.includes(p)&&d(p)},ref:w,readOnly:m||!s})]}),a&&Nt("span",{className:"vm-text-field__label",children:a}),l&&t&&Nt("div",{className:"vm-select-input__icon",onClick:(e=>t=>{M(e),t.stopPropagation()})(""),children:Nt(On,{})}),Nt("div",{className:Cr()({"vm-select-input__icon":!0,"vm-select-input__icon_open":_}),children:Nt(Hn,{})})]}),Nt(Vo,{label:a,value:E,options:n.map((e=>({value:e}))),anchor:v,selected:x,minLength:1,fullWidth:!0,noOptionsText:i,onSelect:M,onOpenAutocomplete:b,onChangeWrapperRef:y})]})},op=st.map((e=>e.id)),ip=e=>{let{jobs:t,instances:n,names:a,job:o,instance:i,size:l,selectedMetrics:s,onChangeJob:c,onChangeInstance:u,onToggleMetric:d,onChangeSize:h}=e;const m=(0,r.useMemo)((()=>o?"":"No instances. Please select job"),[o]),p=(0,r.useMemo)((()=>o?"":"No metric names. Please select job"),[o]),{isMobile:f}=ea(),{value:v,toggle:g,setFalse:y}=fa("false"!==et("EXPLORE_METRICS_TIPS"));return(0,r.useEffect)((()=>{Xe("EXPLORE_METRICS_TIPS","".concat(v))}),[v]),Nt(Ct.FK,{children:[Nt("div",{className:Cr()({"vm-explore-metrics-header":!0,"vm-explore-metrics-header_mobile":f,"vm-block":!0,"vm-block_mobile":f}),children:[Nt("div",{className:"vm-explore-metrics-header__job",children:Nt(ap,{value:o,list:t,label:"Job",placeholder:"Please select job",onChange:c,autofocus:!o&&!!t.length&&!f,searchable:!0})}),Nt("div",{className:"vm-explore-metrics-header__instance",children:Nt(ap,{value:i,list:n,label:"Instance",placeholder:"Please select instance",onChange:u,noOptionsText:m,clearable:!0,searchable:!0})}),Nt("div",{className:"vm-explore-metrics-header__size",children:[Nt(ap,{label:"Size graphs",value:l,list:op,onChange:h}),Nt(_a,{title:"".concat(v?"Hide":"Show"," tip"),children:Nt(ma,{variant:"text",color:v?"warning":"gray",startIcon:Nt(hr,{}),onClick:g,ariaLabel:"visibility tips"})})]}),Nt("div",{className:"vm-explore-metrics-header-metrics",children:Nt(ap,{label:"Metrics",value:s,list:a,placeholder:"Search metric name",onChange:d,noOptionsText:p,clearable:!0,searchable:!0})})]}),v&&Nt(na,{variant:"warning",children:Nt("div",{className:"vm-explore-metrics-header-description",children:[Nt("p",{children:["Please note: this page is solely designed for exploring Prometheus metrics. Prometheus metrics always contain ",Nt("code",{children:"job"})," and ",Nt("code",{children:"instance"})," labels (see ",Nt("a",{className:"vm-link vm-link_colored",href:"https://prometheus.io/docs/concepts/jobs_instances/",children:"these docs"}),"), and this page relies on them as filters. ",Nt("br",{}),"Please use this page for Prometheus metrics only, in accordance with their naming conventions."]}),Nt(ma,{variant:"text",size:"small",startIcon:Nt(On,{}),onClick:y,ariaLabel:"close tips"})]})})]})},lp=ut("job",""),sp=ut("instance",""),cp=ut("metrics",""),up=ut("size",""),dp=st.find((e=>up?e.id===up:e.isDefault))||st[0],hp=()=>{const[e,t]=(0,r.useState)(lp),[n,a]=(0,r.useState)(sp),[o,i]=(0,r.useState)(cp?cp.split("&"):[]),[l,s]=(0,r.useState)(dp);(e=>{let{job:t,instance:n,metrics:a,size:o}=e;const{duration:i,relativeTime:l,period:{date:s}}=fn(),{customStep:c}=Ur(),{setSearchParamsFromKeys:u}=ho(),d=()=>{const e=sm({"g0.range_input":i,"g0.end_input":s,"g0.step_input":c,"g0.relative_time":l,size:o,job:t,instance:n,metrics:a});u(e)};(0,r.useEffect)(d,[i,l,s,c,t,n,a,o]),(0,r.useEffect)(d,[])})({job:e,instance:n,metrics:o.join("&"),size:l.id});const{jobs:c,isLoading:u,error:d}=(()=>{const{serverUrl:e}=Mt(),{period:t}=fn(),[n,a]=(0,r.useState)([]),[o,i]=(0,r.useState)(!1),[l,s]=(0,r.useState)(),c=(0,r.useMemo)((()=>((e,t)=>"".concat(e,"/api/v1/label/job/values?start=").concat(t.start,"&end=").concat(t.end))(e,t)),[e,t]);return(0,r.useEffect)((()=>{(async()=>{i(!0);try{const e=await fetch(c),t=await e.json(),n=t.data||[];a(n.sort(((e,t)=>e.localeCompare(t)))),e.ok?s(void 0):s("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Pp){Pp instanceof Error&&s("".concat(Pp.name,": ").concat(Pp.message))}i(!1)})().catch(console.error)}),[c]),{jobs:n,isLoading:o,error:l}})(),{instances:h,isLoading:m,error:p}=Jm(e),{names:f,isLoading:v,error:g}=Xm(e,n),y=(0,r.useMemo)((()=>u||m||v),[u,m,v]),_=(0,r.useMemo)((()=>d||p||g),[d,p,g]),b=e=>{i(e?t=>t.includes(e)?t.filter((t=>t!==e)):[...t,e]:[])},w=(e,t,n)=>{const r=n>o.length-1;n<0||r||i((e=>{const r=[...e],[a]=r.splice(t,1);return r.splice(n,0,a),r}))};return(0,r.useEffect)((()=>{n&&h.length&&!h.includes(n)&&a("")}),[h,n]),Nt("div",{className:"vm-explore-metrics",children:[Nt(ip,{jobs:c,instances:h,names:f,job:e,size:l.id,instance:n,selectedMetrics:o,onChangeJob:t,onChangeSize:e=>{const t=st.find((t=>t.id===e));t&&s(t)},onChangeInstance:a,onToggleMetric:b}),y&&Nt(xl,{}),_&&Nt(na,{variant:"error",children:_}),!e&&Nt(na,{variant:"info",children:"Please select job to see list of metric names."}),e&&!o.length&&Nt(na,{variant:"info",children:"Please select metric names to see the graphs."}),Nt("div",{className:"vm-explore-metrics-body",children:o.map(((t,r)=>Nt(np,{name:t,job:e,instance:n,index:r,length:o.length,size:l,onRemoveItem:b,onChangeOrder:w},t)))})]})},mp=()=>{const t=gl();return Nt("div",{className:"vm-preview-icons",children:Object.entries(e).map((e=>{let[n,r]=e;return Nt("div",{className:"vm-preview-icons-item",onClick:(a=n,async()=>{await t("<".concat(a,"/>"),"<".concat(a,"/> has been copied"))}),children:[Nt("div",{className:"vm-preview-icons-item__svg",children:r()}),Nt("div",{className:"vm-preview-icons-item__name",children:"<".concat(n,"/>")})]},n);var a}))})};var pp=function(e){return e.copy="Copy",e.copied="Copied",e}(pp||{});const fp=e=>{let{code:t}=e;const[n,a]=(0,r.useState)(pp.copy);return(0,r.useEffect)((()=>{let e=null;return n===pp.copied&&(e=setTimeout((()=>a(pp.copy)),1e3)),()=>{e&&clearTimeout(e)}}),[n]),Nt("code",{className:"vm-code-example",children:[t,Nt("div",{className:"vm-code-example__copy",children:Nt(_a,{title:n,children:Nt(ma,{size:"small",variant:"text",onClick:()=>{navigator.clipboard.writeText(t),a(pp.copied)},startIcon:Nt(rr,{}),ariaLabel:"close"})})})]})},vp=()=>Nt("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/MetricsQL.html",target:"_blank",rel:"help noreferrer",children:"MetricsQL"}),gp=()=>Nt("a",{className:"vm-link vm-link_colored",href:"https://grafana.com/grafana/dashboards/1860-node-exporter-full/",target:"_blank",rel:"help noreferrer",children:"Node Exporter Full"}),yp=()=>Nt("section",{className:"vm-with-template-tutorial",children:[Nt("h2",{className:"vm-with-template-tutorial__title",children:["Tutorial for WITH expressions in ",Nt(vp,{})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["Let's look at the following real query from ",Nt(gp,{})," dashboard:"]}),Nt(fp,{code:'(\n (\n node_memory_MemTotal_bytes{instance=~"$node:$port", job=~"$job"}\n -\n node_memory_MemFree_bytes{instance=~"$node:$port", job=~"$job"}\n )\n /\n node_memory_MemTotal_bytes{instance=~"$node:$port", job=~"$job"}\n) * 100'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"It is clear the query calculates the percentage of used memory for the given $node, $port and $job. Isn't it? :)"})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"What's wrong with this query? Copy-pasted label filters for distinct timeseries which makes it easy to mistype these filters during modification. Let's simplify the query with WITH expressions:"}),Nt(fp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"}\n)\n(\n node_memory_MemTotal_bytes{commonFilters}\n -\n node_memory_MemFree_bytes{commonFilters}\n)\n /\nnode_memory_MemTotal_bytes{commonFilters} * 100'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["Now label filters are located in a single place instead of three distinct places. The query mentions node_memory_MemTotal_bytes metric twice and ","{commonFilters}"," three times. WITH expressions may improve this:"]}),Nt(fp,{code:'WITH (\n my_resource_utilization(free, limit, filters) = (limit{filters} - free{filters}) / limit{filters} * 100\n)\nmy_resource_utilization(\n node_memory_MemFree_bytes,\n node_memory_MemTotal_bytes,\n {instance=~"$node:$port",job=~"$job"},\n)'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"Now the template function my_resource_utilization() may be used for monitoring arbitrary resources - memory, CPU, network, storage, you name it."})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["Let's take another nice query from ",Nt(gp,{})," dashboard:"]}),Nt(fp,{code:'(\n (\n (\n count(\n count(node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"}) by (cpu)\n )\n )\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',instance=~"$node:$port",job=~"$job"}[5m]))\n )\n )\n *\n 100\n)\n /\ncount(\n count(node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"}) by (cpu)\n)'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"Do you understand what does this mess do? Is it manageable? :) WITH expressions are happy to help in a few iterations."})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"1. Extract common filters used in multiple places into a commonFilters variable:"}),Nt(fp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"}\n)\n(\n (\n (\n count(\n count(node_cpu_seconds_total{commonFilters}) by (cpu)\n )\n )\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n )\n )\n *\n 100\n)\n /\ncount(\n count(node_cpu_seconds_total{commonFilters}) by (cpu)\n)'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:'2. Extract "count(count(...) by (cpu))" into cpuCount variable:'}),Nt(fp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(node_cpu_seconds_total{commonFilters}) by (cpu))\n)\n(\n (\n cpuCount\n -\n avg(\n sum by (mode) (rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n )\n )\n *\n 100\n) / cpuCount'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"3. Extract rate(...) part into cpuIdle variable, since it is clear now that this part calculates the number of idle CPUs:"}),Nt(fp,{code:'WITH (\n commonFilters = {instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(node_cpu_seconds_total{commonFilters}) by (cpu)),\n cpuIdle = sum(rate(node_cpu_seconds_total{mode=\'idle\',commonFilters}[5m]))\n)\n((cpuCount - cpuIdle) * 100) / cpuCount'})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:["4. Put node_cpu_seconds_total","{commonFilters}"," into its own varialbe with the name cpuSeconds:"]}),Nt(fp,{code:'WITH (\n cpuSeconds = node_cpu_seconds_total{instance=~"$node:$port",job=~"$job"},\n cpuCount = count(count(cpuSeconds) by (cpu)),\n cpuIdle = sum(rate(cpuSeconds{mode=\'idle\'}[5m]))\n)\n((cpuCount - cpuIdle) * 100) / cpuCount'}),Nt("p",{className:"vm-with-template-tutorial-section__text",children:"Now the query became more clear comparing to the initial query."})]}),Nt("div",{className:"vm-with-template-tutorial-section",children:[Nt("p",{className:"vm-with-template-tutorial-section__text",children:"WITH expressions may be nested and may be put anywhere. Try expanding the following query:"}),Nt(fp,{code:"WITH (\n f(a, b) = WITH (\n f1(x) = b-x,\n f2(x) = x+x\n ) f1(a)*f2(b)\n) f(foo, with(x=bar) x)"})]})]}),_p=()=>{const{serverUrl:e}=Mt(),[t,n]=He(),[a,o]=(0,r.useState)(""),[i,l]=(0,r.useState)(!1),[s,c]=(0,r.useState)();return{data:a,error:s,loading:i,expand:async r=>{t.set("expr",r),n(t);const a=((e,t)=>"".concat(e,"/expand-with-exprs?query=").concat(encodeURIComponent(t),"&format=json"))(e,r);l(!0);try{const e=await fetch(a),t=await e.json();o((null===t||void 0===t?void 0:t.expr)||""),c(String(t.error||""))}catch(Pp){Pp instanceof Error&&"AbortError"!==Pp.name&&c("".concat(Pp.name,": ").concat(Pp.message))}l(!1)}}},bp=()=>{const[e]=He(),{data:t,loading:n,error:a,expand:o}=_p(),[i,l]=(0,r.useState)(e.get("expr")||""),s=()=>{o(i)};return(0,r.useEffect)((()=>{i&&o(i)}),[]),Nt("section",{className:"vm-with-template",children:[n&&Nt(xl,{}),Nt("div",{className:"vm-with-template-body vm-block",children:[Nt("div",{className:"vm-with-template-body__expr",children:Nt(Wa,{type:"textarea",label:"MetricsQL query with optional WITH expressions",value:i,error:a,autofocus:!0,onEnter:s,onChange:e=>{l(e)}})}),Nt("div",{className:"vm-with-template-body__result",children:Nt(Wa,{type:"textarea",label:"MetricsQL query after expanding WITH expressions and applying other optimizations",value:t,disabled:!0})}),Nt("div",{className:"vm-with-template-body-top",children:Nt(ma,{variant:"contained",onClick:s,startIcon:Nt(qn,{}),children:"Expand"})})]}),Nt("div",{className:"vm-block",children:Nt(yp,{})})]})},wp=()=>{const{serverUrl:e}=Mt(),[t,n]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1),[i,l]=(0,r.useState)();return{data:t,error:i,loading:a,fetchData:async(t,r)=>{const a=((e,t,n)=>{const r=["format=json","relabel_configs=".concat(encodeURIComponent(t)),"metric=".concat(encodeURIComponent(n))];return"".concat(e,"/metric-relabel-debug?").concat(r.join("&"))})(e,t,r);o(!0);try{const e=await fetch(a),t=await e.json();n(t.error?null:t),l(String(t.error||""))}catch(Pp){Pp instanceof Error&&"AbortError"!==Pp.name&&l("".concat(Pp.name,": ").concat(Pp.message))}o(!1)}}},kp={config:'- if: \'{bar_label=~"b.*"}\'\n source_labels: [foo_label, bar_label]\n separator: "_"\n target_label: foobar\n- action: labeldrop\n regex: "foo_.*"\n- target_label: job\n replacement: "my-application-2"',labels:'{__name__="my_metric", bar_label="bar", foo_label="foo", job="my-application", instance="192.168.0.1"}'},xp=()=>{const[e,t]=He(),{data:n,loading:a,error:o,fetchData:i}=wp(),[l,s]=wm("","config"),[c,u]=wm("","labels"),d=(0,r.useCallback)((()=>{i(l,c),e.set("config",l),e.set("labels",c),t(e)}),[l,c]);return(0,r.useEffect)((()=>{const t=e.get("config")||"",n=e.get("labels")||"";(n||t)&&(i(t,n),s(t),u(n))}),[]),Nt("section",{className:"vm-relabeling",children:[a&&Nt(xl,{}),Nt("div",{className:"vm-relabeling-header vm-block",children:[Nt("div",{className:"vm-relabeling-header-configs",children:Nt(Wa,{type:"textarea",label:"Relabel configs",value:l,autofocus:!0,onChange:e=>{s(e||"")},onEnter:d})}),Nt("div",{className:"vm-relabeling-header__labels",children:Nt(Wa,{type:"textarea",label:"Labels",value:c,onChange:e=>{u(e||"")},onEnter:d})}),Nt("div",{className:"vm-relabeling-header-bottom",children:[Nt("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/relabeling.html",rel:"help noreferrer",children:[Nt(In,{}),"Relabeling cookbook"]}),Nt("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/vmagent.html#relabeling",rel:"help noreferrer",children:[Nt(ir,{}),"Documentation"]}),Nt(ma,{variant:"text",onClick:()=>{const{config:n,labels:r}=kp;s(n),u(r),i(n,r),e.set("config",n),e.set("labels",r),t(e)},children:"Try example"}),Nt(ma,{variant:"contained",onClick:d,startIcon:Nt(qn,{}),children:"Submit"})]})]}),o&&Nt(na,{variant:"error",children:o}),n&&Nt("div",{className:"vm-relabeling-steps vm-block",children:[n.originalLabels&&Nt("div",{className:"vm-relabeling-steps-item",children:Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Original labels:"}),Nt("code",{dangerouslySetInnerHTML:{__html:n.originalLabels}})]})}),n.steps.map(((e,t)=>Nt("div",{className:"vm-relabeling-steps-item",children:[Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Step:"}),t+1]}),Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Relabeling Rule:"}),Nt("code",{children:Nt("pre",{children:e.rule})})]}),Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Input Labels:"}),Nt("code",{children:Nt("pre",{dangerouslySetInnerHTML:{__html:e.inLabels}})})]}),Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Output labels:"}),Nt("code",{children:Nt("pre",{dangerouslySetInnerHTML:{__html:e.outLabels}})})]})]},t))),n.resultingLabels&&Nt("div",{className:"vm-relabeling-steps-item",children:Nt("div",{className:"vm-relabeling-steps-item__row",children:[Nt("span",{children:"Resulting labels:"}),Nt("code",{dangerouslySetInnerHTML:{__html:n.resultingLabels}})]})})]})]})},Sp=e=>{let{rows:t,columns:n,defaultOrderBy:a,defaultOrderDir:o,copyToClipboard:i,paginationOffset:l}=e;const[s,c]=(0,r.useState)(a),[u,d]=(0,r.useState)(o||"desc"),[h,m]=(0,r.useState)(null),p=(0,r.useMemo)((()=>{const{startIndex:e,endIndex:n}=l;return Nm(t,Em(u,s)).slice(e,n)}),[t,s,u,l]),f=(e,t)=>async()=>{if(h!==t)try{await navigator.clipboard.writeText(String(e)),m(t)}catch(Pp){console.error(Pp)}};return(0,r.useEffect)((()=>{if(null===h)return;const e=setTimeout((()=>m(null)),2e3);return()=>clearTimeout(e)}),[h]),Nt("table",{className:"vm-table",children:[Nt("thead",{className:"vm-table-header",children:Nt("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((e=>{return Nt("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:(t=e.key,()=>{d((e=>"asc"===e&&s===t?"desc":"asc")),c(t)}),children:Nt("div",{className:"vm-table-cell__content",children:[Nt("div",{children:String(e.title||e.key)}),Nt("div",{className:Cr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":s===e.key,"vm-table__sort-icon_desc":"desc"===u&&s===e.key}),children:Nt(Hn,{})})]})},String(e.key));var t})),i&&Nt("th",{className:"vm-table-cell vm-table-cell_header"})]})}),Nt("tbody",{className:"vm-table-body",children:p.map(((e,t)=>Nt("tr",{className:"vm-table__row",children:[n.map((t=>Nt("td",{className:Cr()({"vm-table-cell":!0,["".concat(t.className)]:t.className}),children:e[t.key]||"-"},String(t.key)))),i&&Nt("td",{className:"vm-table-cell vm-table-cell_right",children:e[i]&&Nt("div",{className:"vm-table-cell__content",children:Nt(_a,{title:h===t?"Copied":"Copy row",children:Nt(ma,{variant:"text",color:h===t?"success":"gray",size:"small",startIcon:Nt(h===t?Xn:rr,{}),onClick:f(e[i],t),ariaLabel:"copy row"})})})})]},t)))})]})},Cp=()=>{const{isMobile:e}=ea(),{timezone:t}=fn(),{data:n,lastUpdated:a,isLoading:i,error:l,fetchData:s}=(()=>{const{serverUrl:e}=Mt(),[t,n]=(0,r.useState)([]),[a,i]=(0,r.useState)(o()().format(It)),[l,s]=(0,r.useState)(!1),[c,u]=(0,r.useState)(),d=(0,r.useMemo)((()=>"".concat(e,"/api/v1/status/active_queries")),[e]),h=async()=>{s(!0);try{const e=await fetch(d),t=await e.json();n(t.data),i(o()().format("HH:mm:ss:SSS")),e.ok?u(void 0):u("".concat(t.errorType,"\r\n").concat(null===t||void 0===t?void 0:t.error))}catch(Pp){Pp instanceof Error&&u("".concat(Pp.name,": ").concat(Pp.message))}s(!1)};return(0,r.useEffect)((()=>{h().catch(console.error)}),[d]),{data:t,lastUpdated:a,isLoading:l,error:c,fetchData:h}})(),c=(0,r.useMemo)((()=>n.map((e=>{const t=o()(e.start).tz().format(Pt),n=o()(e.end).tz().format(Pt);return{duration:e.duration,remote_addr:e.remote_addr,query:e.query,args:"".concat(t," to ").concat(n,", step=").concat(Wt(e.step)),data:JSON.stringify(e,null,2)}}))),[n,t]),u=(0,r.useMemo)((()=>{if(null===c||void 0===c||!c.length)return[];const e=Object.keys(c[0]),t={remote_addr:"client address"},n=["data"];return e.filter((e=>!n.includes(e))).map((e=>({key:e,title:t[e]||e})))}),[c]);return Nt("div",{className:"vm-active-queries",children:[i&&Nt(xl,{}),Nt("div",{className:"vm-active-queries-header",children:[!c.length&&!l&&Nt(na,{variant:"info",children:"There are currently no active queries running"}),l&&Nt(na,{variant:"error",children:l}),Nt("div",{className:"vm-active-queries-header-controls",children:[Nt(ma,{variant:"contained",onClick:async()=>{s().catch(console.error)},startIcon:Nt(Fn,{}),children:"Update"}),Nt("div",{className:"vm-active-queries-header__update-msg",children:["Last updated: ",a]})]})]}),!!c.length&&Nt("div",{className:Cr()({"vm-block":!0,"vm-block_mobile":e}),children:Nt(Sp,{rows:c,columns:u,defaultOrderBy:"duration",copyToClipboard:"data",paginationOffset:{startIndex:0,endIndex:1/0}})})]})},Ep=e=>{let{onClose:t,onUpload:n}=e;const{isMobile:a}=ea(),[o,i]=(0,r.useState)(""),[l,s]=(0,r.useState)(""),c=(0,r.useMemo)((()=>{try{return JSON.parse(o),""}catch(Pp){return Pp instanceof Error?Pp.message:"Unknown error"}}),[o]),u=()=>{s(c),c||(n(o),t())};return Nt("div",{className:Cr()({"vm-json-form vm-json-form_one-field":!0,"vm-json-form_mobile vm-json-form_one-field_mobile":a}),children:[Nt(Wa,{value:o,label:"JSON",type:"textarea",error:l,autofocus:!0,onChange:e=>{s(""),i(e)},onEnter:u}),Nt("div",{className:"vm-json-form-footer",children:Nt("div",{className:"vm-json-form-footer__controls vm-json-form-footer__controls_right",children:[Nt(ma,{variant:"outlined",color:"error",onClick:t,children:"Cancel"}),Nt(ma,{variant:"contained",onClick:u,children:"apply"})]})})]})},Np=e=>{let{data:t,period:n}=e;const{isMobile:a}=ea(),{tableCompact:o}=Fr(),i=jr(),[l,s]=(0,r.useState)([]),[c,u]=(0,r.useState)(),[d,h]=(0,r.useState)(),[m,p]=(0,r.useState)(!1),[f,v]=(0,r.useState)([]),[g,y]=(0,r.useState)(),_=(0,r.useMemo)((()=>Kh(d||[]).map((e=>e.key))),[d]),b=(0,r.useMemo)((()=>{const e=t.some((e=>"matrix"===e.data.resultType));return t.some((e=>"vector"===e.data.resultType))&&e?Lr:e?Lr.filter((e=>"chart"===e.value)):Lr.filter((e=>"chart"!==e.value))}),[t]),[w,k]=(0,r.useState)(b[0].value),{yaxis:x,spanGaps:S}=Ur(),C=Br(),E=e=>{C({type:"SET_YAXIS_LIMITS",payload:e})};return(0,r.useEffect)((()=>{const e="chart"===w?"matrix":"vector",n=t.filter((t=>t.data.resultType===e&&t.trace)).map((e=>{var t,n;return e.trace?new Nl(e.trace,(null===e||void 0===e||null===(t=e.vmui)||void 0===t||null===(n=t.params)||void 0===n?void 0:n.query)||"Query"):null}));s(n.filter(Boolean))}),[t,w]),(0,r.useEffect)((()=>{const e=[],n=[],r=[];t.forEach(((t,a)=>{const o=t.data.result.map((e=>{var n,r,o;return{...e,group:Number(null!==(n=null===(r=t.vmui)||void 0===r||null===(o=r.params)||void 0===o?void 0:o.id)&&void 0!==n?n:a)+1}}));var i,l;"matrix"===t.data.resultType?(n.push(...o),e.push((null===(i=t.vmui)||void 0===i||null===(l=i.params)||void 0===l?void 0:l.query)||"Query")):r.push(...o)})),v(e),u(n),h(r)}),[t]),(0,r.useEffect)((()=>{p(!!c&&Tl(c))}),[c]),Nt("div",{className:Cr()({"vm-query-analyzer-view":!0,"vm-query-analyzer-view_mobile":a}),children:[!!l.length&&Nt(Vl,{traces:l,onDeleteClick:e=>{s((t=>t.filter((t=>t.idValue!==e.idValue))))}}),Nt("div",{className:Cr()({"vm-block":!0,"vm-block_mobile":a}),children:[Nt("div",{className:"vm-custom-panel-body-header",children:[Nt("div",{className:"vm-custom-panel-body-header__tabs",children:Nt(Tr,{activeItem:w,items:b,onChange:e=>{k(e)}})}),Nt("div",{className:"vm-custom-panel-body-header__graph-controls",children:["chart"===w&&Nt(Sa,{}),"chart"===w&&Nt(qh,{yaxis:x,setYaxisLimits:E,toggleEnableLimits:()=>{C({type:"TOGGLE_ENABLE_YAXIS_LIMITS"})},spanGaps:{value:S,onChange:e=>{C({type:"SET_SPAN_GAPS",payload:e})}}}),"table"===w&&Nt(Xh,{columns:_,selectedColumns:g,onChangeColumns:y,tableCompact:o,toggleTableCompact:()=>{i({type:"TOGGLE_TABLE_COMPACT"})}})]})]}),c&&n&&"chart"===w&&Nt($h,{data:c,period:n,customStep:n.step||"1s",query:f,yaxis:x,setYaxisLimits:E,setPeriod:()=>null,height:a?.5*window.innerHeight:500,isHistogram:m,spanGaps:S}),d&&"code"===w&&Nt(Wh,{data:d}),d&&"table"===w&&Nt(Zh,{data:d,displayColumns:g})]})]})},Ap=e=>{var t,n;let{data:a,period:i}=e;const l=(0,r.useMemo)((()=>a.filter((e=>e.stats&&"matrix"===e.data.resultType))),[a]),s=(0,r.useMemo)((()=>{var e,t;return null===(e=a.find((e=>{var t;return null===e||void 0===e||null===(t=e.vmui)||void 0===t?void 0:t.comment})))||void 0===e||null===(t=e.vmui)||void 0===t?void 0:t.comment}),[a]),c=(0,r.useMemo)((()=>{if(!i)return"";const e=o()(1e3*i.start).tz().format(Pt),t=o()(1e3*i.end).tz().format(Pt);return"".concat(e," - ").concat(t)}),[i]),{value:u,setTrue:d,setFalse:h}=fa(!1);return Nt(Ct.FK,{children:[Nt("div",{className:"vm-query-analyzer-info-header",children:[Nt(ma,{startIcon:Nt(In,{}),variant:"outlined",color:"warning",onClick:d,children:"Show report info"}),i&&Nt(Ct.FK,{children:[Nt("div",{className:"vm-query-analyzer-info-header__period",children:[Nt(or,{})," step: ",i.step]}),Nt("div",{className:"vm-query-analyzer-info-header__period",children:[Nt($n,{})," ",c]})]})]}),u&&Nt(ya,{title:"Report info",onClose:h,children:Nt("div",{className:"vm-query-analyzer-info",children:[s&&Nt("div",{className:"vm-query-analyzer-info-item vm-query-analyzer-info-item_comment",children:[Nt("div",{className:"vm-query-analyzer-info-item__title",children:"Comment:"}),Nt("div",{className:"vm-query-analyzer-info-item__text",children:s})]}),l.map(((e,t)=>{var n;return Nt("div",{className:"vm-query-analyzer-info-item",children:[Nt("div",{className:"vm-query-analyzer-info-item__title",children:l.length>1?"Query ".concat(t+1,":"):"Stats:"}),Nt("div",{className:"vm-query-analyzer-info-item__text",children:[Object.entries(e.stats||{}).map((e=>{let[t,n]=e;return Nt("div",{children:[t,": ",null!==n&&void 0!==n?n:"-"]},t)})),"isPartial: ",String(null!==(n=e.isPartial)&&void 0!==n?n:"-")]})]},t)})),Nt("div",{className:"vm-query-analyzer-info-type",children:null!==(t=l[0])&&void 0!==t&&null!==(n=t.vmui)&&void 0!==n&&n.params?"The report was created using vmui":"The report was created manually"})]})})]})},Mp=()=>{const[e,t]=(0,r.useState)([]),[n,a]=(0,r.useState)(""),o=(0,r.useMemo)((()=>!!e.length),[e]),{value:i,setTrue:l,setFalse:s}=fa(!1),c=(0,r.useMemo)((()=>{var t,n;if(!e)return;const r=null===(t=e[0])||void 0===t||null===(n=t.vmui)||void 0===n?void 0:n.params,a={start:+((null===r||void 0===r?void 0:r.start)||0),end:+((null===r||void 0===r?void 0:r.end)||0),step:null===r||void 0===r?void 0:r.step,date:""};if(!r){const t=e.filter((e=>"matrix"===e.data.resultType)).map((e=>e.data.result)).flat().map((e=>{var t;return e.values?null===(t=e.values)||void 0===t?void 0:t.map((e=>e[0])):[0]})).flat(),n=Array.from(new Set(t.filter(Boolean))).sort(((e,t)=>e-t));a.start=n[0],a.end=n[n.length-1],a.step=Yt((e=>{const t=e.slice(1).map(((t,n)=>t-e[n])),n={};t.forEach((e=>{const t=e.toString();n[t]=(n[t]||0)+1}));let r=0,a=0;for(const o in n)n[o]>a&&(a=n[o],r=Number(o));return r})(n))}return a.date=Jt(tn(a.end)),a}),[e]),u=e=>{try{const n=JSON.parse(e),r=Array.isArray(n)?n:[n];(e=>e.every((e=>{if("object"===typeof e&&null!==e){const t=e.data;if("object"===typeof t&&null!==t){const e=t.result,n=t.resultType;return Array.isArray(e)&&"string"===typeof n}}return!1})))(r)?t(r):a("Invalid structure - JSON does not match the expected format")}catch(Pp){Pp instanceof Error&&a("".concat(Pp.name,": ").concat(Pp.message))}},d=e=>{e.map((e=>{const t=new FileReader;t.onload=e=>{var t;const n=String(null===(t=e.target)||void 0===t?void 0:t.result);u(n)},t.readAsText(e)}))},h=e=>{a("");const t=Array.from(e.target.files||[]);d(t),e.target.value=""},{files:m,dragging:p}=Qm();return(0,r.useEffect)((()=>{d(m)}),[m]),Nt("div",{className:"vm-trace-page",children:[o&&Nt("div",{className:"vm-trace-page-header",children:[Nt("div",{className:"vm-trace-page-header-errors",children:Nt(Ap,{data:e,period:c})}),Nt("div",{children:Nt(Zm,{onOpenModal:l,onChange:h})})]}),n&&Nt("div",{className:"vm-trace-page-header-errors-item vm-trace-page-header-errors-item_margin-bottom",children:[Nt(na,{variant:"error",children:n}),Nt(ma,{className:"vm-trace-page-header-errors-item__close",startIcon:Nt(On,{}),variant:"text",color:"error",onClick:()=>{a("")}})]}),o&&Nt(Np,{data:e,period:c}),!o&&Nt("div",{className:"vm-trace-page-preview",children:[Nt("p",{className:"vm-trace-page-preview__text",children:["Please, upload file with JSON response content.","\n","The file must contain query information in JSON format.","\n","Graph will be displayed after file upload.","\n","Attach files by dragging & dropping, selecting or pasting them."]}),Nt(Zm,{onOpenModal:l,onChange:h})]}),i&&Nt(ya,{title:"Paste JSON",onClose:s,children:Nt(Ep,{onClose:s,onUpload:u})}),p&&Nt("div",{className:"vm-trace-page__dropzone"})]})},Tp=()=>{const[e,t]=(0,r.useState)(!1);return Nt(Ct.FK,{children:Nt(Oe,{children:Nt(aa,{children:Nt(Ct.FK,{children:[Nt(Km,{onLoaded:t}),e&&Nt(xe,{children:Nt(we,{path:"/",element:Nt(Ho,{}),children:[Nt(we,{path:We.home,element:Nt(om,{})}),Nt(we,{path:We.metrics,element:Nt(hp,{})}),Nt(we,{path:We.cardinality,element:Nt(zm,{})}),Nt(we,{path:We.topQueries,element:Nt(Um,{})}),Nt(we,{path:We.trace,element:Nt(Gm,{})}),Nt(we,{path:We.queryAnalyzer,element:Nt(Mp,{})}),Nt(we,{path:We.dashboards,element:Nt(cm,{})}),Nt(we,{path:We.withTemplate,element:Nt(bp,{})}),Nt(we,{path:We.relabel,element:Nt(xp,{})}),Nt(we,{path:We.activeQueries,element:Nt(Cp,{})}),Nt(we,{path:We.icons,element:Nt(mp,{})})]})})]})})})})},Lp=e=>{e&&n.e(685).then(n.bind(n,685)).then((t=>{let{onCLS:n,onINP:r,onFCP:a,onLCP:o,onTTFB:i}=t;n(e),r(e),a(e),o(e),i(e)}))},Op=document.getElementById("root");Op&&(0,r.render)(Nt(Tp,{}),Op),Lp()})()})(); \ No newline at end of file diff --git a/app/vmselect/vmui/static/js/main.621c4b4d.js.LICENSE.txt b/app/vmselect/vmui/static/js/main.621c4b4d.js.LICENSE.txt deleted file mode 100644 index c4b51e538..000000000 --- a/app/vmselect/vmui/static/js/main.621c4b4d.js.LICENSE.txt +++ /dev/null @@ -1,38 +0,0 @@ -/*! - Copyright (c) 2018 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/ - -/** - * @remix-run/router v1.19.2 - * - * Copyright (c) Remix Software Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE.md file in the root directory of this source tree. - * - * @license MIT - */ - -/** - * React Router DOM v6.26.2 - * - * Copyright (c) Remix Software Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE.md file in the root directory of this source tree. - * - * @license MIT - */ - -/** - * React Router v6.26.2 - * - * Copyright (c) Remix Software Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE.md file in the root directory of this source tree. - * - * @license MIT - */