D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
share
/
grafana
/
public
/
build
/
Filename :
prometheusPlugin.be4439956a02756980e7.js
back
Copy
"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7004],{55701:(ue,z,l)=>{l.d(z,{O6:()=>n,Ql:()=>J,ZO:()=>O,f0:()=>V,qV:()=>_,we:()=>K,xu:()=>q,zj:()=>N});var w=l(4002),e=l(42994),Z=l(62434),S=l(4737);function K(s,y){const E=[C()],b=["$__interval"];let d;return s===S.B5.QuantileOverTime&&(b.push("0.95"),E.push({name:"Quantile",type:"number"})),y&&(E.push({name:"By label",type:"string",restParam:!0,optional:!0}),d=(0,e.ZI)(`__${s}_by`)),{id:s,name:(0,e.t7)(s),params:E,defaultParams:b,alternativesKey:"range function",category:S.Ly.RangeFunctions,orderRank:S.jK.RangeVectorFunction,renderer:Y,addOperationHandler:V,paramChangedHandler:d,explainHandler:(f,R)=>{let M=Z.r8.find(B=>B.insertText===f.id)?.documentation??"";return f.params[0]==="$__interval"?`${M} \`$__interval\` is a variable that will be replaced with the [calculated interval](https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#__interval) based on the time range and width of the graph. In Dashboards, you can affect the interval variable using **Max data points** and **Min interval**. You can find these options under **Query options** right of the data source select dropdown.`:`${M} The [range vector](https://grafana.com/docs/loki/latest/logql/metric_queries/#range-vector-aggregation) is set to \`${f.params[0]}\`.`}}}function n(s){const y=K(s,!0),E=y.params.slice(0,-1);return[y,{id:`__${s}_by`,name:`${(0,e.t7)(s)} by`,params:[...E,{name:"Label",type:"string",restParam:!0,optional:!0,editor:w.g}],defaultParams:[...y.defaultParams,""],alternativesKey:"range function with grouping",category:S.Ly.RangeFunctions,renderer:H(s,"by"),paramChangedHandler:(0,e.j8)(s),explainHandler:(0,e.Sp)(s,"by"),addOperationHandler:V,hideFromList:!0},{id:`__${s}_without`,name:`${(0,e.t7)(s)} without`,params:[...E,{name:"Label",type:"string",restParam:!0,optional:!0,editor:w.g}],defaultParams:[...y.defaultParams,""],alternativesKey:"range function with grouping",category:S.Ly.RangeFunctions,renderer:H(s,"without"),paramChangedHandler:(0,e.j8)(s),explainHandler:(0,e.Sp)(s,"without"),addOperationHandler:V,hideFromList:!0}]}function H(s,y){return function(b,d,f){const R=d.params.findIndex(k=>k.restParam),M=b.params.slice(0,R),B=b.params.slice(R);return M.length===2&&s===S.B5.QuantileOverTime?`${s}(${M[1]}, ${f} [${M[0]}]) ${y} (${B.join(", ")})`:`${s}(${f} [${M[0]}]) ${y} (${B.join(", ")})`}}function Y(s,y,E){const b=s.params??[],d=b[0]??"$__interval";if(b.length===2&&s.id===S.B5.QuantileOverTime){const f=b[1];return`${s.id}(${f}, ${E} [${d}])`}return`${s.id}(${E} [${b[0]??"$__interval"}])`}function q(s,y,E){return["<","<=",">",">="].includes(String(s.params[1]))?`${E} | ${s.params[0]} ${s.params[1]} ${s.params[2]}`:`${E} | ${s.params[0]} ${s.params[1]} \`${s.params[2]}\``}function O(s,y){const E=s.params[1].toString().startsWith("!");return y.filter(f=>f.id===S.B5.LabelFilter&&f.params[0]===s.params[0]&&f.params[2]===s.params[2]).some(f=>!!(E&&f.params[1].toString().startsWith("!")===!1||E===!1&&f.params[1].toString().startsWith("!")))}function J(s,y,E){return`${E} | ${s.id}`}function I(s){return s.category===S.Ly.RangeFunctions}function j(s,y,E){const b=s.findIndex(d=>{const f=y.getOperationDef(d.id);return f?E(f):!1});return b===-1?s.length:b}function V(s,y,E){const b={id:s.id,params:s.defaultParams},d=[...y.operations],f=d.find(R=>{const M=E.getOperationDef(R.id);return M?I(M):!1});switch(s.category){case S.Ly.Aggregations:case S.Ly.Functions:if(!f){const M=j(d,E,B=>B.category===S.Ly.Functions);d.splice(M,0,{id:S.B5.Rate,params:["$__interval"]})}d.push(b);break;case S.Ly.RangeFunctions:if(f){const M=d.indexOf(f);d[M]=b;break}default:const R=j(d,E,M=>(s.orderRank??100)<(M.orderRank??100));d.splice(R,0,b);break}return{...y,operations:d}}function _(s,y){return{...y,binaryQueries:[...y.binaryQueries??[],{operator:"/",query:y}]}}function N(s,y){return function(b,d,f){return y?`${f} ${s} \`(?i)${b.params[0]}\``:`${f} ${s} \`${b.params[0]}\``}}function C(){return{name:"Range",type:"string",options:["$__interval","$__range","1m","5m","10m","1h","24h"]}}},4737:(ue,z,l)=>{l.d(z,{AI:()=>K,B5:()=>Z,Hv:()=>w,Ly:()=>e,jK:()=>S});var w=(n=>(n.Log="log",n.Metric="metric",n))(w||{}),e=(n=>(n.Aggregations="Aggregations",n.RangeFunctions="Range functions",n.Functions="Functions",n.Formats="Formats",n.LineFilters="Line filters",n.LabelFilters="Label filters",n.BinaryOps="Binary operations",n))(e||{}),Z=(n=>(n.Json="json",n.Logfmt="logfmt",n.Regexp="regexp",n.Pattern="pattern",n.Unpack="unpack",n.LineFormat="line_format",n.LabelFormat="label_format",n.Decolorize="decolorize",n.Rate="rate",n.RateCounter="rate_counter",n.CountOverTime="count_over_time",n.SumOverTime="sum_over_time",n.AvgOverTime="avg_over_time",n.MaxOverTime="max_over_time",n.MinOverTime="min_over_time",n.FirstOverTime="first_over_time",n.LastOverTime="last_over_time",n.StdvarOverTime="stdvar_over_time",n.StddevOverTime="stddev_over_time",n.QuantileOverTime="quantile_over_time",n.BytesRate="bytes_rate",n.BytesOverTime="bytes_over_time",n.AbsentOverTime="absent_over_time",n.Sum="sum",n.Avg="avg",n.Min="min",n.Max="max",n.Stddev="stddev",n.Stdvar="stdvar",n.Count="count",n.TopK="topk",n.BottomK="bottomk",n.LineContains="__line_contains",n.LineContainsNot="__line_contains_not",n.LineContainsCaseInsensitive="__line_contains_case_insensitive",n.LineContainsNotCaseInsensitive="__line_contains_not_case_insensitive",n.LineMatchesRegex="__line_matches_regex",n.LineMatchesRegexNot="__line_matches_regex_not",n.LineFilterIpMatches="__line_filter_ip_matches",n.LabelFilter="__label_filter",n.LabelFilterNoErrors="__label_filter_no_errors",n.LabelFilterIpMatches="__label_filter_ip_marches",n.Unwrap="unwrap",n.SumBy="__sum_by",n.SumWithout="__sum_without",n.Addition="__addition",n.Subtraction="__subtraction",n.MultiplyBy="__multiply_by",n.DivideBy="__divide_by",n.Modulo="__modulo",n.Exponent="__exponent",n.NestedQuery="__nested_query",n.EqualTo="__equal_to",n.NotEqualTo="__not_equal_to",n.GreaterThan="__greater_than",n.LessThan="__less_than",n.GreaterOrEqual="__greater_or_equal",n.LessOrEqual="__less_or_equal",n))(Z||{}),S=(n=>(n[n.LineFilters=1]="LineFilters",n[n.Parsers=2]="Parsers",n[n.PipeOperations=3]="PipeOperations",n[n.Unwrap=4]="Unwrap",n[n.NoErrors=5]="NoErrors",n[n.RangeVectorFunction=5]="RangeVectorFunction",n[n.Last=6]="Last",n))(S||{});const K={equals:{label:"=",value:"=",description:"Equals",isMultiValue:!1},doesNotEqual:{label:"!=",value:"!=",description:"Does not equal",isMultiValue:!1},matchesRegex:{label:"=~",value:"=~",description:"Matches regex",isMultiValue:!0},doesNotMatchRegex:{label:"!~",value:"!~",description:"Does not match regex",isMultiValue:!0},greaterThan:{label:">",value:">",description:"Greater than",isMultiValue:!1},greaterThanOrEqual:{label:">=",value:">=",description:"Greater than or equal to",isMultiValue:!1},lessThan:{label:"<",value:"<",description:"Less than",isMultiValue:!1},lessThanOrEqual:{label:"<=",value:"<=",description:"Less than or equal to",isMultiValue:!1},contains:{label:"|=",value:"|=",description:"Contains",isMultiValue:!1},doesNotContain:{label:"!=",value:"!=",description:"Does not contain",isMultiValue:!1}}},8842:(ue,z,l)=>{l.r(z),l.d(z,{plugin:()=>xt});var w=l(68246),e=l(27702);const Z=[{title:"Request Rate",expression:"rate(http_request_total[5m])",label:"Given an HTTP request counter, this query calculates the per-second average request rate over the last 5 minutes."},{title:"95th Percentile of Request Latencies",expression:"histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[5m])) by (le))",label:"Calculates the 95th percentile of HTTP request rate over 5 minute windows."},{title:"Alerts Firing",expression:'sort_desc(sum(sum_over_time(ALERTS{alertstate="firing"}[24h])) by (alertname))',label:"Sums up the alerts that have been firing over the last 24 hours."},{title:"Step",label:"Defines the graph resolution using a duration format (15s, 1m, 3h, ...). Small steps create high-resolution graphs but can be slow over larger time ranges. Using a longer step lowers the resolution and smooths the graph by producing fewer datapoints. If no step is given the resolution is calculated automatically."}],K=t=>e.createElement("div",null,e.createElement("h2",null,"PromQL Cheat Sheet"),Z.map((a,r)=>e.createElement("div",{className:"cheat-sheet-item",key:r},e.createElement("div",{className:"cheat-sheet-item__title"},a.title),a.expression?e.createElement("button",{type:"button",className:"cheat-sheet-item__example",onClick:o=>t.onClickExample({refId:"A",expr:a.expression})},e.createElement("code",null,a.expression)):null,e.createElement("div",{className:"cheat-sheet-item__label"},a.label))));var n=l(62247),H=l(89949),Y=l(53933),q=l(74639),O=l(63250),J=l(29473),I=l(60426),j=l(83788),V=l(86312),_=l(3613),N=l(66670),C=l(42844),s=l(66310),y=l(13741),E=l(41640),b=l(76897),d=l(85400),f=l(50230),R=l(86383),M=l(60692);const B=t=>{const{pattern:a,onPatternSelect:r,hasNewQueryOption:o,hasPreviousQuery:i,selectedPatternName:c,setSelectedPatternName:m}=t,p=(0,s.wW)(k),u={grammar:M.ZP,name:"promql"};return e.createElement(f.Z,{className:p.card},e.createElement(f.Z.Heading,null,a.name),e.createElement("div",{className:p.rawQueryContainer},e.createElement(R.U,{"aria-label":`${a.name} raw query`,query:d.Z.renderQuery({labels:[],operations:a.operations,binaryQueries:a.binaryQueries}),lang:u,className:p.rawQuery})),e.createElement(f.Z.Actions,null,c!==a.name?e.createElement(N.zx,{size:"sm","aria-label":"use this query button",onClick:()=>{i?m(a.name):r(a)}},"Use this query"):e.createElement(e.Fragment,null,e.createElement("div",{className:p.spacing},`If you would like to use this query, ${o?"you can either apply this query pattern or create a new query":"this query pattern will be applied to your current query"}.`),e.createElement(N.zx,{size:"sm","aria-label":"back button",fill:"outline",onClick:()=>m(null)},"Back"),e.createElement(N.zx,{size:"sm","aria-label":"apply query starter button",onClick:()=>{r(a)}},"Apply query"),o&&e.createElement(N.zx,{size:"sm","aria-label":"create new query button",onClick:()=>{r(a,!0)}},"Create new query"))))},k=t=>({card:(0,C.css)` width: 49.5%; display: flex; flex-direction: column; `,rawQueryContainer:(0,C.css)` flex-grow: 1; `,rawQuery:(0,C.css)` background-color: ${t.colors.background.primary}; padding: ${t.spacing(1)}; margin-top: ${t.spacing(1)}; `,spacing:(0,C.css)` margin-bottom: ${t.spacing(1)}; `});var G=l(84848),Fe=l(29326);const Re=t=>{const{isOpen:a,onClose:r,onChange:o,onAddQuery:i,query:c,queries:m,app:p}=t,[u,h]=(0,e.useState)([]),[x,v]=(0,e.useState)(null),A=(0,s.wW)($e),Q=!!i,W=(0,e.useMemo)(()=>{const g=(0,G._)(c.expr??""),P=g.query.operations.length>0,F=g.query.metric,X=g.query.labels.length>0,ie=g.query.binaryQueries?g.query.binaryQueries.length>0:!1;return P||F||X||ie},[c.expr]),oe=(g,P=!1)=>{const F=(0,G._)(P?"":c.expr);(0,V.ff)("grafana_prom_kickstart_your_query_selected",{app:p??"",editorMode:c.editorMode,selectedPattern:g.name,preSelectedOperationsCount:F.query.operations.length,preSelectedLabelsCount:F.query.labels.length,createNewQuery:Q&&P}),F.query.operations=g.operations,F.query.binaryQueries=g.binaryQueries,Q&&P?i({...c,refId:(0,b.Hs)(m??[c]),expr:d.Z.renderQuery(F.query)}):o({...c,expr:d.Z.renderQuery(F.query)}),v(null),r()};return e.createElement(y.u,{"aria-label":"Kick start your query modal",isOpen:a,title:"Kick start your query",onDismiss:r},e.createElement("div",{className:A.spacing},"Kick start your query by selecting one of these queries. You can then continue to complete your query."),Object.values(Fe.Fz).map(g=>e.createElement(E.U,{"aria-label":`open and close ${g} query starter card`,key:g,label:`${(0,H.capitalize)(g)} query starters`,isOpen:u.includes(g),collapsible:!0,onToggle:()=>h(P=>P.includes(g)?P.filter(F=>F!==g):[...P,g])},e.createElement("div",{className:A.cardsContainer},d.Z.getQueryPatterns().filter(P=>P.type===g).map(P=>e.createElement(B,{key:P.name,pattern:P,hasNewQueryOption:Q,hasPreviousQuery:W,onPatternSelect:oe,selectedPatternName:x,setSelectedPatternName:v}))))),e.createElement(N.zx,{"aria-label":"close kick start your query modal",variant:"secondary",onClick:r},"Close"))},$e=t=>({cardsContainer:(0,C.css)` display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-between; `,spacing:(0,C.css)` margin-bottom: ${t.spacing(1)}; `});var Ne=l(87295),Be=l(5481),ce=l(18585),D=l(39568),me=l(56812),T=l(72054);const de="PrometheusQueryEditorModeDefault";function pe(t,a,r){t.expr===""&&me.Z.set(de,a),r({...t,editorMode:a})}function De(t,a=D.c.Builder){if(t!=null&&t!=="")return D.c.Code;const r=me.Z.get(de);switch(r){case D.c.Builder:case D.c.Code:return r;default:return a}}function Ae(t,a,r){let o=t;t.editorMode||(o={...t,editorMode:De(t.expr,r)}),t.expr||(o={...o,expr:"",legendFormat:T.pD.Auto}),t.range==null&&t.instant==null&&(o={...o,range:!0},a===n.zj.Explore&&(o.instant=!0));const i=t.instant&&t.range;return a===n.zj.UnifiedAlerting&&i&&(o={...o,instant:!1,range:!0}),o}var we=l(34099),He=l(34667),ee=l(57942),Ve=l(1234),We=l(3664),ze=l(61589),Ze=l(63971),Ke=l(70161),Ue=l(52390),je=l(23852),Ge=l(81078),L=l(28580),te=l(31465),ge=l(67437),Le=l(86146);const fe=e.memo(t=>{const{nestedQuery:a,index:r,datasource:o,onChange:i,onRemove:c,onRunQuery:m,showExplain:p}=t,u=(0,s.wW)(Je);return e.createElement("div",{className:u.card},e.createElement("div",{className:u.header},e.createElement("div",{className:u.name},"Operator"),e.createElement(L.Ph,{width:"auto",options:Ye,value:(0,Ge.E)(a.operator),onChange:h=>{i(r,{...a,operator:h.value})}}),e.createElement("div",{className:u.name},"Vector matches"),e.createElement("div",{className:u.vectorMatchWrapper},e.createElement(L.Ph,{width:"auto",value:a.vectorMatchesType||"on",allowCustomValue:!0,options:[{value:"on",label:"on"},{value:"ignoring",label:"ignoring"}],onChange:h=>{i(r,{...a,vectorMatchesType:h.value})}}),e.createElement(te.H,{className:u.vectorMatchInput,minWidth:20,defaultValue:a.vectorMatches,onCommitChange:h=>{i(r,{...a,vectorMatches:h.currentTarget.value,vectorMatchesType:a.vectorMatchesType||"on"})}})),e.createElement(J.B,{grow:1}),e.createElement(ge.h,{name:"times",size:"sm",onClick:()=>c(r),tooltip:"Remove match"})),e.createElement("div",{className:u.body},e.createElement(j._,null,e.createElement(ae,{showExplain:p,query:a.query,datasource:o,onRunQuery:m,onChange:h=>{i(r,{...a,query:h})}}))))}),Ye=Le.iQ.map(t=>({label:t.sign,value:t.sign}));fe.displayName="NestedQuery";const Je=t=>({card:(0,C.css)({label:"card",display:"flex",flexDirection:"column",gap:t.spacing(.5)}),header:(0,C.css)({label:"header",padding:t.spacing(.5,.5,.5,1),gap:t.spacing(1),display:"flex",alignItems:"center"}),name:(0,C.css)({label:"name",whiteSpace:"nowrap"}),body:(0,C.css)({label:"body",paddingLeft:t.spacing(2)}),vectorMatchInput:(0,C.css)({label:"vectorMatchInput",marginLeft:-1}),vectorMatchWrapper:(0,C.css)({label:"vectorMatchWrapper",display:"flex"})});function Xe(t){const{query:a,datasource:r,onChange:o,onRunQuery:i,showExplain:c}=t,m=a.binaryQueries??[],p=(h,x)=>{const v=[...m];v.splice(h,1,x),o({...a,binaryQueries:v})},u=h=>{const x=[...m.slice(0,h),...m.slice(h+1)];o({...a,binaryQueries:x})};return e.createElement(je.K,{direction:"column",gap:1},m.map((h,x)=>e.createElement(fe,{key:x.toString(),nestedQuery:h,index:x,onChange:p,datasource:r,onRemove:u,onRunQuery:i,showExplain:c})))}var qe=l(56746);const ae=e.memo(t=>{const{datasource:a,query:r,onChange:o,onRunQuery:i,data:c,showExplain:m}=t,[p,u]=(0,e.useState)(),h={grammar:M.ZP,name:"promql"},x=a.getInitHints();return e.createElement(e.Fragment,null,e.createElement(ee.p,null,e.createElement(Ue.U,{query:r,onChange:o,datasource:a})),x.length?e.createElement("div",{className:"query-row-break"},e.createElement("div",{className:"prom-query-field-info text-warning"},x[0].label," ",x[0].fix?e.createElement("button",{type:"button",className:"text-warning"},x[0].fix.label):null)):null,m&&e.createElement(Ve.B,{stepNumber:1,title:e.createElement(R.U,{query:`${r.metric} ${d.Z.renderLabels(r.labels)}`,lang:h})},qe.A),e.createElement(Ze.B,null,e.createElement(We.P,{queryModeller:d.Z,datasource:a,query:r,onChange:o,onRunQuery:i,highlightedOp:p}),e.createElement(Ke.L,{datasource:a,query:r,onChange:o,data:c,queryModeller:d.Z,buildVisualQueryFromString:G._})),m&&e.createElement(ze.V,{lang:h,query:r,stepNumber:2,queryModeller:d.Z,onMouseEnter:v=>u(v),onMouseLeave:()=>u(void 0)}),r.binaryQueries&&r.binaryQueries.length>0&&e.createElement(Xe,{query:r,datasource:a,onChange:o,onRunQuery:i,showExplain:m}))});ae.displayName="PromQueryBuilder";var Oe=l(2906);function Ie({query:t}){return t?e.createElement(ee.p,null,e.createElement(Oe.s,null,e.createElement(R.U,{query:t,lang:{grammar:M.ZP,name:"promql"}}))):null}var _e=l(63824);const ne=He.config.featureToggles.prometheusMetricEncyclopedia;function ke(t){const{query:a,onChange:r,onRunQuery:o,datasource:i,data:c,showExplain:m}=t,[p,u]=(0,e.useReducer)(he.reducer,{expr:a.expr});(0,e.useEffect)(()=>{u(tt(a.expr)),ne&&u(at({useBackend:a.useBackend??!1,disableTextWrap:a.disableTextWrap??!1,fullMetaSearch:a.fullMetaSearch??!1,includeNullMetadata:a.includeNullMetadata??!0}))},[a]);const h=x=>{const v=d.Z.renderQuery(x);if(u(et({visQuery:x,expr:v})),ne){const A=(0,_e.Gw)(x);r({...t.query,expr:v,...A})}else r({...t.query,expr:v})};return p.visQuery?e.createElement(e.Fragment,null,e.createElement(ae,{query:p.visQuery,datasource:i,onChange:h,onRunQuery:o,data:c,showExplain:m}),e.createElement(Ie,{query:a.expr})):null}const he=(0,we.oM)({name:"prom-builder-container",initialState:{expr:""},reducers:{visualQueryChange:(t,a)=>{t.expr=a.payload.expr,t.visQuery=a.payload.visQuery},exprChanged:(t,a)=>{if(!t.visQuery||t.expr!==a.payload){t.expr=a.payload;const r=(0,G._)(a.payload??"");t.visQuery=r.query}},setMetricsModalSettings:(t,a)=>{t.visQuery&&ne&&(t.visQuery.useBackend=a.payload.useBackend,t.visQuery.disableTextWrap=a.payload.disableTextWrap,t.visQuery.fullMetaSearch=a.payload.fullMetaSearch,t.visQuery.includeNullMetadata=a.payload.includeNullMetadata)}}}),{visualQueryChange:et,exprChanged:tt,setMetricsModalSettings:at}=he.actions;var U=l(81924),nt=l(63201),ve=l(40705),ye=l(24077),Ee=l(60644),rt=l(53901),lt=l(80011);function st({datasource:t,onChange:a,query:r,...o}){const[i,c]=(0,e.useState)(null),m=(0,s.wW)(ot),p=(0,ye.Z)(i);(0,e.useEffect)(()=>{t.exemplarsAvailable?r.instant&&!r.range?(c("Exemplars are not available for instant queries"),a(!1)):(c(null),p&&!i&&a(!0)):(c("Exemplars for this query are not available"),a(!1))},[t.exemplarsAvailable,r.instant,r.range,a,p,i]);const u=(0,C.cx)({[m.activeIcon]:!!r.exemplar},m.eyeIcon);return e.createElement(rt.W,{width:"auto","data-testid":o["data-testid"]},e.createElement(lt.u,{content:i??""},e.createElement("div",{className:m.iconWrapper},"Exemplars",e.createElement(ge.h,{name:"eye",tooltip:r.exemplar?"Disable query with exemplars":"Enable query with exemplars",disabled:!!i,className:u,onClick:()=>{a(!r.exemplar)}}))))}function ot(t){return{eyeIcon:(0,C.css)` margin-left: ${t.spacing(2)}; `,activeIcon:(0,C.css)` color: ${t.colors.primary.main}; `,iconWrapper:(0,C.css)` display: flex; align-items: center; `}}const it=(0,e.memo)(({query:t,datasource:a,onChange:r,onRunQuery:o})=>{const i=be(!0),c=(0,ye.Z)(t),m=(0,e.useCallback)(v=>{(!(0,H.isEqual)(t,c)||v!==t.exemplar)&&r({...t,exemplar:v})},[c,t,r]);function p(v){r({...t,interval:v})}function u(v){v.currentTarget.value!==t.interval&&p(v.currentTarget.value)}function h(v){v.key==="Enter"&&v.shiftKey&&o()}const x=xe(t,r);return e.createElement("div",{"aria-label":"Prometheus extra field",className:"gf-form-inline","data-testid":re.extraFieldEditor},e.createElement("div",{"data-testid":re.queryTypeField,className:(0,C.cx)("gf-form explore-input-margin",(0,C.css)` flex-wrap: nowrap; `),"aria-label":"Query type field"},e.createElement(Ee.c,{width:"auto"},"Query type"),e.createElement(ve.S,{options:i,value:t.range&&t.instant?"both":t.instant?"instant":"range",onChange:x})),e.createElement("div",{"data-testid":re.stepField,className:(0,C.cx)("gf-form",(0,C.css)` flex-wrap: nowrap; `),"aria-label":"Step field"},e.createElement(Ee.c,{width:6,tooltip:"Time units and built-in variables can be used here, for example: $__interval, $__rate_interval, 5s, 1m, 3h, 1d, 1y (Default if no unit is specified: s)"},"Min step"),e.createElement("input",{type:"text",className:"gf-form-input width-4",placeholder:"auto",onChange:u,onKeyDown:h,value:t.interval??""})),e.createElement(st,{onChange:m,datasource:a,query:t}))});it.displayName="PromExploreExtraField";function be(t){const a=[{value:"range",label:"Range",description:"Run query over a range of time"},{value:"instant",label:"Instant",description:'Run query against a single point in time. For this query, the "To" time is used'}];return t&&a.push({value:"both",label:"Both",description:"Run an Instant query and a Range query"}),a}function xe(t,a){return r=>{a(r==="instant"?{...t,instant:!0,range:!1,exemplar:!1}:r==="range"?{...t,instant:!1,range:!0}:{...t,instant:!0,range:!0})}}const re={extraFieldEditor:"prom-editor-extra-field",stepField:"prom-editor-extra-field-step",queryTypeField:"prom-editor-extra-field-query-type"};var ut=l(85187);const le=[{label:"Auto",value:T.pD.Auto,description:"Only includes unique labels"},{label:"Verbose",value:T.pD.Verbose,description:"All label names and values"},{label:"Custom",value:T.pD.Custom,description:"Provide a naming template"}],Ce=e.memo(({legendFormat:t,onChange:a,onRunQuery:r})=>{const o=Qe(t),i=(0,e.useRef)(null),c=p=>{let u=p.currentTarget.value;u.length===0&&(u=T.pD.Auto),u!==t&&(a(u),r())},m=p=>{switch(p.value){case T.pD.Auto:a(T.pD.Auto);break;case T.pD.Custom:a("{{label_name}}"),setTimeout(()=>{i.current?.focus(),i.current?.setSelectionRange(2,12,"forward")},10);break;case T.pD.Verbose:a("");break}r()};return e.createElement(U.S,{label:"Legend",tooltip:"Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname."},e.createElement(e.Fragment,null,o===T.pD.Custom&&e.createElement(te.H,{id:"legendFormat",minWidth:22,placeholder:"auto",defaultValue:t,onCommitChange:c,ref:i}),o!==T.pD.Custom&&e.createElement(L.Ph,{inputId:"legend.mode",isSearchable:!1,placeholder:"Select legend mode",options:le,width:22,onChange:m,value:le.find(p=>p.value===o)})))});Ce.displayName="PromQueryLegendEditor";function Qe(t){return t===T.pD.Auto?T.pD.Auto:t==null||t===""?T.pD.Verbose:T.pD.Custom}function ct(t){const a=Qe(t);return a!==T.pD.Custom?le.find(r=>r.value===a)?.label:t}const Me=e.memo(({query:t,app:a,onChange:r,onRunQuery:o})=>{const i=Q=>{r({...t,format:Q.value}),o()},c=Q=>{r({...t,interval:Q.currentTarget.value}),o()},m=be(a===n.zj.Explore||a===n.zj.PanelEditor),p=xe(t,r),u=Q=>{const W=Q.currentTarget.checked;r({...t,exemplar:W}),o()},h=Q=>{r({...t,intervalFactor:Q.value}),o()},x=se.find(Q=>Q.value===t.format)||se[0],v=mt(t),A=m.find(Q=>Q.value===v).label;return e.createElement(ee.p,null,e.createElement(ut.d,{title:"Options",collapsedInfo:dt(t,x.label,A,a)},e.createElement(Ce,{legendFormat:t.legendFormat,onChange:Q=>r({...t,legendFormat:Q}),onRunQuery:o}),e.createElement(U.S,{label:"Min step",tooltip:e.createElement(e.Fragment,null,"An additional lower limit for the step parameter of the Prometheus query and for the"," ",e.createElement("code",null,"$__interval")," and ",e.createElement("code",null,"$__rate_interval")," variables.")},e.createElement(te.H,{type:"text","aria-label":"Set lower limit for the step parameter",placeholder:"auto",minWidth:10,onCommitChange:c,defaultValue:t.interval})),e.createElement(U.S,{label:"Format"},e.createElement(L.Ph,{value:x,allowCustomValue:!0,onChange:i,options:se})),e.createElement(U.S,{label:"Type"},e.createElement(ve.S,{options:m,value:v,onChange:p})),Se(t,a)&&e.createElement(U.S,{label:"Exemplars"},e.createElement(nt.r,{value:t.exemplar||!1,onChange:u})),t.intervalFactor&&t.intervalFactor>1&&e.createElement(U.S,{label:"Resolution"},e.createElement(L.Ph,{"aria-label":"Select resolution",isSearchable:!1,options:Pe,onChange:h,value:Pe.find(Q=>Q.value===t.intervalFactor)}))))});function Se(t,a){return!(a===n.zj.UnifiedAlerting||!t.range)}function mt(t){return t.range&&t.instant?"both":t.instant?"instant":"range"}function dt(t,a,r,o){const i=[];return i.push(`Legend: ${ct(t.legendFormat)}`),i.push(`Format: ${a}`),i.push(`Step: ${t.interval??"auto"}`),i.push(`Type: ${r}`),Se(t,o)&&(t.exemplar?i.push("Exemplars: true"):i.push("Exemplars: false")),i}Me.displayName="PromQueryBuilderOptions";var pt=l(86096);const se=[{label:"Time series",value:"time_series"},{label:"Table",value:"table"},{label:"Heatmap",value:"heatmap"}],Pe=(0,H.map)([1,2,3,4,5,10],t=>({value:t,label:"1/"+t})),Te=e.memo(t=>{const{onChange:a,onRunQuery:r,data:o,app:i,onAddQuery:c,datasource:{defaultEditor:m},queries:p}=t,[u,h]=(0,e.useState)(!1),[x,v]=(0,e.useState)(!1),[A,Q]=(0,e.useState)(!1),{flag:W,setFlag:oe}=(0,ce.P5)(ce.ar),g=Ae(t.query,i,m),P=g.editorMode,F=(0,e.useCallback)($=>{if((0,V.ff)("user_grafana_prometheus_editor_mode_clicked",{newEditor:$,previousEditor:g.editorMode??"",newQuery:!g.expr,app:i??""}),$===D.c.Builder&&(0,G._)(g.expr||"").errors.length){h(!0);return}pe(g,$,a)},[a,g,i]);(0,e.useEffect)(()=>{Q(!1)},[o]);const X=$=>{(0,H.isEqual)($,t.query)||Q(!0),a($)},ie=$=>{oe($.currentTarget.checked)};return e.createElement(e.Fragment,null,e.createElement(_.s,{isOpen:u,title:"Query parsing",body:"There were errors while trying to parse the query. Continuing to visual builder may lose some parts of the query.",confirmText:"Continue",onConfirm:()=>{pe(g,D.c.Builder,a),h(!1)},onDismiss:()=>h(!1)}),e.createElement(Re,{isOpen:x,onClose:()=>v(!1),query:g,queries:p,app:i,onChange:a,onAddQuery:c}),e.createElement(O.K,null,e.createElement(N.zx,{"aria-label":q.wl.components.QueryBuilder.queryPatterns,variant:"secondary",size:"sm",onClick:()=>v($=>!$)},"Kick start your query"),e.createElement(Be.n,{label:"Explain",value:W,onChange:ie}),e.createElement(J.B,{grow:1}),i!==n.zj.Explore&&i!==n.zj.Correlations&&e.createElement(N.zx,{variant:A?"primary":"secondary",size:"sm",onClick:r,icon:o?.state===Y.Gu.Loading?"fa fa-spinner":void 0,disabled:o?.state===Y.Gu.Loading},"Run queries"),e.createElement(Ne.k,{mode:P,onChange:F})),e.createElement(I.T,{v:.5}),e.createElement(j._,null,P===D.c.Code&&e.createElement(pt.j,{...t,query:g,showExplain:W,onChange:X}),P===D.c.Builder&&e.createElement(ke,{query:g,datasource:t.datasource,onChange:X,onRunQuery:t.onRunQuery,data:o,showExplain:W}),e.createElement(Me,{query:g,app:t.app,onChange:a,onRunQuery:r})))});Te.displayName="PromQueryEditorSelector";var gt=l(95054);function ft(t){const{datasource:a,query:r,range:o,data:i,onChange:c,onRunQuery:m}=t;return e.createElement(gt.ZP,{datasource:a,query:r,onRunQuery:m,onChange:c,history:[],range:o,data:i,"data-testid":ht.editor})}const ht={editor:"prom-editor-cloud-alerting"};function vt(t){const{app:a}=t;switch(a){case n.zj.CloudAlerting:return e.createElement(ft,{...t});default:return e.createElement(Te,{...t})}}const yt=(0,e.memo)(vt);var Et=l(83923),bt=l(26807);const xt=new w.hf(bt.vQ).setQueryEditor(yt).setConfigEditor(Et.Z5).setQueryEditorHelp(K)}}]); //# sourceMappingURL=prometheusPlugin.be4439956a02756980e7.js.map