diff --git a/src/graphql/fragments/demand-log.ts b/src/graphql/fragments/demand-log.ts index 6f971f61..dda6b507 100644 --- a/src/graphql/fragments/demand-log.ts +++ b/src/graphql/fragments/demand-log.ts @@ -14,19 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +export const queryNamespaces = { + query: `namespaces: listNamespaces`, +}; export const queryContainers = { variable: "$condition: ContainerQueryCondition", query: ` - containers: queryContainers(condition: $condition) { - containers - }`, + containers: queryContainers(condition: $condition)`, }; export const queryStreamingLogs = { - variable: "$condition: StreamingLogQueryCondition!", + variable: "$condition: OndemandLogQueryCondition!", query: ` - logs: queryStreamingLogs(condition: $condition) { + logs: ondemandPodLogs(condition: $condition) { logs { timestamp contentType diff --git a/src/graphql/query/demand-log.ts b/src/graphql/query/demand-log.ts index 69cfa940..6948b9db 100644 --- a/src/graphql/query/demand-log.ts +++ b/src/graphql/query/demand-log.ts @@ -15,8 +15,14 @@ * limitations under the License. */ -import { queryContainers, queryStreamingLogs } from "../fragments/demand-log"; +import { + queryContainers, + queryStreamingLogs, + queryNamespaces, +} from "../fragments/demand-log"; export const fetchContainers = `query queryContainers(${queryContainers.variable}) {${queryContainers.query}}`; -export const fetchStreamingLogs = `query queryStreamingLogs(${queryStreamingLogs.variable}) {${queryStreamingLogs.query}}`; +export const fetchDemandPodLogs = `query queryStreamingLogs(${queryStreamingLogs.variable}) {${queryStreamingLogs.query}}`; + +export const fetchNamespaces = `query queryContainers {${queryNamespaces.query}}`; diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index efff77c9..c5d4444e 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -140,6 +140,7 @@ const msg = { limit: "Limit", page: "Page", interval: "Refresh Interval", + namespace: "Namespace", hourTip: "Select Hour", minuteTip: "Select Minute", secondTip: "Select Second", diff --git a/src/locales/lang/es.ts b/src/locales/lang/es.ts index b83acd75..f09aa095 100644 --- a/src/locales/lang/es.ts +++ b/src/locales/lang/es.ts @@ -140,6 +140,7 @@ const msg = { processSelect: "Click para seleccionar proceso", page: "Página", interval: "Intervalo de actualización", + namespace: "Espacio de nombres", hourTip: "Seleccione Hora", minuteTip: "Seleccione Minuto", secondTip: "Seleccione Segundo", diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index aa725ae8..6dd3b242 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -138,6 +138,7 @@ const msg = { limit: "范围", page: "页面", interval: "刷新间隔时间", + namespace: "命名空间", hourTip: "选择小时", minuteTip: "选择分钟", secondTip: "选择秒数", diff --git a/src/store/modules/demand-log.ts b/src/store/modules/demand-log.ts index 3c2bce46..002860a6 100644 --- a/src/store/modules/demand-log.ts +++ b/src/store/modules/demand-log.ts @@ -15,6 +15,7 @@ * limitations under the License. */ import { defineStore } from "pinia"; +import { Option } from "@/types/app"; import { Instance } from "@/types/selector"; import { store } from "@/store"; import graphql from "@/graphql"; @@ -30,6 +31,7 @@ interface DemandLogState { selectorStore: any; logs: DemandLog[]; loadLogs: boolean; + namespaces: Option[]; } export const demandLogStore = defineStore({ @@ -38,6 +40,7 @@ export const demandLogStore = defineStore({ containers: [{ label: "Detail", value: "Detail" }], instances: [{ value: "", label: "" }], conditions: { + namespace: "", container: "", serviceId: "", serviceInstanceId: "", @@ -47,6 +50,7 @@ export const demandLogStore = defineStore({ selectorStore: useSelectorStore(), logs: [], loadLogs: false, + namespaces: [], }), actions: { setLogCondition(data: Conditions) { @@ -67,21 +71,35 @@ export const demandLogStore = defineStore({ this.instances = res.data.data.pods || []; return res.data; }, - async getContainers(instanceId?: string) { - const serviceId = - this.selectorStore.currentService && - this.selectorStore.currentService.id; - const serviceInstanceId = - instanceId || - (this.selectorStore.currentInstance && - this.selectorStore.currentInstance.id); + async getNamespaces() { + const res: AxiosResponse = await graphql + .query("fetchNamespaces") + .params({}); + + if (res.data.errors) { + return res.data; + } + this.namespaces = (res.data.data.namespaces || []).map((d: string) => { + return { + label: d, + value: d, + }; + }); + return res.data; + }, + async getContainers(namespace: string, serviceInstanceId: string) { + if (!this.selectorStore.currentService) { + return new Promise((resolve) => resolve({ errors: "No service" })); + } + const serviceId = this.selectorStore.currentService.id; const condition = { serviceId, serviceInstanceId, + namespace, }; - const res: AxiosResponse = await graphql.query("fetchContainers").params({ - condition, - }); + const res: AxiosResponse = await graphql + .query("fetchContainers") + .params({ condition }); if (res.data.errors) { return res.data; @@ -95,7 +113,7 @@ export const demandLogStore = defineStore({ async getDemandLogs() { this.loadLogs = true; const res: AxiosResponse = await graphql - .query("fetchStreamingLogs") + .query("fetchDemandPodLogs") .params({ condition: this.conditions }); this.loadLogs = false; if (res.data.errors) { diff --git a/src/types/demand-log.ts b/src/types/demand-log.ts index a685792a..7559949c 100644 --- a/src/types/demand-log.ts +++ b/src/types/demand-log.ts @@ -17,6 +17,7 @@ import { DurationTime, Paging } from "./app"; export interface Conditions { + namespace: string; container: string; serviceId: string; serviceInstanceId: string; diff --git a/src/views/dashboard/related/demand-log/Header.vue b/src/views/dashboard/related/demand-log/Header.vue index ce8ee57d..7cebee44 100644 --- a/src/views/dashboard/related/demand-log/Header.vue +++ b/src/views/dashboard/related/demand-log/Header.vue @@ -25,6 +25,17 @@ limitations under the License. --> class="selectors" /> +