-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create copy logs and download logs button
- Loading branch information
Showing
11 changed files
with
668 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useState } from "react";import streamsaver from "streamsaver"; | ||
import { useKurtosisClient } from "../../../client/enclaveManager/KurtosisClientContext"; | ||
import { EnclaveFullInfo } from "../../../emui/enclaves/types"; | ||
import { DownloadButton } from "../../CopyButton"; | ||
import {ServiceInfo} from "enclave-manager-sdk/build/api_container_service_pb"; | ||
import {isDefined, stripAnsi} from "../utils"; | ||
|
||
type DownloadLogsButtonProps = { | ||
enclave:EnclaveFullInfo, | ||
service?:ServiceInfo, | ||
}; | ||
|
||
export const DownloadLogsButton = ({ enclave, service }: DownloadLogsButtonProps) => { | ||
const kurtosisClient = useKurtosisClient(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [logLinesToDownload, setLogLinesToDownload] = useState(propsLogLines); | ||
|
||
const handleDownloadClick = async () => { | ||
setIsLoading(true); | ||
const abortController = new AbortController(); | ||
const writableStream = streamsaver.createWriteStream(logsFileName || "logs.txt"); | ||
const writer = writableStream.getWriter(); | ||
|
||
if (service) { | ||
console.log("pulling logs") | ||
for await (const lineGroup of await kurtosisClient.getServiceLogs(abortController, enclave, [service], false, 0, true)) { | ||
const lineGroupForService = lineGroup.serviceLogsByServiceUuid[service.serviceUuid]; | ||
if (!isDefined(lineGroupForService)) continue; | ||
const parsedLogLines = serviceLogLineToLogLineMessage(lineGroupForService.line, lineGroupForService.timestamp); | ||
console.log("writing logs") | ||
setLogLinesToDownload((logLinesToDownload) => [...logLinesToDownload, ...parsedLogLines]); | ||
} | ||
} else { | ||
setLogLinesToDownload(() => [...logLines]) | ||
} | ||
|
||
try { | ||
console.log("downloading logs") | ||
await writer.write(logLinesToDownload.map(({message}) => message) | ||
.filter(isDefined) | ||
.map(stripAnsi) | ||
.join("\n")); | ||
} catch(err) { | ||
console.error(err) | ||
} | ||
await writer.close(); | ||
console.log("finished downloading logs") | ||
setLogLinesToDownload(() => []) | ||
setIsLoading(false); | ||
}; | ||
|
||
return ( | ||
<CopyButton | ||
contentName={"logs"} | ||
valueToCopy={getLogsValue} | ||
size={"sm"} | ||
isDisabled={logLines.length === 0} | ||
isIconButton | ||
aria-label={"Copy logs"} | ||
color={"gray.100"} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useState } from "react";import streamsaver from "streamsaver"; | ||
import { useKurtosisClient } from "../client/enclaveManager/KurtosisClientContext"; | ||
import { EnclaveFullInfo } from "../emui/enclaves/types"; | ||
import { DownloadButton } from "./DownloadButton"; | ||
import {ServiceInfo} from "enclave-manager-sdk/build/api_container_service_pb"; | ||
import {isDefined, stripAnsi} from "../utils"; | ||
import {Timestamp} from "@bufbuild/protobuf/dist/esm"; | ||
import {LogLineMessage} from "./enclaves/logs/types"; | ||
import {DateTime} from "luxon"; | ||
|
||
type DownloadLogsButtonProps = { | ||
logsFileName:string, | ||
enclave:EnclaveFullInfo, | ||
service?: ServiceInfo, | ||
logsToDownload: LogLineMessage[]; | ||
}; | ||
|
||
export const DownloadLogsButton = ({ logsFileName, enclave, service, logsToDownload }: DownloadLogsButtonProps) => { | ||
const kurtosisClient = useKurtosisClient(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [logLinesToDownload, setLogLinesToDownload] = useState(logsToDownload); | ||
|
||
const serviceLogLineToLogLineMessage = (lines: string[], timestamp?: Timestamp): LogLineMessage[] => { | ||
return lines.map((line) => ({ | ||
message: line, | ||
timestamp: isDefined(timestamp) ? DateTime.fromJSDate(timestamp?.toDate()) : undefined, | ||
})); | ||
}; | ||
|
||
const handleDownloadClick = async () => { | ||
setIsLoading(true); | ||
const writableStream = streamsaver.createWriteStream(logsFileName || "logs.txt"); | ||
const writer = writableStream.getWriter(); | ||
|
||
if (service){ | ||
console.log("pulling logs") | ||
const abortController = new AbortController(); | ||
for await (const lineGroup of await kurtosisClient.getServiceLogs(abortController, enclave, [service], false, 0, true)) { | ||
const lineGroupForService = lineGroup.serviceLogsByServiceUuid[service.serviceUuid]; | ||
if (!isDefined(lineGroupForService)) continue; | ||
const parsedLogLines = serviceLogLineToLogLineMessage(lineGroupForService.line, lineGroupForService.timestamp); | ||
console.log("writing logs") | ||
setLogLinesToDownload((logLinesToDownload) => [...logLinesToDownload, ...parsedLogLines]); | ||
} | ||
|
||
try { | ||
console.log("downloading logs") | ||
await writer.write(logLinesToDownload.map(({message}) => message) | ||
.filter(isDefined) | ||
.map(stripAnsi) | ||
.join("\n")); | ||
} catch(err) { | ||
console.error(err) | ||
} | ||
await writer.close(); | ||
} | ||
|
||
|
||
if(logsToDownload) { | ||
|
||
} | ||
|
||
console.log("finished downloading logs") | ||
setIsLoading(false); | ||
}; | ||
|
||
const getLogsValue = () => { | ||
return logsToDownload | ||
.map(({ message }) => message) | ||
.filter(isDefined) | ||
.map(stripAnsi) | ||
.join("\n"); | ||
}; | ||
|
||
return ( | ||
<DownloadButton | ||
size={"sm"} | ||
fileName={logsFileName || `logs.txt`} | ||
isDisabled={logLinesToDownload.length === 0} | ||
isIconButton | ||
aria-label={"Download logs"} | ||
color={"gray.100"} | ||
isLoading={isLoading} | ||
onClick={handleDownloadClick()} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"files": { | ||
"main.js": "./static/js/main.d987c6a5.js", | ||
"main.js": "./static/js/main.61105ad3.js", | ||
"index.html": "./index.html", | ||
"main.d987c6a5.js.map": "./static/js/main.d987c6a5.js.map" | ||
"main.61105ad3.js.map": "./static/js/main.61105ad3.js.map" | ||
}, | ||
"entrypoints": [ | ||
"static/js/main.d987c6a5.js" | ||
"static/js/main.61105ad3.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Kurtosis Enclave Manager"/><title>Kurtosis Enclave Manager</title><script defer="defer" src="./static/js/main.d987c6a5.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html> | ||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Kurtosis Enclave Manager"/><title>Kurtosis Enclave Manager</title><script defer="defer" src="./static/js/main.61105ad3.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html> |
6 changes: 3 additions & 3 deletions
6
.../server/webapp/static/js/main.d987c6a5.js → .../server/webapp/static/js/main.61105ad3.js
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ver/webapp/static/js/main.d987c6a5.js.map → ...ver/webapp/static/js/main.61105ad3.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.