"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4023],{90950:(G,S,e)=>{e.d(S,{n:()=>P});var m=e(9892),t=e(66111),i=e(73446),C=e(72648),N=e(11543),I=e(81764),p=e(8944),L=e(62911);function P({options:f,onOptionsChange:R}){const W=(0,C.wW)(U);return t.createElement("div",{className:W.container},t.createElement("h3",{className:"page-heading"},"Node graph"),t.createElement("div",{className:W.infoText},"Show or hide the node graph visualization",t.createElement(L.j,{hrefSuffix:`${f.type}/#node-graph`})),t.createElement(N.Z,{className:W.row},t.createElement(I._,{tooltip:"Displays the node graph above the trace view. Default: disabled",label:"Enable node graph",labelWidth:26},t.createElement(p.x,{id:"enableNodeGraph",value:f.jsonData.nodeGraph?.enabled,onChange:l=>(0,i.tp)({onOptionsChange:R,options:f},"nodeGraph",{...f.jsonData.nodeGraph,enabled:l.currentTarget.checked})}))))}const U=f=>({infoText:m.css`
    label: infoText;
    padding-bottom: ${f.spacing(2)};
    color: ${f.colors.text.secondary};
  `,container:m.css`
    label: container;
    width: 100%;
  `,row:m.css`
    label: row;
    align-items: baseline;
  `})},48288:(G,S,e)=>{e.d(S,{F:()=>R});var m=e(9892),t=e(66111),i=e(73446),C=e(53117),N=e(72648),I=e(11543),p=e(81764),L=e(31403),P=e(46967),U=e(62911),f=e(33045);function R({options:l,onOptionsChange:h}){const F=(0,N.wW)(W);return t.createElement("div",{className:(0,m.css)({width:"100%"})},t.createElement("h3",{className:"page-heading"},"Trace to metrics"),t.createElement("div",{className:F.infoText},"Navigate from a trace span to the selected data source's metrics",t.createElement(U.j,{hrefSuffix:`${l.type}/#trace-to-metrics`})),t.createElement(I.Z,{className:F.row},t.createElement(p._,{tooltip:"The Prometheus data source the trace is going to navigate to",label:"Data source",labelWidth:26},t.createElement(C.q,{inputId:"trace-to-metrics-data-source-picker",pluginId:"prometheus",current:l.jsonData.tracesToMetrics?.datasourceUid,noDefault:!0,width:40,onChange:E=>(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,datasourceUid:E.uid})})),l.jsonData.tracesToMetrics?.datasourceUid?t.createElement(L.zx,{type:"button",variant:"secondary",size:"sm",fill:"text",onClick:()=>{(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,datasourceUid:void 0})}},"Clear"):null),t.createElement(I.Z,null,t.createElement(p._,{label:"Span start time shift",labelWidth:26,grow:!0,tooltip:"Shifts the start time of the span. Default: 0 (Time units can be used here, for example: 5s, -1m, 3h)"},t.createElement(P.I,{type:"text",placeholder:"0",width:40,onChange:E=>(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,spanStartTimeShift:E.currentTarget.value}),value:l.jsonData.tracesToMetrics?.spanStartTimeShift||""}))),t.createElement(I.Z,null,t.createElement(p._,{label:"Span end time shift",labelWidth:26,grow:!0,tooltip:"Shifts the end time of the span. Default: 0 (Time units can be used here, for example: 5s, -1m, 3h)"},t.createElement(P.I,{type:"text",placeholder:"0",width:40,onChange:E=>(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,spanEndTimeShift:E.currentTarget.value}),value:l.jsonData.tracesToMetrics?.spanEndTimeShift||""}))),t.createElement(I.Z,null,t.createElement(p._,{tooltip:"Tags that will be used in the metrics query",label:"Tags",labelWidth:26},t.createElement(f.a,{values:l.jsonData.tracesToMetrics?.tags??[],onChange:E=>(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,tags:E})}))),l.jsonData.tracesToMetrics?.queries?.map((E,j)=>t.createElement("div",{key:j,className:F.queryRow},t.createElement(p._,{label:"Link Label",labelWidth:26,tooltip:"Descriptive label for the linked query"},t.createElement(P.I,{label:"Link Label",type:"text",allowFullScreen:!0,value:E.name,width:40,onChange:O=>{let A=l.jsonData.tracesToMetrics?.queries.slice()??[];A[j].name=O.currentTarget.value,(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:A})}})),t.createElement(p._,{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},t.createElement(P.I,{label:"Query",type:"text",allowFullScreen:!0,value:E.query,onChange:O=>{let A=l.jsonData.tracesToMetrics?.queries.slice()??[];A[j].query=O.currentTarget.value,(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:A})}})),t.createElement(L.zx,{variant:"destructive",title:"Remove query",icon:"times",type:"button",onClick:()=>{let O=l.jsonData.tracesToMetrics?.queries.slice();O?.splice(j,1),(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:O})}}))),t.createElement(L.zx,{variant:"secondary",title:"Add query",icon:"plus",type:"button",onClick:()=>{(0,i.tp)({onOptionsChange:h,options:l},"tracesToMetrics",{...l.jsonData.tracesToMetrics,queries:[...l.jsonData.tracesToMetrics?.queries??[],{query:""}]})}},"Add query"))}const W=l=>({infoText:m.css`
    padding-bottom: ${l.spacing(2)};
    color: ${l.colors.text.secondary};
  `,row:m.css`
    label: row;
    align-items: baseline;
  `,queryRow:m.css`
    display: flex;
  `})},86098:(G,S,e)=>{e.r(S),e.d(S,{plugin:()=>Ee});var m=e(89424),t=e(66111),i=e(35645),C=e(12006),N=e(90950),I=e(83437),p=e(48288),L=e(95638);const P=({options:r,onOptionsChange:a})=>t.createElement(t.Fragment,null,t.createElement(C.E,{defaultUrl:"http://localhost:9411",dataSourceConfig:r,showAccessOptions:!1,onChange:a,secureSocksDSProxyEnabled:i.v.secureSocksDSProxyEnabled}),t.createElement("div",{className:"gf-form-group"},t.createElement(I.Z,{options:r,onOptionsChange:a})),i.v.featureToggles.traceToMetrics?t.createElement("div",{className:"gf-form-group"},t.createElement(p.F,{options:r,onOptionsChange:a})):null,t.createElement("div",{className:"gf-form-group"},t.createElement(N.n,{options:r,onOptionsChange:a})),t.createElement("div",{className:"gf-form-group"},t.createElement(L.SpanBarSettings,{options:r,onOptionsChange:a})));var U=e(9892),f=e(82897),R=e(13821),W=e(68324),l=e(41213),h=e(72648),F=e(11543),E=e(81764),j=e(2594),O=e(30784),A=e(19974),w=e(69659),Q=e(659),b=e(60499),J=e(3153);const K="/api/v2",Y=r=>({tracesCascader:(0,U.css)({label:"tracesCascader",marginRight:r.spacing(1)})}),H=({query:r,onChange:a,onRunQuery:n,datasource:s})=>{const c=X(s),o=(0,h.l4)(),x=(0,h.wW)(Y),{onLoadOptions:D,allOptions:d}=k(s),v=(0,t.useCallback)((u,M)=>{if(M.length===3){const B=M[2].value;a({...r,query:B}),n()}},[a,n,r]),g=u=>{const M={...r,query:u};a(M)};let T=q(c,d);return t.createElement(t.Fragment,null,t.createElement(F.Z,null,t.createElement(E._,{label:"Query type"},t.createElement(j.S,{options:[{value:"traceID",label:"TraceID"},{value:"upload",label:"JSON File"}],value:r.queryType||"traceID",onChange:u=>a({...r,queryType:u}),size:"md"}))),r.queryType==="upload"?t.createElement("div",{className:(0,U.css)({padding:o.spacing(2)})},t.createElement(O.Yo,{options:{multiple:!1},onLoad:u=>{s.uploadedJson=u,n()}})):t.createElement(F.Z,null,t.createElement(A.O,{options:T,onChange:v,loadData:D,variant:"secondary",buttonProps:{className:x.tracesCascader}},"Traces"),t.createElement("div",{className:"gf-form gf-form--grow flex-shrink-1 min-width-15"},t.createElement(w.q,{query:r.query,onChange:g,onRunQuery:n,placeholder:"Insert Trace ID (run with Shift+Enter)",portalOrigin:"zipkin"}))))};function X(r){const a=`${K}/services`,[n,s]=(0,R.Z)(async()=>{try{const c=await r.metadataRequest(a);return c?c.sort().map(o=>({label:o,value:o,isLeaf:!1})):[]}catch(c){const o=c instanceof Error?c:"An unknown error occurred";throw(0,J.WI)((0,Q.$l)((0,b.t_)("Failed to load services from Zipkin",o))),c}},[r]);return(0,W.Z)(()=>{s()}),n}function k(r){const a=(0,l.Z)(),[n,s]=(0,t.useState)({}),[,c]=(0,R.Z)(async function(d){const v=`${K}/spans`;try{const g=await r.metadataRequest(v,{serviceName:d});a()&&s(T=>{const u=(0,f.fromPairs)(g.map(M=>[M,void 0]));return{...T,[d]:u}})}catch(g){const T=g instanceof Error?g:"An unknown error occurred";throw(0,J.WI)((0,Q.$l)((0,b.t_)("Failed to load spans from Zipkin",T))),g}},[r,n]),[,o]=(0,R.Z)(async function(d,v){const g=`${K}/traces`,T={serviceName:d,spanName:v};try{const u=await r.metadataRequest(g,T);if(a()){const M=u.length?(0,f.fromPairs)(u.map(B=>{const $=B.find(ve=>!ve.parentId);return[`${$.name} [${Math.floor($.duration/1e3)} ms]`,$.traceId]})):te;s(B=>{const $=B[d];return{...B,[d]:{...$,[v]:M}}})}}catch(u){const M=u instanceof Error?u:"An unknown error occurred";throw(0,J.WI)((0,Q.$l)((0,b.t_)("Failed to load spans from Zipkin",M))),u}},[r]);return{onLoadOptions:(0,t.useCallback)(D=>{const d=D[0].value;if(D.length===1)c(d);else if(D.length===2){const v=D[1].value;o(d,v)}},[c,o]),allOptions:n}}function q(r,a){return(0,t.useMemo)(()=>{let n=[];return r.value&&r.value.length?n=r.value.map(s=>({...s,children:a[s.value]&&Object.keys(a[s.value]).map(c=>({label:c,value:c,isLeaf:!1,children:a[s.value][c]&&Object.keys(a[s.value][c]).map(o=>({label:o,value:a[s.value][c][o]}))}))})):r.value&&!r.value.length&&(n=ee),n},[r,a])}const _="__NO_TRACES__",ee=[{label:"No traces found",value:"no_traces",isLeaf:!0}],te={"[No traces in time range]":_};var Z=e(59980),ae=e(65583),re=e(9471),ne=e(53678),se=e(99098),oe=e(20308),le=e(54899),ce=e(8878),y=e(92468),z=e(49427);function ie(r){const{nodes:a,edges:n}=ue(r),[s,c]=(0,z.np)();for(const o of a)s.add(o);for(const o of n)c.add(o);return[s,c]}function ue(r){const a=[],n=[],s=de(r),c=(0,z.nO)(o=>{if(!(o>=r.length))return{span:r[o],id:r[o].id,parentIds:r[o].parentId?[r[o].parentId]:[]}});for(const o of r){const x=c[o.id].children.map(g=>{const T=c[g].span;return[T.timestamp,T.timestamp+T.duration]}),D=(0,z.et)(x),d=o.duration-D,v=(0,z.fy)(o.duration/1e3,s/1e3,d/1e3);a.push({[y.z.id]:o.id,[y.z.title]:o.localEndpoint?.serviceName||o.remoteEndpoint?.serviceName||"unknown",[y.z.subTitle]:o.name,[y.z.mainStat]:v.main,[y.z.secondaryStat]:v.secondary,[y.z.color]:d/s}),o.parentId&&c[o.parentId].span&&n.push({[y.z.id]:o.parentId+"--"+o.id,[y.z.target]:o.id,[y.z.source]:o.parentId})}return{nodes:a,edges:n}}function de(r){let a=0,n=1/0;for(const s of r)s.timestamp<n&&(n=s.timestamp),s.timestamp+s.duration>a&&(a=s.timestamp+s.duration);return a-n}var me=e(26991);class fe extends m.MF{constructor(a,n=(0,oe.J)()){super(a),this.instanceSettings=a,this.templateSrv=n,this.uploadedJson=null,this.nodeGraph=a.jsonData.nodeGraph}query(a){const n=a.targets[0];if(n.queryType==="upload"){if(!this.uploadedJson)return(0,Z.of)({data:[]});try{const s=JSON.parse(this.uploadedJson);return(0,Z.of)(V({data:s},this.nodeGraph?.enabled))}catch{return(0,Z.of)({error:{message:"JSON is not valid Zipkin format"},data:[]})}}if(n.query){const s=this.applyVariables(n,a.scopedVars);return this.request(`${K}/trace/${encodeURIComponent(s.query)}`).pipe((0,re.U)(c=>V(c,this.nodeGraph?.enabled)))}return(0,Z.of)(he)}async metadataRequest(a,n){return(await(0,ae.n)(this.request(a,n,{hideFromInspector:!0}))).data}async testDatasource(){return await this.metadataRequest(`${K}/services`),{status:"success",message:"Data source is working"}}getQueryDisplayText(a){return a.query}interpolateVariablesInQueries(a,n){return!a||a.length===0?[]:a.map(s=>({...s,datasource:this.getRef(),...this.applyVariables(s,n)}))}applyVariables(a,n){return{...{...a},query:this.templateSrv.replace(a.query??"",n)}}request(a,n,s){const c=n?(0,ce.tW)(n):"",o=`${this.instanceSettings.url}${a}${c.length?`?${c}`:""}`,x={...s,url:o};return(0,le.i)().fetch(x)}}function V(r,a=!1){let n=r?.data?[(0,me.m)(r?.data)]:[];return a&&n.push(...ie(r?.data)),{data:n}}const he={data:[new ne.v({fields:[{name:"trace",type:se.fS.trace,values:[]}],meta:{preferredVisualisationType:"trace",custom:{traceFormat:"zipkin"}}})]},Ee=new m.hf(fe).setQueryEditor(H).setConfigEditor(P)},68324:(G,S,e)=>{e.d(S,{Z:()=>i});var m=e(49380),t=function(C){(0,m.Z)(function(){C()})};const i=t}}]);

//# sourceMappingURL=zipkinPlugin.80c7e1ba72c4ddc3f273.js.map