D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
share
/
grafana
/
public
/
build
/
Filename :
760.8091fa41208384ade014.js
back
Copy
"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[760],{5562:(ie,V,r)=>{r.d(V,{i:()=>D});var C=r(42844),A=r(27702),j=r(66310);const D=({hideLine:N=!1})=>{const R=(0,j.wW)(e);return N?A.createElement("hr",{className:R.dividerHideLine}):A.createElement("hr",{className:R.divider})},e=N=>({divider:(0,C.css)` margin: ${N.spacing(4,0)}; `,dividerHideLine:(0,C.css)` border: none; margin: ${N.spacing(3,0)}; `})},83392:(ie,V,r)=>{r.d(V,{n:()=>N});var C=r(27702),A=r(64826);const j=C.lazy(()=>Promise.all([r.e(3565),r.e(7142)]).then(r.bind(r,11742))),D=R=>C.createElement(C.Suspense,{fallback:null},C.createElement(j,{...R})),e=R=>{const $=(0,C.useRef)(null),{onRunQuery:B,onChange:O,...I}=R,y=T=>{$.current=T,O(T),B()},Q=T=>{O(T)};return C.createElement(D,{onRunQuery:y,onBlur:Q,...I})};class N extends C.PureComponent{constructor($){super($),this._isMounted=!1,this.onChangeQuery=(B,O)=>{const{query:I,onChange:y,onRunQuery:Q}=this.props;if(y){const T={...I,expr:B};y(T),O&&Q&&Q()}},this.state={labelsLoaded:!1}}async componentDidMount(){this._isMounted=!0,await this.props.datasource.languageProvider.start(),this._isMounted&&this.setState({labelsLoaded:!0})}componentWillUnmount(){this._isMounted=!1}componentDidUpdate($){const{range:B,datasource:{languageProvider:O}}=this.props;(0,A.rf)(B,$.range)&&O.fetchLabels()}render(){const{ExtraFieldElement:$,query:B,datasource:O,history:I,onRunQuery:y,onQueryType:Q}=this.props,T=this.props.placeholder??"Enter a Loki query (run with Shift+Enter)";return C.createElement(C.Fragment,null,C.createElement("div",{className:"gf-form-inline gf-form-inline--xs-view-flex-column flex-grow-1","data-testid":this.props["data-testid"]},C.createElement("div",{className:"gf-form--grow flex-shrink-1 min-width-15"},C.createElement(e,{datasource:O,history:I??[],onChange:this.onChangeQuery,onRunQuery:y,initialValue:B.expr??"",placeholder:T,onQueryType:Q}))),$)}}},64826:(ie,V,r)=>{r.d(V,{Hk:()=>B,U9:()=>N,_z:()=>O,aC:()=>I,iS:()=>R,rf:()=>j,tU:()=>$});function C(y){return A(y/1e3)}function A(y){return Math.floor(y/60)}function j(y,Q){if(y&&Q){const T=C(y.from.valueOf())===C(Q.from.valueOf()),G=C(y.to.valueOf())===C(Q.to.valueOf());return!(T&&G)}return!1}const D=/[*+?()|\\.\[\]{}^$]/g;function e(y){return y.replace(D,"\\$&")}function N(y){return y.replace(/\\/g,"\\\\").replace(/\n/g,"\\n").replace(/"/g,'\\"')}function R(y){return y.replace(/\\n/g,` `).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}function $(y){return N(e(y))}function B(y,Q){return O(Q)?$(y):N(y)}function O(y){return!!(y&&(y.includes("=~")||y.includes("!~")))}function I(y){const Q=["b","kib","Kib","kb","KB","mib","Mib","mb","MB","gib","Gib","gb","GB","tib","Tib","tb","TB","pib","Pib","pb","PB","eib","Eib","eb","EB"],T=new RegExp(`^(?:-?\\d+(?:\\.\\d+)?)(?:${Q.join("|")})$`);return!!y.match(T)}},50760:(ie,V,r)=>{r.r(V),r.d(V,{plugin:()=>Oa});var C=r(68246),A=r(84714),j=r(32713),D=r(89949),e=r(27702),N=r(86312);const R=['{job="default/prometheus"}'],$=["job","app","k8s_app"],B=5,O=[{title:"Log pipeline",expression:'{job="mysql"} |= "metrics" | logfmt | duration > 10s',label:'This query targets the MySQL job, keeps logs that contain the substring "metrics", and then parses and filters the logs further.'},{title:"Count over time",expression:'count_over_time({job="mysql"}[5m])',label:"This query counts all the log lines within the last five minutes for the MySQL job."},{title:"Rate",expression:'rate(({job="mysql"} |= "error" != "timeout")[10s])',label:"This query gets the per-second rate of all non-timeout errors within the last ten seconds for the MySQL job."},{title:"Aggregate, count, and group",expression:'sum(count_over_time({job="mysql"}[5m])) by (level)',label:"Get the count of logs during the last five minutes, grouping by level."}];class I extends e.PureComponent{constructor(){super(...arguments),this.state={userExamples:[]},this.checkUserLabels=async()=>{const t=this.props.datasource?.languageProvider;if(t.started){const s=t.getLabelKeys()||[],n=$.find(l=>s.includes(l));if(n){const l=await t.getLabelValues(n),i=(0,D.shuffle)(l).slice(0,B).map(u=>`{${n}="${u}"}`);this.setState({userExamples:i})}}else this.scheduleUserLabelChecking()}}componentDidMount(){this.scheduleUserLabelChecking(),(0,N.ff)("grafana_loki_cheatsheet_opened",{})}componentWillUnmount(){clearTimeout(this.userLabelTimer)}scheduleUserLabelChecking(){this.userLabelTimer=setTimeout(this.checkUserLabels,1e3)}renderExpression(t){const{onClickExample:s}=this.props,n=l=>{s(l),(0,N.ff)("grafana_loki_cheatsheet_example_clicked",{})};return e.createElement("button",{type:"button",className:"cheat-sheet-item__example",key:t,onClick:l=>n({refId:"A",expr:t})},e.createElement("code",null,t))}render(){const{userExamples:t}=this.state,s=t.length>0;return e.createElement("div",null,e.createElement("h2",null,"Loki Cheat Sheet"),e.createElement("div",{className:"cheat-sheet-item"},e.createElement("div",{className:"cheat-sheet-item__title"},"See your logs"),e.createElement("div",{className:"cheat-sheet-item__label"},"Start by selecting a log stream from the Label browser, or alternatively you can write a stream selector into the query field."),s?e.createElement("div",null,e.createElement("div",{className:"cheat-sheet-item__label"},"Here are some example streams from your logs:"),t.map(n=>this.renderExpression(n))):e.createElement("div",null,e.createElement("div",{className:"cheat-sheet-item__label"},"Here is an example of a log stream:"),this.renderExpression(R[0]))),e.createElement("div",{className:"cheat-sheet-item"},e.createElement("div",{className:"cheat-sheet-item__title"},"Combine stream selectors"),this.renderExpression('{app="cassandra",namespace="prod"}'),e.createElement("div",{className:"cheat-sheet-item__label"},"Returns all log lines from streams that have both labels.")),e.createElement("div",{className:"cheat-sheet-item"},e.createElement("div",{className:"cheat-sheet-item__title"},"Filtering for search terms."),this.renderExpression('{app="cassandra"} |~ "(duration|latency)s*(=|is|of)s*[d.]+"'),this.renderExpression('{app="cassandra"} |= "exact match"'),this.renderExpression('{app="cassandra"} != "do not match"'),e.createElement("div",{className:"cheat-sheet-item__label"},e.createElement("a",{href:"https://grafana.com/docs/loki/latest/logql/#log-pipeline",target:"logql"},"LogQL")," ","supports exact and regular expression filters.")),O.map(n=>e.createElement("div",{className:"cheat-sheet-item",key:n.expression},e.createElement("div",{className:"cheat-sheet-item__title"},n.title),this.renderExpression(n.expression),e.createElement("div",{className:"cheat-sheet-item__label"},n.label))))}}var y=r(62247),Q=r(24077),T=r(53933),G=r(74639),at=r(63250),ce=r(23852),Me=r(29473),st=r(60426),Qe=r(83788),X=r(34667),nt=r(3613),k=r(66670),lt=r(87295),rt=r(5481),H=r(39568),Te=r(18585),h=r(42844),z=r(66310),ke=r(13741),we=r(52419),ot=r(74273),it=r(25472),ct=r(37221),ae=r(79978),ue=r(36162),se=r(1128),Fe=r(64022),de=r(64826);const me=1e3,pe=1e4,ut=4,ge="{}";function W(a){const t=[];for(const s of a)if(s.selected&&s.values&&s.values.length>0){const n=s.values.filter(l=>l.selected).map(l=>l.name);n.length>1?t.push(`${s.name}=~"${n.map(de.tU).join("|")}"`):n.length===1&&t.push(`${s.name}="${(0,de.U9)(n[0])}"`)}return["{",t.join(","),"}"].join("")}function dt(a,t,s){return a.map(n=>{const l=t[n.name];if(l){let i;if(n.name===s&&n.values)i=n.values;else{const u=new Set(n.values?.filter(o=>o.selected).map(o=>o.name)||[]);i=l.map(o=>({name:o,selected:u.has(o)}))}return{...n,loading:!1,values:i,facets:i.length}}return{...n,loading:!1,hidden:!l,values:void 0,facets:0}})}const mt=a=>({wrapper:(0,h.css)` background-color: ${a.colors.background.secondary}; padding: ${a.spacing(2)}; width: 100%; `,list:(0,h.css)` margin-top: ${a.spacing(1)}; display: flex; flex-wrap: wrap; max-height: 200px; overflow: auto; `,section:(0,h.css)` & + & { margin: ${a.spacing(2,0)}; } position: relative; `,selector:(0,h.css)` font-family: ${a.typography.fontFamilyMonospace}; margin-bottom: ${a.spacing(1)}; `,status:(0,h.css)` margin-bottom: ${a.spacing(1)}; color: ${a.colors.text.secondary}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity 100ms linear; opacity: 0; `,statusShowing:(0,h.css)` opacity: 1; `,error:(0,h.css)` color: ${a.colors.error.main}; `,valueList:(0,h.css)` margin-right: ${a.spacing(1)}; resize: horizontal; `,valueListWrapper:(0,h.css)` border-left: 1px solid ${a.colors.border.medium}; margin: ${a.spacing(1,0)}; padding: ${a.spacing(1,0,1,1)}; `,valueListArea:(0,h.css)` display: flex; flex-wrap: wrap; margin-top: ${a.spacing(1)}; `,valueTitle:(0,h.css)` margin-left: -${a.spacing(.5)}; margin-bottom: ${a.spacing(1)}; `,validationStatus:(0,h.css)` padding: ${a.spacing(.5)}; margin-bottom: ${a.spacing(1)}; color: ${a.colors.text.maxContrast}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; `});class pt extends e.Component{constructor(){super(...arguments),this.state={labels:[],searchTerm:"",status:"Ready",error:"",validationStatus:""},this.onChangeSearch=t=>{this.setState({searchTerm:t.target.value})},this.onClickRunLogsQuery=()=>{(0,N.ff)("grafana_loki_label_browser_closed",{app:this.props.app,closeType:"showLogsButton"});const t=W(this.state.labels);this.props.onChange(t)},this.onClickRunMetricsQuery=()=>{(0,N.ff)("grafana_loki_label_browser_closed",{app:this.props.app,closeType:"showLogsRateButton"});const s=`rate(${W(this.state.labels)}[$__interval])`;this.props.onChange(s)},this.onClickClear=()=>{this.setState(t=>({labels:t.labels.map(n=>({...n,values:void 0,selected:!1,loading:!1,hidden:!1,facets:void 0})),searchTerm:"",status:"",error:"",validationStatus:""})),this.props.deleteLastUsedLabels()},this.onClickLabel=(t,s,n)=>{const l=this.state.labels.find(o=>o.name===t);if(!l)return;const i=!l.selected;let u={selected:i};if(l.values&&!i){const o=l.values.map(c=>({...c,selected:!1}));u={...u,facets:0,values:o}}this.setState({searchTerm:""}),this.updateLabelState(t,u,"",()=>this.doFacettingForLabel(t))},this.onClickValue=(t,s,n)=>{const l=this.state.labels.find(u=>u.name===t);if(!l||!l.values)return;this.setState({searchTerm:""});const i=l.values.map(u=>({...u,selected:u.name===s?!u.selected:u.selected}));this.updateLabelState(t,{values:i},"",()=>this.doFacetting(t))},this.onClickValidate=()=>{const t=W(this.state.labels);this.validateSelector(t)},this.doFacetting=t=>{const s=W(this.state.labels);if(s===ge){const n=this.state.labels.map(l=>({...l,facets:0,values:void 0,hidden:!1}));this.setState({labels:n},()=>{this.state.labels.forEach(l=>l.selected&&this.fetchValues(l.name,s))})}else this.fetchSeries(s,t)}}updateLabelState(t,s,n="",l){this.setState(i=>{const u=i.labels.map(c=>c.name===t?{...c,...s}:c),o=n?"":i.error;return{labels:u,status:n,error:o,validationStatus:""}},l)}componentDidMount(){const{languageProvider:t,autoSelect:s=ut,lastUsedLabels:n}=this.props;if(t){const l=n;t.start().then(()=>{let i=t.getLabelKeys();if(i.length>me){const o=`Too many labels found (showing only ${me} of ${i.length})`;i=i.slice(0,me),this.setState({error:o})}const u=i.map((o,c,m)=>({name:o,selected:m.length<=s&&l.length===0||l.includes(o),loading:!1}));this.setState({labels:u},()=>{this.state.labels.forEach(o=>{o.selected&&this.fetchValues(o.name,ge)})})})}}doFacettingForLabel(t){const s=this.state.labels.find(l=>l.name===t);if(!s)return;const n=this.state.labels.filter(l=>l.selected).map(l=>l.name);this.props.storeLastUsedLabels(n),s.selected?s.values||this.fetchValues(t,W(this.state.labels)):this.doFacetting()}async fetchValues(t,s){const{languageProvider:n}=this.props;this.updateLabelState(t,{loading:!0},`Fetching values for ${t}`);try{let l=await n.getLabelValues(t);if(s!==W(this.state.labels)){this.updateLabelState(t,{loading:!1},"");return}if(l.length>pe){const u=`Too many values for ${t} (showing only ${pe} of ${l.length})`;l=l.slice(0,pe),this.setState({error:u})}const i=l.map(u=>({name:u}));this.updateLabelState(t,{values:i,loading:!1})}catch(l){console.error(l)}}async fetchSeries(t,s){const{languageProvider:n}=this.props;s&&this.updateLabelState(s,{loading:!0},`Loading labels for ${t}`);try{const l=await n.fetchSeriesLabels(t,!0);if(t!==W(this.state.labels)){s&&this.updateLabelState(s,{loading:!1});return}if(Object.keys(l).length===0){this.setState({error:`Empty results, no matching label for ${t}`});return}const i=dt(this.state.labels,l,s);this.setState({labels:i,error:""}),s&&this.updateLabelState(s,{loading:!1})}catch(l){console.error(l)}}async validateSelector(t){const{languageProvider:s}=this.props;this.setState({validationStatus:`Validating selector ${t}`,error:""});const n=await s.fetchSeries(t);this.setState({validationStatus:`Selector is valid (${n.length} streams found)`})}render(){const{theme:t}=this.props,{labels:s,searchTerm:n,status:l,error:i,validationStatus:u}=this.state;if(s.length===0)return e.createElement(we.u,{text:"Loading labels..."});const o=mt(t),c=W(this.state.labels),m=c===ge;let p=s.filter(d=>d.selected&&d.values);return n?p=p.map(d=>{const L=d.values.filter(v=>{if(v.selected)return v.highlightParts=void 0,!0;const E=(0,ct.C)(v.name.toLowerCase(),n.toLowerCase());return E.found?(v.highlightParts=E.ranges,v.order=E.distance,!0):!1});return{...d,values:(0,D.sortBy)(L,v=>v.selected?-1/0:v.order)}}):p=this.state.labels.filter(d=>d.selected&&d.values).map(d=>({...d,values:d?.values?d.values.map(L=>({...L,highlightParts:void 0})):[]})),e.createElement("div",{className:o.wrapper},e.createElement("div",{className:o.section},e.createElement(ae._,{description:"Which labels would you like to consider for your search?"},"1. Select labels to search in"),e.createElement("div",{className:o.list},s.map(d=>e.createElement(ue._,{key:d.name,name:d.name,loading:d.loading,active:d.selected,hidden:d.hidden,facets:d.facets,onClick:this.onClickLabel})))),e.createElement("div",{className:o.section},e.createElement(ae._,{description:"Choose the label values that you would like to use for the query. Use the search field to find values across selected labels."},"2. Find values for the selected labels"),e.createElement("div",null,e.createElement(se.I,{onChange:this.onChangeSearch,"aria-label":"Filter expression for values",value:n,placeholder:"Enter a label value"})),e.createElement("div",{className:o.valueListArea},p.map(d=>e.createElement("div",{role:"list",key:d.name,className:o.valueListWrapper},e.createElement("div",{className:o.valueTitle,"aria-label":`Values for ${d.name}`},e.createElement(ue._,{name:d.name,loading:d.loading,active:d.selected,hidden:d.hidden,facets:d.facets||d.values?.length,onClick:this.onClickLabel})),e.createElement(it.t7,{height:200,itemCount:d.values?.length||0,itemSize:28,itemKey:L=>d.values[L].name,width:200,className:o.valueList},({index:L,style:v})=>{const E=d.values?.[L];return E?e.createElement("div",{style:v},e.createElement(ue._,{name:d.name,value:E?.name,active:E?.selected,highlightParts:E?.highlightParts,onClick:this.onClickValue,searchTerm:n})):null}))))),e.createElement("div",{className:o.section},e.createElement(ae._,null,"3. Resulting selector"),e.createElement("div",{"aria-label":"selector",className:o.selector},c),u&&e.createElement("div",{className:o.validationStatus},u),e.createElement("div",{className:(0,h.cx)(o.status,(l||i)&&o.statusShowing)},e.createElement("span",{className:i?o.error:""},i||l)),e.createElement(Fe.Lh,null,e.createElement(k.zx,{"aria-label":"Use selector as logs button",disabled:m,onClick:this.onClickRunLogsQuery},"Show logs"),e.createElement(k.zx,{"aria-label":"Use selector as metrics button",variant:"secondary",disabled:m,onClick:this.onClickRunMetricsQuery},"Show logs rate"),e.createElement(k.zx,{"aria-label":"Validate submit button",variant:"secondary",disabled:m,onClick:this.onClickValidate},"Validate selector"),e.createElement(k.zx,{"aria-label":"Selector clear button",variant:"secondary",onClick:this.onClickClear},"Clear"))))}}const gt=(0,z.HE)(pt),ht=a=>{const{isOpen:t,onClose:s,datasource:n,app:l}=a,[i,u]=(0,e.useState)(!1),[o,c]=(0,e.useState)(!1),m="grafana.datasources.loki.browser.labels",p=(0,z.wW)(ft);(0,e.useEffect)(()=>{t&&n.languageProvider.fetchLabels().then(E=>{u(!0),c(E.length>0)})},[n,t]);const d=E=>{const{query:b,onChange:f,onRunQuery:g}=a,S={...b,expr:E};f(S),g()},L=E=>{d(E),s()},v=()=>{(0,N.ff)("grafana_loki_label_browser_closed",{app:l,closeType:"modalClose"}),s()};return e.createElement(ke.u,{isOpen:t,title:"Label browser",onDismiss:v,className:p.modal},!i&&e.createElement(we.u,{text:"Loading labels..."}),i&&!o&&e.createElement("p",null,"No labels found."),i&&o&&e.createElement(ot.G,{storageKey:m,defaultValue:[]},(E,b,f)=>e.createElement(gt,{languageProvider:n.languageProvider,onChange:L,lastUsedLabels:E,storeLastUsedLabels:b,deleteLastUsedLabels:f,app:l})))},ft=a=>({modal:(0,h.css)` width: 85vw; ${a.breakpoints.down("md")} { width: 100%; } `});var vt=r(34099),w=r(58029),K=r(16516),Et=r(8508),he=r(57942),Pe=r(2906),Z=r(81924),yt=r(38162),J=r(81078),bt=r(70774),Lt=r(76715),fe=r(48024),q=r(28580),_=r(4737),St=r(42994);function xt({item:a,items:t,defaultOp:s,onChange:n,onDelete:l,onGetLabelNames:i,onGetLabelValues:u,invalidLabel:o,invalidValue:c}){const[m,p]=(0,e.useState)({}),[d,L]=(0,e.useState)(!1),[v,E]=(0,e.useState)(!1),b="You have conflicting label filters",f=(x=a.op)=>De.find(F=>F.label===x)?.isMultiValue,g=x=>x?x.indexOf("|")>0?x.split("|"):[x]:[],S=()=>{const x=m.labelValues?[...m.labelValues]:[],F=g(a?.value).map(J.E);return(0,D.uniqBy)([...F,...x],"value")},U=(0,St.Zc)(a,t);return e.createElement("div",{"data-testid":"prometheus-dimensions-filter-item"},e.createElement(fe._,{error:b,invalid:U?!0:void 0},e.createElement(bt.B,null,e.createElement(q.Ph,{placeholder:"Select label","aria-label":G.wl.components.QueryBuilder.labelSelect,inputId:"prometheus-dimensions-filter-item-key",width:"auto",value:a.label?(0,J.E)(a.label):null,allowCustomValue:!0,onOpenMenu:async()=>{p({isLoadingLabelNames:!0});const x=await i(a);L(!0),p({labelNames:x,isLoadingLabelNames:void 0})},onCloseMenu:()=>{L(!1)},isOpen:d,isLoading:m.isLoadingLabelNames,options:m.labelNames,onChange:x=>{x.label&&n({...a,op:a.op??s,label:x.label})},invalid:U||o}),e.createElement(q.Ph,{"aria-label":G.wl.components.QueryBuilder.matchOperatorSelect,value:(0,J.E)(a.op??s),options:De,width:"auto",onChange:x=>{x.value!=null&&n({...a,op:x.value,value:f(x.value)?a.value:g(a?.value)[0]})},invalid:U}),e.createElement(q.Ph,{placeholder:"Select value","aria-label":G.wl.components.QueryBuilder.valueSelect,inputId:"prometheus-dimensions-filter-item-value",width:"auto",value:f()?g(a?.value).map(J.E):g(a?.value).map(J.E)[0],allowCustomValue:!0,onOpenMenu:async()=>{p({isLoadingLabelValues:!0});const x=await u(a);p({...m,labelValues:x,isLoadingLabelValues:void 0}),E(!0)},onCloseMenu:()=>{E(!1)},isOpen:v,isMulti:f(),isLoading:m.isLoadingLabelValues,options:S(),onChange:x=>{if(x.value)n({...a,value:x.value,op:a.op??s});else{const F=x.map(oe=>oe.label).join("|");n({...a,value:F,op:a.op??s})}},invalid:U||c}),e.createElement(Lt._,{"aria-label":"remove",icon:"times",variant:"secondary",onClick:l}))))}const De=[_.AI.equals,_.AI.doesNotEqual,_.AI.matchesRegex,_.AI.doesNotMatchRegex],Ct="Select at least 1 label filter (label and value)";function Nt({labelsFilters:a,onChange:t,onGetLabelNames:s,onGetLabelValues:n,labelFilterRequired:l}){const i="=",[u,o]=(0,e.useState)([{op:i}]);(0,e.useEffect)(()=>{a.length>0?o(a):o([{op:i}])},[a]);const c=p=>{o(p);const d=p.filter(L=>L.label!=null&&L.value!=null);(0,D.isEqual)(d,a)||t(d)},m=u.some(p=>p.label&&p.value);return e.createElement(Pe.s,null,e.createElement(Z.S,{label:"Label filters",error:Ct,invalid:l&&!m},e.createElement(yt.k,{items:u,onChange:c,renderItem:(p,d,L)=>e.createElement(xt,{item:p,items:u,defaultOp:i,onChange:d,onDelete:L,onGetLabelNames:s,onGetLabelValues:n,invalidLabel:l&&!p.label,invalidValue:l&&!p.value})})))}var Oe=r(1234),Mt=r(3664),$e=r(61589),Qt=r(63971),Tt=r(70161),ne=r(86383),le=r(62434);const Re="Fetch all log lines matching label filters.",Be=e.memo(({query:a})=>{const t=(0,K._z)(a||"").query,s={grammar:le.xY,name:"lokiql"};return e.createElement(ce.K,{gap:0,direction:"column"},e.createElement(Oe.B,{stepNumber:1,title:e.createElement(ne.U,{query:`${w.y.renderLabels(t.labels)}`,lang:s})},Re),e.createElement($e.V,{stepNumber:2,queryModeller:w.y,query:t,lang:s}))});Be.displayName="LokiQueryBuilderExplained";var ee=r(31465),Ie=r(67437),kt=r(12906);const Ue=e.memo(({nestedQuery:a,index:t,datasource:s,onChange:n,onRemove:l,onRunQuery:i,showExplain:u})=>{const o=(0,z.wW)(Ft);return e.createElement("div",{className:o.card},e.createElement("div",{className:o.header},e.createElement("div",{className:o.name},"Operator"),e.createElement(q.Ph,{"aria-label":"Select operator",width:"auto",options:wt,value:(0,J.E)(a.operator),onChange:c=>{n(t,{...a,operator:c.value})}}),e.createElement("div",{className:o.name},"Vector matches"),e.createElement("div",{className:o.vectorMatchWrapper},e.createElement(q.Ph,{width:"auto",value:a.vectorMatchesType||"on",allowCustomValue:!0,options:[{value:"on",label:"on"},{value:"ignoring",label:"ignoring"}],onChange:c=>{n(t,{...a,vectorMatchesType:c.value})}}),e.createElement(ee.H,{className:o.vectorMatchInput,minWidth:20,defaultValue:a.vectorMatches,onCommitChange:c=>{n(t,{...a,vectorMatches:c.currentTarget.value,vectorMatchesType:a.vectorMatchesType||"on"})}})),e.createElement(Me.B,{grow:1}),e.createElement(Ie.h,{name:"times",size:"sm",onClick:()=>l(t),tooltip:"Remove nested query"})),e.createElement("div",{className:o.body},e.createElement(Qe._,null,e.createElement(ve,{showExplain:u,query:a.query,datasource:s,onRunQuery:i,onChange:c=>{n(t,{...a,query:c})}}))))}),wt=kt.i.map(a=>({label:a.sign,value:a.sign}));Ue.displayName="NestedQuery";const Ft=a=>({card:(0,h.css)({label:"card",display:"flex",flexDirection:"column",gap:a.spacing(.5)}),header:(0,h.css)({label:"header",padding:a.spacing(.5,.5,.5,1),gap:a.spacing(1),display:"flex",alignItems:"center"}),name:(0,h.css)({label:"name",whiteSpace:"nowrap"}),body:(0,h.css)({label:"body",paddingLeft:a.spacing(2)}),vectorMatchInput:(0,h.css)({label:"vectorMatchInput",marginLeft:-1}),vectorMatchWrapper:(0,h.css)({label:"vectorMatchWrapper",display:"flex"})});function Pt({query:a,datasource:t,onChange:s,onRunQuery:n,showExplain:l}){const i=a.binaryQueries??[],u=(c,m)=>{const p=[...i];p.splice(c,1,m),s({...a,binaryQueries:p})},o=c=>{const m=[...i.slice(0,c),...i.slice(c+1)];s({...a,binaryQueries:m})};return e.createElement(ce.K,{direction:"column",gap:1},i.map((c,m)=>e.createElement(Ue,{key:m.toString(),nestedQuery:c,index:m,onChange:u,datasource:t,onRemove:o,onRunQuery:n,showExplain:l})))}const ve=e.memo(({datasource:a,query:t,onChange:s,onRunQuery:n,showExplain:l})=>{const[i,u]=(0,e.useState)(),[o,c]=(0,e.useState)(void 0),m=b=>{s({...t,labels:b})},p=async b=>{const f=await b;return[...a.getVariables(),...f].map(g=>({label:g,value:g}))},d=async b=>{const f=t.labels.filter(F=>F!==b);if(f.length===0)return await a.languageProvider.fetchLabels();const g=w.y.renderLabels(f),S=await a.languageProvider.fetchSeriesLabels(g),U=f.map(F=>F.label);return Object.keys(S).filter(F=>!U.includes(F)).sort()},L=async b=>{if(!b.label)return[];let f;const g=t.labels.filter(S=>S!==b);if(g.length===0)f=await a.languageProvider.fetchLabelValues(b.label);else{const S=w.y.renderLabels(g);f=(await a.languageProvider.fetchSeriesLabels(S))[a.interpolateString(b.label)]}return f?f.map(S=>(0,de.Hk)(S,b.op)):[]},v=(0,e.useMemo)(()=>{const{labels:b,operations:f}=t;return!b.length&&f.length?!(f.length===1&&f[0].id===_.B5.LineContains&&f[0].params[0]===""):!1},[t]);(0,e.useEffect)(()=>{(async()=>{const f={expr:w.y.renderQuery(t),refId:"data-samples"},S={series:await a.getDataSamples(f),state:T.Gu.Done,timeRange:(0,Et.JK)()};u(S)})().catch(console.error)},[a,t]);const E={grammar:le.ZP,name:"logql"};return e.createElement("div",{"data-testid":be.editor},e.createElement(he.p,null,e.createElement(Nt,{onGetLabelNames:b=>p(d(b)),onGetLabelValues:b=>p(L(b)),labelsFilters:t.labels,onChange:m,labelFilterRequired:v})),l&&e.createElement(Oe.B,{stepNumber:1,title:e.createElement(ne.U,{query:`${w.y.renderLabels(t.labels)}`,lang:E})},Re),e.createElement(Qt.B,null,e.createElement(Mt.P,{queryModeller:w.y,query:t,onChange:s,onRunQuery:n,datasource:a,highlightedOp:o}),e.createElement(Tt.L,{datasource:a,query:t,onChange:s,data:i,queryModeller:w.y,buildVisualQueryFromString:K._z})),l&&e.createElement($e.V,{stepNumber:2,queryModeller:w.y,query:t,lang:E,onMouseEnter:b=>{c(b)},onMouseLeave:()=>{c(void 0)}}),t.binaryQueries&&t.binaryQueries.length>0&&e.createElement(Pt,{query:t,datasource:a,onChange:s,onRunQuery:n,showExplain:l}))});ve.displayName="LokiQueryBuilder";function Dt({query:a}){return e.createElement(he.p,null,e.createElement(Pe.s,null,e.createElement(ne.U,{query:a,lang:{grammar:le.xY,name:"lokiql"}})))}function Ot(a){const{query:t,onChange:s,onRunQuery:n,datasource:l,showExplain:i}=a,[u,o]=(0,e.useReducer)(Ve.reducer,{expr:t.expr,visQuery:t.expr===""?{labels:[],operations:[{id:"__line_contains",params:[""]}]}:void 0});(0,e.useEffect)(()=>{o(Bt(t.expr))},[t.expr]);const c=m=>{const p=w.y.renderQuery(m);o(Rt({visQuery:m,expr:p})),s({...a.query,expr:p})};return u.visQuery?e.createElement(e.Fragment,null,e.createElement(ve,{query:u.visQuery,datasource:l,onChange:c,onRunQuery:n,showExplain:i,"data-testid":be.editor}),t.expr!==""&&e.createElement(Dt,{query:t.expr})):null}const $t={expr:""},Ve=(0,vt.oM)({name:"loki-builder-container",initialState:$t,reducers:{visualQueryChange:(a,t)=>{a.expr=t.payload.expr,a.visQuery=t.payload.visQuery},exprChanged:(a,t)=>{if(!a.visQuery||a.expr!==t.payload){a.expr=t.payload;const s=(0,K._z)(t.payload);a.visQuery=s.query}}}}),{visualQueryChange:Rt,exprChanged:Bt}=Ve.actions;var Ae=r(32082),It=r(40705),Ut=r(63439),Vt=r(85187),te=r(53769),Ee=r(73565);const ze=e.memo(({app:a,query:t,onChange:s,onRunQuery:n,maxLines:l,queryStats:i})=>{const[u,o]=(0,e.useState)(!0),c=g=>{s({...t,queryType:g}),n()},m=g=>{(0,N.ff)("grafana_loki_resolution_clicked",{app:a,resolution:g.value}),s({...t,resolution:g.value}),n()},p=g=>{const S=g.currentTarget.value;if(!(0,Ae.jO)(S)){o(!1);return}o(!0),s({...t,splitDuration:S}),n()},d=g=>{s({...t,legendFormat:g.currentTarget.value}),n()};function L(g){const S=(0,te.Wz)(g.currentTarget.value);t.maxLines!==S&&(s({...t,maxLines:S}),n())}function v(g){s({...t,step:(0,D.trim)(g.currentTarget.value)}),n()}const E=(0,Ee.Lw)(t),b=(0,Ee.rE)(t.expr),f=(0,e.useMemo)(()=>!!(!t.step||(0,Ae.fI)(t.step)||!isNaN(Number(t.step))),[t.step]);return e.createElement(he.p,null,e.createElement(Vt.d,{title:"Options",collapsedInfo:At(t,E,l,b,f),queryStats:i},e.createElement(Z.S,{label:"Legend",tooltip:"Series name override or template. Ex. {{hostname}} will be replaced with label value for hostname."},e.createElement(ee.H,{placeholder:"{{label}}",type:"string",minWidth:14,defaultValue:t.legendFormat,onCommitChange:d})),e.createElement(Z.S,{label:"Type"},e.createElement(It.S,{options:te.uG,value:E,onChange:c})),b&&e.createElement(Z.S,{label:"Line limit",tooltip:"Upper limit for number of log lines returned by query."},e.createElement(ee.H,{className:"width-4",placeholder:l.toString(),type:"number",min:0,defaultValue:t.maxLines?.toString()??"",onCommitChange:L})),!b&&e.createElement(e.Fragment,null,e.createElement(Z.S,{label:"Step",tooltip:"Use the step parameter when making metric queries to Loki. If not filled, Grafana's calculated interval will be used. Example valid values: 1s, 5m, 10h, 1d.",invalid:!f,error:"Invalid step. Example valid values: 1s, 5m, 10h, 1d."},e.createElement(ee.H,{className:"width-6",placeholder:"auto",type:"string",defaultValue:t.step??"",onCommitChange:v})),t.resolution!==void 0&&t.resolution>1&&e.createElement(e.Fragment,null,e.createElement(Z.S,{label:"Resolution",tooltip:"Changes the step parameter of Loki metrics range queries. With a resolution of 1/1, each pixel corresponds to one data point. 1/10 retrieves one data point per 10 pixels. Lower resolutions perform better."},e.createElement(q.Ph,{isSearchable:!1,onChange:m,options:te.oZ,value:t.resolution||1,"aria-label":"Select resolution"})),e.createElement(Ut.b,{severity:"warning",title:"The 'Resolution' is deprecated. Use 'Step' editor instead to change step parameter."}))),X.config.featureToggles.lokiQuerySplittingConfig&&X.config.featureToggles.lokiQuerySplitting&&e.createElement(Z.S,{label:"Split Duration",tooltip:"Defines the duration of a single query when query splitting is enabled."},e.createElement(ee.H,{minWidth:14,type:"string",min:0,defaultValue:t.splitDuration??"1d",onCommitChange:p,invalid:!u}))))});function At(a,t,s,n,l){const i=te.uG.find(c=>c.value===t),u=te.oZ.find(c=>c.value===(a.resolution??1)),o=[];return a.legendFormat&&o.push(`Legend: ${a.legendFormat}`),o.push(`Type: ${i?.label}`),n&&o.push(`Line limit: ${a.maxLines??s}`),n||(a.step&&o.push(`Step: ${l?a.step:"Invalid value"}`),a.resolution&&o.push(`Resolution: ${u?.label}`)),o}ze.displayName="LokiQueryBuilderOptions";var We=r(80011),je=r(73453),zt=r(72625),Ge=r(83392),Wt=r(99633);async function He(a,t){if(!t)return null;const s=await a.getQueryStats(t);return s?Object.values(s).every(n=>n===0)?null:s:null}function Ke(a,t){return(0,Wt.v9)(a)?a.isSame(t):a===t}function jt(a,t,s,n){return t===void 0||a.trim()!==t.trim()?!0:!(Ke(s.raw.from,n?.raw.from)&&Ke(s.raw.to,n?.raw.to))}function Gt({query:a,datasource:t,range:s,onRunQuery:n,onChange:l,data:i,app:u,showExplain:o,history:c,setQueryStats:m}){const p=(0,z.wW)(Ht),d=X.config.featureToggles.lokiFormatQuery,L=async()=>l({...a,expr:(0,Ee.Ix)(a.expr,t)});return e.createElement("div",{className:p.wrapper},e.createElement(Ge.n,{datasource:t,query:a,range:s,onRunQuery:n,onChange:l,history:c,data:i,app:u,"data-testid":be.editor,onQueryType:async v=>{const E=await He(t,v);m(E)},ExtraFieldElement:e.createElement(e.Fragment,null,d&&e.createElement("div",{className:p.buttonGroup},e.createElement("div",null,e.createElement(Fe.Lh,{spacing:"sm"},e.createElement(Ie.h,{onClick:L,name:"brackets-curly",size:"xs",tooltip:"Format query"}),e.createElement(We.u,{content:`Use ${(0,zt.vl)()}+z to undo`},e.createElement(je.J,{className:p.hint,name:"keyboard"}))))))}),o&&e.createElement(Be,{query:a.expr}))}const Ht=a=>({wrapper:(0,h.css)` max-width: 100%; .gf-form { margin-bottom: 0.5; } `,buttonGroup:(0,h.css)` border: 1px solid ${a.colors.border.medium}; border-top: none; padding: ${a.spacing(.5,.5,.5,.5)}; margin-bottom: ${a.spacing(.5)}; display: flex; flex-grow: 1; justify-content: end; font-size: ${a.typography.bodySmall.fontSize}; `,hint:(0,h.css)` color: ${a.colors.text.disabled}; white-space: nowrap; cursor: help; `});var Kt=r(41640),Zt=r(76897),ye=r(50230);const Yt=a=>{const{pattern:t,onPatternSelect:s,hasNewQueryOption:n,hasPreviousQuery:l,selectedPatternName:i,setSelectedPatternName:u}=a,o=(0,z.wW)(Xt),c={grammar:le.ZP,name:"logql"};return e.createElement(ye.Z,{className:o.card},e.createElement(ye.Z.Heading,null,t.name),e.createElement("div",{className:o.rawQueryContainer},e.createElement(ne.U,{query:w.y.renderQuery({labels:[],operations:t.operations}),lang:c,className:o.rawQuery})),e.createElement(ye.Z.Actions,null,i!==t.name?e.createElement(k.zx,{size:"sm",onClick:()=>{l?u(t.name):s(t)}},"Use this query"):e.createElement(e.Fragment,null,e.createElement("div",{className:o.spacing},`If you would like to use this query, ${n?"you can either replace your current query or create a new query":"your current query will be replaced"}.`),e.createElement(k.zx,{size:"sm",fill:"outline",onClick:()=>u(null)},"Back"),e.createElement(k.zx,{size:"sm",onClick:()=>{s(t)}},"Replace query"),n&&e.createElement(k.zx,{size:"sm",onClick:()=>{s(t,!0)}},"Create new query"))))},Xt=a=>({card:(0,h.css)` width: 49.5%; display: flex; flex-direction: column; `,rawQueryContainer:(0,h.css)` flex-grow: 1; `,rawQuery:(0,h.css)` background-color: ${a.colors.background.primary}; padding: ${a.spacing(1)}; margin-top: ${a.spacing(1)}; `,spacing:(0,h.css)` margin-bottom: ${a.spacing(1)}; `}),Jt=a=>{const{isOpen:t,onClose:s,onChange:n,onAddQuery:l,query:i,queries:u,app:o}=a,[c,m]=(0,e.useState)([]),[p,d]=(0,e.useState)(null),L=(0,z.wW)(qt),v=!!l,E=(0,e.useMemo)(()=>(0,K._z)(i.expr).query.operations.length>0,[i.expr]),b=(f,g=!1)=>{const S=(0,K._z)(g?"":i.expr);(0,N.ff)("grafana_loki_query_patterns_selected",{version:"v2",app:o??"",editorMode:i.editorMode,selectedPattern:f.name,preSelectedOperationsCount:S.query.operations.length,preSelectedLabelsCount:S.query.labels.length,createNewQuery:v&&g}),S.query.operations=f.operations,v&&g?l({...i,refId:(0,Zt.Hs)(u??[i]),expr:w.y.renderQuery(S.query)}):n({...i,expr:w.y.renderQuery(S.query)}),d(null),s()};return e.createElement(ke.u,{isOpen:t,title:"Kick start your query",onDismiss:s,className:L.modal},e.createElement("div",{className:L.spacing},"Kick start your query by selecting one of these queries. You can then continue to complete your query."),Object.values(_.Hv).map(f=>e.createElement(Kt.U,{key:f,label:`${(0,D.capitalize)(f)} query starters`,isOpen:c.includes(f),collapsible:!0,onToggle:()=>m(g=>g.includes(f)?g.filter(S=>S!==f):[...g,f])},e.createElement("div",{className:L.cardsContainer},w.y.getQueryPatterns().filter(g=>g.type===f).map(g=>e.createElement(Yt,{key:g.name,pattern:g,hasNewQueryOption:v,hasPreviousQuery:E,onPatternSelect:b,selectedPatternName:p,setSelectedPatternName:d}))))),e.createElement(k.zx,{variant:"secondary",onClick:s},"Close"))},qt=a=>({cardsContainer:(0,h.css)` display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-between; `,spacing:(0,h.css)` margin-bottom: ${a.spacing(1)}; `,modal:(0,h.css)` width: 85vw; ${a.breakpoints.down("md")} { width: 100%; } `});var Ze=r(56812),_t=r(24513);const Ye="LokiQueryEditorModeDefault";function ea(a,t,s){a.expr===""&&Ze.Z.set(Ye,t),s({...a,editorMode:t})}function ta(a){if(a!=null&&a!=="")return H.c.Code;switch(Ze.Z.get(Ye)){case"code":return H.c.Code;case"builder":default:return H.c.Builder}}function aa(a){let t=a;return a.editorMode||(t={...a,editorMode:ta(a.expr)}),a.expr==null&&(t={...t,expr:""}),a.queryType==null&&(t={...t,queryType:_t.EM.Range}),t}const be={editor:"loki-editor"},Xe=e.memo(a=>{const{onChange:t,onRunQuery:s,onAddQuery:n,data:l,app:i,queries:u,datasource:o}=a,[c,m]=(0,e.useState)(!1),[p,d]=(0,e.useState)(!1),[L,v]=(0,e.useState)(!1),[E,b]=(0,e.useState)(!1),[f,g]=(0,e.useState)(null),{flag:S,setFlag:U}=(0,Te.P5)(Te.iS),x=o.getTimeRange(),F=o.predefinedOperations,oe=(0,Q.Z)(x),M=aa(a.query);X.config.featureToggles.lokiPredefinedOperations&&!M.expr&&F&&(M.expr=`{} ${F}`);const tt=(0,Q.Z)(M.expr),xe=M.editorMode,$a=P=>{U(P.currentTarget.checked)},Ra=(0,e.useCallback)(P=>{if((0,N.ff)("grafana_loki_editor_mode_clicked",{newEditor:P,previousEditor:M.editorMode??"",newQuery:!M.expr,app:i??""}),P===H.c.Builder&&(0,K._z)(M.expr||"").errors.length){m(!0);return}ea(M,P,t)},[t,M,i]);(0,e.useEffect)(()=>{v(!1)},[l]);const Ce=P=>{(0,D.isEqual)(P,a.query)||v(!0),t(P)},Ba=()=>{(0,N.ff)("grafana_loki_label_browser_opened",{app:i}),b(P=>!P)};return(0,e.useEffect)(()=>{jt(M.expr,tt,x,oe)&&(async()=>{const Ia=await He(o,M.expr);g(Ia)})()},[o,x,oe,M,tt,g]),e.createElement(e.Fragment,null,e.createElement(nt.s,{isOpen:c,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:()=>{t({...M,editorMode:H.c.Builder}),m(!1)},onDismiss:()=>m(!1)}),e.createElement(Jt,{isOpen:p,onClose:()=>d(!1),query:M,queries:u,app:i,onChange:t,onAddQuery:n}),e.createElement(ht,{isOpen:E,datasource:o,query:M,app:i,onClose:()=>b(!1),onChange:Ce,onRunQuery:s}),e.createElement(at.K,null,e.createElement(ce.K,{gap:1},e.createElement(k.zx,{"aria-label":G.wl.components.QueryBuilder.queryPatterns,variant:"secondary",size:"sm",onClick:()=>{d(Ne=>!Ne);const P=(0,K._z)(M.expr||"");(0,N.ff)("grafana_loki_query_patterns_opened",{version:"v2",app:i??"",editorMode:M.editorMode,preSelectedOperationsCount:P.query.operations.length,preSelectedLabelsCount:P.query.labels.length})}},"Kick start your query"),e.createElement(k.zx,{variant:"secondary",size:"sm",onClick:Ba,"data-testid":"label-browser-button"},"Label browser")),e.createElement(rt.n,{label:"Explain query",value:S,onChange:$a}),e.createElement(Me.B,{grow:1}),i!==y.zj.Explore&&i!==y.zj.Correlations&&e.createElement(k.zx,{variant:L?"primary":"secondary",size:"sm",onClick:s,icon:l?.state===T.Gu.Loading?"fa fa-spinner":void 0,disabled:l?.state===T.Gu.Loading},"Run queries"),e.createElement(lt.k,{mode:xe,onChange:Ra})),e.createElement(st.T,{v:.5}),e.createElement(Qe._,null,xe===H.c.Code&&e.createElement(Gt,{...a,query:M,onChange:Ce,showExplain:S,setQueryStats:g}),xe===H.c.Builder&&e.createElement(Ot,{datasource:a.datasource,query:M,onChange:Ce,onRunQuery:a.onRunQuery,showExplain:S}),e.createElement(ze,{query:M,onChange:t,onRunQuery:s,app:i,maxLines:o.maxLines,queryStats:f})))});Xe.displayName="LokiQueryEditor";function sa(a){const{query:t,data:s,datasource:n,onChange:l,onRunQuery:i,history:u}=a;return e.createElement(Ge.n,{datasource:n,query:t,onChange:l,onRunQuery:i,history:u,data:s,placeholder:"Enter a Loki query","data-testid":na.editor})}const na={editor:"loki-editor-cloud-alerting"};function la(a){const{app:t}=a;switch(t){case y.zj.CloudAlerting:return e.createElement(sa,{...a});default:return e.createElement(Xe,{...a})}}const ra=(0,e.memo)(la),Ua={editor:"loki-editor"};var oa=r(77195),ia=r(19010),ca=r(49257),re=r(5562),Le=r(78102),Je=r(42074);function ua({options:a,onOptionsChange:t}){return e.createElement(Le._,{title:"Alerting"},e.createElement(fe._,{labelWidth:29,label:"Manage alert rules in Alerting UI",disabled:a.readOnly,tooltip:"Manage alert rules for this data source. To manage other alerting resources, add an Alertmanager data source."},e.createElement(Je.x,{value:a.jsonData.manageAlerts!==!1,onChange:s=>t({...a,jsonData:{...a.jsonData,manageAlerts:s.currentTarget.checked}})})))}var da=r(3569),ma=r(24094),qe=r(47449),pa=r(29241),ga=r(60105),ha=r(20205);const fa=a=>{const{derivedFields:t,className:s}=a,[n,l]=(0,e.useState)("");let i=[];return n&&t&&(i=Ea(t,n)),e.createElement("div",{className:s},e.createElement(fe._,{label:"Debug log message",labelWidth:24,grow:!0},e.createElement(ga.K,{type:"text","aria-label":"Prometheus Query",placeholder:"Paste an example log line here to test the regular expressions of your derived fields",value:n,onChange:u=>l(u.currentTarget.value)})),!!i.length&&e.createElement(va,{fields:i}))},va=({fields:a})=>e.createElement("table",{className:"filter-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Name"),e.createElement("th",null,"Value"),e.createElement("th",null,"Url"))),e.createElement("tbody",null,a.map(t=>{let s=t.value;return t.error&&t.error instanceof Error?s=t.error.message:t.href&&(s=e.createElement("a",{href:t.href},s)),e.createElement("tr",{key:`${t.name}=${t.value}`},e.createElement("td",null,t.name),e.createElement("td",null,s),e.createElement("td",null,t.href?e.createElement("a",{href:t.href},t.href):""))})));function Ea(a,t){return a.filter(s=>s.name&&s.matcherRegex).map(s=>{try{const n=t.match(s.matcherRegex),l=n&&n[1];let i=null;return s.url&&l&&(i=(0,ha.a_)({field:{name:"",type:pa.fS.string,values:[l],config:{links:[{title:"",url:s.url}]}},rowIndex:0,range:{}})[0]),{name:s.name,value:l||"<no match>",href:i?i.href:void 0}}catch(n){return{name:s.name,error:n}}})}var Y=r(22209),ya=r(22965),ba=r(53229);const La=a=>({row:(0,h.css)` display: flex; align-items: baseline; `,nameField:(0,h.css)` flex: 2; margin-right: ${a.spacing(.5)}; `,regexField:(0,h.css)` flex: 3; margin-right: ${a.spacing(.5)}; `,urlField:(0,h.css)` flex: 1; margin-right: ${a.spacing(.5)}; `,urlDisplayLabelField:(0,h.css)` flex: 1; `,internalLink:(0,h.css)` margin-right: ${a.spacing(1)}; `,dataSource:(0,h.css)``}),Sa=a=>{const{value:t,onChange:s,onDelete:n,suggestions:l,className:i,validateName:u}=a,o=(0,z.wW)(La),[c,m]=(0,e.useState)(!!t.datasourceUid),p=(0,Q.Z)(t.datasourceUid);(0,e.useEffect)(()=>{!p&&t.datasourceUid&&!c&&m(!0),p&&!t.datasourceUid&&c&&m(!1)},[p,t.datasourceUid,c]);const d=v=>E=>{s({...t,[v]:E.currentTarget.value})},L=!u(t.name);return e.createElement("div",{className:i,"data-testid":"derived-field"},e.createElement("div",{className:"gf-form"},e.createElement(Y.g,{className:o.nameField,label:"Name",invalid:L,error:"The name is already in use"},e.createElement(se.I,{value:t.name,onChange:d("name"),placeholder:"Field name",invalid:L})),e.createElement(Y.g,{className:o.regexField,label:e.createElement(_e,{label:"Regex",content:"Use to parse and capture some part of the log message. You can use the captured groups in the template."})},e.createElement(se.I,{value:t.matcherRegex,onChange:d("matcherRegex")})),e.createElement(Y.g,{label:""},e.createElement(k.zx,{variant:"destructive",title:"Remove field",icon:"times",onClick:v=>{v.preventDefault(),n()}}))),e.createElement("div",{className:"gf-form"},e.createElement(Y.g,{label:c?"Query":"URL",className:o.urlField},e.createElement(ya.v,{placeholder:c?"${__value.raw}":"http://example.com/${__value.raw}",value:t.url||"",onChange:v=>s({...t,url:v}),suggestions:l})),e.createElement(Y.g,{className:o.urlDisplayLabelField,label:e.createElement(_e,{label:"URL Label",content:"Use to override the button label when this derived field is found in a log."})},e.createElement(se.I,{value:t.urlDisplayLabel,onChange:d("urlDisplayLabel")}))),e.createElement("div",{className:"gf-form"},e.createElement(Y.g,{label:"Internal link",className:o.internalLink},e.createElement(Je.r,{value:c,onChange:v=>{const{checked:E}=v.currentTarget;E||s({...t,datasourceUid:void 0}),m(E)}})),c&&e.createElement(Y.g,{label:"",className:o.dataSource},e.createElement(ba.q,{tracing:!0,onChange:v=>s({...t,datasourceUid:v.uid}),current:t.datasourceUid,noDefault:!0}))))},_e=({content:a,label:t})=>e.createElement(ae._,null,t,e.createElement(We.u,{placement:"top",content:a,theme:"info"},e.createElement(je.J,{tabIndex:0,name:"info-circle",size:"sm",style:{marginLeft:"10px"}}))),xa=a=>({addButton:(0,h.css)` margin-right: 10px; `,derivedField:(0,h.css)` margin-bottom: ${a.spacing(1)}; `,container:(0,h.css)` margin-bottom: ${a.spacing(4)}; `,debugSection:(0,h.css)` margin-top: ${a.spacing(4)}; `}),Ca=({fields:a=[],onChange:t})=>{const s=(0,z.l4)(),n=xa(s),[l,i]=(0,e.useState)(!1),u=(0,e.useCallback)(o=>a.filter(c=>c.name&&c.name===o).length<=1,[a]);return e.createElement(Le._,{title:"Derived fields",description:e.createElement(qe.W,{description:"Derived fields can be used to extract new fields from a log message and create a link from its value.",suffix:"loki/#configure-derived-fields",feature:"derived fields"})},e.createElement("div",{className:n.container},a.map((o,c)=>e.createElement(Sa,{className:n.derivedField,key:c,value:o,onChange:m=>{const p=[...a];p.splice(c,1,m),t(p)},onDelete:()=>{const m=[...a];m.splice(c,1),t(m)},validateName:u,suggestions:[{value:da.W.valueRaw,label:"Raw value",documentation:"Exact string captured by the regular expression",origin:ma.L8.Value}]})),e.createElement("div",null,e.createElement(k.zx,{variant:"secondary",className:n.addButton,icon:"plus",onClick:o=>{o.preventDefault();const c=[...a,{name:"",matcherRegex:"",urlDisplayLabel:"",url:""}];t(c)}},"Add"),a.length>0&&e.createElement(k.zx,{variant:"secondary",type:"button",onClick:()=>i(!l)},l?"Hide example log message":"Show example log message")),l&&e.createElement("div",{className:n.debugSection},e.createElement(fa,{className:(0,h.css)` margin-bottom: 10px; `,derivedFields:a}))))};var Na=r(82367),Ma=r(25357);const{FormField:et}=Na.LegacyForms,Qa=a=>{const{maxLines:t,onMaxLinedChange:s,predefinedOperations:n,onPredefinedOperationsChange:l}=a;return e.createElement(Le._,{title:"Queries",description:e.createElement(qe.W,{description:"Additional options to customize your querying experience. ",suffix:"loki/#configure-the-data-source",feature:"query settings"})},e.createElement("div",{className:"gf-form-inline"},e.createElement("div",{className:"gf-form"},e.createElement(et,{label:"Maximum lines",labelWidth:11,inputWidth:20,inputEl:e.createElement("input",{type:"number",className:"gf-form-input width-8 gf-form-input--has-help-icon",value:t,onChange:i=>s(i.currentTarget.value),spellCheck:!1,placeholder:"1000"}),tooltip:e.createElement(e.Fragment,null,"Loki queries must contain a limit of the maximum number of lines returned (default: 1000). Increase this limit to have a bigger result set for ad-hoc analysis. Decrease this limit if your browser becomes sluggish when displaying the log results.")}))),X.config.featureToggles.lokiPredefinedOperations&&e.createElement("div",{className:"gf-form-inline"},e.createElement("div",{className:"gf-form"},e.createElement(et,{label:"Predefined operations",labelWidth:11,inputEl:e.createElement("input",{type:"string",className:"gf-form-input width-20 gf-form-input--has-help-icon",value:n,onChange:i=>l(i.currentTarget.value),spellCheck:!1,placeholder:"| unpack | line_format"}),tooltip:e.createElement("div",null,'Predefined operations are used as an initial state for your queries. They are useful, if you want to unpack, parse or format all log lines. Currently we support only log operations starting with |. For example: | unpack | line_format "{{.message}}".')}),e.createElement(Ma.C,{text:"Experimental",color:"orange",icon:"exclamation-triangle",tooltip:"Predefined operations is an experimental feature that may change in the future."}))))},Se=a=>(t,s)=>({...t,jsonData:{...t.jsonData,[a]:s}}),Ta=Se("maxLines"),ka=Se("predefinedOperations"),wa=Se("derivedFields"),Fa=a=>{const{options:t,onOptionsChange:s}=a,n=(0,e.useCallback)(l=>{(0,N.ff)("grafana_loki_predefined_operations_changed",{value:l}),s(ka(t,l))},[t,s]);return e.createElement(e.Fragment,null,e.createElement(oa.j,{dataSourceName:"Loki",docsLink:"https://grafana.com/docs/grafana/latest/datasources/loki",hasRequiredFields:!1}),e.createElement(re.i,null),e.createElement(ca.E,{defaultUrl:"http://localhost:3100",dataSourceConfig:t,showAccessOptions:!1,onChange:s,secureSocksDSProxyEnabled:X.config.secureSocksDSProxyEnabled}),e.createElement(re.i,null),e.createElement(ia.K,{title:"Additional settings",description:"Additional settings are optional settings that can be configured for more control over your data source.",isCollapsible:!0,isInitiallyOpen:!0},e.createElement(ua,{options:t,onOptionsChange:s}),e.createElement(re.i,{hideLine:!0}),e.createElement(Qa,{maxLines:t.jsonData.maxLines||"",onMaxLinedChange:l=>s(Ta(t,l)),predefinedOperations:t.jsonData.predefinedOperations||"",onPredefinedOperationsChange:n}),e.createElement(re.i,{hideLine:!0}),e.createElement(Ca,{fields:t.jsonData.derivedFields,onChange:l=>s(wa(t,l))})))};var Pa=r(61875),Da=r(57864);const Oa=new C.hf(Pa.KV).setQueryEditor(ra).setConfigEditor(Fa).setQueryEditorHelp(I);(0,j.N$)().subscribe(A.Pl,Da.uJ)}}]); //# sourceMappingURL=760.8091fa41208384ade014.js.map