a)?-1:1})):e}),[m,t,c,d,o]),_=(0,r.useMemo)((function(){return y.some((function(e){return e.copyValue}))}),[y]),b=function(e){return function(){!function(e){h((function(t){return"asc"===t&&c===e?"desc":"asc"})),s(e)}(e)}};return y.length?Ut("div",{className:Rr()({"vm-table-view":!0,"vm-table-view_mobile":a}),children:Ut("table",{className:"vm-table",ref:u,children:[Ut("thead",{className:"vm-table-header",children:Ut("tr",{className:"vm-table__row vm-table__row_header",children:[m.map((function(e,t){return Ut("td",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:b(e.key),children:Ut("div",{className:"vm-table-cell__content",children:[e.key,Ut("div",{className:Rr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":c===e.key,"vm-table__sort-icon_desc":"desc"===d&&c===e.key}),children:Ut(nr,{})})]})},t)})),Ut("td",{className:"vm-table-cell vm-table-cell_header vm-table-cell_right vm-table-cell_sort",onClick:b("Value"),children:Ut("div",{className:"vm-table-cell__content",children:[Ut("div",{className:Rr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":"Value"===c,"vm-table__sort-icon_desc":"desc"===d}),children:Ut(nr,{})}),"Value"]})}),_&&Ut("td",{className:"vm-table-cell vm-table-cell_header"})]})}),Ut("tbody",{className:"vm-table-body",children:y.map((function(e,t){return Ut("tr",{className:"vm-table__row",children:[e.metadata.map((function(e,n){return Ut("td",{className:Rr()({"vm-table-cell vm-table-cell_no-wrap":!0,"vm-table-cell_gray":y[t-1]&&y[t-1].metadata[n]===e}),children:e},n)})),Ut("td",{className:"vm-table-cell vm-table-cell_right vm-table-cell_no-wrap",children:e.values.length?e.values.map((function(e){return Ut("p",{children:e},e)})):e.value}),_&&Ut("td",{className:"vm-table-cell vm-table-cell_right",children:e.copyValue&&Ut("div",{className:"vm-table-cell__content",children:Ut(Ai,{title:"Copy row",children:Ut(bi,{variant:"text",color:"gray",size:"small",startIcon:Ut(_r,{}),onClick:(n=e.copyValue,Yi($i().mark((function e(){return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i(n,"Row has been copied");case 2:case"end":return e.stop()}}),e)})))),ariaLabel:"copy row"})})})})]},t);var n}))})]})}):Ut(fi,{variant:"warning",children:"No data to show"})},pd=function(e){var t=e.text,n=e.href,r=e.children,i=e.colored,a=void 0===i||i,o=e.underlined,u=void 0!==o&&o,l=e.withIcon,c=void 0!==l&&l;return Ut("a",{href:n,className:Rr()({"vm-link":!0,"vm-link_colored":a,"vm-link_underlined":u,"vm-link_with-icon":c}),target:"_blank",rel:"noreferrer",children:t||r})},vd=Ut(pd,{text:"last_over_time",href:"https://docs.victoriametrics.com/MetricsQL.html#last_over_time",underlined:!0}),gd=Ut(pd,{text:"instant query",href:"https://docs.victoriametrics.com/keyConcepts.html#instant-query",underlined:!0}),yd=function(){return Ut("div",{children:[Ut("p",{children:["This tab shows ",gd," results for the last 5 minutes ending at the selected time range."]}),Ut("p",{children:["Please wrap the query into ",vd," if you need results over arbitrary lookbehind interval."]})]})},_d=function(){var e=ei(),t=e.displayType,n=e.isTracingEnabled,i=$n().query,a=Pn().period,o=In(),u=ci().isMobile;!function(){var e=Wt().tenantId,t=ei().displayType,n=$n().query,i=Pn(),a=i.duration,o=i.relativeTime,u=i.period,l=u.date,c=u.step,s=ai().customStep,f=v(lt(),2)[1],d=function(){var r={};n.forEach((function(n,i){var u,f="g".concat(i);r["".concat(f,".expr")]=n,r["".concat(f,".range_input")]=a,r["".concat(f,".end_input")]=l,r["".concat(f,".tab")]=(null===(u=qr.find((function(e){return e.value===t})))||void 0===u?void 0:u.prometheusCode)||0,r["".concat(f,".relative_time")]=o,r["".concat(f,".tenantID")]=e,c!==s&&s&&(r["".concat(f,".step_input")]=s)})),f(sd(r))};(0,r.useEffect)(d,[e,t,n,a,o,l,c,s]),(0,r.useEffect)(d,[])}();var l=v((0,r.useState)(),2),c=l[0],s=l[1],f=v((0,r.useState)([]),2),d=f[0],h=f[1],m=v((0,r.useState)([]),2),p=m[0],g=m[1],_=v((0,r.useState)(!i[0]),2),b=_[0],w=_[1],D=wi(!1),k=D.value,x=D.setTrue,C=D.setFalse,S=ai(),E=S.customStep,A=S.yaxis,N=oi(),M=Kf({visible:!0,customStep:E,hideQuery:p,showAllSeries:k}),F=M.isLoading,T=M.liveData,O=M.graphData,L=M.error,P=M.queryErrors,I=M.setQueryErrors,R=M.queryStats,B=M.warning,z=M.traces,j=M.isHistogram,H=function(e){N({type:"SET_YAXIS_LIMITS",payload:e})},$=(0,r.useMemo)((function(){return fd(T||[]).map((function(e){return e.key}))}),[T]),V=ei().tableCompact,Y=ti();return Vr("popstate",(function(){return window.location.reload()})),(0,r.useEffect)((function(){z&&h([].concat(y(d),y(z)))}),[z]),(0,r.useEffect)((function(){h([])}),[t]),(0,r.useEffect)(C,[i]),(0,r.useEffect)((function(){N({type:"SET_IS_HISTOGRAM",payload:j})}),[O]),Ut("div",{className:Rr()({"vm-custom-panel":!0,"vm-custom-panel_mobile":u}),children:[Ut(Yf,{queryErrors:b?[]:P,setQueryErrors:I,setHideError:w,stats:R,onHideQuery:function(e){g(e)},onRunQuery:function(){w(!1)}}),n&&Ut("div",{className:"vm-custom-panel__trace",children:Ut(od,{traces:d,onDeleteClick:function(e){var t=d.filter((function(t){return t.idValue!==e.idValue}));h(y(t))}})}),F&&Ut(nd,{}),!b&&L&&Ut(fi,{variant:"error",children:L}),!(null!==T&&void 0!==T&&T.length)&&"chart"!==t&&Ut(fi,{variant:"info",children:Ut(yd,{})}),B&&Ut(fi,{variant:"warning",children:Ut("div",{className:Rr()({"vm-custom-panel__warning":!0,"vm-custom-panel__warning_mobile":u}),children:[Ut("p",{children:B}),Ut(bi,{color:"warning",variant:"outlined",onClick:x,children:"Show all"})]})}),Ut("div",{className:Rr()({"vm-custom-panel-body":!0,"vm-custom-panel-body_mobile":u,"vm-block":!0,"vm-block_mobile":u}),children:[Ut("div",{className:"vm-custom-panel-body-header",children:[Ut(Wr,{}),"chart"===t&&Ut("div",{className:"vm-custom-panel-body-header__left",children:[Ut(Oi,{}),Ut(td,{yaxis:A,setYaxisLimits:H,toggleEnableLimits:function(){N({type:"TOGGLE_ENABLE_YAXIS_LIMITS"})}})]}),"table"===t&&Ut(cd,{columns:$,defaultColumns:c,onChangeColumns:s,tableCompact:V,toggleTableCompact:function(){Y({type:"TOGGLE_TABLE_COMPACT"})}})]}),O&&a&&"chart"===t&&Ut(As,{data:O,period:a,customStep:E,query:i,yaxis:A,setYaxisLimits:H,setPeriod:function(e){var t=e.from,n=e.to;o({type:"SET_PERIOD",payload:{from:t,to:n}})},height:u?.5*window.innerHeight:500,isHistogram:j}),T&&"code"===t&&Ut(Jf,{data:T}),T&&"table"===t&&Ut(md,{data:T,displayColumns:c})]})]})},bd=function(e){var t=e.title,n=e.description,i=e.unit,a=e.expr,o=e.showLegend,u=e.filename,l=e.alias,c=ci().isMobile,s=Pn().period,f=ai().customStep,d=In(),h=(0,r.useRef)(null),m=v((0,r.useState)(!1),2),p=m[0],g=m[1],y=v((0,r.useState)({limits:{enable:!1,range:{1:[0,0]}}}),2),_=y[0],b=y[1],w=(0,r.useMemo)((function(){return Array.isArray(a)&&a.every((function(e){return e}))}),[a]),D=Kf({predefinedQuery:w?a:[],display:"chart",visible:p,customStep:f}),k=D.isLoading,x=D.graphData,C=D.error,S=D.warning,E=function(e){var t=dt({},_);t.limits.range=e,b(t)};return(0,r.useEffect)((function(){var e=new IntersectionObserver((function(e){e.forEach((function(e){return g(e.isIntersecting)}))}),{threshold:.1});return h.current&&e.observe(h.current),function(){h.current&&e.unobserve(h.current)}}),[h]),w?Ut("div",{className:"vm-predefined-panel",ref:h,children:[Ut("div",{className:"vm-predefined-panel-header",children:[Ut(Ai,{title:Ut((function(){return Ut("div",{className:"vm-predefined-panel-header__description vm-default-styles",children:[n&&Ut(Vt.HY,{children:[Ut("div",{children:[Ut("span",{children:"Description:"}),Ut("div",{dangerouslySetInnerHTML:{__html:Cf.parse(n)}})]}),Ut("hr",{})]}),Ut("div",{children:[Ut("span",{children:"Queries:"}),Ut("div",{children:a.map((function(e,t){return Ut("div",{children:e},"".concat(t,"_").concat(e))}))})]})]})}),{}),children:Ut("div",{className:"vm-predefined-panel-header__info",children:Ut(Gn,{})})}),Ut("h3",{className:"vm-predefined-panel-header__title",children:t||""}),Ut(td,{yaxis:_,setYaxisLimits:E,toggleEnableLimits:function(){var e=dt({},_);e.limits.enable=!e.limits.enable,b(e)}})]}),Ut("div",{className:"vm-predefined-panel-body",children:[k&&Ut(nd,{}),C&&Ut(fi,{variant:"error",children:C}),S&&Ut(fi,{variant:"warning",children:S}),x&&Ut(As,{data:x,period:s,customStep:f,query:a,yaxis:_,unit:i,alias:l,showLegend:o,setYaxisLimits:E,setPeriod:function(e){var t=e.from,n=e.to;d({type:"SET_PERIOD",payload:{from:t,to:n}})},fullWidth:!1,height:c?.5*window.innerHeight:500})]})]}):Ut(fi,{variant:"error",children:[Ut("code",{children:'"expr"'})," not found. Check the configuration file ",Ut("b",{children:u}),"."]})},wd=function(e){var t=e.index,n=e.title,i=e.panels,a=e.filename,o=Yr(),u=(0,r.useMemo)((function(){return o.width/12}),[o]),l=v((0,r.useState)(!t),2),c=l[0],s=l[1],f=v((0,r.useState)([]),2),d=f[0],h=f[1];(0,r.useEffect)((function(){h(i&&i.map((function(e){return e.width||12})))}),[i]);var m=v((0,r.useState)({start:0,target:0,enable:!1}),2),p=m[0],g=m[1],y=(0,r.useCallback)((function(e){if(p.enable){var t=p.start,n=Math.ceil((t-e.clientX)/u);if(!(Math.abs(n)>=12)){var r=d.map((function(e,t){return e-(t===p.target?n:0)}));h(r)}}}),[p,u]),_=(0,r.useCallback)((function(){g(dt(dt({},p),{},{enable:!1}))}),[p]),b=function(e){return function(t){!function(e,t){g({start:e.clientX,target:t,enable:!0})}(t,e)}};return Vr("mousemove",y),Vr("mouseup",_),Ut("div",{className:"vm-predefined-dashboard",children:Ut(Ea,{defaultExpanded:c,onChange:function(e){return s(e)},title:Ut((function(){return Ut("div",{className:Rr()({"vm-predefined-dashboard-header":!0,"vm-predefined-dashboard-header_open":c}),children:[(n||a)&&Ut("span",{className:"vm-predefined-dashboard-header__title",children:n||"".concat(t+1,". ").concat(a)}),i&&Ut("span",{className:"vm-predefined-dashboard-header__count",children:["(",i.length," panels)"]})]})}),{}),children:Ut("div",{className:"vm-predefined-dashboard-panels",children:Array.isArray(i)&&i.length?i.map((function(e,t){return Ut("div",{className:"vm-predefined-dashboard-panels-panel vm-block vm-block_empty-padding",style:{gridColumn:"span ".concat(d[t])},children:[Ut(bd,{title:e.title,description:e.description,unit:e.unit,expr:e.expr,alias:e.alias,filename:a,showLegend:e.showLegend}),Ut("button",{className:"vm-predefined-dashboard-panels-panel__resizer",onMouseDown:b(t),"aria-label":"resize the panel"})]},t)})):Ut("div",{className:"vm-predefined-dashboard-panels-panel__alert",children:Ut(fi,{variant:"error",children:[Ut("code",{children:'"panels"'})," not found. Check the configuration file ",Ut("b",{children:a}),"."]})})})})})},Dd=function(){!function(){var e=Pn(),t=e.duration,n=e.relativeTime,i=e.period.date,a=ai().customStep,o=_a().setSearchParamsFromKeys,u=function(){var e,r=sd((st(e={},"g0.range_input",t),st(e,"g0.end_input",i),st(e,"g0.step_input",a),st(e,"g0.relative_time",n),e));o(r)};(0,r.useEffect)(u,[t,n,i,a]),(0,r.useEffect)(u,[])}();var e=ci().isMobile,t=vi(),n=t.dashboardsSettings,i=t.dashboardsLoading,a=t.dashboardsError,o=v((0,r.useState)(0),2),u=o[0],l=o[1],c=(0,r.useMemo)((function(){return n.map((function(e,t){return{label:e.title||"",value:t}}))}),[n]),s=(0,r.useMemo)((function(){return n[u]||{}}),[n,u]),f=(0,r.useMemo)((function(){return null===s||void 0===s?void 0:s.rows}),[s]),d=(0,r.useMemo)((function(){return s.title||s.filename||""}),[s]),h=(0,r.useMemo)((function(){return Array.isArray(f)&&!!f.length}),[f]),m=function(e){return function(){!function(e){l(e)}(e)}};return Ut("div",{className:"vm-predefined-panels",children:[i&&Ut(nd,{}),!n.length&&a&&Ut(fi,{variant:"error",children:a}),!n.length&&Ut(fi,{variant:"info",children:"Dashboards not found"}),c.length>1&&Ut("div",{className:Rr()({"vm-predefined-panels-tabs":!0,"vm-predefined-panels-tabs_mobile":e}),children:c.map((function(e){return Ut("div",{className:Rr()({"vm-predefined-panels-tabs__tab":!0,"vm-predefined-panels-tabs__tab_active":e.value==u}),onClick:m(e.value),children:e.label},e.value)}))}),Ut("div",{className:"vm-predefined-panels__dashboards",children:[h&&f.map((function(e,t){return Ut(wd,{index:t,filename:d,title:e.title,panels:e.panels},"".concat(u,"_").concat(t))})),!!n.length&&!h&&Ut(fi,{variant:"error",children:[Ut("code",{children:'"rows"'})," not found. Check the configuration file ",Ut("b",{children:d}),"."]})]})]})},kd=function(e,t){var n=t.match?"&match[]="+encodeURIComponent(t.match):"",r=t.focusLabel?"&focusLabel="+encodeURIComponent(t.focusLabel):"";return"".concat(e,"/api/v1/status/tsdb?topN=").concat(t.topN,"&date=").concat(t.date).concat(n).concat(r)},xd=function(){function e(){_(this,e),this.tsdbStatus=void 0,this.tabsNames=void 0,this.isPrometheus=void 0,this.tsdbStatus=this.defaultTSDBStatus,this.tabsNames=["table","graph"],this.isPrometheus=!1,this.getDefaultState=this.getDefaultState.bind(this)}return k(e,[{key:"tsdbStatusData",get:function(){return this.tsdbStatus},set:function(e){this.isPrometheus=!(null===e||void 0===e||!e.headStats),this.tsdbStatus=e}},{key:"defaultTSDBStatus",get:function(){return{totalSeries:0,totalSeriesPrev:0,totalSeriesByAll:0,totalLabelValuePairs:0,seriesCountByMetricName:[],seriesCountByLabelName:[],seriesCountByFocusLabelValue:[],seriesCountByLabelValuePair:[],labelValueCountByLabelName:[]}}},{key:"isPrometheusData",get:function(){return this.isPrometheus}},{key:"keys",value:function(e,t){var n=e&&/__name__=".+"/.test(e),r=e&&/{.+=".+"}/g.test(e),i=e&&/__name__=".+", .+!=""/g.test(e),a=[];return a=t||i?a.concat("seriesCountByFocusLabelValue"):n?a.concat("labelValueCountByLabelName"):r?a.concat("seriesCountByMetricName","seriesCountByLabelName"):a.concat("seriesCountByMetricName","seriesCountByLabelName","seriesCountByLabelValuePair","labelValueCountByLabelName"),a}},{key:"getDefaultState",value:function(e,t){var n=this;return this.keys(e,t).reduce((function(e,t){return dt(dt({},e),{},{tabs:dt(dt({},e.tabs),{},st({},t,n.tabsNames)),containerRefs:dt(dt({},e.containerRefs),{},st({},t,(0,r.useRef)(null)))})}),{tabs:{},containerRefs:{}})}},{key:"sectionsTitles",value:function(e){return{seriesCountByMetricName:"Metric names with the highest number of series",seriesCountByLabelName:"Labels with the highest number of series",seriesCountByFocusLabelValue:'Values for "'.concat(e,'" label with the highest number of series'),seriesCountByLabelValuePair:"Label=value pairs with the highest number of series",labelValueCountByLabelName:"Labels with the highest number of unique values"}}},{key:"sectionsTips",get:function(){return{seriesCountByMetricName:"\n \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
"}}},{key:"tablesHeaders",get:function(){return{seriesCountByMetricName:Cd,seriesCountByLabelName:Sd,seriesCountByFocusLabelValue:Ed,seriesCountByLabelValuePair:Ad,labelValueCountByLabelName:Nd}}},{key:"totalSeries",value:function(e){return"labelValueCountByLabelName"===e?-1:arguments.length>1&&void 0!==arguments[1]&&arguments[1]?this.tsdbStatus.totalSeriesPrev:this.tsdbStatus.totalSeries}}]),e}(),Cd=[{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:""}],Sd=[{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:""}],Ed=[{id:"name",label:"Label value"},{id:"value",label:"Number of series"},{id:"percentage",label:"Share in total"},{disablePadding:!1,id:"action",label:"",numeric:!1}],Ad=[{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:""}],Nd=[{id:"name",label:"Label name"},{id:"value",label:"Number of unique values"},{id:"action",label:""}],Md={seriesCountByMetricName:function(e){var t=e.query;return Fd("__name__",t)},seriesCountByLabelName:function(e){var t=e.query;return"{".concat(t,'!=""}')},seriesCountByFocusLabelValue:function(e){var t=e.query,n=e.focusLabel;return Fd(n,t)},seriesCountByLabelValuePair:function(e){var t=e.query.split("="),n=t[0],r=t.slice(1).join("=");return Fd(n,r)},labelValueCountByLabelName:function(e){var t=e.query,n=e.match;return""===n?"{".concat(t,'!=""}'):"".concat(n.replace("}",""),", ").concat(t,'!=""}')}},Fd=function(e,t){return e?"{"+e+"="+JSON.stringify(t)+"}":""},Td=function(e){var t,n=e.totalSeries,r=void 0===n?0:n,i=e.totalSeriesPrev,a=void 0===i?0:i,o=e.totalSeriesAll,u=void 0===o?0:o,l=e.seriesCountByMetricName,c=void 0===l?[]:l,s=e.isPrometheus,f=ci().isMobile,d=v(lt(),1)[0],h=d.get("match"),m=d.get("focusLabel"),p=/__name__/.test(h||""),g=(null===(t=c[0])||void 0===t?void 0:t.value)/u*100,y=r-a,_=Math.abs(y)/a*100,b=[{title:"Total series",value:r.toLocaleString("en-US"),dynamic:r&&a&&!s?"".concat(_.toFixed(2),"%"):"",display:!m,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(g)?"-":"".concat(g.toFixed(2),"%"),display:p,info:"The share of these series in the total number of time series."}].filter((function(e){return e.display}));return b.length?Ut("div",{className:Rr()({"vm-cardinality-totals":!0,"vm-cardinality-totals_mobile":f}),children:b.map((function(e){var t=e.title,n=e.value,r=e.info,i=e.dynamic;return Ut("div",{className:"vm-cardinality-totals-card",children:[Ut("h4",{className:"vm-cardinality-totals-card__title",children:[t,r&&Ut(Ai,{title:Ut("p",{className:"vm-cardinality-totals-card__tooltip",children:r}),children:Ut("div",{className:"vm-cardinality-totals-card__info-icon",children:Ut(Gn,{})})})]}),Ut("span",{className:"vm-cardinality-totals-card__value",children:n}),!!i&&Ut(Ai,{title:"in relation to the previous day: ".concat(a.toLocaleString("en-US")),children:Ut("span",{className:Rr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":y<0,"vm-dynamic-number_negative vm-dynamic-number_up":y>0}),children:i})})]},t)}))}):null},Od=function(e,t){var n=v(lt(),1)[0],i=n.get(t)?n.get(t):e,a=v((0,r.useState)(i),2),o=a[0],u=a[1];return(0,r.useEffect)((function(){i!==o&&u(i)}),[i]),[o,u]},Ld=["isPrometheus","isCluster"],Pd=function(e){var t=e.isPrometheus,n=e.isCluster,i=Br(e,Ld),a=ci().isMobile,o=v(lt(),1)[0],u=_a().setSearchParamsFromKeys,l=o.get("tips")||"",c=v(Od("","match"),2),s=c[0],f=c[1],d=v(Od("","focusLabel"),2),h=d[0],m=d[1],p=v(Od(10,"topN"),2),g=p[0],y=p[1],_=(0,r.useMemo)((function(){return g<0?"Number must be bigger than zero":""}),[g]),b=function(){u({match:s,topN:g,focusLabel:h})};return(0,r.useEffect)((function(){var e=o.get("match"),t=+(o.get("topN")||10),n=o.get("focusLabel");e!==s&&f(e||""),t!==g&&y(t),n!==h&&m(n||"")}),[o]),Ut("div",{className:Rr()({"vm-cardinality-configurator":!0,"vm-cardinality-configurator_mobile":a,"vm-block":!0,"vm-block_mobile":a}),children:[Ut("div",{className:"vm-cardinality-configurator-controls",children:[Ut("div",{className:"vm-cardinality-configurator-controls__query",children:Ut(Ji,{label:"Time series selector",type:"string",value:s,onChange:f,onEnter:b})}),Ut("div",{className:"vm-cardinality-configurator-controls__item",children:Ut(Ji,{label:"Focus label",type:"text",value:h||"",onChange:m,onEnter:b,endIcon:Ut(Ai,{title:Ut("div",{children:Ut("p",{children:"To identify values with the highest number of series for the selected label."})}),children:Ut(xr,{})})})}),Ut("div",{className:"vm-cardinality-configurator-controls__item vm-cardinality-configurator-controls__item_limit",children:Ut(Ji,{label:"Limit entries",type:"number",value:t?10:g,error:_,disabled:t,helperText:t?"not available for Prometheus":"",onChange:function(e){var t=+e;y(isNaN(t)?0:t)},onEnter:b})})]}),Ut("div",{className:"vm-cardinality-configurator-bottom",children:[Ut(Td,dt({isPrometheus:t,isCluster:n},i)),n&&Ut("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Ut(pd,{href:"https://docs.victoriametrics.com/#cardinality-explorer-statistic-inaccurancy",withIcon:!0,children:[Ut(Dr,{}),"Statistic inaccuracy explanation"]})}),Ut("div",{className:"vm-cardinality-configurator-bottom-helpful",children:Ut(pd,{href:"https://docs.victoriametrics.com/#cardinality-explorer",withIcon:!0,children:[Ut(Dr,{}),"Documentation"]})}),Ut("div",{className:"vm-cardinality-configurator-bottom__execute",children:[Ut(Ai,{title:l?"Hide tips":"Show tips",children:Ut(bi,{variant:"text",color:l?"warning":"gray",startIcon:Ut(Ar,{}),onClick:function(){var e=o.get("tips")||"";u({tips:e?"":"true"})},ariaLabel:"visibility tips"})}),Ut(bi,{variant:"text",startIcon:Ut(Qn,{}),onClick:function(){u({match:"",focusLabel:""})},children:"Reset"}),Ut(bi,{startIcon:Ut(ur,{}),onClick:b,children:"Execute Query"})]})]})]})};function Id(e){var t=e.order,n=e.orderBy,r=e.onRequestSort,i=e.headerCells;return Ut("thead",{className:"vm-table-header vm-cardinality-panel-table__header",children:Ut("tr",{className:"vm-table__row vm-table__row_header",children:i.map((function(e){return Ut("th",{className:Rr()({"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:(i=e.id,function(e){r(e,i)}),children:Ut("div",{className:"vm-table-cell__content",children:[e.info?Ut(Ai,{title:e.info,children:[Ut("div",{className:"vm-metrics-content-header__tip-icon",children:Ut(Gn,{})}),e.label]}):Ut(Vt.HY,{children:e.label}),"action"!==e.id&&"percentage"!==e.id&&Ut("div",{className:Rr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":n===e.id,"vm-table__sort-icon_desc":"desc"===t&&n===e.id}),children:Ut(nr,{})})]})},e.id);var i}))})})}function Rd(e,t,n){return t[n]e[n]?1:0}function Bd(e,t){return"desc"===e?function(e,n){return Rd(e,n,t)}:function(e,n){return-Rd(e,n,t)}}function zd(e,t){var n=e.map((function(e,t){return[e,t]}));return n.sort((function(e,n){var r=t(e[0],n[0]);return 0!==r?r:e[1]-n[1]})),n.map((function(e){return e[0]}))}var jd=function(e){var t=e.rows,n=e.headerCells,i=e.defaultSortColumn,a=e.tableCells,o=v((0,r.useState)("desc"),2),u=o[0],l=o[1],c=v((0,r.useState)(i),2),s=c[0],f=c[1],d=zd(t,Bd(u,s));return Ut("table",{className:"vm-table vm-cardinality-panel-table",children:[Ut(Id,{order:u,orderBy:s,onRequestSort:function(e,t){l(s===t&&"asc"===u?"desc":"asc"),f(t)},rowCount:t.length,headerCells:n}),Ut("tbody",{className:"vm-table-header",children:d.map((function(e){return Ut("tr",{className:"vm-table__row",children:a(e)},e.name)}))})]})},Hd=function(e){var t=e.row,n=e.totalSeries,r=e.totalSeriesPrev,i=e.onActionClick,a=n>0?t.value/n*100:-1,o=r>0?t.valuePrev/r*100:-1,u=[a,o].some((function(e){return-1===e})),l=a-o,c=u?"":"".concat(l.toFixed(2),"%"),s=function(){i(t.name)};return Ut(Vt.HY,{children:[Ut("td",{className:"vm-table-cell",children:Ut("span",{className:"vm-link vm-link_colored",onClick:s,children:t.name})},t.name),Ut("td",{className:"vm-table-cell",children:[t.value,!!t.diff&&Ut(Ai,{title:"in relation to the previous day: ".concat(t.valuePrev),children:Ut("span",{className:Rr()({"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),a>0&&Ut("td",{className:"vm-table-cell",children:Ut("div",{className:"vm-cardinality-panel-table__progress",children:[Ut(rd,{value:a}),c&&Ut(Ai,{title:"in relation to the previous day",children:Ut("span",{className:Rr()({"vm-dynamic-number":!0,"vm-dynamic-number_positive vm-dynamic-number_down":l<0,"vm-dynamic-number_negative vm-dynamic-number_up":l>0}),children:c})})]})},t.progressValue),Ut("td",{className:"vm-table-cell vm-table-cell_right",children:Ut("div",{className:"vm-table-cell__content",children:Ut(Ai,{title:"Filter by ".concat(t.name),children:Ut(bi,{variant:"text",size:"small",onClick:s,children:Ut(lr,{})})})})},"action")]})},$d=function(e){var t=e.data,n=v((0,r.useState)([]),2),i=n[0],a=n[1],o=v((0,r.useState)([0,0]),2),u=o[0],l=o[1];return(0,r.useEffect)((function(){var e=t.sort((function(e,t){return t.value-e.value})),n=function(e){var t=e.map((function(e){return e.value})),n=Math.ceil(t[0]||1),r=n/9;return new Array(11).fill(n+r).map((function(e,t){return Math.round(e-r*t)}))}(e);l(n),a(e.map((function(e){return dt(dt({},e),{},{percentage:e.value/n[0]*100})})))}),[t]),Ut("div",{className:"vm-simple-bar-chart",children:[Ut("div",{className:"vm-simple-bar-chart-y-axis",children:u.map((function(e){return Ut("div",{className:"vm-simple-bar-chart-y-axis__tick",children:e},e)}))}),Ut("div",{className:"vm-simple-bar-chart-data",children:i.map((function(e){var t=e.name,n=e.value,r=e.percentage;return Ut(Ai,{title:"".concat(t,": ").concat(n),placement:"top-center",children:Ut("div",{className:"vm-simple-bar-chart-data-item",style:{maxHeight:"".concat(r||0,"%")}})},"".concat(t,"_").concat(n))}))})]})},Vd=function(e){var t=e.rows,n=e.tabs,i=void 0===n?[]:n,a=e.chartContainer,o=e.totalSeries,u=e.totalSeriesPrev,l=e.onActionClick,c=e.sectionTitle,s=e.tip,f=e.tableHeaderCells,d=e.isPrometheus,h=ci().isMobile,m=v((0,r.useState)("table"),2),p=m[0],g=m[1],y=d&&!t.length,_=(0,r.useMemo)((function(){return i.map((function(e,t){return{value:e,label:e,icon:Ut(0===t?sr:cr,{})}}))}),[i]);return Ut("div",{className:Rr()({"vm-metrics-content":!0,"vm-metrics-content_mobile":h,"vm-block":!0,"vm-block_mobile":h}),children:[Ut("div",{className:"vm-metrics-content-header vm-section-header",children:[Ut("h5",{className:Rr()({"vm-metrics-content-header__title":!0,"vm-section-header__title":!0,"vm-section-header__title_mobile":h}),children:[!h&&s&&Ut(Ai,{title:Ut("p",{dangerouslySetInnerHTML:{__html:s},className:"vm-metrics-content-header__tip"}),children:Ut("div",{className:"vm-metrics-content-header__tip-icon",children:Ut(Gn,{})})}),c]}),Ut("div",{className:"vm-section-header__tabs",children:Ut(Ur,{activeItem:p,items:_,onChange:g})})]}),y&&Ut("div",{className:"vm-metrics-content-prom-data",children:[Ut("div",{className:"vm-metrics-content-prom-data__icon",children:Ut(Gn,{})}),Ut("h3",{className:"vm-metrics-content-prom-data__title",children:"Prometheus Data Limitation"}),Ut("p",{className:"vm-metrics-content-prom-data__text",children:["Due to missing data from your Prometheus source, some tables may appear empty.",Ut("br",{}),"This does not indicate an issue with your system or our tool."]})]}),!y&&"table"===p&&Ut("div",{ref:a,className:Rr()({"vm-metrics-content__table":!0,"vm-metrics-content__table_mobile":h}),children:Ut(jd,{rows:t,headerCells:f,defaultSortColumn:"value",tableCells:function(e){return Ut(Hd,{row:e,totalSeries:o,totalSeriesPrev:u,onActionClick:l})}})}),!y&&"graph"===p&&Ut("div",{className:"vm-metrics-content__chart",children:Ut($d,{data:t.map((function(e){return{name:e.name,value:e.value}}))})})]})},Yd=function(e){var t=e.title,n=e.children;return Ut("div",{className:"vm-cardinality-tip",children:[Ut("div",{className:"vm-cardinality-tip-header",children:[Ut("div",{className:"vm-cardinality-tip-header__tip-icon",children:Ut(Ar,{})}),Ut("h4",{className:"vm-cardinality-tip-header__title",children:t||"Tips"})]}),Ut("p",{className:"vm-cardinality-tip__description",children:n})]})},Ud=function(){return Ut(Yd,{title:"Metrics with a high number of series",children:Ut("ul",{children:[Ut("li",{children:["Identify and eliminate labels with frequently changed values to reduce their\xa0",Ut(pd,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-cardinality",children:"cardinality"}),"\xa0and\xa0",Ut(pd,{href:"https://docs.victoriametrics.com/FAQ.html#what-is-high-churn-rate",children:"high churn rate"})]}),Ut("li",{children:["Find unused time series and\xa0",Ut(pd,{href:"https://docs.victoriametrics.com/relabeling.html",children:"drop entire metrics"})]}),Ut("li",{children:["Aggregate time series before they got ingested into the database via\xa0",Ut(pd,{href:"https://docs.victoriametrics.com/stream-aggregation.html",children:"streaming aggregation"})]})]})})},qd=function(){return Ut(Yd,{title:"Labels with a high number of unique values",children:Ut("ul",{children:[Ut("li",{children:"Decrease the number of unique label values to reduce cardinality"}),Ut("li",{children:["Drop the label entirely via\xa0",Ut(pd,{href:"https://docs.victoriametrics.com/relabeling.html",children:"relabeling"})]}),Ut("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"})]})})},Wd=function(){return Ut(Yd,{title:"Dashboard of a single metric",children:[Ut("p",{children:"This dashboard helps to understand the cardinality of a single metric."}),Ut("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."}),Ut("p",{children:"Use the series selector at the top of the page to apply additional filters."})]})},Zd=function(){return Ut(Yd,{title:"Dashboard of a label",children:[Ut("p",{children:"This dashboard helps you understand the count of time series per label."}),Ut("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."}),Ut("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."})]})},Qd=function(){var e=ci().isMobile,t=v(lt(),1)[0],n=_a().setSearchParamsFromKeys,i=t.get("tips")||"",o=t.get("match")||"",u=t.get("focusLabel")||"",l=function(){var e=new xd,t=v(lt(),1)[0],n=t.get("match"),i=t.get("focusLabel"),o=+(t.get("topN")||10),u=t.get("date")||a()().tz().format(Gt),l=Wt().serverUrl,c=v((0,r.useState)(!1),2),s=c[0],f=c[1],d=v((0,r.useState)(),2),h=d[0],m=d[1],p=v((0,r.useState)(e.defaultTSDBStatus),2),g=p[0],y=p[1],_=v((0,r.useState)(!1),2),b=_[0],w=_[1],D=function(){var e=Yi($i().mark((function e(t){var n;return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(t);case 2:if(!(n=e.sent).ok){e.next=7;break}return e.next=6,n.json();case 6:return e.abrupt("return",e.sent);case 7:throw new Error("Request failed with status ".concat(n.status));case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),k=function(e,t){Object.keys(e).forEach((function(n){var r=n,i=e[r],a=t[r];Array.isArray(i)&&Array.isArray(a)&&i.forEach((function(e){var t,n=null===(t=a.find((function(t){return t.name===e.name})))||void 0===t?void 0:t.value;e.diff=n?e.value-n:0,e.valuePrev=n||0}))}))},x=function(){var t=Yi($i().mark((function t(r){var i,o,u,c,s,d,h,p,g,_,b,w,x,C,S,E,A,N,M,F,T,O;return $i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(l){t.next=2;break}return t.abrupt("return");case 2:return m(""),f(!0),y(e.defaultTSDBStatus),i=dt(dt({},r),{},{date:r.date,topN:0,match:"",focusLabel:""}),o=dt(dt({},r),{},{date:a()(r.date).subtract(1,"day").tz().format(Gt)}),u=[kd(l,r),kd(l,o),kd(l,i)],t.prev=8,t.next=11,Promise.all(u.map(D));case 11:C=t.sent,S=v(C,3),E=S[0],A=S[1],N=S[2],M=dt({},A.data),F=N.data,T=dt(dt({},E.data),{},{totalSeries:(null===(c=E.data)||void 0===c?void 0:c.totalSeries)||(null===(s=E.data)||void 0===s||null===(d=s.headStats)||void 0===d?void 0:d.numSeries)||0,totalLabelValuePairs:(null===(h=E.data)||void 0===h?void 0:h.totalLabelValuePairs)||(null===(p=E.data)||void 0===p||null===(g=p.headStats)||void 0===g?void 0:g.numLabelValuePairs)||0,seriesCountByLabelName:(null===(_=E.data)||void 0===_?void 0:_.seriesCountByLabelName)||[],seriesCountByFocusLabelValue:(null===(b=E.data)||void 0===b?void 0:b.seriesCountByFocusLabelValue)||[],totalSeriesByAll:(null===F||void 0===F?void 0:F.totalSeries)||(null===F||void 0===F||null===(w=F.headStats)||void 0===w?void 0:w.numSeries)||0,totalSeriesPrev:(null===M||void 0===M?void 0:M.totalSeries)||(null===M||void 0===M||null===(x=M.headStats)||void 0===x?void 0:x.numSeries)||0}),O=null===n||void 0===n?void 0:n.replace(/[{}"]/g,""),T.seriesCountByLabelValuePair=T.seriesCountByLabelValuePair.filter((function(e){return e.name!==O})),k(T,M),y(T),f(!1),t.next=30;break;case 26:t.prev=26,t.t0=t.catch(8),f(!1),t.t0 instanceof Error&&m("".concat(t.t0.name,": ").concat(t.t0.message));case 30:case"end":return t.stop()}}),t,null,[[8,26]])})));return function(e){return t.apply(this,arguments)}}();return(0,r.useEffect)((function(){x({topN:o,match:n,date:u,focusLabel:i})}),[l,n,i,o,u]),(0,r.useEffect)((function(){h&&(y(e.defaultTSDBStatus),f(!1))}),[h]),(0,r.useEffect)((function(){var e=Dt(l);w(!!e)}),[l]),e.tsdbStatusData=g,{isLoading:s,appConfigurator:e,error:h,isCluster:b}}(),c=l.isLoading,s=l.appConfigurator,f=l.error,d=l.isCluster,h=s.tsdbStatusData,m=s.getDefaultState,p=s.tablesHeaders,g=s.sectionsTips,y=m(o,u);return Ut("div",{className:Rr()({"vm-cardinality-panel":!0,"vm-cardinality-panel_mobile":e}),children:[c&&Ut(nd,{message:"Please wait while cardinality stats is calculated. \n This may take some time if the db contains big number of time series."}),Ut(Pd,{isPrometheus:s.isPrometheusData,totalSeries:h.totalSeries,totalSeriesPrev:h.totalSeriesPrev,totalSeriesAll:h.totalSeriesByAll,totalLabelValuePairs:h.totalLabelValuePairs,seriesCountByMetricName:h.seriesCountByMetricName,isCluster:d}),i&&Ut("div",{className:"vm-cardinality-panel-tips",children:[!o&&!u&&Ut(Ud,{}),o&&!u&&Ut(Wd,{}),!o&&!u&&Ut(qd,{}),u&&Ut(Zd,{})]}),f&&Ut(fi,{variant:"error",children:f}),s.keys(o,u).map((function(e){return Ut(Vd,{sectionTitle:s.sectionsTitles(u)[e],tip:g[e],rows:h[e],onActionClick:(t=e,function(e){var r={match:Md[t]({query:e,focusLabel:u,match:o})};"labelValueCountByLabelName"!==t&&"seriesCountByLabelName"!=t||(r.focusLabel=e),"seriesCountByFocusLabelValue"==t&&(r.focusLabel=""),n(r)}),tabs:y.tabs[e],chartContainer:y.containerRefs[e],totalSeriesPrev:s.totalSeries(e,!0),totalSeries:s.totalSeries(e),tableHeaderCells:p[e],isPrometheus:s.isPrometheusData},e);var t}))]})},Gd=function(e){return["topByAvgDuration","topByCount","topBySumDuration"].forEach((function(t){var n=e[t];Array.isArray(n)&&n.forEach((function(e){var t=yn(1e3*e.timeRangeSeconds);e.url=function(e,t){var n,r=e.query,i=e.timeRangeSeconds,a=["g0.expr=".concat(encodeURIComponent(r))],o=null===(n=bn.find((function(e){return e.duration===t})))||void 0===n?void 0:n.id;return o&&a.push("g0.relative_time=".concat(o)),i&&a.push("g0.range_input=".concat(t)),"".concat(gt.home,"?").concat(a.join("&"))}(e,t),e.timeRange=t}))})),e},Kd=function(e){var t=e.topN,n=e.maxLifetime,i=Wt().serverUrl,a=_a().setSearchParamsFromKeys,o=v((0,r.useState)(null),2),u=o[0],l=o[1],c=v((0,r.useState)(!1),2),s=c[0],f=c[1],d=v((0,r.useState)(),2),h=d[0],m=d[1],p=(0,r.useMemo)((function(){return function(e,t,n){return"".concat(e,"/api/v1/status/top_queries?topN=").concat(t||"","&maxLifetime=").concat(n||"")}(i,t,n)}),[i,t,n]),g=function(){var e=Yi($i().mark((function e(){var r,i;return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return f(!0),a({topN:t,maxLifetime:n}),e.prev=2,e.next=5,fetch(p);case 5:return r=e.sent,e.next=8,r.json();case 8:i=e.sent,l(r.ok?Gd(i):null),m(String(i.error||"")),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(2),e.t0 instanceof Error&&"AbortError"!==e.t0.name&&m("".concat(e.t0.name,": ").concat(e.t0.message));case 16:f(!1);case 17:case"end":return e.stop()}}),e,null,[[2,13]])})));return function(){return e.apply(this,arguments)}}();return{data:u,error:h,loading:s,fetch:g}},Jd=function(e){var t=e.rows,n=e.columns,i=e.defaultOrderBy,a=ws(),o=v((0,r.useState)(i||"count"),2),u=o[0],l=o[1],c=v((0,r.useState)("desc"),2),s=c[0],f=c[1],d=(0,r.useMemo)((function(){return zd(t,Bd(s,u))}),[t,u,s]),h=function(e){return function(){var t;t=e,f((function(e){return"asc"===e&&u===t?"desc":"asc"})),l(t)}},m=function(e){var t=e.query;return Yi($i().mark((function e(){return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a(t,"Query has been copied");case 2:case"end":return e.stop()}}),e)})))};return Ut("table",{className:"vm-table",children:[Ut("thead",{className:"vm-table-header",children:Ut("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((function(e){return Ut("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:h(e.sortBy||e.key),children:Ut("div",{className:"vm-table-cell__content",children:[e.title||e.key,Ut("div",{className:Rr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":u===e.key,"vm-table__sort-icon_desc":"desc"===s&&u===e.key}),children:Ut(nr,{})})]})},e.key)})),Ut("th",{className:"vm-table-cell vm-table-cell_header"})," "]})}),Ut("tbody",{className:"vm-table-body",children:d.map((function(e,t){return Ut("tr",{className:"vm-table__row",children:[n.map((function(t){return Ut("td",{className:"vm-table-cell",children:e[t.key]||"-"},t.key)})),Ut("td",{className:"vm-table-cell vm-table-cell_no-padding",children:Ut("div",{className:"vm-top-queries-panels__table-actions",children:[e.url&&Ut(Ai,{title:"Execute query",children:Ut(rt,{to:e.url,target:"_blank",rel:"noreferrer","aria-disabled":!0,children:Ut(bi,{variant:"text",size:"small",startIcon:Ut(lr,{}),ariaLabel:"execute query"})})}),Ut(Ai,{title:"Copy query",children:Ut(bi,{variant:"text",size:"small",startIcon:Ut(_r,{}),onClick:m(e),ariaLabel:"copy query"})})]})})]},t)}))})]})},Xd=["table","JSON"].map((function(e,t){return{value:String(t),label:e,icon:Ut(0===t?sr:fr,{})}})),eh=function(e){var t=e.rows,n=e.title,i=e.columns,a=e.defaultOrderBy,o=ci().isMobile,u=v((0,r.useState)(0),2),l=u[0],c=u[1];return Ut("div",{className:Rr()({"vm-top-queries-panel":!0,"vm-block":!0,"vm-block_mobile":o}),children:[Ut("div",{className:Rr()({"vm-top-queries-panel-header":!0,"vm-section-header":!0,"vm-top-queries-panel-header_mobile":o}),children:[Ut("h5",{className:Rr()({"vm-section-header__title":!0,"vm-section-header__title_mobile":o}),children:n}),Ut("div",{className:"vm-section-header__tabs",children:Ut(Ur,{activeItem:String(l),items:Xd,onChange:function(e){c(+e)}})})]}),Ut("div",{className:Rr()({"vm-top-queries-panel__table":!0,"vm-top-queries-panel__table_mobile":o}),children:[0===l&&Ut(Jd,{rows:t,columns:i,defaultOrderBy:a}),1===l&&Ut(Jf,{data:t})]})]})},th=function(){var e=ci().isMobile,t=v(Od(10,"topN"),2),n=t[0],i=t[1],o=v(Od("10m","maxLifetime"),2),u=o[0],l=o[1],c=Kd({topN:n,maxLifetime:u}),s=c.data,f=c.error,d=c.loading,h=c.fetch,m=(0,r.useMemo)((function(){var e=u.trim().split(" ").reduce((function(e,t){var n=dn(t);return n?dt(dt({},e),n):dt({},e)}),{});return!!a().duration(e).asMilliseconds()}),[u]),p=(0,r.useMemo)((function(){return!!n&&n<1}),[n]),g=(0,r.useMemo)((function(){return p?"Number must be bigger than zero":""}),[p]),y=(0,r.useMemo)((function(){return m?"":"Invalid duration value"}),[m]),_=function(e){if(!s)return e;var t=s[e];return"number"===typeof t?Bc(t,t,t):t||e},b=function(e){"Enter"===e.key&&h()};return(0,r.useEffect)((function(){s&&(n||i(+s.topN),u||l(s.maxLifetime))}),[s]),(0,r.useEffect)((function(){return h(),window.addEventListener("popstate",h),function(){window.removeEventListener("popstate",h)}}),[]),Ut("div",{className:Rr()({"vm-top-queries":!0,"vm-top-queries_mobile":e}),children:[d&&Ut(nd,{containerStyles:{height:"500px"}}),Ut("div",{className:Rr()({"vm-top-queries-controls":!0,"vm-block":!0,"vm-block_mobile":e}),children:[Ut("div",{className:"vm-top-queries-controls-fields",children:[Ut("div",{className:"vm-top-queries-controls-fields__item",children:Ut(Ji,{label:"Max lifetime",value:u,error:y,helperText:"For example ".concat("30ms, 15s, 3d4h, 1y2w"),onChange:function(e){l(e)},onKeyDown:b})}),Ut("div",{className:"vm-top-queries-controls-fields__item",children:Ut(Ji,{label:"Number of returned queries",type:"number",value:n||"",error:g,onChange:function(e){i(+e)},onKeyDown:b})})]}),Ut("div",{className:Rr()({"vm-top-queries-controls-bottom":!0,"vm-top-queries-controls-bottom_mobile":e}),children:[Ut("div",{className:"vm-top-queries-controls-bottom__info",children:["VictoriaMetrics tracks the last\xa0",Ut(Ai,{title:"search.queryStats.lastQueriesCount",children:Ut("b",{children:_("search.queryStats.lastQueriesCount")})}),"\xa0queries with durations at least\xa0",Ut(Ai,{title:"search.queryStats.minQueryDuration",children:Ut("b",{children:_("search.queryStats.minQueryDuration")})})]}),Ut("div",{className:"vm-top-queries-controls-bottom__button",children:Ut(bi,{startIcon:Ut(ur,{}),onClick:h,children:"Execute"})})]})]}),f&&Ut(fi,{variant:"error",children:f}),s&&Ut(Vt.HY,{children:Ut("div",{className:"vm-top-queries-panels",children:[Ut(eh,{rows:s.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"}),Ut(eh,{rows:s.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"}),Ut(eh,{rows:s.topByCount,title:"Most frequently executed queries",columns:[{key:"query"},{key:"timeRange",sortBy:"timeRangeSeconds",title:"query time interval"},{key:"count"}]})]})})]})},nh={"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)"},rh={"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)"},ih=function(){var e=v((0,r.useState)(zt()),2),t=e[0],n=e[1],i=function(e){n(e.matches)};return(0,r.useEffect)((function(){var e=window.matchMedia("(prefers-color-scheme: dark)");return e.addEventListener("change",i),function(){return e.removeEventListener("change",i)}}),[]),t},ah=["primary","secondary","error","warning","info","success"],oh=function(e){var t,n=e.onLoaded,i=_t(),a=yt().palette,o=void 0===a?{}:a,u=Wt().theme,l=ih(),c=Zt(),s=Yr(),f=v((0,r.useState)((st(t={},It.dark,nh),st(t,It.light,rh),st(t,It.system,zt()?nh:rh),t)),2),d=f[0],h=f[1],m=function(){var e=window,t=e.innerWidth,n=e.innerHeight,r=document.documentElement,i=r.clientWidth,a=r.clientHeight;Bt("scrollbar-width","".concat(t-i,"px")),Bt("scrollbar-height","".concat(n-a,"px")),Bt("vh","".concat(.01*n,"px"))},p=function(){ah.forEach((function(e,t){var r=function(e){var 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"}(Rt("color-".concat(e)));Bt("".concat(e,"-text"),r),t===ah.length-1&&(c({type:"SET_DARK_THEME"}),n(!0))}))},g=function(){var e=Ot("THEME")||It.system,t=d[e];Object.entries(t).forEach((function(e){var t=v(e,2),n=t[0],r=t[1];Bt(n,r)})),p(),i&&(ah.forEach((function(e){var t=o[e];t&&Bt("color-".concat(e),t)})),p())};return(0,r.useEffect)((function(){m(),g()}),[d]),(0,r.useEffect)(m,[s]),(0,r.useEffect)((function(){var e=zt()?nh:rh;d[It.system]!==e?h((function(t){return dt(dt({},t),{},st({},It.system,e))})):g()}),[u,l]),(0,r.useEffect)((function(){i&&c({type:"SET_THEME",payload:It.light})}),[]),null},uh=function(){var e=v((0,r.useState)([]),2),t=e[0],n=e[1],i=v((0,r.useState)(!1),2),a=i[0],o=i[1],u=(0,r.useRef)(document.body),l=function(e){e.preventDefault(),e.stopPropagation(),"dragenter"===e.type||"dragover"===e.type?o(!0):"dragleave"===e.type&&o(!1)};return Vr("dragenter",l,u),Vr("dragleave",l,u),Vr("dragover",l,u),Vr("drop",(function(e){var t;e.preventDefault(),e.stopPropagation(),o(!1),null!==e&&void 0!==e&&null!==(t=e.dataTransfer)&&void 0!==t&&t.files&&e.dataTransfer.files[0]&&function(e){var t=Array.from(e||[]);n(t)}(e.dataTransfer.files)}),u),Vr("paste",(function(e){var t,r=null===(t=e.clipboardData)||void 0===t?void 0:t.items;if(r){var i=Array.from(r).filter((function(e){return"application/json"===e.type})).map((function(e){return e.getAsFile()})).filter((function(e){return null!==e}));n(i)}}),u),{files:t,dragging:a}},lh=function(e){var t=e.onOpenModal,n=e.onChange;return Ut("div",{className:"vm-trace-page-controls",children:[Ut(bi,{variant:"outlined",onClick:t,children:"Paste JSON"}),Ut(Ai,{title:"The file must contain tracing information in JSON format",children:Ut(bi,{children:["Upload Files",Ut("input",{id:"json",type:"file",accept:"application/json",multiple:!0,title:" ",onChange:n})]})})]})},ch=function(){var e=v((0,r.useState)([]),2),t=e[0],n=e[1],i=v((0,r.useState)([]),2),a=i[0],o=i[1],u=(0,r.useMemo)((function(){return!!t.length}),[t]),l=wi(!1),c=l.value,s=l.setTrue,f=l.setFalse,d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";o((function(n){return[{filename:t,text:": ".concat(e.message)}].concat(y(n))}))},h=function(e,t){try{var r=JSON.parse(e),i=r.trace||r;if(!i.duration_msec)return void d(new Error(Pt.traceNotFound),t);var a=new Gf(i,t);n((function(e){return[a].concat(y(e))}))}catch(o){o instanceof Error&&d(o,t)}},m=function(e){e.map((function(e){var t=new FileReader,n=(null===e||void 0===e?void 0:e.name)||"";t.onload=function(e){var t,r=String(null===(t=e.target)||void 0===t?void 0:t.result);h(r,n)},t.readAsText(e)}))},p=function(e){o([]);var t=Array.from(e.target.files||[]);m(t),e.target.value=""},g=function(e){return function(){!function(e){o((function(t){return t.filter((function(t,n){return n!==e}))}))}(e)}},_=uh(),b=_.files,w=_.dragging;return(0,r.useEffect)((function(){m(b)}),[b]),Ut("div",{className:"vm-trace-page",children:[Ut("div",{className:"vm-trace-page-header",children:[Ut("div",{className:"vm-trace-page-header-errors",children:a.map((function(e,t){return Ut("div",{className:"vm-trace-page-header-errors-item",children:[Ut(fi,{variant:"error",children:[Ut("b",{className:"vm-trace-page-header-errors-item__filename",children:e.filename}),Ut("span",{children:e.text})]}),Ut(bi,{className:"vm-trace-page-header-errors-item__close",startIcon:Ut(Zn,{}),variant:"text",color:"error",onClick:g(t)})]},"".concat(e,"_").concat(t))}))}),Ut("div",{children:u&&Ut(lh,{onOpenModal:s,onChange:p})})]}),u&&Ut("div",{children:Ut(od,{jsonEditor:!0,traces:t,onDeleteClick:function(e){var r=t.filter((function(t){return t.idValue!==e.idValue}));n(y(r))}})}),!u&&Ut("div",{className:"vm-trace-page-preview",children:[Ut("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",Ut("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."]}),Ut(lh,{onOpenModal:s,onChange:p})]}),c&&Ut(Ei,{title:"Paste JSON",onClose:f,children:Ut(ad,{editable:!0,displayTitle:!0,defaultTile:"JSON ".concat(t.length+1),onClose:f,onUpload:h})}),w&&Ut("div",{className:"vm-trace-page__dropzone"})]})},sh=function(e){var t=Wt().serverUrl,n=Pn().period,i=v((0,r.useState)([]),2),a=i[0],o=i[1],u=v((0,r.useState)(!1),2),l=u[0],c=u[1],s=v((0,r.useState)(),2),f=s[0],d=s[1],h=(0,r.useMemo)((function(){return function(e,t,n){var 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)((function(){if(e){var t=function(){var e=Yi($i().mark((function e(){var t,n,r;return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c(!0),e.prev=1,e.next=4,fetch(h);case 4:return t=e.sent,e.next=7,t.json();case 7:n=e.sent,r=n.data||[],o(r.sort((function(e,t){return e.localeCompare(t)}))),t.ok?d(void 0):d("".concat(n.errorType,"\r\n").concat(null===n||void 0===n?void 0:n.error)),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof Error&&d("".concat(e.t0.name,": ").concat(e.t0.message));case 16:c(!1);case 17:case"end":return e.stop()}}),e,null,[[1,13]])})));return function(){return e.apply(this,arguments)}}();t().catch(console.error)}}),[h]),{instances:a,isLoading:l,error:f}},fh=function(e,t){var n=Wt().serverUrl,i=Pn().period,a=v((0,r.useState)([]),2),o=a[0],u=a[1],l=v((0,r.useState)(!1),2),c=l[0],s=l[1],f=v((0,r.useState)(),2),d=f[0],h=f[1],m=(0,r.useMemo)((function(){return function(e,t,n,r){var i=Object.entries({job:n,instance:r}).filter((function(e){return e[1]})).map((function(e){var t=v(e,2),n=t[0],r=t[1];return"".concat(n,"=").concat(JSON.stringify(r))})).join(","),a="{".concat(i,"}");return"".concat(e,"/api/v1/label/__name__/values?match[]=").concat(encodeURIComponent(a),"&start=").concat(t.start,"&end=").concat(t.end)}(n,i,e,t)}),[n,i,e,t]);return(0,r.useEffect)((function(){if(e){var t=function(){var e=Yi($i().mark((function e(){var t,n,r;return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s(!0),e.prev=1,e.next=4,fetch(m);case 4:return t=e.sent,e.next=7,t.json();case 7:n=e.sent,r=n.data||[],u(r.sort((function(e,t){return e.localeCompare(t)}))),t.ok?h(void 0):h("".concat(n.errorType,"\r\n").concat(null===n||void 0===n?void 0:n.error)),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof Error&&h("".concat(e.t0.name,": ").concat(e.t0.message));case 16:s(!1);case 17:case"end":return e.stop()}}),e,null,[[1,13]])})));return function(){return e.apply(this,arguments)}}();t().catch(console.error)}}),[m]),{names:o,isLoading:c,error:d}},dh=function(e){var t=e.name,n=e.job,i=e.instance,a=e.rateEnabled,o=e.isBucket,u=e.height,l=ci().isMobile,c=ai(),s=c.customStep,f=c.yaxis,d=Pn().period,h=oi(),m=In(),p=mn(d.end-d.start),g=hn(s),y=yn(10*g*1e3),_=v((0,r.useState)(!1),2),b=_[0],w=_[1],D=b&&s===p?y:s,k=wi(!1),x=k.value,C=k.setTrue,S=(0,r.useMemo)((function(){var e=Object.entries({job:n,instance:i}).filter((function(e){return e[1]})).map((function(e){var t=v(e,2),n=t[0],r=t[1];return"".concat(n,"=").concat(JSON.stringify(r))}));e.push("__name__=".concat(JSON.stringify(t))),"node_cpu_seconds_total"==t&&e.push('mode!="idle"');var r="{".concat(e.join(","),"}");if(o)return"sum(rate(".concat(r,")) by (vmrange, le)");var u=a?"rollup_rate(".concat(r,")"):"rollup(".concat(r,")");return"\nwith (q = ".concat(u,') (\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,i,a,o]),E=Kf({predefinedQuery:[S],visible:!0,customStep:D,showAllSeries:x}),A=E.isLoading,N=E.graphData,M=E.error,F=E.warning,T=E.isHistogram;return(0,r.useEffect)((function(){w(T)}),[T]),Ut("div",{className:Rr()({"vm-explore-metrics-graph":!0,"vm-explore-metrics-graph_mobile":l}),children:[A&&Ut(nd,{}),M&&Ut(fi,{variant:"error",children:M}),F&&Ut(fi,{variant:"warning",children:Ut("div",{className:"vm-explore-metrics-graph__warning",children:[Ut("p",{children:F}),Ut(bi,{color:"warning",variant:"outlined",onClick:C,children:"Show all"})]})}),N&&d&&Ut(As,{data:N,period:d,customStep:D,query:[S],yaxis:f,setYaxisLimits:function(e){h({type:"SET_YAXIS_LIMITS",payload:e})},setPeriod:function(e){var t=e.from,n=e.to;m({type:"SET_PERIOD",payload:{from:t,to:n}})},showLegend:!1,height:u,isHistogram:T})]})},hh=function(e){var t=e.name,n=e.index,r=e.length,i=e.isBucket,a=e.rateEnabled,o=e.onChangeRate,u=e.onRemoveItem,l=e.onChangeOrder,c=ci().isMobile,s=wi(!1),f=s.value,d=s.setTrue,h=s.setFalse,m=function(){u(t)},p=function(){l(t,n,n+1)},v=function(){l(t,n,n-1)};return Ut("div",c?{className:"vm-explore-metrics-item-header vm-explore-metrics-item-header_mobile",children:[Ut("div",{className:"vm-explore-metrics-item-header__name",children:t}),Ut(bi,{variant:"text",size:"small",startIcon:Ut(Sr,{}),onClick:d,ariaLabel:"open panel settings"}),f&&Ut(Ei,{title:t,onClose:h,children:Ut("div",{className:"vm-explore-metrics-item-header-modal",children:[Ut("div",{className:"vm-explore-metrics-item-header-modal-order",children:[Ut(bi,{startIcon:Ut(mr,{}),variant:"outlined",onClick:v,disabled:0===n,ariaLabel:"move graph up"}),Ut("p",{children:["position:",Ut("span",{className:"vm-explore-metrics-item-header-modal-order__index",children:["#",n+1]})]}),Ut(bi,{endIcon:Ut(hr,{}),variant:"outlined",onClick:p,disabled:n===r-1,ariaLabel:"move graph down"})]}),!i&&Ut("div",{className:"vm-explore-metrics-item-header-modal__rate",children:[Ut(Pf,{label:Ut("span",{children:["enable ",Ut("code",{children:"rate()"})]}),value:a,onChange:o,fullWidth:!0}),Ut("p",{children:"calculates the average per-second speed of metrics change"})]}),Ut(bi,{startIcon:Ut(Zn,{}),color:"error",variant:"outlined",onClick:m,fullWidth:!0,children:"Remove graph"})]})})]}:{className:"vm-explore-metrics-item-header",children:[Ut("div",{className:"vm-explore-metrics-item-header-order",children:[Ut(Ai,{title:"move graph up",children:Ut(bi,{className:"vm-explore-metrics-item-header-order__up",startIcon:Ut(tr,{}),variant:"text",color:"gray",size:"small",onClick:v,ariaLabel:"move graph up"})}),Ut("div",{className:"vm-explore-metrics-item-header__index",children:["#",n+1]}),Ut(Ai,{title:"move graph down",children:Ut(bi,{className:"vm-explore-metrics-item-header-order__down",startIcon:Ut(tr,{}),variant:"text",color:"gray",size:"small",onClick:p,ariaLabel:"move graph down"})})]}),Ut("div",{className:"vm-explore-metrics-item-header__name",children:t}),!i&&Ut("div",{className:"vm-explore-metrics-item-header__rate",children:Ut(Ai,{title:"calculates the average per-second speed of metric's change",children:Ut(Pf,{label:Ut("span",{children:["enable ",Ut("code",{children:"rate()"})]}),value:a,onChange:o})})}),Ut("div",{className:"vm-explore-metrics-item-header__close",children:Ut(Ai,{title:"close graph",children:Ut(bi,{startIcon:Ut(Zn,{}),variant:"text",color:"gray",size:"small",onClick:m,ariaLabel:"close graph"})})})]})},mh=function(e){var t=e.name,n=e.job,i=e.instance,a=e.index,o=e.length,u=e.size,l=e.onRemoveItem,c=e.onChangeOrder,s=(0,r.useMemo)((function(){return/_sum?|_total?|_count?/.test(t)}),[t]),f=(0,r.useMemo)((function(){return/_bucket?/.test(t)}),[t]),d=v((0,r.useState)(s),2),h=d[0],m=d[1],p=Yr(),g=(0,r.useMemo)(u.height,[u,p]);return(0,r.useEffect)((function(){m(s)}),[n]),Ut("div",{className:"vm-explore-metrics-item vm-block vm-block_empty-padding",children:[Ut(hh,{name:t,index:a,length:o,isBucket:f,rateEnabled:h,size:u.id,onChangeRate:m,onRemoveItem:l,onChangeOrder:c}),Ut(dh,{name:t,job:n,instance:i,rateEnabled:h,isBucket:f,height:g},"".concat(t,"_").concat(n,"_").concat(i,"_").concat(h))]})},ph=function(e){var t=e.values,n=e.onRemoveItem,r=ci().isMobile;return r?Ut("span",{className:"vm-select-input-content__counter",children:["selected ",t.length]}):Ut(Vt.HY,{children:t.map((function(e){return Ut("div",{className:"vm-select-input-content__selected",children:[Ut("span",{children:e}),Ut("div",{onClick:(t=e,function(e){n(t),e.stopPropagation()}),children:Ut(Zn,{})})]},e);var t}))})},vh=function(e){var t=e.value,n=e.list,i=e.label,a=e.placeholder,o=e.noOptionsText,u=e.clearable,l=void 0!==u&&u,c=e.searchable,s=void 0!==c&&c,f=e.autofocus,d=e.onChange,h=Wt().isDarkTheme,m=ci().isMobile,p=v((0,r.useState)(""),2),g=p[0],y=p[1],_=(0,r.useRef)(null),b=v((0,r.useState)(!1),2),w=b[0],D=b[1],k=(0,r.useRef)(null),x=Array.isArray(t),C=Array.isArray(t)?t:void 0,S=m&&x&&!(null===C||void 0===C||!C.length),E=(0,r.useMemo)((function(){return w?g:Array.isArray(t)?"":t}),[t,g,w,x]),A=(0,r.useMemo)((function(){return w?g||"(.+)":""}),[g,w]),N=function(){k.current&&k.current.blur()},M=function(e){d(e),x||(D(!1),N()),x&&k.current&&k.current.focus()};return(0,r.useEffect)((function(){y(""),w&&k.current&&k.current.focus(),w||N()}),[w,k]),(0,r.useEffect)((function(){f&&k.current&&!m&&k.current.focus()}),[f,k]),Vr("keyup",(function(e){k.current!==e.target&&D(!1)})),Ut("div",{className:Rr()({"vm-select":!0,"vm-select_dark":h}),children:[Ut("div",{className:"vm-select-input",onClick:function(e){e.target instanceof HTMLInputElement||D((function(e){return!e}))},ref:_,children:[Ut("div",{className:"vm-select-input-content",children:[!(null===C||void 0===C||!C.length)&&Ut(ph,{values:C,onRemoveItem:M}),!S&&Ut("input",{value:E,type:"text",placeholder:a,onInput:function(e){y(e.target.value)},onFocus:function(){D(!0)},ref:k,readOnly:m||!s})]}),i&&Ut("span",{className:"vm-text-field__label",children:i}),l&&t&&Ut("div",{className:"vm-select-input__icon",onClick:function(e){return function(t){M(e),t.stopPropagation()}}(""),children:Ut(Zn,{})}),Ut("div",{className:Rr()({"vm-select-input__icon":!0,"vm-select-input__icon_open":w}),children:Ut(nr,{})})]}),Ut(Ms,{label:i,value:A,options:n.map((function(e){return{value:e}})),anchor:_,selected:C,minLength:1,fullWidth:!0,noOptionsText:o,onSelect:M,onOpenAutocomplete:D})]})},gh=Nt.map((function(e){return e.id})),yh=function(e){var t=e.jobs,n=e.instances,i=e.names,a=e.job,o=e.instance,u=e.size,l=e.selectedMetrics,c=e.onChangeJob,s=e.onChangeInstance,f=e.onToggleMetric,d=e.onChangeSize,h=(0,r.useMemo)((function(){return a?"":"No instances. Please select job"}),[a]),m=(0,r.useMemo)((function(){return a?"":"No metric names. Please select job"}),[a]),p=ci().isMobile,v=wi("false"!==Ot("EXPLORE_METRICS_TIPS")),g=v.value,y=v.toggle,_=v.setFalse;return(0,r.useEffect)((function(){Tt("EXPLORE_METRICS_TIPS","".concat(g))}),[g]),Ut(Vt.HY,{children:[Ut("div",{className:Rr()({"vm-explore-metrics-header":!0,"vm-explore-metrics-header_mobile":p,"vm-block":!0,"vm-block_mobile":p}),children:[Ut("div",{className:"vm-explore-metrics-header__job",children:Ut(vh,{value:a,list:t,label:"Job",placeholder:"Please select job",onChange:c,autofocus:!a,searchable:!0})}),Ut("div",{className:"vm-explore-metrics-header__instance",children:Ut(vh,{value:o,list:n,label:"Instance",placeholder:"Please select instance",onChange:s,noOptionsText:h,clearable:!0,searchable:!0})}),Ut("div",{className:"vm-explore-metrics-header__size",children:[Ut(vh,{label:"Size graphs",value:u,list:gh,onChange:d}),Ut(Ai,{title:"".concat(g?"Hide":"Show"," tip"),children:Ut(bi,{variant:"text",color:g?"warning":"gray",startIcon:Ut(Ar,{}),onClick:y,ariaLabel:"visibility tips"})})]}),Ut("div",{className:"vm-explore-metrics-header-metrics",children:Ut(vh,{label:"Metrics",value:l,list:i,placeholder:"Search metric name",onChange:f,noOptionsText:m,clearable:!0,searchable:!0})})]}),g&&Ut(fi,{variant:"warning",children:Ut("div",{className:"vm-explore-metrics-header-description",children:[Ut("p",{children:["Please note: this page is solely designed for exploring Prometheus metrics. Prometheus metrics always contain ",Ut("code",{children:"job"})," and ",Ut("code",{children:"instance"})," labels (see ",Ut("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. ",Ut("br",{}),"Please use this page for Prometheus metrics only, in accordance with their naming conventions."]}),Ut(bi,{variant:"text",size:"small",startIcon:Ut(Zn,{}),onClick:_,ariaLabel:"close tips"})]})})]})},_h=Ft("job",""),bh=Ft("instance",""),wh=Ft("metrics",""),Dh=Ft("size",""),kh=Nt.find((function(e){return Dh?e.id===Dh:e.isDefault}))||Nt[0],xh=function(){var e=v((0,r.useState)(_h),2),t=e[0],n=e[1],i=v((0,r.useState)(bh),2),a=i[0],o=i[1],u=v((0,r.useState)(wh?wh.split("&"):[]),2),l=u[0],c=u[1],s=v((0,r.useState)(kh),2),f=s[0],d=s[1];!function(e){var t=e.job,n=e.instance,i=e.metrics,a=e.size,o=Pn(),u=o.duration,l=o.relativeTime,c=o.period.date,s=ai().customStep,f=_a().setSearchParamsFromKeys,d=function(){var e,r=sd((st(e={},"g0.range_input",u),st(e,"g0.end_input",c),st(e,"g0.step_input",s),st(e,"g0.relative_time",l),st(e,"size",a),st(e,"job",t),st(e,"instance",n),st(e,"metrics",i),e));f(r)};(0,r.useEffect)(d,[u,l,c,s,t,n,i,a]),(0,r.useEffect)(d,[])}({job:t,instance:a,metrics:l.join("&"),size:f.id});var h=function(){var e=Wt().serverUrl,t=Pn().period,n=v((0,r.useState)([]),2),i=n[0],a=n[1],o=v((0,r.useState)(!1),2),u=o[0],l=o[1],c=v((0,r.useState)(),2),s=c[0],f=c[1],d=(0,r.useMemo)((function(){return function(e,t){return"".concat(e,"/api/v1/label/job/values?start=").concat(t.start,"&end=").concat(t.end)}(e,t)}),[e,t]);return(0,r.useEffect)((function(){var e=function(){var e=Yi($i().mark((function e(){var t,n,r;return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return l(!0),e.prev=1,e.next=4,fetch(d);case 4:return t=e.sent,e.next=7,t.json();case 7:n=e.sent,r=n.data||[],a(r.sort((function(e,t){return e.localeCompare(t)}))),t.ok?f(void 0):f("".concat(n.errorType,"\r\n").concat(null===n||void 0===n?void 0:n.error)),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof Error&&f("".concat(e.t0.name,": ").concat(e.t0.message));case 16:l(!1);case 17:case"end":return e.stop()}}),e,null,[[1,13]])})));return function(){return e.apply(this,arguments)}}();e().catch(console.error)}),[d]),{jobs:i,isLoading:u,error:s}}(),m=h.jobs,p=h.isLoading,g=h.error,_=sh(t),b=_.instances,w=_.isLoading,D=_.error,k=fh(t,a),x=k.names,C=k.isLoading,S=k.error,E=(0,r.useMemo)((function(){return p||w||C}),[p,w,C]),A=(0,r.useMemo)((function(){return g||D||S}),[g,D,S]),N=function(e){c(e?function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(y(t),[e])}:[])},M=function(e,t,n){var r=n>l.length-1;n<0||r||c((function(e){var r=y(e),i=v(r.splice(t,1),1)[0];return r.splice(n,0,i),r}))};return(0,r.useEffect)((function(){a&&b.length&&!b.includes(a)&&o("")}),[b,a]),Ut("div",{className:"vm-explore-metrics",children:[Ut(yh,{jobs:m,instances:b,names:x,job:t,size:f.id,instance:a,selectedMetrics:l,onChangeJob:n,onChangeSize:function(e){var t=Nt.find((function(t){return t.id===e}));t&&d(t)},onChangeInstance:o,onToggleMetric:N}),E&&Ut(nd,{}),A&&Ut(fi,{variant:"error",children:A}),!t&&Ut(fi,{variant:"info",children:"Please select job to see list of metric names."}),t&&!l.length&&Ut(fi,{variant:"info",children:"Please select metric names to see the graphs."}),Ut("div",{className:"vm-explore-metrics-body",children:l.map((function(e,n){return Ut(mh,{name:e,job:t,instance:a,index:n,length:l.length,size:f,onRemoveItem:N,onChangeOrder:M},e)}))})]})},Ch=function(){var t=ws();return Ut("div",{className:"vm-preview-icons",children:Object.entries(e).map((function(e){var n,r=v(e,2),i=r[0],a=r[1];return Ut("div",{className:"vm-preview-icons-item",onClick:(n=i,Yi($i().mark((function e(){return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t("<".concat(n,"/>"),"<".concat(n,"/> has been copied"));case 2:case"end":return e.stop()}}),e)})))),children:[Ut("div",{className:"vm-preview-icons-item__svg",children:a()}),Ut("div",{className:"vm-preview-icons-item__name",children:"<".concat(i,"/>")})]},i)}))})},Sh=function(e){return e.copy="Copy",e.copied="Copied",e}(Sh||{}),Eh=function(e){var t=e.code,n=v((0,r.useState)(Sh.copy),2),i=n[0],a=n[1];return(0,r.useEffect)((function(){var e=null;return i===Sh.copied&&(e=setTimeout((function(){return a(Sh.copy)}),1e3)),function(){e&&clearTimeout(e)}}),[i]),Ut("code",{className:"vm-code-example",children:[t,Ut("div",{className:"vm-code-example__copy",children:Ut(Ai,{title:i,children:Ut(bi,{size:"small",variant:"text",onClick:function(){navigator.clipboard.writeText(t),a(Sh.copied)},startIcon:Ut(_r,{}),ariaLabel:"close"})})})]})},Ah=function(){return Ut("a",{className:"vm-link vm-link_colored",href:"https://docs.victoriametrics.com/MetricsQL.html",target:"_blank",rel:"help noreferrer",children:"MetricsQL"})},Nh=function(){return Ut("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"})},Mh=function(){return Ut("section",{className:"vm-with-template-tutorial",children:[Ut("h2",{className:"vm-with-template-tutorial__title",children:["Tutorial for WITH expressions in ",Ut(Ah,{})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("p",{className:"vm-with-template-tutorial-section__text",children:["Let's look at the following real query from ",Ut(Nh,{})," dashboard:"]}),Ut(Eh,{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'}),Ut("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? :)"})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("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:"}),Ut(Eh,{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'})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("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:"]}),Ut(Eh,{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)'}),Ut("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."})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("p",{className:"vm-with-template-tutorial-section__text",children:["Let's take another nice query from ",Ut(Nh,{})," dashboard:"]}),Ut(Eh,{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)'}),Ut("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."})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("p",{className:"vm-with-template-tutorial-section__text",children:"1. Extract common filters used in multiple places into a commonFilters variable:"}),Ut(Eh,{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)'})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("p",{className:"vm-with-template-tutorial-section__text",children:'2. Extract "count(count(...) by (cpu))" into cpuCount variable:'}),Ut(Eh,{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'})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("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:"}),Ut(Eh,{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'})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("p",{className:"vm-with-template-tutorial-section__text",children:["4. Put node_cpu_seconds_total","{commonFilters}"," into its own varialbe with the name cpuSeconds:"]}),Ut(Eh,{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'}),Ut("p",{className:"vm-with-template-tutorial-section__text",children:"Now the query became more clear comparing to the initial query."})]}),Ut("div",{className:"vm-with-template-tutorial-section",children:[Ut("p",{className:"vm-with-template-tutorial-section__text",children:"WITH expressions may be nested and may be put anywhere. Try expanding the following query:"}),Ut(Eh,{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)"})]})]})},Fh=function(e,t){return"".concat(e,"/expand-with-exprs?query=").concat(encodeURIComponent(t),"&format=json")},Th=function(){var e=v(lt(),1)[0],t=function(){var e=Wt().serverUrl,t=v(lt(),2),n=t[0],i=t[1],a=v((0,r.useState)(""),2),o=a[0],u=a[1],l=v((0,r.useState)(!1),2),c=l[0],s=l[1],f=v((0,r.useState)(),2),d=f[0],h=f[1],m=function(){var t=Yi($i().mark((function t(r){var a,o,l;return $i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.set("expr",r),i(n),a=Fh(e,r),s(!0),t.prev=4,t.next=7,fetch(a);case 7:return o=t.sent,t.next=10,o.json();case 10:l=t.sent,u((null===l||void 0===l?void 0:l.expr)||""),h(String(l.error||"")),t.next=18;break;case 15:t.prev=15,t.t0=t.catch(4),t.t0 instanceof Error&&"AbortError"!==t.t0.name&&h("".concat(t.t0.name,": ").concat(t.t0.message));case 18:s(!1);case 19:case"end":return t.stop()}}),t,null,[[4,15]])})));return function(e){return t.apply(this,arguments)}}();return{data:o,error:d,loading:c,expand:m}}(),n=t.data,i=t.loading,a=t.error,o=t.expand,u=v((0,r.useState)(e.get("expr")||""),2),l=u[0],c=u[1],s=function(){o(l)};return(0,r.useEffect)((function(){l&&o(l)}),[]),Ut("section",{className:"vm-with-template",children:[i&&Ut(nd,{}),Ut("div",{className:"vm-with-template-body vm-block",children:[Ut("div",{className:"vm-with-template-body__expr",children:Ut(Ji,{type:"textarea",label:"MetricsQL query with optional WITH expressions",value:l,error:a,autofocus:!0,onEnter:s,onChange:function(e){c(e)}})}),Ut("div",{className:"vm-with-template-body__result",children:Ut(Ji,{type:"textarea",label:"MetricsQL query after expanding WITH expressions and applying other optimizations",value:n,disabled:!0})}),Ut("div",{className:"vm-with-template-body-top",children:Ut(bi,{variant:"contained",onClick:s,startIcon:Ut(ur,{}),children:"Expand"})})]}),Ut("div",{className:"vm-block",children:Ut(Mh,{})})]})},Oh=function(e,t,n){var r=["format=json","relabel_configs=".concat(encodeURIComponent(t)),"metric=".concat(encodeURIComponent(n))];return"".concat(e,"/metric-relabel-debug?").concat(r.join("&"))},Lh='- 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"',Ph='{__name__="my_metric", bar_label="bar", foo_label="foo", job="my-application", instance="192.168.0.1"}',Ih=function(){var e=v(lt(),2),t=e[0],n=e[1],i=function(){var e=Wt().serverUrl,t=v((0,r.useState)(null),2),n=t[0],i=t[1],a=v((0,r.useState)(!1),2),o=a[0],u=a[1],l=v((0,r.useState)(),2),c=l[0],s=l[1],f=function(){var t=Yi($i().mark((function t(n,r){var a,o,l;return $i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=Oh(e,n,r),u(!0),t.prev=2,t.next=5,fetch(a);case 5:return o=t.sent,t.next=8,o.json();case 8:l=t.sent,i(l.error?null:l),s(String(l.error||"")),t.next=16;break;case 13:t.prev=13,t.t0=t.catch(2),t.t0 instanceof Error&&"AbortError"!==t.t0.name&&s("".concat(t.t0.name,": ").concat(t.t0.message));case 16:u(!1);case 17:case"end":return t.stop()}}),t,null,[[2,13]])})));return function(e,n){return t.apply(this,arguments)}}();return{data:n,error:c,loading:o,fetchData:f}}(),a=i.data,o=i.loading,u=i.error,l=i.fetchData,c=v(Od("","config"),2),s=c[0],f=c[1],d=v(Od("","labels"),2),h=d[0],m=d[1],p=(0,r.useCallback)((function(){l(s,h),t.set("config",s),t.set("labels",h),n(t)}),[s,h]);return(0,r.useEffect)((function(){var e=t.get("config")||"",n=t.get("labels")||"";(n||e)&&(l(e,n),f(e),m(n))}),[]),Ut("section",{className:"vm-relabeling",children:[o&&Ut(nd,{}),Ut("div",{className:"vm-relabeling-header vm-block",children:[Ut("div",{className:"vm-relabeling-header-configs",children:Ut(Ji,{type:"textarea",label:"Relabel configs",value:s,autofocus:!0,onChange:function(e){f(e||"")},onEnter:p})}),Ut("div",{className:"vm-relabeling-header__labels",children:Ut(Ji,{type:"textarea",label:"Labels",value:h,onChange:function(e){m(e||"")},onEnter:p})}),Ut("div",{className:"vm-relabeling-header-bottom",children:[Ut("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/relabeling.html",rel:"help noreferrer",children:[Ut(Gn,{}),"Relabeling cookbook"]}),Ut("a",{className:"vm-link vm-link_with-icon",target:"_blank",href:"https://docs.victoriametrics.com/vmagent.html#relabeling",rel:"help noreferrer",children:[Ut(Dr,{}),"Documentation"]}),Ut(bi,{variant:"text",onClick:function(){var e=Lh,r=Ph;f(e),m(r),l(e,r),t.set("config",e),t.set("labels",r),n(t)},children:"Try example"}),Ut(bi,{variant:"contained",onClick:p,startIcon:Ut(ur,{}),children:"Submit"})]})]}),u&&Ut(fi,{variant:"error",children:u}),a&&Ut("div",{className:"vm-relabeling-steps vm-block",children:[a.originalLabels&&Ut("div",{className:"vm-relabeling-steps-item",children:Ut("div",{className:"vm-relabeling-steps-item__row",children:[Ut("span",{children:"Original labels:"}),Ut("code",{dangerouslySetInnerHTML:{__html:a.originalLabels}})]})}),a.steps.map((function(e,t){return Ut("div",{className:"vm-relabeling-steps-item",children:[Ut("div",{className:"vm-relabeling-steps-item__row",children:[Ut("span",{children:"Step:"}),t+1]}),Ut("div",{className:"vm-relabeling-steps-item__row",children:[Ut("span",{children:"Relabeling Rule:"}),Ut("code",{children:Ut("pre",{children:e.rule})})]}),Ut("div",{className:"vm-relabeling-steps-item__row",children:[Ut("span",{children:"Input Labels:"}),Ut("code",{children:Ut("pre",{dangerouslySetInnerHTML:{__html:e.inLabels}})})]}),Ut("div",{className:"vm-relabeling-steps-item__row",children:[Ut("span",{children:"Output labels:"}),Ut("code",{children:Ut("pre",{dangerouslySetInnerHTML:{__html:e.outLabels}})})]})]},t)})),a.resultingLabels&&Ut("div",{className:"vm-relabeling-steps-item",children:Ut("div",{className:"vm-relabeling-steps-item__row",children:[Ut("span",{children:"Resulting labels:"}),Ut("code",{dangerouslySetInnerHTML:{__html:a.resultingLabels}})]})})]})]})},Rh=function(e){var t=e.rows,n=e.columns,i=e.defaultOrderBy,a=e.copyToClipboard,o=e.paginationOffset,u=v((0,r.useState)(i),2),l=u[0],c=u[1],s=v((0,r.useState)("desc"),2),f=s[0],d=s[1],h=v((0,r.useState)(null),2),m=h[0],p=h[1],g=(0,r.useMemo)((function(){var e=o.startIndex,n=o.endIndex;return zd(t,Bd(f,l)).slice(e,n)}),[t,l,f,o]),y=function(e,t){return Yi($i().mark((function n(){return $i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(m!==t){n.next=2;break}return n.abrupt("return");case 2:return n.prev=2,n.next=5,navigator.clipboard.writeText(String(e));case 5:p(t),n.next=11;break;case 8:n.prev=8,n.t0=n.catch(2),console.error(n.t0);case 11:case"end":return n.stop()}}),n,null,[[2,8]])})))};return(0,r.useEffect)((function(){if(null!==m){var e=setTimeout((function(){return p(null)}),2e3);return function(){return clearTimeout(e)}}}),[m]),Ut("table",{className:"vm-table",children:[Ut("thead",{className:"vm-table-header",children:Ut("tr",{className:"vm-table__row vm-table__row_header",children:[n.map((function(e){return Ut("th",{className:"vm-table-cell vm-table-cell_header vm-table-cell_sort",onClick:(t=e.key,function(){d((function(e){return"asc"===e&&l===t?"desc":"asc"})),c(t)}),children:Ut("div",{className:"vm-table-cell__content",children:[Ut("div",{children:String(e.title||e.key)}),Ut("div",{className:Rr()({"vm-table__sort-icon":!0,"vm-table__sort-icon_active":l===e.key,"vm-table__sort-icon_desc":"desc"===f&&l===e.key}),children:Ut(nr,{})})]})},String(e.key));var t})),a&&Ut("th",{className:"vm-table-cell vm-table-cell_header"})]})}),Ut("tbody",{className:"vm-table-body",children:g.map((function(e,t){return Ut("tr",{className:"vm-table__row",children:[n.map((function(t){return Ut("td",{className:Rr()(st({"vm-table-cell":!0},"".concat(t.className),t.className)),children:e[t.key]||"-"},String(t.key))})),a&&Ut("td",{className:"vm-table-cell vm-table-cell_right",children:e[a]&&Ut("div",{className:"vm-table-cell__content",children:Ut(Ai,{title:m===t?"Copied":"Copy row",children:Ut(bi,{variant:"text",color:m===t?"success":"gray",size:"small",startIcon:Ut(m===t?pr:_r,{}),onClick:y(e[a],t),ariaLabel:"copy row"})})})})]},t)}))})]})},Bh=function(){var e=ci().isMobile,t=Pn().timezone,n=function(){var e=Wt().serverUrl,t=v((0,r.useState)([]),2),n=t[0],i=t[1],o=v((0,r.useState)(a()().format(Jt)),2),u=o[0],l=o[1],c=v((0,r.useState)(!1),2),s=c[0],f=c[1],d=v((0,r.useState)(),2),h=d[0],m=d[1],p=(0,r.useMemo)((function(){return"".concat(e,"/api/v1/status/active_queries")}),[e]),g=function(){var e=Yi($i().mark((function e(){var t,n;return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return f(!0),e.prev=1,e.next=4,fetch(p);case 4:return t=e.sent,e.next=7,t.json();case 7:n=e.sent,i(n.data),l(a()().format("HH:mm:ss:SSS")),t.ok?m(void 0):m("".concat(n.errorType,"\r\n").concat(null===n||void 0===n?void 0:n.error)),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof Error&&m("".concat(e.t0.name,": ").concat(e.t0.message));case 16:f(!1);case 17:case"end":return e.stop()}}),e,null,[[1,13]])})));return function(){return e.apply(this,arguments)}}();return(0,r.useEffect)((function(){g().catch(console.error)}),[p]),{data:n,lastUpdated:u,isLoading:s,error:h,fetchData:g}}(),i=n.data,o=n.lastUpdated,u=n.isLoading,l=n.error,c=n.fetchData,s=(0,r.useMemo)((function(){return i.map((function(e){var t=a()(e.start).tz().format(Kt),n=a()(e.end).tz().format(Kt);return{duration:e.duration,remote_addr:e.remote_addr,query:e.query,args:"".concat(t," to ").concat(n,", step=").concat(fn(e.step)),data:JSON.stringify(e,null,2)}}))}),[i,t]),f=(0,r.useMemo)((function(){if(null===s||void 0===s||!s.length)return[];var e=Object.keys(s[0]),t={remote_addr:"client address"},n=["data"];return e.filter((function(e){return!n.includes(e)})).map((function(e){return{key:e,title:t[e]||e}}))}),[s]),d=function(){var e=Yi($i().mark((function e(){return $i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:c().catch(console.error);case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();return Ut("div",{className:"vm-active-queries",children:[u&&Ut(nd,{}),Ut("div",{className:"vm-active-queries-header",children:[!s.length&&!l&&Ut(fi,{variant:"info",children:"There are currently no active queries running"}),l&&Ut(fi,{variant:"error",children:l}),Ut("div",{className:"vm-active-queries-header-controls",children:[Ut(bi,{variant:"contained",onClick:d,startIcon:Ut(er,{}),children:"Update"}),Ut("div",{className:"vm-active-queries-header__update-msg",children:["Last updated: ",o]})]})]}),!!s.length&&Ut("div",{className:Rr()({"vm-block":!0,"vm-block_mobile":e}),children:Ut(Rh,{rows:s,columns:f,defaultOrderBy:"duration",copyToClipboard:"data",paginationOffset:{startIndex:0,endIndex:1/0}})})]})},zh=function(){var e=v((0,r.useState)(!1),2),t=e[0],n=e[1];return Ut(Vt.HY,{children:Ut(et,{children:Ut(gi,{children:Ut(Vt.HY,{children:[Ut(oh,{onLoaded:n}),t&&Ut(Ve,{children:Ut(He,{path:"/",element:Ut(Pa,{}),children:[Ut(He,{path:gt.home,element:Ut(_d,{})}),Ut(He,{path:gt.metrics,element:Ut(xh,{})}),Ut(He,{path:gt.cardinality,element:Ut(Qd,{})}),Ut(He,{path:gt.topQueries,element:Ut(th,{})}),Ut(He,{path:gt.trace,element:Ut(ch,{})}),Ut(He,{path:gt.dashboards,element:Ut(Dd,{})}),Ut(He,{path:gt.withTemplate,element:Ut(Th,{})}),Ut(He,{path:gt.relabel,element:Ut(Ih,{})}),Ut(He,{path:gt.activeQueries,element:Ut(Bh,{})}),Ut(He,{path:gt.icons,element:Ut(Ch,{})})]})})]})})})})},jh=function(e){e&&n.e(522).then(n.bind(n,522)).then((function(t){var n=t.getCLS,r=t.getFID,i=t.getFCP,a=t.getLCP,o=t.getTTFB;n(e),r(e),i(e),a(e),o(e)}))},Hh=document.getElementById("root");Hh&&(0,r.render)(Ut(zh,{}),Hh),jh()}()}();
\ No newline at end of file
diff --git a/app/vmselect/vmui/static/js/main.19e7f129.js.LICENSE.txt b/app/vmselect/vmui/static/js/main.0c55974f.js.LICENSE.txt
similarity index 100%
rename from app/vmselect/vmui/static/js/main.19e7f129.js.LICENSE.txt
rename to app/vmselect/vmui/static/js/main.0c55974f.js.LICENSE.txt
diff --git a/app/vmui/packages/vmui/src/api/types.ts b/app/vmui/packages/vmui/src/api/types.ts
index 17c46f821..839b43f9a 100644
--- a/app/vmui/packages/vmui/src/api/types.ts
+++ b/app/vmui/packages/vmui/src/api/types.ts
@@ -22,7 +22,8 @@ export interface TracingData {
}
export interface QueryStats {
- seriesFetched?: string;
+ seriesFetched?: number;
+ executionTimeMsec?: number;
resultLength?: number;
isPartial?: boolean;
}
diff --git a/app/vmui/packages/vmui/src/components/Configurators/QueryEditor/QueryEditor.tsx b/app/vmui/packages/vmui/src/components/Configurators/QueryEditor/QueryEditor.tsx
index 4b3bb8b72..c28686b86 100644
--- a/app/vmui/packages/vmui/src/components/Configurators/QueryEditor/QueryEditor.tsx
+++ b/app/vmui/packages/vmui/src/components/Configurators/QueryEditor/QueryEditor.tsx
@@ -41,7 +41,7 @@ const QueryEditor: FC = ({
const warning = [
{
- show: stats?.seriesFetched === "0" && !stats.resultLength,
+ show: stats?.seriesFetched == 0 && !stats.resultLength,
text: seriesFetchedWarning
},
{
@@ -50,6 +50,10 @@ const QueryEditor: FC = ({
}
].filter((w) => w.show).map(w => w.text).join("");
+ if (stats) {
+ label = `${label} (${stats.executionTimeMsec || 0}ms)`;
+ }
+
const handleSelect = (val: string) => {
onChange(val);
};
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 368f06036..74bae86aa 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -62,8 +62,9 @@ The sandbox cluster installation is running under the constant load generated by
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): add support for functions, labels, values in autocomplete. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3006).
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): retain specified time interval when executing a query from `Top Queries`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5097).
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): improve repeated VMUI page load times by enabling caching of static js and css at web browser side according to [these recommendations](https://developer.chrome.com/docs/lighthouse/performance/uses-long-cache-ttl/).
-* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): show information about lines with bigger values at the top of the legend under the graph in order to simplify graph analysis.
+* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): sort legend under the graph in descending order of median values. This should simplify graph analysis, since usually the most important lines have bigger values.
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): reduce vertical space usage, so more information is visible on the screen without scrolling.
+* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): show query execution duration in the header of query input field. This should help optimizing query performance.
* FEATURE: support `Strict-Transport-Security`, `Content-Security-Policy` and `X-Frame-Options` HTTP response headers in the all VictoriaMetrics components. The values for headers can be specified via the following command-line flags: `-http.header.hsts`, `-http.header.csp` and `-http.header.frameOptions`.
* FEATURE: [vmalert-tool](https://docs.victoriametrics.com/#vmalert-tool): add `unittest` command to run unittest for alerting and recording rules. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4789) for details.
* FEATURE: dashboards/vmalert: add new panel `Missed evaluations` for indicating alerting groups that miss their evaluations.