Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: slow query search (#14997)
ecmadaob53b07260237
diff --git a/frontend/src/components/SlowQuery/Panel/LogFilter.vue b/frontend/src/components/SlowQuery/Panel/LogFilter.vueindex 94781996ab..a924c1c050 100644--- a/frontend/src/components/SlowQuery/Panel/LogFilter.vue+++ b/frontend/src/components/SlowQuery/Panel/LogFilter.vue@@ -9,33 +9,13 @@:params="params":placeholder="''":scope-options="scopeOptions"+ :readonly-scopes="readonlyScopes"+ @update:params="$emit('update:params', $event)"+ />+ <TimeRange+ :params="params"@update:params="$emit('update:params', $event)"/>- <NInputGroup style="width: auto">- <NDatePicker- :value="fromTime"- :disabled="loading"- :is-date-disabled="isDateDisabled"- :placeholder="$t('slow-query.filter.from-date')"- type="date"- clearable- format="yyyy-MM-dd"- style="width: 12rem"- @update:value="changeFromTime($event)"- />- <NDatePicker- :value="toTime"- :disabled="loading"- :is-date-disabled="isDateDisabled"- :placeholder="$t('slow-query.filter.to-date')"- type="date"- clearable- format="yyyy-MM-dd"- style="width: 12rem"- @update:value="changeToTime($event)"- />- </NInputGroup>-<div class="flex items-center justify-end space-x-2"><slot name="suffix" /></div>@@ -43,27 +23,26 @@</div></template><script lang="ts" setup>-import dayjs from "dayjs";-import { NDatePicker, NInputGroup } from "naive-ui";import { computed } from "vue";-import AdvancedSearch from "@/components/AdvancedSearch";+import AdvancedSearch, { TimeRange } from "@/components/AdvancedSearch";import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";import { useSlowQueryPolicyList } from "@/store";-import type { SearchParams, SearchScopeId } from "@/utils";+import type { SearchParams, SearchScopeId, SearchScope } from "@/utils";-const props = defineProps<{- fromTime: number | undefined;- toTime: number | undefined;- params: SearchParams;- supportOptionIdList: SearchScopeId[];- loading?: boolean;-}>();+const props = withDefaults(+ defineProps<{+ params: SearchParams;+ readonlyScopes?: SearchScope[];+ supportOptionIdList: SearchScopeId[];+ loading?: boolean;+ }>(),+ {+ readonlyScopes: () => [],+ loading: false,+ }+);-const emit = defineEmits<{- (- event: "update:time",- params: { fromTime: number | undefined; toTime: number | undefined }- ): void;+defineEmits<{(event: "update:params", params: SearchParams): void;}>();@@ -73,36 +52,4 @@ const scopeOptions = useCommonSearchScopeOptions(computed(() => props.params),computed(() => props.supportOptionIdList));--const changeTime = (- fromTime: number | undefined,- toTime: number | undefined-) => {- if (fromTime && toTime && fromTime > toTime) {- // Swap if from > to- changeTime(toTime, fromTime);- return;- }- if (fromTime) {- // fromTime is the start of the day- fromTime = dayjs(fromTime).startOf("day").valueOf();- }- if (toTime) {- // toTime is the end of the day- toTime = dayjs(toTime).endOf("day").valueOf();- }- emit("update:time", { fromTime, toTime });-};-const changeFromTime = (fromTime: number | undefined) => {- const { toTime } = props;- changeTime(fromTime, toTime);-};-const changeToTime = (toTime: number | undefined) => {- const { fromTime } = props;- changeTime(fromTime, toTime);-};--const isDateDisabled = (date: number) => {- return date > dayjs().endOf("day").valueOf();-};</script>diff --git a/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue b/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vueindex be3142a68d..476efcaa27 100644--- a/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue+++ b/frontend/src/components/SlowQuery/Panel/SlowQueryPanel.vue@@ -2,11 +2,9 @@<div class="space-y-4" v-bind="$attrs"><LogFilterv-model:params="state.params"- :from-time="state.timeRange.fromTime"- :to-time="state.timeRange.toTime":loading="loading"+ :readonly-scopes="readonlySearchScopes":support-option-id-list="supportOptionIdList"- @update:time="state.timeRange = $event"><template #suffix><NButton@@ -104,20 +102,12 @@ const props = withDefaults(});-const emit = defineEmits<{- (event: "update:scopes", scopes: SearchScope[]): void;-}>();-interface LocalState {- timeRange: {- fromTime: number | undefined;- toTime: number | undefined;- };params: SearchParams;showSetting: boolean;}-const defaultSlowQueryTimeRange = () => {+const defaultSlowQueryTimeRange = computed(() => {const now = dayjs();const aWeekAgo = now.subtract(7, "days").startOf("day").valueOf();const tonight = now.endOf("day").valueOf();@@ -125,13 +115,18 @@ const defaultSlowQueryTimeRange = () => {fromTime: aWeekAgo,toTime: tonight,};-};+});const state = reactive<LocalState>({- timeRange: defaultSlowQueryTimeRange(),params: {query: "",- scopes: [],+ scopes: [+ ...props.readonlySearchScopes,+ {+ id: "created",+ value: `${defaultSlowQueryTimeRange.value.fromTime},${defaultSlowQueryTimeRange.value.toTime}`,+ },+ ],},showSetting: false,});@@ -147,30 +142,15 @@ const hasSyncPermission = computed(() =>hasWorkspacePermissionV2("bb.instances.sync"));-const searchScopes = computed(() => {- return [...props.readonlySearchScopes, ...state.params.scopes];-});--watch(- () => searchScopes.value,- (scopes) => emit("update:scopes", scopes)-);-const selectedInstanceName = computed(() => {- return searchScopes.value.find((s) => s.id === "instance")?.value;+ return state.params.scopes.find((s) => s.id === "instance")?.value;});const selectedProjectName = computed(() => {- return searchScopes.value.find((s) => s.id === "project")?.value;+ return state.params.scopes.find((s) => s.id === "project")?.value;});-const params = computed(() => {- const query = buildListSlowQueriesRequest(- searchScopes.value,- state.timeRange- );- return query;-});+const params = computed(() => buildListSlowQueriesRequest(state.params));const allowAdmin = computed(() => {const neededWorkspacePermissions: Permission[] = [diff --git a/frontend/src/components/SlowQuery/Panel/types.ts b/frontend/src/components/SlowQuery/Panel/types.tsindex d4d43feb78..01c978781f 100644--- a/frontend/src/components/SlowQuery/Panel/types.ts+++ b/frontend/src/components/SlowQuery/Panel/types.ts@@ -2,18 +2,16 @@ import dayjs from "dayjs";import { useDatabaseV1Store } from "@/store";import { isValidDatabaseName } from "@/types";import { ListSlowQueriesRequest } from "@/types/proto/v1/database_service";-import type { SearchScope } from "@/utils";+import { getTsRangeFromSearchParams, type SearchParams } from "@/utils";-export const buildListSlowQueriesRequest = (- scopes: SearchScope[],- timeRange: { fromTime: number | undefined; toTime: number | undefined }-) => {+export const buildListSlowQueriesRequest = (searchParams: SearchParams) => {const request = {} as Partial<ListSlowQueriesRequest>;+ const { scopes } = searchParams;const project = scopes.find((s) => s.id === "project")?.value;const environment = scopes.find((s) => s.id === "environment")?.value;const database = scopes.find((s) => s.id === "database")?.value;- const { fromTime, toTime } = timeRange;+ const createdTsRange = getTsRangeFromSearchParams(searchParams, "created");const query: string[] = [];request.parent = `projects/${project}`;@@ -25,13 +23,10 @@ export const buildListSlowQueriesRequest = (} else if (environment) {query.push(`environment = "environments/${environment}"`);}-- if (fromTime) {- const start = dayjs(fromTime).toISOString();+ if (createdTsRange) {+ const start = dayjs(createdTsRange[0]).toISOString();+ const end = dayjs(createdTsRange[1]).toISOString();query.push(`start_time >= "${start}"`);- }- if (toTime) {- const end = dayjs(toTime).toISOString();query.push(`start_time <= "${end}"`);}if (query.length > 0) {