feat: update profile

This commit is contained in:
Fine 2023-03-28 16:57:20 +08:00
parent 5973632f0f
commit 1d8851c7cc
6 changed files with 72 additions and 50 deletions

View File

@ -22,6 +22,13 @@ export const ProfileSegment = {
spans { spans {
spanId spanId
parentSpanId parentSpanId
segmentId
refs {
traceId
parentSegmentId
parentSpanId
type
}
serviceCode serviceCode
startTime startTime
endTime endTime
@ -41,6 +48,7 @@ export const ProfileSegment = {
value value
} }
} }
profiled
} }
} }
`, `,
@ -79,23 +87,55 @@ export const GetProfileTaskList = {
`, `,
}; };
export const GetProfileTaskSegmentList = { export const GetProfileTaskSegmentList = {
variable: "$taskID: String", variable: "$taskID: ID!",
query: ` query: `
segmentList: getProfileTaskSegmentList(taskID: $taskID) { segmentList: getProfileTaskSegments(taskID: $taskID) {
segmentId traceId
instanceId
instanceName
endpointNames endpointNames
start
duration duration
traceIds start
isError spans {
spanId
parentSpanId
segmentId
refs {
traceId
parentSegmentId
parentSpanId
type
}
serviceCode
serviceInstanceName
startTime
endTime
endpointName
type
peer
component
isError
layer
tags {
key value
}
logs {
time
data {
key
value
}
}
profiled
}
} }
`, `,
}; };
export const GetProfileAnalyze = { export const GetProfileAnalyze = {
variable: "$segmentId: String!, $timeRanges: [ProfileAnalyzeTimeRange!]!", variable: "$queries: [SegmentProfileAnalyzeQuery!]!",
query: ` query: `
analyze: getProfileAnalyze(segmentId: $segmentId, timeRanges: $timeRanges) { analyze: getSegmentsProfileAnalyze(queries: $queries) {
tip tip
trees { trees {
elements { elements {

View File

@ -65,6 +65,9 @@ export const profileStore = defineStore({
...data, ...data,
}; };
}, },
setSegmentSpans(spans: Recordable<SegmentSpan>[]) {
this.segmentSpans = spans;
},
setCurrentSpan(span: Recordable<SegmentSpan>) { setCurrentSpan(span: Recordable<SegmentSpan>) {
this.currentSpan = span; this.currentSpan = span;
}, },
@ -128,7 +131,7 @@ export const profileStore = defineStore({
} }
const { segmentList } = res.data.data; const { segmentList } = res.data.data;
this.segmentList = segmentList; this.segmentList = segmentList || [];
if (!segmentList.length) { if (!segmentList.length) {
this.segmentSpans = []; this.segmentSpans = [];
this.analyzeTrees = []; this.analyzeTrees = [];
@ -137,47 +140,28 @@ export const profileStore = defineStore({
} }
if (segmentList[0]) { if (segmentList[0]) {
this.currentSegment = segmentList[0]; this.currentSegment = segmentList[0];
this.getSegmentSpans({ segmentId: segmentList[0].segmentId }); this.getSegmentSpans(segmentList[0].segmentId);
} else { } else {
this.currentSegment = {}; this.currentSegment = {};
} }
return res.data; return res.data;
}, },
async getSegmentSpans(params: { segmentId: string }) { async getSegmentSpans() {
if (!params.segmentId) { this.analyzeTrees = [];
return new Promise((resolve) => resolve({})); this.segmentSpans = this.currentSegment.spans.map((d: SegmentSpan) => {
}
const res: AxiosResponse = await graphql.query("queryProfileSegment").params(params);
if (res.data.errors) {
this.segmentSpans = [];
return res.data;
}
const { segment } = res.data.data;
if (!segment) {
this.segmentSpans = [];
this.analyzeTrees = [];
return res.data;
}
this.segmentSpans = segment.spans.map((d: SegmentSpan) => {
return { return {
...d, ...d,
segmentId: this.currentSegment?.segmentId, // traceId: (this.currentSegment.traceIds as any)[0],
traceId: (this.currentSegment.traceIds as any)[0],
}; };
}); });
if (!(segment.spans && segment.spans.length)) { const index = this.currentSegment.spans.length - 1 || 0;
this.analyzeTrees = []; this.currentSpan = this.currentSegment.spans[index];
return res.data;
}
const index = segment.spans.length - 1 || 0;
this.currentSpan = segment.spans[index];
return res.data;
}, },
async getProfileAnalyze(params: { segmentId: string; timeRanges: Array<{ start: number; end: number }> }) { async getProfileAnalyze(params: Array<{ segmentId: string; timeRange: { start: number; end: number } }>) {
if (!params.segmentId) { // if (!params.segmentId) {
return new Promise((resolve) => resolve({})); // return new Promise((resolve) => resolve({}));
} // }
if (!params.timeRanges.length) { if (!params.length) {
return new Promise((resolve) => resolve({})); return new Promise((resolve) => resolve({}));
} }
const res: AxiosResponse = await graphql.query("getProfileAnalyze").params(params); const res: AxiosResponse = await graphql.query("getProfileAnalyze").params(params);

View File

@ -22,7 +22,6 @@ declare module '@vue/runtime-core' {
ElMenuItemGroup: typeof import('element-plus/es')['ElMenuItemGroup'] ElMenuItemGroup: typeof import('element-plus/es')['ElMenuItemGroup']
ElOption: typeof import('element-plus/es')['ElOption'] ElOption: typeof import('element-plus/es')['ElOption']
ElPagination: typeof import('element-plus/es')['ElPagination'] ElPagination: typeof import('element-plus/es')['ElPagination']
ElPopconfirm: typeof import('element-plus/es')['ElPopconfirm']
ElPopover: typeof import('element-plus/es')['ElPopover'] ElPopover: typeof import('element-plus/es')['ElPopover']
ElProgress: typeof import('element-plus/es')['ElProgress'] ElProgress: typeof import('element-plus/es')['ElProgress']
ElRadio: typeof import('element-plus/es')['ElRadio'] ElRadio: typeof import('element-plus/es')['ElRadio']

View File

@ -22,6 +22,7 @@ export interface Trace {
start: string; start: string;
traceIds: Array<string | any>; traceIds: Array<string | any>;
segmentId: string; segmentId: string;
spans: Span[];
} }
export interface Span { export interface Span {

View File

@ -51,7 +51,6 @@ limitations under the License. -->
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useProfileStore } from "@/store/modules/profile"; import { useProfileStore } from "@/store/modules/profile";
import type { Trace } from "@/types/trace"; import type { Trace } from "@/types/trace";
import { ElMessage } from "element-plus";
import { dateFormat } from "@/utils/dateFormat"; import { dateFormat } from "@/utils/dateFormat";
const { t } = useI18n(); const { t } = useI18n();
@ -61,11 +60,7 @@ limitations under the License. -->
async function selectTrace(item: Trace) { async function selectTrace(item: Trace) {
profileStore.setCurrentSegment(item); profileStore.setCurrentSegment(item);
selectedKey.value = item.segmentId; selectedKey.value = item.segmentId;
const res = await profileStore.getSegmentSpans({ segmentId: item.segmentId }); profileStore.setSegmentSpans(item.spans);
if (res.errors) {
ElMessage.error(res.errors);
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -88,10 +88,13 @@ limitations under the License. -->
async function analyzeProfile() { async function analyzeProfile() {
emits("loading", true); emits("loading", true);
updateTimeRange(); updateTimeRange();
const res = await profileStore.getProfileAnalyze({ const param = timeRange.value.map((t: { start: number; end: number }) => {
segmentId: profileStore.currentSegment.segmentId, return {
timeRanges: timeRange.value, segmentId: profileStore.currentSegment.segmentId,
timeRange: t,
};
}); });
const res = await profileStore.getProfileAnalyze(param);
emits("loading", false); emits("loading", false);
if (res.errors) { if (res.errors) {
ElMessage.error(res.errors); ElMessage.error(res.errors);