Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-10256][DashBoard] Modify the data source IP item of the file data source form in the data access module #10258

Merged
merged 6 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions inlong-dashboard/src/core/utils/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// eslint-disable-next-line
export default {
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
fileIp:
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?:,\s*(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]))*$|^All$/,
url: /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i,
port: /^([1-9](\d{0,3}))$|^([1-5]\d{4})$|^(6[0-4]\d{3})$|^(65[0-4]\d{2})$|^(655[0-2]\d)$|^(6553[0-5])$/,
};
32 changes: 22 additions & 10 deletions inlong-dashboard/src/plugins/sources/defaults/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { RenderList } from '@/plugins/RenderList';
import i18n from '@/i18n';
import rulesPattern from '@/core/utils/pattern';
import { SourceInfo } from '../common/SourceInfo';
import MultiSelectWithALL, { ALL_OPTION_VALUE } from '@/ui/components/MultiSelectWithAll';

const { I18n } = DataWithBackend;
const { FieldDecorator, IngestionField } = RenderRow;
Expand Down Expand Up @@ -82,15 +83,17 @@ export default class PulsarSource
clusterId: number;

@FieldDecorator({
type: 'select',
type: MultiSelectWithALL,
tooltip: i18n.t('meta.Sources.File.FileIpHelp'),
rules: [
{
pattern: rulesPattern.ip,
pattern: rulesPattern.fileIp,
message: i18n.t('meta.Sources.File.IpRule'),
required: true,
},
],
props: values => ({
mode: 'multiple',
disabled: Boolean(values.id),
showSearch: true,
allowClear: true,
Expand All @@ -108,20 +111,29 @@ export default class PulsarSource
},
}),
requestParams: {
formatResult: result =>
result?.list?.map(item => ({
...item,
label: item.ip,
value: item.ip,
})),
formatResult: result => {
const allOption = {
label: ALL_OPTION_VALUE,
value: ALL_OPTION_VALUE,
};
return result?.list
? [
allOption,
...result.list.map(item => ({
label: item.ip,
value: item.ip,
})),
]
: [allOption];
},
},
},
}),
})
@ColumnDecorator()
@IngestionField()
@I18n('meta.Sources.File.DataSourceIP')
agentIp: string;
agentIp: string[] | string;

@FieldDecorator({
type: 'input',
Expand Down Expand Up @@ -182,7 +194,7 @@ export default class PulsarSource
initialValue: '0h',
rules: [
{
pattern: /-?[0-9][mhd]$/,
pattern: /-?\d+[mhd]$/,
required: true,
message: i18n.t('meta.Sources.File.TimeOffsetRules'),
},
Expand Down
50 changes: 50 additions & 0 deletions inlong-dashboard/src/ui/components/MultiSelectWithAll/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { useState, useEffect } from 'react';
import HighSelect from '@/ui/components/HighSelect';

export const ALL_OPTION_VALUE = 'All';
const MultiSelectWithALL = props => {
const [selectedValues, setSelectedValues] = useState([]);

const handleSelectChange = (value, option) => {
let newSelectedValues = [];
if (value[value.length - 1] === ALL_OPTION_VALUE) {
newSelectedValues = [ALL_OPTION_VALUE];
} else {
newSelectedValues = value.filter(item => item !== ALL_OPTION_VALUE);
}

setSelectedValues(newSelectedValues);
if (props.onChange) {
props.onChange(newSelectedValues);
}
};

useEffect(() => {
if ('value' in props) {
setSelectedValues(props.value || []);
}
}, [props.value]);

return <HighSelect {...props} value={selectedValues} onChange={handleSelectChange} />;
};

export default MultiSelectWithALL;
3 changes: 2 additions & 1 deletion inlong-dashboard/src/ui/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"meta.Sources.File.ClusterName": "集群名称",
"meta.Sources.File.FilePath": "⽂件路径",
"meta.Sources.File.FilePathHelp": "必须是绝对路径,支持正则表达式,多个时以逗号分隔,如:/data/.*log",
"meta.Sources.File.IpRule": "请输入正确的IP地址",
"meta.Sources.File.FileIpHelp": "请选择文件采集节点 IP,若 IP 不固定请选择 All",
"meta.Sources.File.IpRule": "请输入正确的 IP 地址",
"meta.Sources.File.TimeOffset": "时间偏移量",
"meta.Sources.File.TimeOffsetHelp": "从文件的某个时间开始采集,'1m'表示1分钟之后,'-1m'表示1分钟之前,支持m(分钟),h(小时),d(天),空则从当前时间开始采集",
"meta.Sources.File.TimeOffsetRules": "只能包含数字和字母 m、h、d",
Expand Down
1 change: 1 addition & 0 deletions inlong-dashboard/src/ui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"meta.Sources.File.ClusterName": "Cluster name",
"meta.Sources.File.FilePath": "File path",
"meta.Sources.File.FilePathHelp": "Must be an absolute path and support regular expressions, such as: /data/.*log",
"meta.Sources.File.FileIpHelp": "Please select the file collection node IP. If the IP is not fixed, please select All",
"meta.Sources.File.IpRule": "Please enter the IP address correctly",
"meta.Sources.File.TimeOffset": "Time offset",
"meta.Sources.File.TimeOffsetHelp": "The file will be collected from a certain time,' 1m' means 1 minute later,' -1m' means 1 minute before, and m(minute), h(hour), d(day) are supported. If it is empty, the file will be collected from the current time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useRequest, useUpdateEffect } from '@/ui/hooks';
import { useTranslation } from 'react-i18next';
import { useDefaultMeta, useLoadMeta, SourceMetaType } from '@/plugins';
import request from '@/core/utils/request';
import { ALL_OPTION_VALUE } from '@/ui/components/MultiSelectWithAll';

export interface Props extends ModalProps {
// When editing, use the ID to call the interface for obtaining details
Expand Down Expand Up @@ -67,6 +68,7 @@ const Comp: React.FC<Props> = ({
const onOk = async () => {
const values = await form.validateFields();
const submitData = new Entity()?.stringify(values) || values;
submitData.agentIp = submitData.agentIp.join(',');
const isUpdate = Boolean(id);
if (isUpdate) {
submitData.id = id;
Expand Down
Loading