[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: {
type: 'string',
pattern: '^[a-zA-Z0-9_-]+$',
maxLength: 255,
},
version: {
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
const containerPorts = {};
if (ports) {
@ -203,7 +203,7 @@ const convertTaskDetail = async (taskStatus, ports, userName, jobName, taskRoleN
containerIp: taskStatus.attemptStatus.podHostIP,
containerPorts,
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,
...launcherConfig.enabledHived && {
hived: {
@ -225,14 +225,19 @@ const convertFrameworkDetail = async (framework) => {
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 diagnostics = completionStatus ? completionStatus.diagnostics : null;
const exitDiagnostics = generateExitDiagnostics(diagnostics);
const detail = {
debugId: framework.metadata.name,
name: decodeName(framework.metadata.name, framework.metadata.annotations),
name: jobName,
jobStatus: {
username: framework.metadata.labels ? framework.metadata.labels.userName : 'unknown',
username: userName,
state: convertState(
framework.status.state,
completionStatus ? completionStatus.code : null,
@ -266,7 +271,7 @@ const convertFrameworkDetail = async (framework) => {
appExitTriggerTaskRoleName: completionStatus && completionStatus.trigger ? completionStatus.trigger.taskRoleName : null,
appExitTriggerTaskIndex: completionStatus && completionStatus.trigger ? completionStatus.trigger.taskIndex : null,
appExitType: completionStatus ? completionStatus.type.name : null,
virtualCluster: framework.metadata.labels ? framework.metadata.labels.virtualCluster : 'unknown',
virtualCluster,
},
taskRoles: {},
};
@ -275,17 +280,12 @@ const convertFrameworkDetail = async (framework) => {
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) {
const taskStatuses = await Promise.all(taskRoleStatus.taskStatuses.map(
async (status) => await convertTaskDetail(
status,
ports[taskRoleStatus.name],
userName,
jobName,
taskRoleStatus.name
`${userName}/${logPathInfix || jobName}/${taskRoleStatus.name}`,
)
));
detail.taskRoles[taskRoleStatus.name] = {
@ -422,7 +422,7 @@ const generateTaskRole = (frameworkName, taskRole, jobInfo, frameworkEnvList, co
},
{
name: 'host-log',
subPath: `${jobInfo.userName}/${jobInfo.jobName}/${convertName(taskRole)}`,
subPath: `${jobInfo.userName}/${jobInfo.logPathInfix}/${convertName(taskRole)}`,
mountPath: '/usr/local/pai/logs',
},
{
@ -478,7 +478,7 @@ const generateTaskRole = (frameworkName, taskRole, jobInfo, frameworkEnvList, co
},
{
name: 'host-log',
subPath: `${jobInfo.userName}/${jobInfo.jobName}/${convertName(taskRole)}`,
subPath: `${jobInfo.userName}/${jobInfo.logPathInfix}/${convertName(taskRole)}`,
mountPath: '/usr/local/pai/logs',
},
{
@ -627,6 +627,7 @@ const generateFrameworkDescription = (frameworkName, virtualCluster, config, raw
jobName,
userName,
virtualCluster,
logPathInfix: `${encodeName(frameworkName)}`,
};
const frameworkDescription = {
apiVersion: launcherConfig.apiVersion,
@ -639,6 +640,7 @@ const generateFrameworkDescription = (frameworkName, virtualCluster, config, raw
},
annotations: {
jobName: jobInfo.jobName,
logPathInfix: jobInfo.logPathInfix,
config: protocolSecret.mask(rawConfig),
},
},