Skip to content

Commit

Permalink
fix(console): logstash v3 updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tfan authored and tke-robot committed Aug 17, 2020
1 parent e977604 commit 2ceefc3
Show file tree
Hide file tree
Showing 15 changed files with 399 additions and 250 deletions.
5 changes: 0 additions & 5 deletions web/console/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ const commonRouterConfig: RouterConfig[] = [
title: '日志采集',
watchModule: ConsoleModuleEnum.LogAgent
},
{
url: '/tkestack/log/setting',
title: '日志组件',
watchModule: ConsoleModuleEnum.LogAgent
},
{
url: '/tkestack/persistent-event',
title: '事件持久化',
Expand Down
9 changes: 1 addition & 8 deletions web/console/helpers/urlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,7 @@ export const reduceK8sRestfulPath = (options: K8sRestfulPathOptions) => {
meshId
} = options;

/// #if project
//业务侧ns eg: cls-xxx-ns 需要去除前缀
if (namespace && !isSpetialNamespace) {
namespace = namespace.startsWith('global')
? namespace.split('-').splice(1).join('-')
: namespace.split('-').splice(2).join('-');
}
/// #endif
namespace = namespace.replace(new RegExp(`^${clusterId}-`), '');
let url: string = '';
let isAddon = resourceInfo.requestType && resourceInfo.requestType.addon ? resourceInfo.requestType.addon : false;

Expand Down
3 changes: 3 additions & 0 deletions web/console/src/modules/common/models/Namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export interface Namespace extends Identifiable {
/**命名空间 */
namespace?: string;

/** 用在业务侧的命名空间全名 */
namespaceValue?: string;

/**描述 */
description?: string;

Expand Down
13 changes: 8 additions & 5 deletions web/console/src/modules/logStash/actions/clusterActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { generateFetcherActionCreator } from '@tencent/qcloud-redux-fetcher';
import { generateQueryActionCreator } from '@tencent/qcloud-redux-query';

import { resourceConfig } from '../../../../config';
import {
Cluster, ClusterFilter, CreateResource, Resource, ResourceFilter, ResourceInfo
} from '../../common/models';
import { Cluster, ClusterFilter, CreateResource, Resource, ResourceFilter, ResourceInfo } from '../../common/models';
import { CommonAPI } from '../../common/webapi';
import * as ActionType from '../constants/ActionType';
import { FFReduxActionName } from '../constants/Config';
Expand Down Expand Up @@ -70,10 +68,15 @@ const fetchClusterActions = generateFetcherActionCreator({
let agents = await CommonAPI.fetchLogagents();
let clusterHasLogAgent = {};
for (let agent of agents.records) {
clusterHasLogAgent[agent.spec.clusterName] = agent.metadata.name;
clusterHasLogAgent[agent.spec.clusterName] = { name: agent.metadata.name, status: agent.status.phase };
}
for (let cluster of response.records) {
cluster.spec.logAgentName = clusterHasLogAgent[cluster.metadata.name];
let logagent = clusterHasLogAgent[cluster.metadata.name];
if (logagent) {
let { name, status } = logagent;
cluster.spec.logAgentName = name;
cluster.spec.logAgentStatus = status;
}
}

return response;
Expand Down
64 changes: 34 additions & 30 deletions web/console/src/modules/logStash/actions/editLogStashActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,19 @@ export const editLogStashActions = {

let { logStashEdit, route, clusterSelection } = getState();
let { containerFileNamespace, containerFileWorkloadType } = logStashEdit;
let { name } = clusterSelection[0].metadata;
let isCanFetchResourceList = containerFileNamespace && containerFileWorkloadType ? true : false;
dispatch(
resourceActions.applyFilter({
clusterId: name,
regionId: +route.queries['rid'],
namespace: containerFileNamespace,
workloadType: containerFileWorkloadType,
isCanFetchResourceList: isCanFetchResourceList
})
);
if (clusterSelection[0]) {
let { name } = clusterSelection[0].metadata;
let isCanFetchResourceList = containerFileNamespace && containerFileWorkloadType ? true : false;
dispatch(
resourceActions.applyFilter({
clusterId: name,
regionId: +route.queries['rid'],
namespace: containerFileNamespace,
workloadType: containerFileWorkloadType,
isCanFetchResourceList: isCanFetchResourceList
})
);
}
};
},

Expand All @@ -383,26 +385,28 @@ export const editLogStashActions = {

//拉取podList
let { logStashEdit, route, clusterSelection } = getState();
let { name } = clusterSelection[0].metadata;
const { containerFileNamespace, containerFileWorkload } = logStashEdit;
if (containerFileNamespace && containerFileWorkload) {
dispatch(
podActions.applyFilter({
namespace: containerFileNamespace,
clusterId: name,
regionId: +route.queries['rid'],
specificName: containerFileWorkload,
isCanFetchPodList: containerFileNamespace && containerFileWorkload ? true : false
})
);
} else {
dispatch(
podActions.fetch({
noCache: true
})
);
if (clusterSelection[0]) {
let { name } = clusterSelection[0].metadata;
const { containerFileNamespace, containerFileWorkload } = logStashEdit;
if (containerFileNamespace && containerFileWorkload) {
dispatch(
podActions.applyFilter({
namespace: containerFileNamespace,
clusterId: name,
regionId: +route.queries['rid'],
specificName: containerFileWorkload,
isCanFetchPodList: containerFileNamespace && containerFileWorkload ? true : false
})
);
} else {
dispatch(
podActions.fetch({
noCache: true
})
);
}
dispatch(editLogStashActions.initContainerFileContainerFilePaths());
}
dispatch(editLogStashActions.initContainerFileContainerFilePaths());
};
},

Expand Down
20 changes: 13 additions & 7 deletions web/console/src/modules/logStash/actions/namespaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ const fetchNamespaceListActions = generateFetcherActionCreator({
let agents = await CommonAPI.fetchLogagents();
let clusterHasLogAgent = {};
for (let agent of agents.records) {
clusterHasLogAgent[agent.spec.clusterName] = agent.metadata.name;
clusterHasLogAgent[agent.spec.clusterName] = { name: agent.metadata.name, status: agent.status.phase };
}
for (let ns of response.records) {
ns.cluster.spec.logAgentName = clusterHasLogAgent[ns.cluster.metadata.name];
let logagent = clusterHasLogAgent[ns.cluster.metadata.name];
if (logagent) {
let { name, status } = logagent;
ns.cluster.spec.logAgentName = name;
ns.cluster.spec.logAgentStatus = status;
}
}
}
return response;
Expand Down Expand Up @@ -59,15 +64,16 @@ const restActions = {
*/
autoSelectNamespaceForCreate: () => {
return async (dispatch: Redux.Dispatch, getState: GetState) => {
let { route } = getState();
let { route, namespaceList } = getState();
let urlParams = router.resolve(route);

//只有在创建状态下才需要帮用户选择默认选项
if (urlParams['mode'] === 'create') {
if (getState().namespaceList.data.recordCount) {
dispatch({ type: ActionType.SelectContainerFileNamespace, payload: 'default' });
if (namespaceList.data.recordCount) {
let namespace = namespaceList.data.records[0].namespace;
dispatch({ type: ActionType.SelectContainerFileNamespace, payload: namespace });
let containerLogsArr: ContainerLogs[] = cloneDeep(getState().logStashEdit.containerLogs);
containerLogsArr[0].namespaceSelection = 'default';
containerLogsArr[0].namespaceSelection = namespace;
dispatch({
type: ActionType.UpdateContainerLogs,
payload: containerLogsArr
Expand All @@ -76,7 +82,7 @@ const restActions = {
dispatch(
resourceActions.applyFilter({
clusterId: route.queries['clusterId'],
namespace: 'default',
namespace,
workloadType: 'deployment',
regionId: +route.queries['rid']
})
Expand Down
7 changes: 2 additions & 5 deletions web/console/src/modules/logStash/actions/workflowActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export const workflowActions = {
{
[OperationTrigger.Done]: (dispatch, getState) => {
let deleteLog = getState().inlineDeleteLog;
let { route, namespaceFliter } = getState();
let { route, namespaceSelection } = getState();
if (isSuccessWorkflow(deleteLog)) {
dispatch(
logActions.applyFilter({
clusterId: route.queries['clusterId'],
isClear: false,
namespace: namespaceFliter
namespace: namespaceSelection
})
);
dispatch(workflowActions.inlineDeleteLog.reset());
Expand Down Expand Up @@ -79,9 +79,6 @@ export const workflowActions = {
// 初始化flow
dispatch(workflowActions.modifyLogStash.reset());

//首页namespace重设
dispatch(namespaceActions.selectNamespace(''));

// 进行路由的跳转,回列表页
let newRouteQueies = JSON.parse(
JSON.stringify(Object.assign({}, route.queries, { stashName: undefined, namespace: undefined }))
Expand Down
28 changes: 17 additions & 11 deletions web/console/src/modules/logStash/components/EditLogStashPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
let { canCreate, tip, ifLogDaemonset } = isCanCreateLogStash(
clusterSelection[0],
logList.data.records,
isDaemonsetNormal
isDaemonsetNormal,
isOpenLogStash
);

/** 渲染日志类型 */
Expand Down Expand Up @@ -165,7 +166,7 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
</ExternalLink>
</Trans>
</Text>
{!isOpenLogStash && (
{!(clusterSelection && clusterSelection[0] && clusterSelection[0].spec.logAgentName || isOpenLogStash) && (
<Text theme="danger">
<Trans>
该集群未开启日志收集功能,
Expand Down Expand Up @@ -250,11 +251,11 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
</FormPanel.Item>
)}

<EditOriginContainerPanel />
<EditOriginContainerPanel isEdit={mode === 'update'} />

<EditOriginNodePanel />

<EditOriginContainerFilePanel />
<EditOriginContainerFilePanel isEdit={mode === 'update'} />

<EditConsumerPanel />
<FormPanel.Footer>
Expand Down Expand Up @@ -311,8 +312,10 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {

private async _handleSubmit(mode) {
let { actions, route, logStashEdit, clusterVersion, logSelection, clusterSelection } = this.props;
let { rid, clusterId } = route.queries;
// let { rid, clusterId } = route.queries;
let { rid } = route.queries;
let { logAgentName } = clusterSelection[0].spec;
let { name: clusterId } = clusterSelection[0].metadata;
let {
logStashName,
logMode,
Expand Down Expand Up @@ -353,7 +356,8 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
);

if (valResult) {
let { rid, clusterId } = route.queries;
// let { rid, clusterId } = route.queries;
let { rid } = route.queries;

let logResourceInfo = resourceConfig(clusterVersion)['logcs'];

Expand All @@ -377,12 +381,14 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
});
});
return {
namespace: containerLog.namespaceSelection,
namespace: containerLog.namespaceSelection.replace(new RegExp(`^${clusterId}-`), ''),
all_containers: containerLog.collectorWay === 'container',
workloads
};
}
);
// 按照v1.3的日志采集规范,指定容器只允许设置一个ns,这里要把namespace改写成这里指定的具体的ns,而不是kube-system
namespace = namespaces[0] && namespaces[0].namespace;
}
let containerLogInput: ContainerLogInput = {
container_log_input: {
Expand Down Expand Up @@ -461,7 +467,7 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
apiVersion: (logResourceInfo.group ? logResourceInfo.group + '/' : '') + logResourceInfo.version,
metadata: {
name: logStashName,
namespace
namespace: namespace.replace(new RegExp(`^${clusterId}-`), '')
},
spec: {
input: inputType,
Expand All @@ -485,13 +491,13 @@ export class EditLogStashPanel extends React.Component<RootProps, any> {
let resource: CreateResource = {
id: uuid(),
resourceInfo: logResourceInfo,
mode: mode === 'update' ? 'modify' : mode, //更新方式为put,不是patch,update对应的为patch,modify对应为put
namespace,
mode: mode === 'update' ? 'modify' : mode, // 更新方式为put,不是patch,update对应的为patch,modify对应为put
namespace: namespace.replace(new RegExp(`^${clusterId}-`), ''),
clusterId,
logAgentName,
jsonData,
isStrategic: false,
resourceIns: mode === 'update' ? logStashName : '' //更新的需要需要带上具体的name
resourceIns: mode === 'update' ? logStashName : '' // 更新的需要需要带上具体的name
};
actions.workflow.modifyLogStash.start([resource], +rid);
actions.workflow.modifyLogStash.perform();
Expand Down
Loading

0 comments on commit 2ceefc3

Please sign in to comment.