Moves log downloading to core.

This commit is contained in:
ThatBen 2023-09-14 15:26:46 +02:00
parent 0b67dc56bb
commit 7ef3f615e1
4 changed files with 26 additions and 16 deletions

View File

@ -8,16 +8,14 @@ using Utils;
namespace CodexPlugin
{
public interface IOnlineCodexNode
public interface IOnlineCodexNode : IHasContainer
{
string GetName();
RunningContainer Container { get; }
CodexDebugResponse GetDebugInfo();
CodexDebugPeerResponse GetDebugPeer(string peerId);
ContentId UploadFile(TrackedFile file);
TrackedFile? DownloadContent(ContentId contentId, string fileLabel = "");
void ConnectToPeer(IOnlineCodexNode node);
IDownloadedLog DownloadLog(int? tailLines = null);
CodexDebugVersionResponse Version { get; }
void BringOffline();
IMetricsScrapeTarget MetricsScrapeTarget { get; }
@ -109,15 +107,6 @@ namespace CodexPlugin
Log($"Successfully connected to peer {peer.GetName()}.");
}
public IDownloadedLog DownloadLog(int? tailLines = null)
{
var workflow = tools.CreateWorkflow();
var file = tools.GetLog().CreateSubfile();
var logHandler = new LogDownloadHandler(CodexAccess.GetName(), file);
workflow.DownloadContainerLog(CodexAccess.Container, logHandler);
return logHandler.DownloadLog();
}
public void BringOffline()
{
if (Group.Count() > 1) throw new InvalidOperationException("Codex-nodes that are part of a group cannot be " +

View File

@ -1,4 +1,6 @@
namespace Core
using KubernetesWorkflow;
namespace Core
{
public sealed class CoreInterface
{
@ -13,5 +15,24 @@
{
return entryPoint.GetPlugin<T>();
}
public IDownloadedLog DownloadLog(IHasContainer containerSource, int? tailLines = null)
{
return DownloadLog(containerSource.Container, tailLines);
}
public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
{
var workflow = entryPoint.Tools.CreateWorkflow();
var file = entryPoint.Tools.GetLog().CreateSubfile();
var logHandler = new LogDownloadHandler(container.Name, file);
workflow.DownloadContainerLog(container, logHandler, tailLines);
return logHandler.DownloadLog();
}
}
public interface IHasContainer
{
RunningContainer Container { get; }
}
}

View File

@ -160,7 +160,7 @@ namespace Tests.BasicTests
var cidTag = cid.Id.Substring(cid.Id.Length - 6);
Measure("upload-log-asserts", () =>
{
var uploadLog = node.DownloadLog(tailLines: 50000);
var uploadLog = Ci.DownloadLog(node, tailLines: 50000);
var storeLines = uploadLog.FindLinesThatContain("Stored data", "topics=\"codex node\"");
uploadLog.DeleteFile();
@ -181,7 +181,7 @@ namespace Tests.BasicTests
Measure("download-log-asserts", () =>
{
var downloadLog = node.DownloadLog(tailLines: 50000);
var downloadLog = Ci.DownloadLog(node, tailLines: 50000);
var sentLines = downloadLog.FindLinesThatContain("Sent bytes", "topics=\"codex restapi\"");
downloadLog.DeleteFile();

View File

@ -16,7 +16,7 @@ namespace Tests.BasicTests
primary.UploadFile(GenerateTestFile(5.MB()));
var log = primary.DownloadLog();
var log = Ci.DownloadLog(primary);
log.AssertLogContains("Uploaded file");
}