[Rest Server] Fix log path length (#4400)

Fix log path length, set job name length limit to 255.

Closes #4391.
This commit is contained in:
Yifan Xiong 2020-04-17 16:40:56 +08:00 коммит произвёл GitHub
Родитель 13bea1e062
Коммит 7b1247d087
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 16 добавлений и 13 удалений

Просмотреть файл

@ -34,6 +34,7 @@ const baseSchema = {
name: { name: {
type: 'string', type: 'string',
pattern: '^[a-zA-Z0-9_-]+$', pattern: '^[a-zA-Z0-9_-]+$',
maxLength: 255,
}, },
version: { version: {
type: ['string', 'number'], type: ['string', 'number'],

Просмотреть файл

@ -177,7 +177,7 @@ const convertFrameworkSummary = (framework) => {
}; };
}; };
const convertTaskDetail = async (taskStatus, ports, userName, jobName, taskRoleName) => { const convertTaskDetail = async (taskStatus, ports, logPathPrefix) => {
// get container ports // get container ports
const containerPorts = {}; const containerPorts = {};
if (ports) { if (ports) {
@ -203,7 +203,7 @@ const convertTaskDetail = async (taskStatus, ports, userName, jobName, taskRoleN
containerIp: taskStatus.attemptStatus.podHostIP, containerIp: taskStatus.attemptStatus.podHostIP,
containerPorts, containerPorts,
containerGpus, containerGpus,
containerLog: `http://${taskStatus.attemptStatus.podHostIP}:${process.env.LOG_MANAGER_PORT}/log-manager/tail/${userName}/${jobName}/${taskRoleName}/${taskStatus.attemptStatus.podUID}/`, containerLog: `http://${taskStatus.attemptStatus.podHostIP}:${process.env.LOG_MANAGER_PORT}/log-manager/tail/${logPathPrefix}/${taskStatus.attemptStatus.podUID}/`,
containerExitCode: completionStatus ? completionStatus.code : null, containerExitCode: completionStatus ? completionStatus.code : null,
...launcherConfig.enabledHived && { ...launcherConfig.enabledHived && {
hived: { hived: {
@ -225,14 +225,19 @@ const convertFrameworkDetail = async (framework) => {
attemptStatus.taskRoleStatuses = decompressField(attemptStatus.taskRoleStatusesCompressed); attemptStatus.taskRoleStatuses = decompressField(attemptStatus.taskRoleStatusesCompressed);
} }
const jobName = decodeName(framework.metadata.name, framework.metadata.annotations);
const userName = framework.metadata.labels ? framework.metadata.labels.userName : 'unknown';
const virtualCluster = framework.metadata.labels ? framework.metadata.labels.virtualCluster : 'unknown';
const logPathInfix = framework.metadata.annotations ? framework.metadata.annotations.logPathInfix : null;
const completionStatus = attemptStatus.completionStatus; const completionStatus = attemptStatus.completionStatus;
const diagnostics = completionStatus ? completionStatus.diagnostics : null; const diagnostics = completionStatus ? completionStatus.diagnostics : null;
const exitDiagnostics = generateExitDiagnostics(diagnostics); const exitDiagnostics = generateExitDiagnostics(diagnostics);
const detail = { const detail = {
debugId: framework.metadata.name, debugId: framework.metadata.name,
name: decodeName(framework.metadata.name, framework.metadata.annotations), name: jobName,
jobStatus: { jobStatus: {
username: framework.metadata.labels ? framework.metadata.labels.userName : 'unknown', username: userName,
state: convertState( state: convertState(
framework.status.state, framework.status.state,
completionStatus ? completionStatus.code : null, completionStatus ? completionStatus.code : null,
@ -266,7 +271,7 @@ const convertFrameworkDetail = async (framework) => {
appExitTriggerTaskRoleName: completionStatus && completionStatus.trigger ? completionStatus.trigger.taskRoleName : null, appExitTriggerTaskRoleName: completionStatus && completionStatus.trigger ? completionStatus.trigger.taskRoleName : null,
appExitTriggerTaskIndex: completionStatus && completionStatus.trigger ? completionStatus.trigger.taskIndex : null, appExitTriggerTaskIndex: completionStatus && completionStatus.trigger ? completionStatus.trigger.taskIndex : null,
appExitType: completionStatus ? completionStatus.type.name : null, appExitType: completionStatus ? completionStatus.type.name : null,
virtualCluster: framework.metadata.labels ? framework.metadata.labels.virtualCluster : 'unknown', virtualCluster,
}, },
taskRoles: {}, taskRoles: {},
}; };
@ -275,17 +280,12 @@ const convertFrameworkDetail = async (framework) => {
ports[taskRoleSpec.name] = taskRoleSpec.task.pod.metadata.annotations['rest-server/port-scheduling-spec']; ports[taskRoleSpec.name] = taskRoleSpec.task.pod.metadata.annotations['rest-server/port-scheduling-spec'];
} }
const userName = framework.metadata.labels ? framework.metadata.labels.userName : 'unknown';
const jobName = decodeName(framework.metadata.name, framework.metadata.annotations);
for (let taskRoleStatus of framework.status.attemptStatus.taskRoleStatuses) { for (let taskRoleStatus of framework.status.attemptStatus.taskRoleStatuses) {
const taskStatuses = await Promise.all(taskRoleStatus.taskStatuses.map( const taskStatuses = await Promise.all(taskRoleStatus.taskStatuses.map(
async (status) => await convertTaskDetail( async (status) => await convertTaskDetail(
status, status,
ports[taskRoleStatus.name], ports[taskRoleStatus.name],
userName, `${userName}/${logPathInfix || jobName}/${taskRoleStatus.name}`,
jobName,
taskRoleStatus.name
) )
)); ));
detail.taskRoles[taskRoleStatus.name] = { detail.taskRoles[taskRoleStatus.name] = {
@ -422,7 +422,7 @@ const generateTaskRole = (frameworkName, taskRole, jobInfo, frameworkEnvList, co
}, },
{ {
name: 'host-log', name: 'host-log',
subPath: `${jobInfo.userName}/${jobInfo.jobName}/${convertName(taskRole)}`, subPath: `${jobInfo.userName}/${jobInfo.logPathInfix}/${convertName(taskRole)}`,
mountPath: '/usr/local/pai/logs', mountPath: '/usr/local/pai/logs',
}, },
{ {
@ -478,7 +478,7 @@ const generateTaskRole = (frameworkName, taskRole, jobInfo, frameworkEnvList, co
}, },
{ {
name: 'host-log', name: 'host-log',
subPath: `${jobInfo.userName}/${jobInfo.jobName}/${convertName(taskRole)}`, subPath: `${jobInfo.userName}/${jobInfo.logPathInfix}/${convertName(taskRole)}`,
mountPath: '/usr/local/pai/logs', mountPath: '/usr/local/pai/logs',
}, },
{ {
@ -627,6 +627,7 @@ const generateFrameworkDescription = (frameworkName, virtualCluster, config, raw
jobName, jobName,
userName, userName,
virtualCluster, virtualCluster,
logPathInfix: `${encodeName(frameworkName)}`,
}; };
const frameworkDescription = { const frameworkDescription = {
apiVersion: launcherConfig.apiVersion, apiVersion: launcherConfig.apiVersion,
@ -639,6 +640,7 @@ const generateFrameworkDescription = (frameworkName, virtualCluster, config, raw
}, },
annotations: { annotations: {
jobName: jobInfo.jobName, jobName: jobInfo.jobName,
logPathInfix: jobInfo.logPathInfix,
config: protocolSecret.mask(rawConfig), config: protocolSecret.mask(rawConfig),
}, },
}, },