From 5e161f17c2ca2c8afcc10b81f0b949b4fbfa140f Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Mon, 17 Oct 2022 21:55:14 +0800 Subject: [PATCH] feat: add `readRecords` to metric types (#172) --- src/hooks/data.ts | 7 +++++++ src/hooks/useProcessor.ts | 17 +++++++++++++++++ src/views/dashboard/data.ts | 2 ++ 3 files changed, 26 insertions(+) diff --git a/src/hooks/data.ts b/src/hooks/data.ts index 1656122f..01301b0d 100644 --- a/src/hooks/data.ts +++ b/src/hooks/data.ts @@ -21,6 +21,7 @@ export enum MetricQueryTypes { ReadLabeledMetricsValues = "readLabeledMetricsValues", READHEATMAP = "readHeatMap", ReadSampledRecords = "readSampledRecords", + ReadRecords = "readRecords", } export enum Calculations { @@ -101,4 +102,10 @@ export const RespFields: any = { value refId }`, + readRecords: `{ + id + name + value + refId + }`, }; diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index 55f2edc7..d7301898 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -73,6 +73,22 @@ export function useQueryProcessor(config: any) { topN: c.topN || 10, order: c.sortOrder || "DES", }; + } else if ([MetricQueryTypes.ReadRecords].includes(metricType)) { + variables.push(`$condition${index}: RecordCondition!`); + conditions[`condition${index}`] = { + name, + parentEntity: { + scope: config.catalog, + normal: selectorStore.currentService + ? selectorStore.currentService.normal + : true, + serviceName: ["All"].includes(dashboardStore.entity) + ? null + : selectorStore.currentService.value, + }, + topN: c.topN || 10, + order: c.sortOrder || "DES", + }; } else { if (metricType === MetricQueryTypes.ReadLabeledMetricsValues) { const labels = (c.labelsIndex || "") @@ -435,6 +451,7 @@ export async function useGetMetricEntity(metric: string, metricType: any) { [ MetricQueryTypes.ReadSampledRecords, MetricQueryTypes.SortMetrics, + MetricQueryTypes.ReadRecords, ].includes(metricType) ) { const res = await dashboardStore.fetchMetricList(metric); diff --git a/src/views/dashboard/data.ts b/src/views/dashboard/data.ts index 78536e37..540c3171 100644 --- a/src/views/dashboard/data.ts +++ b/src/views/dashboard/data.ts @@ -45,6 +45,7 @@ export const MetricChartType: any = { readLabeledMetricsValues: [{ label: "Line", value: "Line" }], readHeatMap: [{ label: "Heat Map", value: "HeatMap" }], readSampledRecords: [{ label: "Top List", value: "TopList" }], + readRecords: [{ label: "Top List", value: "TopList" }], }; export const DefaultGraphConfig: { [key: string]: any } = { Bar: { @@ -134,6 +135,7 @@ export const MetricTypes: { { label: "read heatmap values in the duration", value: "readHeatMap" }, ], SAMPLED_RECORD: [ + { label: "get sorted topN values", value: "readRecords" }, { label: "get sorted topN values", value: "readSampledRecords" }, ], };