build: remove lodash library (#454)

This commit is contained in:
Fine0830
2025-03-06 17:10:54 +08:00
committed by GitHub
parent 012ae1db6c
commit 1fe58f5f6c
5 changed files with 93 additions and 79 deletions

View File

@@ -22,7 +22,6 @@ limitations under the License. -->
<script lang="ts" setup>
import { ref, watch, onBeforeUnmount, onMounted } from "vue";
import type { PropType } from "vue";
import _ from "lodash";
import * as d3 from "d3";
import ListGraph from "../../utils/d3-trace-list";
import TreeGraph from "../../utils/d3-trace-tree";
@@ -120,15 +119,19 @@ limitations under the License. -->
const item = props.data.find(
(i: Span) => i.traceId === span.traceId && i.segmentId === span.segmentId && i.spanId === span.spanId - 1,
);
const fixSpanKeyContent = {
traceId: span.traceId,
segmentId: span.segmentId,
spanId: span.spanId - 1,
parentSpanId: span.spanId - 2,
};
if (!item && !_.find(fixSpans, fixSpanKeyContent)) {
const content = fixSpans.find(
(i: Span) =>
i.traceId === span.traceId &&
i.segmentId === span.segmentId &&
i.spanId === span.spanId - 1 &&
i.parentSpanId === span.spanId - 2,
);
if (!item && !content) {
fixSpans.push({
...fixSpanKeyContent,
traceId: span.traceId,
segmentId: span.segmentId,
spanId: span.spanId - 1,
parentSpanId: span.spanId - 2,
refs: [],
endpointName: `VNode: ${span.segmentId}`,
serviceCode: "VirtualNode",
@@ -161,22 +164,26 @@ limitations under the License. -->
if (!exit) {
const ref = span.refs[0];
// create a known broken node.
const i = ref.parentSpanId;
const fixSpanKeyContent = {
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: i,
parentSpanId: i > -1 ? 0 : -1,
};
if (!_.find(fixSpans, fixSpanKeyContent)) {
const parentSpanId = ref.parentSpanId > -1 ? 0 : -1;
const content = fixSpans.find(
(i: Span) =>
i.traceId === ref.traceId &&
i.segmentId === ref.parentSegmentId &&
i.spanId === ref.parentSpanId &&
i.parentSpanId === parentSpanId,
);
if (!content) {
fixSpans.push({
...fixSpanKeyContent,
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: ref.parentSpanId,
parentSpanId,
refs: [],
endpointName: `VNode: ${ref.parentSegmentId}`,
serviceCode: "VirtualNode",
type: `[Broken] ${ref.type}`,
peer: "",
component: `VirtualNode: #${i}`,
component: `VirtualNode: #${ref.parentSpanId}`,
isError: true,
isBroken: true,
layer: "Broken",
@@ -187,16 +194,20 @@ limitations under the License. -->
});
}
// if root broken node is not exist, create a root broken node.
if (fixSpanKeyContent.parentSpanId > -1) {
const fixRootSpanKeyContent = {
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: 0,
parentSpanId: -1,
};
if (!_.find(fixSpans, fixRootSpanKeyContent)) {
if (parentSpanId > -1) {
const content = fixSpans.find(
(i: Span) =>
i.traceId === ref.traceId &&
i.segmentId === ref.parentSegmentId &&
i.spanId === 0 &&
i.parentSpanId === -1,
);
if (!content) {
fixSpans.push({
...fixRootSpanKeyContent,
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: 0,
parentSpanId: -1,
refs: [],
endpointName: `VNode: ${ref.parentSegmentId}`,
serviceCode: "VirtualNode",
@@ -241,14 +252,12 @@ limitations under the License. -->
}
}
if (s.isBroken) {
const children = _.filter(props.data, (span: Span) => {
return _.find(span.refs, {
traceId: s.traceId,
parentSegmentId: s.segmentId,
parentSpanId: s.spanId,
});
});
if (children.length > 0) {
const children = props.data.filter((span: Span) =>
span.refs.find(
(d) => d.traceId === s.traceId && d.parentSegmentId === s.segmentId && d.parentSpanId === s.spanId,
),
);
if (children.length) {
s.children.push(...children);
}
}

View File

@@ -16,7 +16,6 @@
*/
import type { Ref, Span, StatisticsSpan, StatisticsGroupRef, TraceTreeRef } from "@/types/trace";
import lodash from "lodash";
export default class TraceUtil {
public static buildTraceDataList(data: Span[]): string[] {
@@ -91,15 +90,19 @@ export default class TraceUtil {
const index = data.findIndex((patchSpan: Span) => {
return patchSpan.segmentId === span.segmentId && patchSpan.spanId === span.spanId - 1;
});
const fixSpanKeyContent = {
traceId: span.traceId,
segmentId: span.segmentId,
spanId: span.spanId - 1,
parentSpanId: span.spanId - 2,
};
if (index === -1 && !lodash.find(fixSpans, fixSpanKeyContent)) {
const content = fixSpans.find(
(i: Span) =>
i.traceId === span.traceId &&
i.segmentId === span.segmentId &&
i.spanId === span.spanId - 1 &&
i.parentSpanId === span.spanId - 2,
);
if (index === -1 && !content) {
fixSpans.push({
...fixSpanKeyContent,
traceId: span.traceId,
segmentId: span.segmentId,
spanId: span.spanId - 1,
parentSpanId: span.spanId - 2,
refs: [],
endpointName: `VNode: ${span.segmentId}`,
serviceCode: "VirtualNode",
@@ -125,16 +128,20 @@ export default class TraceUtil {
});
if (index === -1) {
// create a known broken node.
const parentSpanId: number = ref.parentSpanId;
const fixSpanKeyContent = {
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: parentSpanId,
parentSpanId: parentSpanId > -1 ? 0 : -1,
};
if (!lodash.find(fixSpans, fixSpanKeyContent)) {
const parentSpanId = ref.parentSpanId > -1 ? 0 : -1;
const item = fixSpans.find(
(i: Span) =>
i.traceId === ref.traceId &&
i.segmentId === ref.parentSegmentId &&
i.spanId === ref.parentSpanId &&
i.parentSpanId === parentSpanId,
);
if (!item) {
fixSpans.push({
...fixSpanKeyContent,
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: ref.parentSpanId,
parentSpanId: parentSpanId,
refs: [],
endpointName: `VNode: ${ref.parentSegmentId}`,
serviceCode: "VirtualNode",
@@ -151,16 +158,20 @@ export default class TraceUtil {
});
}
// if root broken node is not exist, create a root broken node.
if (fixSpanKeyContent.parentSpanId > -1) {
const fixRootSpanKeyContent = {
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: 0,
parentSpanId: -1,
};
if (!lodash.find(fixSpans, fixRootSpanKeyContent)) {
if (parentSpanId > -1) {
const item = fixSpans.find(
(i: Span) =>
i.traceId === ref.traceId &&
i.segmentId === ref.parentSegmentId &&
i.spanId === 0 &&
i.parentSpanId === -1,
);
if (!item) {
fixSpans.push({
...fixRootSpanKeyContent,
traceId: ref.traceId,
segmentId: ref.parentSegmentId,
spanId: 0,
parentSpanId: -1,
refs: [],
endpointName: `VNode: ${ref.parentSegmentId}`,
serviceCode: "VirtualNode",
@@ -210,13 +221,14 @@ export default class TraceUtil {
}
}
if (curSegment.isBroken) {
const children = lodash.filter(data, (span: Span) => {
return lodash.find(span.refs, {
traceId: curSegment.traceId,
parentSegmentId: curSegment.segmentId,
parentSpanId: curSegment.spanId,
});
}) as Span[];
const children = data.filter((span: Span) =>
span.refs.find(
(d) =>
d.traceId === curSegment.traceId &&
d.parentSegmentId === curSegment.segmentId &&
d.parentSpanId === curSegment.spanId,
),
);
if (children.length) {
curSegment.children = curSegment.children || [];
curSegment.children.push(...children);