mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-13 08:17:33 +00:00
feat: edit policy
This commit is contained in:
parent
604725d20c
commit
bca5b923bf
6
src/types/continous-profiling.d.ts
vendored
6
src/types/continous-profiling.d.ts
vendored
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export interface StrategyItem {
|
export interface StrategyItem {
|
||||||
type: string;
|
targetType: string;
|
||||||
checkItems: CheckItems[];
|
checkItems: CheckItems[];
|
||||||
}
|
}
|
||||||
export type CheckItems = {
|
export type CheckItems = {
|
||||||
@ -24,6 +24,6 @@ export type CheckItems = {
|
|||||||
threshold: string;
|
threshold: string;
|
||||||
period: number;
|
period: number;
|
||||||
count: number;
|
count: number;
|
||||||
uriList: string[];
|
uriList?: string[];
|
||||||
uriRegex: string;
|
uriRegex?: string;
|
||||||
};
|
};
|
||||||
|
@ -15,13 +15,27 @@ limitations under the License. -->
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="policy-list">
|
<div class="policy-list">
|
||||||
<el-collapse v-model="activeNames" @change="handleChange">
|
<el-collapse v-model="activeNames">
|
||||||
<el-collapse-item
|
<el-collapse-item v-for="(item, index) in policyList" :key="index" :name="String(index)">
|
||||||
v-for="(item, index) in continousProfilingStore.strategyList"
|
<template #title>
|
||||||
:key="index"
|
<div>
|
||||||
:title="`Policy${index + 1}`"
|
<span class="title">{{ `Policy - ${index + 1}` }}</span>
|
||||||
:name="index"
|
<Icon
|
||||||
>
|
class="mr-5 cp"
|
||||||
|
iconName="remove_circle_outline"
|
||||||
|
size="middle"
|
||||||
|
v-show="policyList.length !== 1"
|
||||||
|
@click="removePolicy($event, index)"
|
||||||
|
/>
|
||||||
|
<Icon
|
||||||
|
class="cp"
|
||||||
|
v-show="index === policyList.length - 1"
|
||||||
|
iconName="add_circle_outlinecontrol_point"
|
||||||
|
size="middle"
|
||||||
|
@click="createPolicy"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
<Policy :data="item" @edit="changePolicy" :order="index" />
|
<Policy :data="item" @edit="changePolicy" :order="index" />
|
||||||
</el-collapse-item>
|
</el-collapse-item>
|
||||||
</el-collapse>
|
</el-collapse>
|
||||||
@ -37,17 +51,17 @@ limitations under the License. -->
|
|||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useContinousProfilingStore } from "@/store/modules/continous-profiling";
|
import { useContinousProfilingStore } from "@/store/modules/continous-profiling";
|
||||||
import Policy from "./Policy.vue";
|
import Policy from "./Policy.vue";
|
||||||
import type { StrategyItem } from "@/types/continous-profiling";
|
import type { StrategyItem, CheckItems } from "@/types/continous-profiling";
|
||||||
|
|
||||||
/* global defineEmits */
|
/* global defineEmits */
|
||||||
const emits = defineEmits(["save"]);
|
const emits = defineEmits(["save"]);
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const continousProfilingStore = useContinousProfilingStore();
|
const continousProfilingStore = useContinousProfilingStore();
|
||||||
const activeNames = ref<string[]>(["1"]);
|
const activeNames = ref(["0"]);
|
||||||
const requestParams = ref<StrategyItem[]>([]);
|
const policyList = ref<StrategyItem[]>(continousProfilingStore.strategyList);
|
||||||
|
|
||||||
function changePolicy(params: StrategyItem, order: number) {
|
function changePolicy(params: StrategyItem, order: number) {
|
||||||
requestParams.value = requestParams.value.map((d: StrategyItem, index: number) => {
|
policyList.value = policyList.value.map((d: StrategyItem, index: number) => {
|
||||||
if (order === index) {
|
if (order === index) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
@ -55,12 +69,45 @@ limitations under the License. -->
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function removePolicy(e: PointerEvent, key: number) {
|
||||||
emits("save", requestParams.value);
|
e.stopPropagation();
|
||||||
|
if (policyList.value.length === 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
policyList.value = policyList.value.filter((_, index: number) => index !== key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(val: any) {
|
function createPolicy(e: PointerEvent) {
|
||||||
activeNames.value = val;
|
e.stopPropagation();
|
||||||
|
policyList.value.push({
|
||||||
|
targetType: "",
|
||||||
|
checkItems: [
|
||||||
|
{
|
||||||
|
type: "",
|
||||||
|
threshold: "",
|
||||||
|
period: NaN,
|
||||||
|
count: NaN,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
activeNames.value = [String(policyList.value.length - 1)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
const params = [];
|
||||||
|
for (const d of policyList.value) {
|
||||||
|
const checkItems = d.checkItems.filter(
|
||||||
|
(item: CheckItems) => item.type && item.threshold && item.period && item.count,
|
||||||
|
);
|
||||||
|
if (d.targetType && checkItems.length) {
|
||||||
|
const v = {
|
||||||
|
...d,
|
||||||
|
checkItems,
|
||||||
|
};
|
||||||
|
params.push(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emits("save", params);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
@ -19,7 +19,7 @@ limitations under the License. -->
|
|||||||
<Selector
|
<Selector
|
||||||
class="profile-input"
|
class="profile-input"
|
||||||
size="small"
|
size="small"
|
||||||
:value="states.type"
|
:value="states.targetType"
|
||||||
:options="TargetTypes"
|
:options="TargetTypes"
|
||||||
placeholder="Select a type"
|
placeholder="Select a type"
|
||||||
@change="changeType"
|
@change="changeType"
|
||||||
@ -84,7 +84,7 @@ limitations under the License. -->
|
|||||||
const states = reactive<StrategyItem>(props.data);
|
const states = reactive<StrategyItem>(props.data);
|
||||||
|
|
||||||
function changeType(opt: { value: string }[]) {
|
function changeType(opt: { value: string }[]) {
|
||||||
states.type = opt[0].value;
|
states.targetType = opt[0].value;
|
||||||
emits("edit", states, props.order);
|
emits("edit", states, props.order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,16 +82,12 @@ limitations under the License. -->
|
|||||||
|
|
||||||
fetchStrategyList();
|
fetchStrategyList();
|
||||||
|
|
||||||
function policyItem(items: CheckItems[]) {
|
|
||||||
return items.map((d: CheckItems) => `${d.type}>=${d.threshold}`).join(";");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function changePolicy(item: StrategyItem) {
|
async function changePolicy(item: StrategyItem) {
|
||||||
continousProfilingStore.setSelectedStrategy(item);
|
continousProfilingStore.setSelectedStrategy(item);
|
||||||
const serviceId = (selectorStore.currentService && selectorStore.currentService.id) || "";
|
const serviceId = (selectorStore.currentService && selectorStore.currentService.id) || "";
|
||||||
await continousProfilingStore.getContinousTaskList({
|
await continousProfilingStore.getContinousTaskList({
|
||||||
serviceId,
|
serviceId,
|
||||||
targets: [item.type],
|
targets: [item.targetType],
|
||||||
triggerType: EBPFProfilingTriggerType.CONTINUOUS_PROFILING,
|
triggerType: EBPFProfilingTriggerType.CONTINUOUS_PROFILING,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user