mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-02 09:44:07 +00:00
Feat: enhance the Trace widget for batch consuming spans (#387)
This commit is contained in:
parent
62eb054ff5
commit
12cd279c90
@ -23,7 +23,6 @@ import type { AxiosResponse } from "axios";
|
|||||||
import { useAppStoreWithOut } from "@/store/modules/app";
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
import { useSelectorStore } from "@/store/modules/selectors";
|
import { useSelectorStore } from "@/store/modules/selectors";
|
||||||
import { QueryOrders } from "@/views/dashboard/data";
|
import { QueryOrders } from "@/views/dashboard/data";
|
||||||
|
|
||||||
interface TraceState {
|
interface TraceState {
|
||||||
services: Service[];
|
services: Service[];
|
||||||
instances: Instance[];
|
instances: Instance[];
|
||||||
@ -168,6 +167,7 @@ export const traceStore = defineStore({
|
|||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
const data = res.data.data.trace.spans;
|
const data = res.data.data.trace.spans;
|
||||||
|
|
||||||
this.setTraceSpans(data || []);
|
this.setTraceSpans(data || []);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
@ -96,10 +96,8 @@ limitations under the License. -->
|
|||||||
node.children.push(data);
|
node.children.push(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node.children && node.children.length > 0) {
|
for (const nodeItem of node.children || []) {
|
||||||
node.children.forEach((nodeItem: Recordable) => {
|
traverseTree(nodeItem, spanId, segmentId, data);
|
||||||
traverseTree(nodeItem, spanId, segmentId, data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function changeTree() {
|
function changeTree() {
|
||||||
@ -108,7 +106,7 @@ limitations under the License. -->
|
|||||||
}
|
}
|
||||||
segmentId.value = [];
|
segmentId.value = [];
|
||||||
const segmentGroup: Recordable = {};
|
const segmentGroup: Recordable = {};
|
||||||
const segmentIdGroup: Recordable = [];
|
const segmentIdGroup: string[] = [];
|
||||||
const fixSpans: Span[] = [];
|
const fixSpans: Span[] = [];
|
||||||
const segmentHeaders: Span[] = [];
|
const segmentHeaders: Span[] = [];
|
||||||
for (const span of props.data) {
|
for (const span of props.data) {
|
||||||
@ -118,7 +116,9 @@ limitations under the License. -->
|
|||||||
if (span.parentSpanId === -1) {
|
if (span.parentSpanId === -1) {
|
||||||
segmentHeaders.push(span);
|
segmentHeaders.push(span);
|
||||||
} else {
|
} else {
|
||||||
const item = props.data.find((i: Span) => i.segmentId === span.segmentId && i.spanId === span.spanId - 1);
|
const item = props.data.find(
|
||||||
|
(i: Span) => i.traceId === span.traceId && i.segmentId === span.segmentId && i.spanId === span.spanId - 1,
|
||||||
|
);
|
||||||
const fixSpanKeyContent = {
|
const fixSpanKeyContent = {
|
||||||
traceId: span.traceId,
|
traceId: span.traceId,
|
||||||
segmentId: span.segmentId,
|
segmentId: span.segmentId,
|
||||||
@ -145,18 +145,18 @@ limitations under the License. -->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
segmentHeaders.forEach((span: Span) => {
|
for (const span of segmentHeaders) {
|
||||||
if (span.refs.length) {
|
if (span.refs.length) {
|
||||||
let exit = 0;
|
let exit = null;
|
||||||
span.refs.forEach((ref) => {
|
for (const ref of span.refs) {
|
||||||
const i = props.data.findIndex(
|
const e = props.data.find(
|
||||||
(i: Recordable) => ref.parentSegmentId === i.segmentId && ref.parentSpanId === i.spanId,
|
(i: Recordable) =>
|
||||||
|
ref.traceId === i.traceId && ref.parentSegmentId === i.segmentId && ref.parentSpanId === i.spanId,
|
||||||
);
|
);
|
||||||
if (i > -1) {
|
if (e) {
|
||||||
exit = 1;
|
exit = e;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (!exit) {
|
if (!exit) {
|
||||||
const ref = span.refs[0];
|
const ref = span.refs[0];
|
||||||
// create a known broken node.
|
// create a known broken node.
|
||||||
@ -214,23 +214,23 @@ limitations under the License. -->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
[...fixSpans, ...props.data].forEach((i) => {
|
for (const i of [...fixSpans, ...props.data]) {
|
||||||
i.label = i.endpointName || "no operation name";
|
i.label = i.endpointName || "no operation name";
|
||||||
i.children = [];
|
i.children = [];
|
||||||
if (!segmentGroup[i.segmentId]) {
|
if (segmentGroup[i.segmentId]) {
|
||||||
|
segmentGroup[i.segmentId].push(i);
|
||||||
|
} else {
|
||||||
segmentIdGroup.push(i.segmentId);
|
segmentIdGroup.push(i.segmentId);
|
||||||
segmentGroup[i.segmentId] = [i];
|
segmentGroup[i.segmentId] = [i];
|
||||||
} else {
|
|
||||||
segmentGroup[i.segmentId].push(i);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
fixSpansSize.value = fixSpans.length;
|
fixSpansSize.value = fixSpans.length;
|
||||||
segmentIdGroup.forEach((id: string) => {
|
for (const id of segmentIdGroup) {
|
||||||
const currentSegment = segmentGroup[id].sort((a: Span, b: Span) => b.parentSpanId - a.parentSpanId);
|
const currentSegment = segmentGroup[id].sort((a: Span, b: Span) => b.parentSpanId - a.parentSpanId);
|
||||||
currentSegment.forEach((s: Recordable) => {
|
for (const s of currentSegment) {
|
||||||
const index = currentSegment.findIndex((i: Span) => i.spanId === s.parentSpanId);
|
const index = currentSegment.findIndex((i: Span) => i.spanId === s.parentSpanId);
|
||||||
if (index !== -1) {
|
if (index > -1) {
|
||||||
if (
|
if (
|
||||||
(currentSegment[index].isBroken && currentSegment[index].parentSpanId === -1) ||
|
(currentSegment[index].isBroken && currentSegment[index].parentSpanId === -1) ||
|
||||||
!currentSegment[index].isBroken
|
!currentSegment[index].isBroken
|
||||||
@ -251,37 +251,53 @@ limitations under the License. -->
|
|||||||
s.children.push(...children);
|
s.children.push(...children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
segmentGroup[id] = currentSegment[currentSegment.length - 1];
|
segmentGroup[id] = currentSegment[currentSegment.length - 1];
|
||||||
});
|
}
|
||||||
segmentIdGroup.forEach((id: string) => {
|
for (const id of segmentIdGroup) {
|
||||||
segmentGroup[id].refs.forEach((ref: Recordable) => {
|
for (const ref of segmentGroup[id].refs) {
|
||||||
if (ref.traceId === props.traceId) {
|
if (ref.traceId === props.traceId) {
|
||||||
traverseTree(segmentGroup[ref.parentSegmentId], ref.parentSpanId, ref.parentSegmentId, segmentGroup[id]);
|
traverseTree(segmentGroup[ref.parentSegmentId], ref.parentSpanId, ref.parentSegmentId, segmentGroup[id]);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
for (const i in segmentGroup) {
|
for (const i in segmentGroup) {
|
||||||
if (segmentGroup[i].refs.length === 0) {
|
if (segmentGroup[i].refs.length) {
|
||||||
|
let exit = null;
|
||||||
|
for (const ref of segmentGroup[i].refs) {
|
||||||
|
const e = props.data.find(
|
||||||
|
(i: Recordable) =>
|
||||||
|
ref.traceId === i.traceId && ref.parentSegmentId === i.segmentId && ref.parentSpanId === i.spanId,
|
||||||
|
);
|
||||||
|
if (e) {
|
||||||
|
exit = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (exit) {
|
||||||
|
segmentId.value.push(segmentGroup[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
segmentId.value.push(segmentGroup[i]);
|
segmentId.value.push(segmentGroup[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
segmentId.value.forEach((i: Span | Recordable) => {
|
for (const i of segmentId.value) {
|
||||||
collapse(i);
|
collapse(i);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
function collapse(d: Span | Recordable) {
|
function collapse(d: Span | Recordable) {
|
||||||
if (d.children) {
|
if (d.children) {
|
||||||
const item = refSpans.value.find((s: Ref) => s.parentSpanId === d.spanId && s.parentSegmentId === d.segmentId);
|
const item = refSpans.value.find((s: Ref) => s.parentSpanId === d.spanId && s.parentSegmentId === d.segmentId);
|
||||||
let dur = d.endTime - d.startTime;
|
let dur = d.endTime - d.startTime;
|
||||||
d.children.forEach((i: Span) => {
|
for (const i of d.children) {
|
||||||
dur -= i.endTime - i.startTime;
|
dur -= i.endTime - i.startTime;
|
||||||
});
|
}
|
||||||
d.dur = dur < 0 ? 0 : dur;
|
d.dur = dur < 0 ? 0 : dur;
|
||||||
if (item) {
|
if (item) {
|
||||||
d.children = d.children.sort(compare("startTime"));
|
d.children = d.children.sort(compare("startTime"));
|
||||||
}
|
}
|
||||||
d.children.forEach((i: Span) => collapse(i));
|
for (const i of d.children) {
|
||||||
|
collapse(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function compare(p: string) {
|
function compare(p: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user