12 |
- "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4023],{19982:(e,a,t)=>{t.d(a,{et:()=>r,fy:()=>s,nO:()=>i,np:()=>l});var n=t(43215);function r(e){e.sort(((e,a)=>e[0]-a[0]));return e.reduce(((e,a)=>{if(!e.length)return[a];const t=e.slice(-1)[0],[n,r]=t,[i,s]=a;return s<r?e:i>r?[...e,a]:[...e.slice(0,-1),[n,s]]}),[]).reduce(((e,a)=>e+(a[1]-a[0])),0)}function i(e){const a={};let t;for(let n=0;t=e(n),t;n++){a[t.id]?a[t.id].span=t.span:a[t.id]={span:t.span,children:[]};for(const e of t.parentIds)e&&(a[e]?a[e].children.push(t.id):a[e]={span:void 0,children:[t.id]})}return a}function s(e,a,t){return{main:`${o(e)}ms (${o(e/a*100)}%)`,secondary:`${o(t)}ms (${o(t/e*100)}%)`}}function o(e){return parseFloat(e.toFixed(2))}function l(){return[new n.MutableDataFrame({fields:[{name:n.NodeGraphDataFrameFieldNames.id,type:n.FieldType.string},{name:n.NodeGraphDataFrameFieldNames.title,type:n.FieldType.string},{name:n.NodeGraphDataFrameFieldNames.subTitle,type:n.FieldType.string},{name:n.NodeGraphDataFrameFieldNames.mainStat,type:n.FieldType.string,config:{displayName:"Total time (% of trace)"}},{name:n.NodeGraphDataFrameFieldNames.secondaryStat,type:n.FieldType.string,config:{displayName:"Self time (% of total)"}},{name:n.NodeGraphDataFrameFieldNames.color,type:n.FieldType.number,config:{color:{mode:"continuous-GrYlRd"},displayName:"Self time / Trace duration"}}],meta:{preferredVisualisationType:"nodeGraph"}}),new n.MutableDataFrame({fields:[{name:n.NodeGraphDataFrameFieldNames.id,type:n.FieldType.string},{name:n.NodeGraphDataFrameFieldNames.target,type:n.FieldType.string},{name:n.NodeGraphDataFrameFieldNames.source,type:n.FieldType.string}],meta:{preferredVisualisationType:"nodeGraph"}})]}},1275:(e,a,t)=>{t.r(a),t.d(a,{plugin:()=>C});var n=t(43215),r=t(68404),i=t(90923),s=t(69783),o=t(28239),l=t(76038),d=t(67211),u=t(45916);var p=t(36636),c=t(82897),m=t(42147),v=t(57686),g=t(29990),h=t(36537),y=t(58257),f=t(56340);const F=e=>({tracesCascader:(0,p.css)({label:"tracesCascader",marginRight:e.spacing(1)})});const N=[{label:"No traces found",value:"no_traces",isLeaf:!0}],T={"[No traces in time range]":"__NO_TRACES__"};var b=t(2937),k=t(58788),D=t(10010),j=t(25857),I=t(19982);function O(e){const{nodes:a,edges:t}=function(e){const a=[],t=[],r=function(e){let a=0,t=1/0;for(const n of e)n.timestamp<t&&(t=n.timestamp),n.timestamp+n.duration>a&&(a=n.timestamp+n.duration);return a-t}(e),i=(0,I.nO)((a=>{if(!(a>=e.length))return{span:e[a],id:e[a].id,parentIds:e[a].parentId?[e[a].parentId]:[]}}));for(const l of e){var s,o;const e=i[l.id].children.map((e=>{const a=i[e].span;return[a.timestamp,a.timestamp+a.duration]})),d=(0,I.et)(e),u=l.duration-d,p=(0,I.fy)(l.duration/1e3,r/1e3,u/1e3);a.push({[n.NodeGraphDataFrameFieldNames.id]:l.id,[n.NodeGraphDataFrameFieldNames.title]:(null===(s=l.localEndpoint)||void 0===s?void 0:s.serviceName)||(null===(o=l.remoteEndpoint)||void 0===o?void 0:o.serviceName)||"unknown",[n.NodeGraphDataFrameFieldNames.subTitle]:l.name,[n.NodeGraphDataFrameFieldNames.mainStat]:p.main,[n.NodeGraphDataFrameFieldNames.secondaryStat]:p.secondary,[n.NodeGraphDataFrameFieldNames.color]:u/r}),l.parentId&&i[l.parentId].span&&t.push({[n.NodeGraphDataFrameFieldNames.id]:l.parentId+"--"+l.id,[n.NodeGraphDataFrameFieldNames.target]:l.id,[n.NodeGraphDataFrameFieldNames.source]:l.parentId})}return{nodes:a,edges:t}}(e),[r,i]=(0,I.np)();for(const e of a)r.add(e);for(const e of t)i.add(e);return[r,i]}var G=t(93829);function S(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}class w extends n.DataSourceApi{constructor(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,i.getTemplateSrv)();super(e),S(this,"uploadedJson",null),S(this,"nodeGraph",void 0),this.instanceSettings=e,this.templateSrv=a,this.nodeGraph=e.jsonData.nodeGraph}query(e){const a=e.targets[0];if("upload"===a.queryType){if(!this.uploadedJson)return(0,b.of)({data:[]});try{var t;const e=JSON.parse(this.uploadedJson);return(0,b.of)(q({data:e},null===(t=this.nodeGraph)||void 0===t?void 0:t.enabled))}catch(e){return(0,b.of)({error:{message:"JSON is not valid Zipkin format"},data:[]})}}if(a.query){const t=this.applyVariables(a,e.scopedVars);return this.request(`/api/v2/trace/${encodeURIComponent(t.query)}`).pipe((0,D.U)((e=>{var a;return q(e,null===(a=this.nodeGraph)||void 0===a?void 0:a.enabled)})))}return(0,b.of)(x)}async metadataRequest(e,a){return(await(0,k.n)(this.request(e,a,{hideFromInspector:!0}))).data}async testDatasource(){return await this.metadataRequest("/api/v2/services"),{status:"success",message:"Data source is working"}}getQueryDisplayText(e){return e.query}interpolateVariablesInQueries(e,a){return e&&0!==e.length?e.map((e=>Object.assign({},e,{datasource:this.getRef()},this.applyVariables(e,a)))):[]}applyVariables(e,a){var t;const n=Object.assign({},e);return Object.assign({},n,{query:this.templateSrv.replace(null!==(t=e.query)&&void 0!==t?t:"",a)})}request(e,a,t){const n=a?(0,j.tW)(a):"",r=`${this.instanceSettings.url}${e}${n.length?`?${n}`:""}`,s=Object.assign({},t,{url:r});return(0,i.getBackendSrv)().fetch(s)}}function q(e){let a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=null!=e&&e.data?[(0,G.m)(null==e?void 0:e.data)]:[];return a&&t.push(...O(null==e?void 0:e.data)),{data:t}}const x={data:[new n.MutableDataFrame({fields:[{name:"trace",type:n.FieldType.trace,values:[]}],meta:{preferredVisualisationType:"trace",custom:{traceFormat:"zipkin"}}})]},C=new n.DataSourcePlugin(w).setQueryEditor((e=>{let{query:a,onChange:t,onRunQuery:n,datasource:i}=e;const o=function(e){const a="/api/v2/services",[t,n]=(0,m.Z)((async()=>{try{const t=await e.metadataRequest(a);return t?t.sort().map((e=>({label:e,value:e,isLeaf:!1}))):[]}catch(e){throw(0,f.WI)((0,h.$l)((0,y.t_)("Failed to load services from Zipkin",e))),e}}),[e]);return(0,v.Z)((()=>{n()})),t}(i),l=(0,s.useTheme2)(),d=(0,s.useStyles2)(F),{onLoadOptions:b,allOptions:k}=function(e){const a=(0,g.Z)(),[t,n]=(0,r.useState)({}),[,i]=(0,m.Z)((async function(t){const r="/api/v2/spans";try{const i=await e.metadataRequest(r,{serviceName:t});a()&&n((e=>{const a=(0,c.fromPairs)(i.map((e=>[e,void 0])));return Object.assign({},e,{[t]:a})}))}catch(e){throw(0,f.WI)((0,h.$l)((0,y.t_)("Failed to load spans from Zipkin",e))),e}}),[e,t]),[,s]=(0,m.Z)((async function(t,r){const i="/api/v2/traces",s={serviceName:t,spanName:r};try{const o=await e.metadataRequest(i,s);if(a()){const e=o.length?(0,c.fromPairs)(o.map((e=>{const a=e.find((e=>!e.parentId));return[`${a.name} [${Math.floor(a.duration/1e3)} ms]`,a.traceId]}))):T;n((a=>{const n=a[t];return Object.assign({},a,{[t]:Object.assign({},n,{[r]:e})})}))}}catch(e){throw(0,f.WI)((0,h.$l)((0,y.t_)("Failed to load spans from Zipkin",e))),e}}),[e]);return{onLoadOptions:(0,r.useCallback)((e=>{const a=e[0].value;if(1===e.length)i(a);else if(2===e.length){const t=e[1].value;s(a,t)}}),[i,s]),allOptions:t}}(i),D=(0,r.useCallback)(((e,r)=>{if(3===r.length){const e=r[2].value;t(Object.assign({},a,{query:e})),n()}}),[t,n,a]);let j=function(e,a){return(0,r.useMemo)((()=>{let t=[];return e.value&&e.value.length?t=e.value.map((e=>Object.assign({},e,{children:a[e.value]&&Object.keys(a[e.value]).map((t=>({label:t,value:t,isLeaf:!1,children:a[e.value][t]&&Object.keys(a[e.value][t]).map((n=>({label:n,value:a[e.value][t][n]})))})))}))):e.value&&!e.value.length&&(t=N),t}),[e,a])}(o,k);return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(s.InlineFieldRow,{children:(0,u.jsx)(s.InlineField,{label:"Query type",children:(0,u.jsx)(s.RadioButtonGroup,{options:[{value:"traceID",label:"TraceID"},{value:"upload",label:"JSON file"}],value:a.queryType||"traceID",onChange:e=>t(Object.assign({},a,{queryType:e})),size:"md"})})}),"upload"===a.queryType?(0,u.jsx)("div",{className:(0,p.css)({padding:l.spacing(2)}),children:(0,u.jsx)(s.FileDropzone,{options:{multiple:!1},onLoad:e=>{i.uploadedJson=e,n()}})}):(0,u.jsxs)(s.InlineFieldRow,{children:[(0,u.jsx)(s.ButtonCascader,{options:j,onChange:D,loadData:b,variant:"secondary",buttonProps:{className:d.tracesCascader},children:"Traces"}),(0,u.jsx)("div",{className:"gf-form gf-form--grow flex-shrink-1 min-width-15",children:(0,u.jsx)(s.QueryField,{query:a.query,onChange:e=>{const n=Object.assign({},a,{query:e});t(n)},onRunQuery:n,placeholder:"Insert Trace ID (run with Shift+Enter)",portalOrigin:"zipkin"})})]})]})})).setConfigEditor((e=>{let{options:a,onOptionsChange:t}=e;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(s.DataSourceHttpSettings,{defaultUrl:"http://localhost:9411",dataSourceConfig:a,showAccessOptions:!1,onChange:t}),(0,u.jsx)("div",{className:"gf-form-group",children:(0,u.jsx)(l.Z,{options:a,onOptionsChange:t})}),i.config.featureToggles.traceToMetrics?(0,u.jsx)("div",{className:"gf-form-group",children:(0,u.jsx)(d.F,{options:a,onOptionsChange:t})}):null,(0,u.jsx)("div",{className:"gf-form-group",children:(0,u.jsx)(o.n,{options:a,onOptionsChange:t})})]})}))},93829:(e,a,t)=>{t.d(a,{H:()=>u,m:()=>i});var n=t(82897),r=t(43215);function i(e){const a=e.map(s),t=new r.MutableDataFrame({fields:[{name:"traceID",type:r.FieldType.string},{name:"spanID",type:r.FieldType.string},{name:"parentSpanID",type:r.FieldType.string},{name:"operationName",type:r.FieldType.string},{name:"serviceName",type:r.FieldType.string},{name:"serviceTags",type:r.FieldType.other},{name:"startTime",type:r.FieldType.number},{name:"duration",type:r.FieldType.number},{name:"logs",type:r.FieldType.other},{name:"tags",type:r.FieldType.other}],meta:{preferredVisualisationType:"trace",custom:{traceFormat:"zipkin"}}});for(const e of a)t.add(e);return t}function s(e){var a,t,n,r;const i={traceID:e.traceId,spanID:e.id,parentSpanID:e.parentId,operationName:e.name,serviceName:(null===(a=e.localEndpoint)||void 0===a?void 0:a.serviceName)||(null===(t=e.remoteEndpoint)||void 0===t?void 0:t.serviceName)||"unknown",serviceTags:l(e),startTime:e.timestamp/1e3,duration:e.duration/1e3,logs:null!==(n=null===(r=e.annotations)||void 0===r?void 0:r.map(o))&&void 0!==n?n:[],tags:Object.keys(e.tags||{}).reduce(((a,t)=>"error"===t?(a.push({key:"error",value:!0}),a.push({key:"errorValue",value:e.tags.error}),a):(a.push({key:t,value:e.tags[t]}),a)),[])};var s,d;e.kind&&(i.tags=[{key:"kind",value:e.kind},...null!==(s=i.tags)&&void 0!==s?s:[]]);e.shared&&(i.tags=[{key:"shared",value:e.shared},...null!==(d=i.tags)&&void 0!==d?d:[]]);return i}function o(e){return{timestamp:e.timestamp,fields:[{key:"annotation",value:e.value}]}}function l(e){const a=e.localEndpoint||e.remoteEndpoint;return a?[d("ipv4",a.ipv4),d("ipv6",a.ipv6),d("port",a.port),d("endpointType",e.localEndpoint?"local":"remote")].filter(n.identity):[]}function d(e,a){if(a)return{key:e,value:a}}const u=e=>{let a=[];for(let r=0;r<e.length;r++){var t,n;const i=e.get(r);a.push(Object.assign({traceId:i.traceID,parentId:i.parentSpanID,name:i.operationName,id:i.spanID,timestamp:1e3*i.startTime,duration:1e3*i.duration},p(i),{annotations:i.logs.length?i.logs.map((e=>({timestamp:e.timestamp,value:e.fields[0].value}))):void 0,tags:i.tags.length?i.tags.filter((e=>"kind"!==e.key&&"endpointType"!==e.key&&"shared"!==e.key)).reduce(((e,a)=>"error"===a.key?Object.assign({},e,{[a.key]:i.tags.find((e=>"errorValue"===e.key)).value||""}):Object.assign({},e,{[a.key]:a.value})),{}):void 0,kind:null===(t=i.tags.find((e=>"kind"===e.key)))||void 0===t?void 0:t.value,shared:null===(n=i.tags.find((e=>"shared"===e.key)))||void 0===n?void 0:n.value}))}return a},p=e=>{var a,t,n,r;const i="local"===(null===(a=e.serviceTags.find((e=>"endpointType"===e.key)))||void 0===a?void 0:a.value)?"localEndpoint":"remoteEndpoint";return"unknown"!==e.serviceName?{[i]:{serviceName:e.serviceName,ipv4:null===(t=e.serviceTags.find((e=>"ipv4"===e.key)))||void 0===t?void 0:t.value,ipv6:null===(n=e.serviceTags.find((e=>"ipv6"===e.key)))||void 0===n?void 0:n.value,port:null===(r=e.serviceTags.find((e=>"port"===e.key)))||void 0===r?void 0:r.value}}:void 0}},57686:(e,a,t)=>{t.d(a,{Z:()=>r});var n=t(37784);const r=function(e){(0,n.Z)((function(){e()}))}}}]);
- //# sourceMappingURL=zipkinPlugin.515722975a5799cfa960.js.map
|