From d5e01ee547a97d506828962823cdaa6445869a18 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Mon, 21 Aug 2023 12:30:57 -0400 Subject: [PATCH] 20219: Make log service easier to test using interfaces Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- src/services/log-service/log-service.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/services/log-service/log-service.ts b/src/services/log-service/log-service.ts index f93a3f81..f36044f4 100644 --- a/src/services/log-service/log-service.ts +++ b/src/services/log-service/log-service.ts @@ -21,9 +21,9 @@ export class LogService extends CommonResourceService { super(serverApi, "logs", actions); } - async listLogFiles(containerRequest: ContainerRequestResource) { + async listLogFiles(containerRequest: Pick) { const request = await this.apiWebdavClient.propfind(`container_requests/${containerRequest.uuid}/log/${containerRequest.containerUuid}`); - if (request.responseXML != null) { + if (request?.responseXML != null) { return extractFilesData(request.responseXML) .filter((file) => ( file.path === `/arvados/v1/container_requests/${containerRequest.uuid}/log/${containerRequest.containerUuid}` @@ -32,14 +32,22 @@ export class LogService extends CommonResourceService { return Promise.reject(); } - async getLogFileContents(containerRequest: ContainerRequestResource, fileRecord: CollectionFile, startByte: number, endByte: number): Promise { + /** + * Fetches the specified log file contents from the given container request's container live logs endpoint + * @param containerRequest Container request to fetch logs for + * @param fileRecord Log file to fetch + * @param startByte First byte index of the log file to fetch + * @param endByte Last byte index to include in the response + * @returns A promise that resolves to the LogEventType and a string array of the log file contents + */ + async getLogFileContents(containerRequest: Pick, fileRecord: Pick, startByte: number, endByte: number): Promise { const request = await this.apiWebdavClient.get( `container_requests/${containerRequest.uuid}/log/${containerRequest.containerUuid}/${fileRecord.name}`, {headers: {Range: `bytes=${startByte}-${endByte}`}} ); const logFileType = logFileToLogType(fileRecord); - if (request.responseText && logFileType) { + if (request?.responseText && logFileType) { return { logType: logFileType, contents: request.responseText.split(/\r?\n/), @@ -50,4 +58,4 @@ export class LogService extends CommonResourceService { } } -export const logFileToLogType = (file: CollectionFile) => (file.name.replace(/\.(txt|json)$/, '') as LogEventType); +export const logFileToLogType = (file: Pick) => (file.name.replace(/\.(txt|json)$/, '') as LogEventType); -- 2.30.2