From 66825485ea92078e1c7485c7eec964ac79673d9b Mon Sep 17 00:00:00 2001 From: yangon <2689991790@qq.com> Date: Fri, 7 Jun 2024 10:35:03 +0800 Subject: [PATCH] Some details (#430) --- ui/mock/alertAPI.ts | 14 +- ui/src/api/generated/api.ts | 331 +++++++++++++++--- ui/src/components/InputLabelComp/index.tsx | 9 +- ui/src/components/PreText/index.tsx | 4 +- ui/src/constants/index.ts | 4 +- ui/src/pages/Alert/AlarmFilter/index.tsx | 94 +++-- ui/src/pages/Alert/Channel/ChannelDrawer.tsx | 1 + ui/src/pages/Alert/Event/index.tsx | 22 +- ui/src/pages/Alert/Rules/RuleDrawerForm.tsx | 20 +- ui/src/pages/Alert/Rules/index.tsx | 22 +- .../pages/Alert/Shield/ShieldDrawerForm.tsx | 14 +- ui/src/pages/Alert/Shield/index.tsx | 32 +- .../Subscriptions/SubscripDrawerForm.tsx | 12 +- ui/src/pages/Alert/Subscriptions/index.tsx | 5 +- ui/src/pages/Alert/helper.ts | 27 +- 15 files changed, 457 insertions(+), 154 deletions(-) diff --git a/ui/mock/alertAPI.ts b/ui/mock/alertAPI.ts index 24198fc71..437afde75 100644 --- a/ui/mock/alertAPI.ts +++ b/ui/mock/alertAPI.ts @@ -24,7 +24,7 @@ export default { }, ], rule: 'string', - serverity: 'critical', + severity: 'critical', startsAt: 1716543006, status: { inhibitedBy: ['string'], @@ -57,7 +57,7 @@ export default { }, ], rule: 'string', - serverity: 'info', + severity: 'info', startsAt: 1716548006, status: { inhibitedBy: ['string'], @@ -90,7 +90,7 @@ export default { }, ], rule: 'string', - serverity: 'warning', + severity: 'warning', startsAt: 1716548606, status: { inhibitedBy: ['string'], @@ -238,7 +238,7 @@ export default { lastEvaluation: 0, name: 'string', query: 'string', - serverity: 'critical', + severity: 'critical', state: 'active', summary: 'string', type: 'builtin', @@ -258,7 +258,7 @@ export default { lastEvaluation: 0, name: 'string', query: 'string', - serverity: 'caution', + severity: 'caution', state: 'active', summary: 'string', type: 'customized', @@ -278,7 +278,7 @@ export default { lastEvaluation: 0, name: 'string', query: 'string', - serverity: 'warning', + severity: 'warning', state: 'active', summary: 'string', type: 'builtin', @@ -337,7 +337,7 @@ export default { lastEvaluation: 0, name: 'string', query: 'string', - serverity: 'critical', + severity: 'critical', state: 'active', summary: 'string', type: 'builtin', diff --git a/ui/src/api/generated/api.ts b/ui/src/api/generated/api.ts index cc39a96c0..b51d0b4f0 100644 --- a/ui/src/api/generated/api.ts +++ b/ui/src/api/generated/api.ts @@ -29,12 +29,6 @@ import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerM * @interface AlarmMatcher */ export interface AlarmMatcher { - /** - * - * @type {boolean} - * @memberof AlarmMatcher - */ - 'isEqual'?: boolean; /** * * @type {boolean} @@ -60,14 +54,14 @@ export interface AlarmMatcher { * @enum {string} */ -export const AlarmServerity = { - ServerityCritical: 'critical', - ServerityWarning: 'warning', - ServerityCaution: 'caution', - ServerityInfo: 'info' +export const AlarmSeverity = { + SeverityCritical: 'critical', + SeverityWarning: 'warning', + SeverityCaution: 'caution', + SeverityInfo: 'info' } as const; -export type AlarmServerity = typeof AlarmServerity[keyof typeof AlarmServerity]; +export type AlarmSeverity = typeof AlarmSeverity[keyof typeof AlarmSeverity]; /** @@ -114,10 +108,10 @@ export interface AlertAlert { 'rule': string; /** * - * @type {AlarmServerity} + * @type {AlarmSeverity} * @memberof AlertAlert */ - 'serverity': AlarmServerity; + 'severity': AlarmSeverity; /** * * @type {number} @@ -163,6 +157,12 @@ export interface AlertAlertFilter { * @memberof AlertAlertFilter */ 'instance'?: OceanbaseOBInstance; + /** + * + * @type {OceanbaseOBInstanceType} + * @memberof AlertAlertFilter + */ + 'instanceType'?: OceanbaseOBInstanceType; /** * * @type {string} @@ -171,10 +171,10 @@ export interface AlertAlertFilter { 'keyword'?: string; /** * - * @type {AlarmServerity} + * @type {AlarmSeverity} * @memberof AlertAlertFilter */ - 'serverity'?: AlarmServerity; + 'severity'?: AlarmSeverity; /** * * @type {number} @@ -2143,9 +2143,11 @@ export interface OceanbaseOBInstance { */ export const OceanbaseOBInstanceType = { - OBCluster: 'obcluster', - OBTenant: 'obtenant', - OBServer: 'observer' + TypeUnknown: 'unknown', + TypeOBCluster: 'obcluster', + TypeOBZone: 'obzone', + TypeOBTenant: 'obtenant', + TypeOBServer: 'observer' } as const; export type OceanbaseOBInstanceType = typeof OceanbaseOBInstanceType[keyof typeof OceanbaseOBInstanceType]; @@ -2960,6 +2962,110 @@ export interface ParamZoneTopology { */ 'zone'?: string; } +/** + * + * @export + * @interface PayloadAlert + */ +export interface PayloadAlert { + /** + * + * @type {{ [key: string]: string; }} + * @memberof PayloadAlert + */ + 'annotations'?: { [key: string]: string; }; + /** + * + * @type {string} + * @memberof PayloadAlert + */ + 'endsAt'?: string; + /** + * + * @type {string} + * @memberof PayloadAlert + */ + 'generatorURL'?: string; + /** + * + * @type {{ [key: string]: string; }} + * @memberof PayloadAlert + */ + 'labels'?: { [key: string]: string; }; + /** + * + * @type {string} + * @memberof PayloadAlert + */ + 'startsAt'?: string; + /** + * + * @type {string} + * @memberof PayloadAlert + */ + 'status'?: string; +} +/** + * + * @export + * @interface PayloadWebhookPayload + */ +export interface PayloadWebhookPayload { + /** + * + * @type {Array} + * @memberof PayloadWebhookPayload + */ + 'alerts'?: Array; + /** + * + * @type {{ [key: string]: string; }} + * @memberof PayloadWebhookPayload + */ + 'commonAnnotations'?: { [key: string]: string; }; + /** + * + * @type {{ [key: string]: string; }} + * @memberof PayloadWebhookPayload + */ + 'commonLabels'?: { [key: string]: string; }; + /** + * + * @type {string} + * @memberof PayloadWebhookPayload + */ + 'externalURL'?: string; + /** + * + * @type {string} + * @memberof PayloadWebhookPayload + */ + 'groupKey'?: string; + /** + * + * @type {{ [key: string]: string; }} + * @memberof PayloadWebhookPayload + */ + 'groupLabels'?: { [key: string]: string; }; + /** + * + * @type {string} + * @memberof PayloadWebhookPayload + */ + 'receiver'?: string; + /** + * + * @type {string} + * @memberof PayloadWebhookPayload + */ + 'status'?: string; + /** + * + * @type {string} + * @memberof PayloadWebhookPayload + */ + 'version'?: string; +} /** * * @export @@ -3019,8 +3125,19 @@ export interface ReceiverReceiver { */ export const ReceiverReceiverType = { - TypeDingTalk: 'dingtalk', - TypeWeChat: 'wechat' + TypeDiscord: 'discord', + TypeEmail: 'email', + TypePagerduty: 'pagerduty', + TypeSlack: 'slack', + TypeWebhook: 'webhook', + TypeOpsGenie: 'opsgenie', + TypeWechat: 'wechat', + TypePushover: 'pushover', + TypeVictorOps: 'victorops', + TypeSNS: 'sns', + TypeTelegram: 'telegram', + TypeWebex: 'webex', + TypeMSTeams: 'msteams' } as const; export type ReceiverReceiverType = typeof ReceiverReceiverType[keyof typeof ReceiverReceiverType]; @@ -5041,10 +5158,10 @@ export interface RuleRule { 'instanceType': OceanbaseOBInstanceType; /** * - * @type {CommonKVPair} + * @type {Array} * @memberof RuleRule */ - 'labels': CommonKVPair; + 'labels': Array; /** * * @type {string} @@ -5059,10 +5176,10 @@ export interface RuleRule { 'query': string; /** * - * @type {AlarmServerity} + * @type {AlarmSeverity} * @memberof RuleRule */ - 'serverity': AlarmServerity; + 'severity': AlarmSeverity; /** * * @type {string} @@ -5074,7 +5191,7 @@ export interface RuleRule { * @type {RuleRuleType} * @memberof RuleRule */ - 'type': RuleRuleType; + 'type'?: RuleRuleType; } @@ -5098,10 +5215,10 @@ export interface RuleRuleFilter { 'keyword'?: string; /** * - * @type {AlarmServerity} + * @type {AlarmSeverity} * @memberof RuleRuleFilter */ - 'serverity'?: AlarmServerity; + 'severity'?: AlarmSeverity; } @@ -5164,10 +5281,10 @@ export interface RuleRuleResponse { 'keepFiringFor': number; /** * - * @type {CommonKVPair} + * @type {Array} * @memberof RuleRuleResponse */ - 'labels': CommonKVPair; + 'labels': Array; /** * * @type {string} @@ -5194,10 +5311,10 @@ export interface RuleRuleResponse { 'query': string; /** * - * @type {AlarmServerity} + * @type {AlarmSeverity} * @memberof RuleRuleResponse */ - 'serverity': AlarmServerity; + 'severity': AlarmSeverity; /** * * @type {RuleRuleState} @@ -5215,7 +5332,7 @@ export interface RuleRuleResponse { * @type {RuleRuleType} * @memberof RuleRuleResponse */ - 'type': RuleRuleType; + 'type'?: RuleRuleType; } @@ -5259,6 +5376,12 @@ export interface SilenceSilencerFilter { * @memberof SilenceSilencerFilter */ 'instance'?: OceanbaseOBInstance; + /** + * + * @type {OceanbaseOBInstanceType} + * @memberof SilenceSilencerFilter + */ + 'instanceType'?: OceanbaseOBInstanceType; /** * * @type {string} @@ -5266,6 +5389,8 @@ export interface SilenceSilencerFilter { */ 'keyword'?: string; } + + /** * * @export @@ -5301,13 +5426,19 @@ export interface SilenceSilencerParam { * @type {Array} * @memberof SilenceSilencerParam */ - 'instance': Array; + 'instances': Array; /** * * @type {Array} * @memberof SilenceSilencerParam */ 'matchers': Array; + /** + * + * @type {Array} + * @memberof SilenceSilencerParam + */ + 'rules': Array; /** * * @type {number} @@ -5350,7 +5481,7 @@ export interface SilenceSilencerResponse { * @type {Array} * @memberof SilenceSilencerResponse */ - 'instance': Array; + 'instances': Array; /** * * @type {Array} @@ -5383,7 +5514,9 @@ export interface SilenceSilencerResponse { */ export const SilenceState = { - StateActive: 'active' + StateActive: 'active', + StateExpired: 'expired', + StatePending: 'pending' } as const; export type SilenceState = typeof SilenceState[keyof typeof SilenceState]; @@ -5901,7 +6034,7 @@ export const AlarmApiAxiosParamCreator = function (configuration?: Configuration }; }, /** - * List alerts, filter with alarm objects, serverity, time and keywords. + * List alerts, filter with alarm objects, severity, time and keywords. * @summary List alerts * @param {AlertAlertFilter} [body] alert filter * @param {*} [options] Override http request option. @@ -6037,7 +6170,7 @@ export const AlarmApiAxiosParamCreator = function (configuration?: Configuration }; }, /** - * List alarm rules, filter with alarm objects type, serverity and keywords. + * List alarm rules, filter with alarm objects type, severity and keywords. * @summary List alarm rules * @param {RuleRuleFilter} [body] rule filter * @param {*} [options] Override http request option. @@ -6290,7 +6423,7 @@ export const AlarmApiFp = function(configuration?: Configuration) { return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, /** - * List alerts, filter with alarm objects, serverity, time and keywords. + * List alerts, filter with alarm objects, severity, time and keywords. * @summary List alerts * @param {AlertAlertFilter} [body] alert filter * @param {*} [options] Override http request option. @@ -6339,7 +6472,7 @@ export const AlarmApiFp = function(configuration?: Configuration) { return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, /** - * List alarm rules, filter with alarm objects type, serverity and keywords. + * List alarm rules, filter with alarm objects type, severity and keywords. * @summary List alarm rules * @param {RuleRuleFilter} [body] rule filter * @param {*} [options] Override http request option. @@ -6505,7 +6638,7 @@ export const AlarmApiFactory = function (configuration?: Configuration, basePath return localVarFp.getSilencer(id, options).then((request) => request(axios, basePath)); }, /** - * List alerts, filter with alarm objects, serverity, time and keywords. + * List alerts, filter with alarm objects, severity, time and keywords. * @summary List alerts * @param {AlertAlertFilter} [body] alert filter * @param {*} [options] Override http request option. @@ -6542,7 +6675,7 @@ export const AlarmApiFactory = function (configuration?: Configuration, basePath return localVarFp.listRoutes(options).then((request) => request(axios, basePath)); }, /** - * List alarm rules, filter with alarm objects type, serverity and keywords. + * List alarm rules, filter with alarm objects type, severity and keywords. * @summary List alarm rules * @param {RuleRuleFilter} [body] rule filter * @param {*} [options] Override http request option. @@ -6728,7 +6861,7 @@ export class AlarmApi extends BaseAPI { } /** - * List alerts, filter with alarm objects, serverity, time and keywords. + * List alerts, filter with alarm objects, severity, time and keywords. * @summary List alerts * @param {AlertAlertFilter} [body] alert filter * @param {*} [options] Override http request option. @@ -6773,7 +6906,7 @@ export class AlarmApi extends BaseAPI { } /** - * List alarm rules, filter with alarm objects type, serverity and keywords. + * List alarm rules, filter with alarm objects type, severity and keywords. * @summary List alarm rules * @param {RuleRuleFilter} [body] rule filter * @param {*} [options] Override http request option. @@ -11021,3 +11154,113 @@ export class UserApi extends BaseAPI { +/** + * WebhookApi - axios parameter creator + * @export + */ +export const WebhookApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * Log alerts sent by alertmanager. + * @summary Log alerts + * @param {PayloadWebhookPayload} body payload + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + logAlerts: async (body: PayloadWebhookPayload, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'body' is not null or undefined + assertParamExists('logAlerts', 'body', body) + const localVarPath = `/api/v1/webhook/alert/log`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * WebhookApi - functional programming interface + * @export + */ +export const WebhookApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = WebhookApiAxiosParamCreator(configuration) + return { + /** + * Log alerts sent by alertmanager. + * @summary Log alerts + * @param {PayloadWebhookPayload} body payload + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async logAlerts(body: PayloadWebhookPayload, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.logAlerts(body, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['WebhookApi.logAlerts']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + } +}; + +/** + * WebhookApi - factory interface + * @export + */ +export const WebhookApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = WebhookApiFp(configuration) + return { + /** + * Log alerts sent by alertmanager. + * @summary Log alerts + * @param {PayloadWebhookPayload} body payload + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + logAlerts(body: PayloadWebhookPayload, options?: any): AxiosPromise { + return localVarFp.logAlerts(body, options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * WebhookApi - object-oriented interface + * @export + * @class WebhookApi + * @extends {BaseAPI} + */ +export class WebhookApi extends BaseAPI { + /** + * Log alerts sent by alertmanager. + * @summary Log alerts + * @param {PayloadWebhookPayload} body payload + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof WebhookApi + */ + public logAlerts(body: PayloadWebhookPayload, options?: RawAxiosRequestConfig) { + return WebhookApiFp(this.configuration).logAlerts(body, options).then((request) => request(this.axios, this.basePath)); + } +} + + + diff --git a/ui/src/components/InputLabelComp/index.tsx b/ui/src/components/InputLabelComp/index.tsx index 48a1410b9..c922a5737 100644 --- a/ui/src/components/InputLabelComp/index.tsx +++ b/ui/src/components/InputLabelComp/index.tsx @@ -1,6 +1,5 @@ import { DeleteOutlined, PlusOutlined } from '@ant-design/icons'; import { Button, Checkbox, Col, Input, Popconfirm, Row, Space } from 'antd'; -import { clone } from 'lodash'; type Label = { [T: string]: string | boolean; @@ -46,9 +45,8 @@ export default function InputLabelComp(props: InputLabelCompPorps) { onChange?.([...labels, temp]); }; const remove = (index: number) => { - const newValue = clone(labels); - newValue.splice(index, 1); - onChange?.(newValue); + labels.splice(index, 1); + onChange?.([...labels]); }; return (
@@ -57,6 +55,7 @@ export default function InputLabelComp(props: InputLabelCompPorps) { labelNameInput(e.target.value, index)} placeholder="请输入标签名" @@ -64,6 +63,7 @@ export default function InputLabelComp(props: InputLabelCompPorps) { labelValueInput(e.target.value, index)} placeholder="请输入标签值" @@ -72,6 +72,7 @@ export default function InputLabelComp(props: InputLabelCompPorps) { {regex && ( regChange(e.target.checked, index)} /> 正则 diff --git a/ui/src/components/PreText/index.tsx b/ui/src/components/PreText/index.tsx index 1c5b8270e..2b90689c4 100644 --- a/ui/src/components/PreText/index.tsx +++ b/ui/src/components/PreText/index.tsx @@ -11,7 +11,7 @@ export default function PreText({ cols, value }: PreTextProps) { - {typeof value === 'string' ? value : JSON.stringify(value, null, 4)} + {typeof value === 'string' ? value : JSON.stringify(value, null, 2)} } > @@ -19,7 +19,7 @@ export default function PreText({ cols, value }: PreTextProps) { className={cols ? styles.preText : ''} style={{ WebkitLineClamp: cols }} > - {typeof value === 'string' ? value : JSON.stringify(value, null, 4)} + {typeof value === 'string' ? value : JSON.stringify(value, null, 2)} ); diff --git a/ui/src/constants/index.ts b/ui/src/constants/index.ts index 1e9e14e39..cd568b465 100644 --- a/ui/src/constants/index.ts +++ b/ui/src/constants/index.ts @@ -174,7 +174,7 @@ const LEVER_OPTIONS_ALARM: SelectProps['options'] = [ value: 'info', }, ]; -const SERVERITY_MAP = { +const SEVERITY_MAP = { critical: { color: 'red', label: '严重', @@ -246,7 +246,7 @@ export { REFRESH_FREQUENCY, REFRESH_TENANT_TIME, RESULT_STATUS, - SERVERITY_MAP, + SEVERITY_MAP, SERVER_IMG_MAP, SHILED_STATUS_MAP, STATISTICS_INTERVAL, diff --git a/ui/src/pages/Alert/AlarmFilter/index.tsx b/ui/src/pages/Alert/AlarmFilter/index.tsx index 7c1e0586b..b9a896fbf 100644 --- a/ui/src/pages/Alert/AlarmFilter/index.tsx +++ b/ui/src/pages/Alert/AlarmFilter/index.tsx @@ -2,7 +2,7 @@ import type { OceanbaseOBInstanceType } from '@/api/generated'; import { LEVER_OPTIONS_ALARM, OBJECT_OPTIONS_ALARM, - SERVERITY_MAP, + SEVERITY_MAP, } from '@/constants'; import { Alert } from '@/type/alert'; import { DownOutlined, UpOutlined } from '@ant-design/icons'; @@ -43,28 +43,60 @@ export default function AlarmFilter({ form, type, depend }: AlarmFilterProps) { })); } if (type === 'obtenant') { - return (list as Alert.TenantsList[]).map((cluster) => ({ - label: {cluster.clusterName}, - title: cluster.clusterName, - options: cluster.tenants?.map((item) => ({ - value: item, - label: item, - })), - })); + return (list as Alert.TenantsList[]) + .map((cluster) => ({ + label: {cluster.clusterName}, + title: cluster.clusterName, + options: cluster.tenants?.map((item) => ({ + value: item, + label: item, + })), + })) + .filter((item) => item.options?.length); } if (type === 'observer') { - return (list as Alert.ServersList[]).map((cluster) => ({ - label: {cluster.clusterName}, - title: cluster.clusterName, - options: cluster.servers?.map((item) => ({ - value: item, - label: item, - })), - })); + return (list as Alert.ServersList[]) + .map((cluster) => ({ + label: {cluster.clusterName}, + title: cluster.clusterName, + options: cluster.servers?.map((item) => ({ + value: item, + label: item, + })), + })) + .filter((item) => item.options?.length); } }; const { run: debounceDepend } = useDebounceFn(depend, { wait: 500 }); - const formData = Form.useWatch([], form) as { [T: string]: string | object }; + const formData: any = Form.useWatch([], form); + + const findClusterName = ( + list: API.SimpleClusterList | API.TenantDetail[], + type: 'obtenant' | 'observer', + target: string, + ) => { + if (type === 'observer') { + return ( + (list as API.SimpleClusterList).find((cluster) => { + return cluster.topology.some((zone) => + zone.observers.some((server) => server.address === target), + ); + })?.clusterName || '' + ); + } + if (type === 'obtenant') { + const clusterResourceName = (list as API.TenantDetail[]).find( + (tenant) => { + return tenant.tenantName === target; + }, + )?.clusterResourceName; + if (clusterResourceName) { + return clusterList?.find( + (cluster) => cluster.name === clusterResourceName, + )?.clusterName; + } + } + }; useEffect(() => { if (type === 'event') { setVisibleConfig({ @@ -130,6 +162,20 @@ export default function AlarmFilter({ form, type, depend }: AlarmFilterProps) { filter[key] = Math.ceil(formData[key].valueOf() / 1000); } else if (key === 'instance' && formData[key]?.type) { const temp = {}; + if (formData[key]?.obtenant) { + formData[key].obcluster = findClusterName( + tenantList!, + 'obtenant', + formData[key]?.obtenant, + ); + } + if (formData[key]?.observer) { + formData[key].obcluster = findClusterName( + clusterList!, + 'observer', + formData[key]?.observer, + ); + } Object.keys(formData[key]).forEach((innerKey) => { if (formData[key][innerKey]) { temp[innerKey] = formData[key][innerKey]; @@ -139,10 +185,10 @@ export default function AlarmFilter({ form, type, depend }: AlarmFilterProps) { } } }); - if(filter.instance){ - if(Object.keys(filter.instance).length === 1 && filter.instance?.type){ - filter.instanceType = filter.instance.type - delete filter.instance + if (filter.instance) { + if (Object.keys(filter.instance).length === 1 && filter.instance?.type) { + filter.instanceType = filter.instance.type; + delete filter.instance; } } debounceDepend(filter); @@ -199,7 +245,7 @@ export default function AlarmFilter({ form, type, depend }: AlarmFilterProps) { wrapperCol={{ span: 18 }} labelCol={{ span: 9 }} label="告警等级" - name={'serverity'} + name={'severity'} > ({ value: template.type, label: template.type, diff --git a/ui/src/pages/Alert/Event/index.tsx b/ui/src/pages/Alert/Event/index.tsx index 8bcb599d4..a1ab6928e 100644 --- a/ui/src/pages/Alert/Event/index.tsx +++ b/ui/src/pages/Alert/Event/index.tsx @@ -1,11 +1,11 @@ import { alert } from '@/api'; import type { - AlarmServerity, + AlarmSeverity, AlertAlert, AlertStatus, OceanbaseOBInstance, } from '@/api/generated'; -import { ALERT_STATE_MAP, SERVERITY_MAP } from '@/constants'; +import { ALERT_STATE_MAP, SEVERITY_MAP } from '@/constants'; import { history } from '@umijs/max'; import { useRequest } from 'ahooks'; import { @@ -60,17 +60,17 @@ export default function Event() { }, { title: '告警等级', - dataIndex: 'serverity', - key: 'serverity', + dataIndex: 'severity', + key: 'severity', sorter: (preRecord, curRecord) => { return ( - SERVERITY_MAP[preRecord.serverity].weight - - SERVERITY_MAP[curRecord.serverity].weight + SEVERITY_MAP[preRecord.severity].weight - + SEVERITY_MAP[curRecord.severity].weight ); }, - render: (serverity: AlarmServerity) => ( - - {SERVERITY_MAP[serverity]?.label} + render: (severity: AlarmSeverity) => ( + + {SEVERITY_MAP[severity]?.label} ), }, @@ -96,7 +96,7 @@ export default function Event() { key: 'startsAt', sorter: (preRecord, curRecord) => curRecord.startsAt - preRecord.startsAt, render: (startsAt: number) => ( - {dayjs.unix(startsAt).format('YYYY-MM-DD HH:MM:SS')} + {dayjs.unix(startsAt).format('YYYY-MM-DD HH:mm:ss')} ), }, { @@ -105,7 +105,7 @@ export default function Event() { key: 'endsAt', sorter: (preRecord, curRecord) => curRecord.endsAt - preRecord.endsAt, render: (endsAt: number) => ( - {dayjs.unix(endsAt).format('YYYY-MM-DD HH:MM:SS')} + {dayjs.unix(endsAt).format('YYYY-MM-DD HH:mm:ss')} ), }, { diff --git a/ui/src/pages/Alert/Rules/RuleDrawerForm.tsx b/ui/src/pages/Alert/Rules/RuleDrawerForm.tsx index 051534971..9a8ef2fe9 100644 --- a/ui/src/pages/Alert/Rules/RuleDrawerForm.tsx +++ b/ui/src/pages/Alert/Rules/RuleDrawerForm.tsx @@ -2,7 +2,7 @@ import { alert } from '@/api'; import type { CommonKVPair, RuleRule } from '@/api/generated'; import AlertDrawer from '@/components/AlertDrawer'; import InputLabelComp from '@/components/InputLabelComp'; -import { LEVER_OPTIONS_ALARM, SERVERITY_MAP } from '@/constants'; +import { LEVER_OPTIONS_ALARM, SEVERITY_MAP } from '@/constants'; import { QuestionCircleOutlined } from '@ant-design/icons'; import { useRequest } from 'ahooks'; import type { DrawerProps } from 'antd'; @@ -18,6 +18,7 @@ import { message, } from 'antd'; import { useEffect } from 'react'; +import { validateLabelValues } from '../helper'; type AlertRuleDrawerProps = { ruleName?: string; @@ -46,6 +47,7 @@ export default function RuleDrawerForm({ }; const submit = (values: RuleRule) => { values.type = 'customized'; + if (!values.labels) values.labels = []; alert.createOrUpdateRule(values).then(({ successful }) => { if (successful) { message.success('操作成功!'); @@ -93,7 +95,7 @@ export default function RuleDrawerForm({ }, ]} name={'instanceType'} - label="屏蔽对象类型" + label="对象类型" > 集群 @@ -148,14 +150,14 @@ export default function RuleDrawerForm({ message: '请输入', }, ]} - name={'serverity'} + name={'severity'} label="告警级别" >