"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4023],{5562:(Q,y,e)=>{e.d(y,{i:()=>S});var d=e(42844),l=e(27702),r=e(66310);const S=({hideLine:u=!1})=>{const E=(0,r.wW)(W);return u?l.createElement("hr",{className:E.dividerHideLine}):l.createElement("hr",{className:E.divider})},W=u=>({divider:(0,d.css)`
    margin: ${u.spacing(4,0)};
  `,dividerHideLine:(0,d.css)`
    border: none;
    margin: ${u.spacing(3,0)};
  `})},29126:(Q,y,e)=>{e.d(y,{I:()=>z});var d=e(42844),l=e(27702),r=e(17312),S=e(78102),W=e(66310),u=e(71107),E=e(48024),A=e(42074),L=e(47449);function N({options:f,onOptionsChange:g}){const x=(0,W.wW)(j);return l.createElement("div",{className:x.container},l.createElement(u.Z,{className:x.row},l.createElement(E._,{tooltip:"Displays the node graph above the trace view. Default: disabled",label:"Enable node graph",labelWidth:26},l.createElement(A.x,{id:"enableNodeGraph",value:f.jsonData.nodeGraph?.enabled,onChange:F=>(0,r.tp)({onOptionsChange:g,options:f},"nodeGraph",{...f.jsonData.nodeGraph,enabled:F.currentTarget.checked})}))))}const z=({options:f,onOptionsChange:g})=>l.createElement(S._,{title:"Node graph",description:l.createElement(L.W,{description:"Show or hide the node graph visualization.",suffix:`${f.type}/#node-graph`,feature:"the node graph"})},l.createElement(N,{options:f,onOptionsChange:g})),j=f=>({infoText:(0,d.css)`
    label: infoText;
    padding-bottom: ${f.spacing(2)};
    color: ${f.colors.text.secondary};
  `,container:(0,d.css)`
    label: container;
    width: 100%;
  `,row:(0,d.css)`
    label: row;
    align-items: baseline;
  `})},35977:(Q,y,e)=>{e.d(y,{Y:()=>F});var d=e(42844),l=e(27702),r=e(17312),S=e(19010),W=e(66310),u=e(71107),E=e(48024),A=e(66670),L=e(1128),N=e(53229),z=e(47449),j=e(71654),f=e(19059),g=e(51778);function x({options:c,onOptionsChange:v}){const J=(0,W.wW)(Z);return l.createElement("div",{className:(0,d.css)({width:"100%"})},l.createElement(u.Z,{className:J.row},l.createElement(E._,{tooltip:"The Prometheus data source the trace is going to navigate to",label:"Data source",labelWidth:26},l.createElement(N.q,{inputId:"trace-to-metrics-data-source-picker",pluginId:"prometheus",current:c.jsonData.tracesToMetrics?.datasourceUid,noDefault:!0,width:40,onChange:T=>(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,datasourceUid:T.uid})})),c.jsonData.tracesToMetrics?.datasourceUid?l.createElement(A.zx,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,datasourceUid:void 0})}},"Clear"):null),l.createElement(u.Z,null,l.createElement(j.w,{label:(0,g.mH)("start"),tooltip:(0,g.rr)("start"),value:c.jsonData.tracesToMetrics?.spanStartTimeShift||"",onChange:T=>{(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,spanStartTimeShift:T})},isInvalidError:g.Ny})),l.createElement(u.Z,null,l.createElement(j.w,{label:(0,g.mH)("end"),tooltip:(0,g.rr)("end"),value:c.jsonData.tracesToMetrics?.spanEndTimeShift||"",onChange:T=>{(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,spanEndTimeShift:T})},isInvalidError:g.Ny})),l.createElement(u.Z,null,l.createElement(E._,{tooltip:"Tags that will be used in the metrics query",label:"Tags",labelWidth:26},l.createElement(f.a,{values:c.jsonData.tracesToMetrics?.tags??[],onChange:T=>(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,tags:T})}))),c.jsonData.tracesToMetrics?.queries?.map((T,U)=>l.createElement("div",{key:U,className:J.queryRow},l.createElement(E._,{label:"Link Label",labelWidth:26,tooltip:"Descriptive label for the linked query"},l.createElement(L.I,{label:"Link Label",type:"text",allowFullScreen:!0,value:T.name,width:40,onChange:R=>{let B=c.jsonData.tracesToMetrics?.queries.slice()??[];B[U].name=R.currentTarget.value,(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,queries:B})}})),l.createElement(E._,{label:"Query",labelWidth:10,tooltip:"The Prometheus query that will run when navigating from a trace to metrics. Interpolate tags using the `$__tags` keyword",grow:!0},l.createElement(L.I,{label:"Query",type:"text",allowFullScreen:!0,value:T.query,onChange:R=>{let B=c.jsonData.tracesToMetrics?.queries.slice()??[];B[U].query=R.currentTarget.value,(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,queries:B})}})),l.createElement(A.zx,{variant:"destructive",title:"Remove query",icon:"times",type:"button",onClick:()=>{let R=c.jsonData.tracesToMetrics?.queries.slice();R?.splice(U,1),(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,queries:R})}}))),l.createElement(A.zx,{variant:"secondary",title:"Add query",icon:"plus",type:"button",onClick:()=>{(0,r.tp)({onOptionsChange:v,options:c},"tracesToMetrics",{...c.jsonData.tracesToMetrics,queries:[...c.jsonData.tracesToMetrics?.queries??[],{query:""}]})}},"Add query"))}const F=({options:c,onOptionsChange:v})=>l.createElement(S.K,{title:"Trace to metrics",description:l.createElement(z.W,{description:"Navigate from a trace span to the selected data source's metrics.",suffix:`${c.type}/#trace-to-metrics`,feature:"trace to metrics"}),isCollapsible:!0,isInitiallyOpen:!0},l.createElement(x,{options:c,onOptionsChange:v})),Z=c=>({infoText:(0,d.css)`
    padding-bottom: ${c.spacing(2)};
    color: ${c.colors.text.secondary};
  `,row:(0,d.css)`
    label: row;
    align-items: baseline;
  `,queryRow:(0,d.css)`
    label: queryRow;
    display: flex;
    flex-flow: wrap;
  `})},48561:(Q,y,e)=>{e.r(y),e.d(y,{plugin:()=>Ie});var d=e(68246),l=e(42844),r=e(27702),S=e(77195),W=e(19010),u=e(34667),E=e(66310),A=e(49257),L=e(5562),N=e(29126),z=e(51778),j=e(35977),f=e(32042);const g=({options:a,onOptionsChange:t})=>{const n=(0,E.wW)(x);return r.createElement("div",{className:n.container},r.createElement(S.j,{dataSourceName:"Zipkin",docsLink:"https://grafana.com/docs/grafana/latest/datasources/zipkin",hasRequiredFields:!1}),r.createElement(L.i,null),r.createElement(A.E,{defaultUrl:"http://localhost:9411",dataSourceConfig:a,showAccessOptions:!1,onChange:t,secureSocksDSProxyEnabled:u.config.secureSocksDSProxyEnabled}),r.createElement(z.dw,{options:a,onOptionsChange:t}),r.createElement(L.i,null),u.config.featureToggles.traceToMetrics?r.createElement(r.Fragment,null,r.createElement(j.Y,{options:a,onOptionsChange:t}),r.createElement(L.i,null)):null,r.createElement(W.K,{title:"Additional settings",description:"Additional settings are optional settings that can be configured for more control over your data source.",isCollapsible:!0,isInitiallyOpen:!1},r.createElement(N.I,{options:a,onOptionsChange:t}),r.createElement(L.i,{hideLine:!0}),r.createElement(f.vc,{options:a,onOptionsChange:t})))},x=a=>({container:(0,l.css)`
    label: container;
    margin-bottom: ${a.spacing(2)};
    max-width: 900px;
  `});var F=e(89949),Z=e(26811),c=e(97990),v=e(93562),J=e(13741),T=e(79399),U=e(71107),R=e(48024),B=e(64022),q=e(40705),_=e(66670),ee=e(58964),te=e(9857),Y=e(33877),b=e(73807),X=e(84749);const G="/api/v2",ae=a=>({tracesCascader:(0,l.css)({label:"tracesCascader",marginRight:a.spacing(1)})}),re=({query:a,onChange:t,onRunQuery:n,datasource:s})=>{const[i,o]=(0,r.useState)(!1),$=ne(s),I=(0,E.l4)(),m=(0,E.wW)(ae),{onLoadOptions:h,allOptions:D}=se(s),p=(0,r.useCallback)((M,P)=>{if(P.length===3){const w=P[2].value;t({...a,query:w}),n()}},[t,n,a]);(0,r.useEffect)(()=>{a.queryType||t({...a,queryType:"traceID"})},[a,t]);const O=M=>{const P={...a,query:M};t(P)};let K=oe($,D);return r.createElement(r.Fragment,null,r.createElement(J.u,{title:"Upload trace",isOpen:i,onDismiss:()=>o(!1)},r.createElement("div",{className:(0,l.css)({padding:I.spacing(2)})},r.createElement(T.Yo,{options:{multiple:!1},onLoad:M=>{s.uploadedJson=M,t({...a,queryType:"upload"}),o(!1),n()}}))),r.createElement(U.Z,null,r.createElement(R._,{label:"Query type",grow:!0},r.createElement(B.Lh,{spacing:"sm",align:"center",justify:"space-between"},r.createElement(q.S,{options:[{value:"traceID",label:"TraceID"}],value:a.queryType||"traceID",onChange:M=>t({...a,queryType:M}),size:"md"}),r.createElement(_.zx,{variant:"secondary",size:"sm",onClick:()=>{o(!0)}},"Import trace")))),a.queryType==="traceID"&&r.createElement(U.Z,null,r.createElement(ee.O,{options:K,onChange:p,loadData:h,variant:"secondary",buttonProps:{className:m.tracesCascader}},"Traces"),r.createElement("div",{className:"gf-form gf-form--grow flex-shrink-1 min-width-15"},r.createElement(te.q,{query:a.query,onChange:O,onRunQuery:n,placeholder:"Insert Trace ID (run with Shift+Enter)",portalOrigin:"zipkin"}))))};function ne(a){const t=`${G}/services`,[n,s]=(0,Z.Z)(async()=>{try{const i=await a.metadataRequest(t);return i?i.sort().map(o=>({label:o,value:o,isLeaf:!1})):[]}catch(i){const o=i instanceof Error?i:"An unknown error occurred";throw(0,X.WI)((0,Y.$l)((0,b.t_)("Failed to load services from Zipkin",o))),i}},[a]);return(0,c.Z)(()=>{s()}),n}function se(a){const t=(0,v.Z)(),[n,s]=(0,r.useState)({}),[,i]=(0,Z.Z)(async function(m){const h=`${G}/spans`;try{const D=await a.metadataRequest(h,{serviceName:m});t()&&s(p=>{const O=(0,F.fromPairs)(D.map(K=>[K,void 0]));return{...p,[m]:O}})}catch(D){const p=D instanceof Error?D:"An unknown error occurred";throw(0,X.WI)((0,Y.$l)((0,b.t_)("Failed to load spans from Zipkin",p))),D}},[a,n]),[,o]=(0,Z.Z)(async function(m,h){const D=`${G}/traces`,p={serviceName:m,spanName:h};try{const O=await a.metadataRequest(D,p);if(t()){const K=O.length?(0,F.fromPairs)(O.map(M=>{const P=M.find(w=>!w.parentId);return[`${P.name} [${Math.floor(P.duration/1e3)} ms]`,P.traceId]})):ie;s(M=>{const P=M[m];return{...M,[m]:{...P,[h]:K}}})}}catch(O){const K=O instanceof Error?O:"An unknown error occurred";throw(0,X.WI)((0,Y.$l)((0,b.t_)("Failed to load spans from Zipkin",K))),O}},[a]);return{onLoadOptions:(0,r.useCallback)(I=>{const m=I[0].value;if(I.length===1)i(m);else if(I.length===2){const h=I[1].value;o(m,h)}},[i,o]),allOptions:n}}function oe(a,t){return(0,r.useMemo)(()=>{let n=[];return a.value&&a.value.length?n=a.value.map(s=>({...s,children:t[s.value]&&Object.keys(t[s.value]).map(i=>({label:i,value:i,isLeaf:!1,children:t[s.value][i]&&Object.keys(t[s.value][i]).map(o=>({label:o,value:t[s.value][i][o]}))}))})):a.value&&!a.value.length&&(n=ce),n},[a,t])}const le="__NO_TRACES__",ce=[{label:"No traces found",value:"no_traces",isLeaf:!0}],ie={"[No traces in time range]":le};var V=e(45383),de=e(78209),ue=e(39343),me=e(32053),Ee=e(29241),fe=e(39317),ve=e(73289),ge=e(26631),C=e(12503),H=e(43500);function Te(a){const{nodes:t,edges:n}=he(a),[s,i]=(0,H.np)();for(const o of t)s.add(o);for(const o of n)i.add(o);return[s,i]}function he(a){const t=[],n=[],s=De(a),i=(0,H.nO)(o=>{if(!(o>=a.length))return{span:a[o],id:a[o].id,parentIds:a[o].parentId?[a[o].parentId]:[]}});for(const o of a){const $=i[o.id].children.map(D=>{const p=i[D].span;return[p.timestamp,p.timestamp+p.duration]}),I=(0,H.et)($),m=o.duration-I,h=(0,H.fy)(o.duration/1e3,s/1e3,m/1e3);t.push({[C.z.id]:o.id,[C.z.title]:o.localEndpoint?.serviceName||o.remoteEndpoint?.serviceName||"unknown",[C.z.subTitle]:o.name,[C.z.mainStat]:h.main,[C.z.secondaryStat]:h.secondary,[C.z.color]:m/s}),o.parentId&&i[o.parentId].span&&n.push({[C.z.id]:o.parentId+"--"+o.id,[C.z.target]:o.id,[C.z.source]:o.parentId})}return{nodes:t,edges:n}}function De(a){let t=0,n=1/0;for(const s of a)s.timestamp<n&&(n=s.timestamp),s.timestamp+s.duration>t&&(t=s.timestamp+s.duration);return t-n}var pe=e(66288);class Me extends d.MF{constructor(t,n=(0,fe.J)()){super(t),this.instanceSettings=t,this.templateSrv=n,this.uploadedJson=null,this.nodeGraph=t.jsonData.nodeGraph}query(t){const n=t.targets[0];if(n.queryType==="upload"){if(!this.uploadedJson)return(0,V.of)({data:[]});try{const s=JSON.parse(this.uploadedJson);return(0,V.of)(k({data:s},this.nodeGraph?.enabled))}catch{return(0,V.of)({error:{message:"JSON is not valid Zipkin format"},data:[]})}}if(n.query){const s=this.applyVariables(n,t.scopedVars);return this.request(`${G}/trace/${encodeURIComponent(s.query)}`).pipe((0,ue.U)(i=>k(i,this.nodeGraph?.enabled)))}return(0,V.of)(ye)}async metadataRequest(t,n){return(await(0,de.n)(this.request(t,n,{hideFromInspector:!0}))).data}async testDatasource(){return await this.metadataRequest(`${G}/services`),{status:"success",message:"Data source is working"}}getQueryDisplayText(t){return t.query}interpolateVariablesInQueries(t,n){return!t||t.length===0?[]:t.map(s=>({...s,datasource:this.getRef(),...this.applyVariables(s,n)}))}applyVariables(t,n){return{...{...t},query:this.templateSrv.replace(t.query??"",n)}}request(t,n,s){const i=n?(0,ge.tW)(n):"",o=`${this.instanceSettings.url}${t}${i.length?`?${i}`:""}`,$={...s,url:o};return(0,ve.i)().fetch($)}}function k(a,t=!1){let n=a?.data?[(0,pe.m)(a?.data)]:[];return t&&n.push(...Te(a?.data)),{data:n}}const ye={data:[(0,me.at)({fields:[{name:"trace",type:Ee.fS.trace,values:[]}],meta:{preferredVisualisationType:"trace",custom:{traceFormat:"zipkin"}}})]},Ie=new d.hf(Me).setQueryEditor(re).setConfigEditor(g)},97990:(Q,y,e)=>{e.d(y,{Z:()=>r});var d=e(19559),l=function(S){(0,d.Z)(function(){S()})};const r=l}}]);

//# sourceMappingURL=zipkinPlugin.d804a1d03a4d8e5b659f.js.map