update query

This commit is contained in:
Qiuxia Fan 2022-06-01 15:47:46 +08:00
parent 78bd81ea5d
commit d27f79b89f
5 changed files with 4 additions and 67 deletions

View File

@ -14,9 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
export const queryNamespaces = {
query: `namespaces: listNamespaces`,
};
export const queryContainers = { export const queryContainers = {
variable: "$condition: ContainerQueryCondition", variable: "$condition: ContainerQueryCondition",
@ -33,6 +30,5 @@ export const queryStreamingLogs = {
contentType contentType
content content
} }
total
}`, }`,
}; };

View File

@ -15,14 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { queryContainers, queryStreamingLogs } from "../fragments/demand-log";
queryContainers,
queryStreamingLogs,
queryNamespaces,
} from "../fragments/demand-log";
export const fetchContainers = `query queryContainers(${queryContainers.variable}) {${queryContainers.query}}`; export const fetchContainers = `query queryContainers(${queryContainers.variable}) {${queryContainers.query}}`;
export const fetchDemandPodLogs = `query queryStreamingLogs(${queryStreamingLogs.variable}) {${queryStreamingLogs.query}}`; export const fetchDemandPodLogs = `query queryStreamingLogs(${queryStreamingLogs.variable}) {${queryStreamingLogs.query}}`;
export const fetchNamespaces = `query queryContainers {${queryNamespaces.query}}`;

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { Option } from "@/types/app";
import { Instance } from "@/types/selector"; import { Instance } from "@/types/selector";
import { store } from "@/store"; import { store } from "@/store";
import graphql from "@/graphql"; import graphql from "@/graphql";
@ -31,7 +30,6 @@ interface DemandLogState {
selectorStore: any; selectorStore: any;
logs: Log[]; logs: Log[];
loadLogs: boolean; loadLogs: boolean;
namespaces: Option[];
} }
export const demandLogStore = defineStore({ export const demandLogStore = defineStore({
@ -40,17 +38,13 @@ export const demandLogStore = defineStore({
containers: [{ label: "Detail", value: "Detail" }], containers: [{ label: "Detail", value: "Detail" }],
instances: [{ value: "", label: "" }], instances: [{ value: "", label: "" }],
conditions: { conditions: {
namespace: "",
container: "", container: "",
serviceId: "",
serviceInstanceId: "", serviceInstanceId: "",
queryDuration: useAppStoreWithOut().durationTime, queryDuration: useAppStoreWithOut().durationTime,
paging: { pageNum: 1, pageSize: -1 },
}, },
selectorStore: useSelectorStore(), selectorStore: useSelectorStore(),
logs: [], logs: [],
loadLogs: false, loadLogs: false,
namespaces: [],
}), }),
actions: { actions: {
setLogCondition(data: Conditions) { setLogCondition(data: Conditions) {
@ -71,23 +65,7 @@ export const demandLogStore = defineStore({
this.instances = res.data.data.pods || []; this.instances = res.data.data.pods || [];
return res.data; return res.data;
}, },
async getNamespaces() { async getContainers(serviceInstanceId: string) {
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) { if (!this.selectorStore.currentService) {
return new Promise((resolve) => resolve({ errors: "No service" })); return new Promise((resolve) => resolve({ errors: "No service" }));
} }
@ -95,7 +73,6 @@ export const demandLogStore = defineStore({
const condition = { const condition = {
serviceId, serviceId,
serviceInstanceId, serviceInstanceId,
namespace,
}; };
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
.query("fetchContainers") .query("fetchContainers")

View File

@ -14,15 +14,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { DurationTime, Paging } from "./app"; import { DurationTime } from "./app";
export interface Conditions { export interface Conditions {
namespace: string;
container: string; container: string;
serviceId: string;
serviceInstanceId: string; serviceInstanceId: string;
queryDuration: DurationTime; queryDuration: DurationTime;
paging: Paging;
keywordsOfContent?: string[]; keywordsOfContent?: string[];
excludingKeywordsOfContent?: string; excludingKeywordsOfContent?: string;
} }

View File

@ -25,17 +25,6 @@ limitations under the License. -->
class="selectors" class="selectors"
/> />
</div> </div>
<div class="mr-5 mb-5">
<span class="grey mr-5">{{ t("namespace") }}:</span>
<Selector
size="small"
:value="state.namespace.value"
:options="demandLogStore.namespaces"
placeholder="Select a namespace"
@change="changeField('namespace', $event)"
class="selectors"
/>
</div>
<div class="mr-5 mb-5"> <div class="mr-5 mb-5">
<span class="grey mr-5">{{ t("container") }}:</span> <span class="grey mr-5">{{ t("container") }}:</span>
<Selector <Selector
@ -169,7 +158,6 @@ const intervalTime = ref<number>(1);
const state = reactive<any>({ const state = reactive<any>({
instance: { value: "", label: "" }, instance: { value: "", label: "" },
container: { value: "", label: "None" }, container: { value: "", label: "None" },
namespace: { value: "", label: "None" },
duration: { label: "Last 30 min", value: 1800 }, duration: { label: "Last 30 min", value: 1800 },
}); });
const rangeTime = computed(() => { const rangeTime = computed(() => {
@ -199,22 +187,10 @@ async function fetchSelectors() {
} else { } else {
await getInstances(); await getInstances();
} }
await getNamespaces();
getContainers(); getContainers();
} }
async function getNamespaces() {
const resp = await demandLogStore.getNamespaces();
if (resp.errors) {
ElMessage.error(resp.errors);
return;
}
state.namespace = demandLogStore.namespaces[0];
}
async function getContainers() { async function getContainers() {
const resp = await demandLogStore.getContainers( const resp = await demandLogStore.getContainers(state.instance.id || "");
state.namespace,
state.instance.id || ""
);
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return; return;
@ -235,10 +211,7 @@ function searchLogs() {
instance = selectorStore.currentPod.id; instance = selectorStore.currentPod.id;
} }
demandLogStore.setLogCondition({ demandLogStore.setLogCondition({
serviceId:
(selectorStore.currentService && selectorStore.currentService.id) || "",
serviceInstanceId: instance || state.instance.id || "", serviceInstanceId: instance || state.instance.id || "",
namespace: state.namespace.value,
container: state.container.value, container: state.container.value,
queryDuration: rangeTime.value, queryDuration: rangeTime.value,
keywordsOfContent: keywordsOfContent.value, keywordsOfContent: keywordsOfContent.value,