Allows downloading only log-tails.

This commit is contained in:
benbierens 2023-08-16 16:13:29 +02:00
parent 30364abf21
commit c8cb04d859
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
10 changed files with 52 additions and 30 deletions

View File

@ -55,7 +55,7 @@ namespace ContinuousTests
var appender = new LogAppender(filepath);
lifecycle.CodexStarter.DownloadLog(container, appender);
lifecycle.CodexStarter.DownloadLog(container, appender, null);
}
private static string GetLogName(RunningContainer container)

View File

@ -64,10 +64,10 @@ namespace DistTestCore
RunningGroups.Clear();
}
public void DownloadLog(RunningContainer container, ILogHandler logHandler)
public void DownloadLog(RunningContainer container, ILogHandler logHandler, int? tailLines)
{
var workflow = CreateWorkflow();
workflow.DownloadContainerLog(container, logHandler);
workflow.DownloadContainerLog(container, logHandler, tailLines);
}
private IMetricsAccessFactory CollectMetrics(CodexSetup codexSetup, RunningContainers[] containers)

View File

@ -25,7 +25,7 @@ namespace DistTestCore.Marketplace
WaitUntil(() =>
{
var logHandler = new ContractsReadyLogHandler(Debug);
workflow.DownloadContainerLog(container, logHandler);
workflow.DownloadContainerLog(container, logHandler, null);
return logHandler.Found;
});
Log("Contracts deployed. Extracting addresses...");

View File

@ -80,7 +80,7 @@ namespace DistTestCore.Marketplace
private string FetchPubKey()
{
var enodeFinder = new PubKeyFinder(s => log.Debug(s));
workflow.DownloadContainerLog(container, enodeFinder);
workflow.DownloadContainerLog(container, enodeFinder, null);
return enodeFinder.GetPubKey();
}

View File

@ -16,7 +16,7 @@ namespace DistTestCore
ContentId UploadFile(TestFile file);
TestFile? DownloadContent(ContentId contentId, string fileLabel = "");
void ConnectToPeer(IOnlineCodexNode node);
IDownloadedLog DownloadLog();
IDownloadedLog DownloadLog(int? tailLines = null);
IMetricsAccess Metrics { get; }
IMarketplaceAccess Marketplace { get; }
CodexDebugVersionResponse Version { get; }
@ -103,9 +103,9 @@ namespace DistTestCore
Log($"Successfully connected to peer {peer.GetName()}.");
}
public IDownloadedLog DownloadLog()
public IDownloadedLog DownloadLog(int? tailLines = null)
{
return lifecycle.DownloadLog(CodexAccess.Container);
return lifecycle.DownloadLog(CodexAccess.Container, tailLines);
}
public ICodexSetup BringOffline()

View File

@ -29,7 +29,7 @@ namespace DistTestCore
{
var config = "";
config += "global:\n";
config += " scrape_interval: 30s\n";
config += " scrape_interval: 10s\n";
config += " scrape_timeout: 10s\n";
config += "\n";
config += "scrape_configs:\n";

View File

@ -49,14 +49,14 @@ namespace DistTestCore
FileManager.DeleteAllTestFiles();
}
public IDownloadedLog DownloadLog(RunningContainer container)
public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
{
var subFile = Log.CreateSubfile();
var description = container.Name;
var handler = new LogDownloadHandler(container, description, subFile);
Log.Log($"Downloading logs for {description} to file '{subFile.FullFilename}'");
CodexStarter.DownloadLog(container, handler);
CodexStarter.DownloadLog(container, handler, tailLines);
return new DownloadedLog(subFile, description);
}

View File

@ -53,10 +53,10 @@ namespace KubernetesWorkflow
WaitUntilPodOffline(pod.PodInfo.Name);
}
public void DownloadPodLog(RunningPod pod, ContainerRecipe recipe, ILogHandler logHandler)
public void DownloadPodLog(RunningPod pod, ContainerRecipe recipe, ILogHandler logHandler, int? tailLines)
{
log.Debug();
using var stream = client.Run(c => c.ReadNamespacedPodLog(pod.PodInfo.Name, K8sTestNamespace, recipe.Name));
using var stream = client.Run(c => c.ReadNamespacedPodLog(pod.PodInfo.Name, K8sTestNamespace, recipe.Name, tailLines: tailLines));
logHandler.Log(stream);
}

View File

@ -50,11 +50,11 @@ namespace KubernetesWorkflow
});
}
public void DownloadContainerLog(RunningContainer container, ILogHandler logHandler)
public void DownloadContainerLog(RunningContainer container, ILogHandler logHandler, int? tailLines)
{
K8s(controller =>
{
controller.DownloadPodLog(container.Pod, container.Recipe, logHandler);
controller.DownloadPodLog(container.Pod, container.Recipe, logHandler, tailLines);
});
}

View File

@ -1,4 +1,5 @@
using DistTestCore;
using Logging;
using NUnit.Framework;
using Utils;
@ -61,12 +62,13 @@ namespace Tests.BasicTests
[Test]
public void HoldMyBeerTest()
{
var group = SetupCodexNodes(5, o => o
var blockExpirationTime = TimeSpan.FromMinutes(3);
var group = SetupCodexNodes(1, o => o
.EnableMetrics()
.WithBlockTTL(TimeSpan.FromMinutes(2))
.WithBlockMaintenanceInterval(TimeSpan.FromMinutes(5))
.WithBlockTTL(blockExpirationTime)
.WithBlockMaintenanceInterval(TimeSpan.FromMinutes(1))
.WithBlockMaintenanceNumber(10000)
.WithStorageQuota(1000.MB()));
.WithStorageQuota(2000.MB()));
var nodes = group.Cast<OnlineCodexNode>().ToArray();
@ -78,43 +80,63 @@ namespace Tests.BasicTests
var sizeInBytes = filesize.SizeInBytes;
Assert.That(numberOfBlocks, Is.EqualTo(1282));
var successfulUploads = 0;
var successfulDownloads = 0;
while (DateTime.UtcNow < endTime)
{
foreach (var node in nodes)
{
try
{
var uploadStartTime = DateTime.UtcNow;
var file = GenerateTestFile(filesize);
var cid = node.UploadFile(file);
var cidTag = cid.Id.Substring(cid.Id.Length - 6);
var uploadLog = node.DownloadLog();
Stopwatch.Measure(Get().Log, "upload-log-asserts", () =>
{
var uploadLog = node.DownloadLog(tailLines: 50000);
var storeLines = uploadLog.FindLinesThatContain("Stored data", "topics=\"codex node\"");
uploadLog.DeleteFile();
var storeLines = uploadLog.FindLinesThatContain("Stored data", "topics=\"codex node\"");
uploadLog.DeleteFile();
var storeLine = GetLineForCidTag(storeLines, cidTag);
AssertStoreLineContains(storeLine, numberOfBlocks, sizeInBytes);
var storeLine = GetLineForCidTag(storeLines, cidTag);
AssertStoreLineContains(storeLine, numberOfBlocks, sizeInBytes);
});
successfulUploads++;
var uploadTimeTaken = DateTime.UtcNow - uploadStartTime;
if (uploadTimeTaken >= blockExpirationTime.Subtract(TimeSpan.FromSeconds(10)))
{
Assert.Fail("Upload took too long. Blocks already expired.");
}
var dl = node.DownloadContent(cid);
file.AssertIsEqual(dl);
var downloadLog = node.DownloadLog();
var sentLines = downloadLog.FindLinesThatContain("Sent bytes", "topics=\"codex restapi\"");
downloadLog.DeleteFile();
Stopwatch.Measure(Get().Log, "download-log-asserts", () =>
{
var downloadLog = node.DownloadLog(tailLines: 50000);
var sentLine = GetLineForCidTag(sentLines, cidTag);
AssertSentLineContains(sentLine, sizeInBytes);
var sentLines = downloadLog.FindLinesThatContain("Sent bytes", "topics=\"codex restapi\"");
downloadLog.DeleteFile();
var sentLine = GetLineForCidTag(sentLines, cidTag);
AssertSentLineContains(sentLine, sizeInBytes);
});
successfulDownloads++;
}
catch
{
Log("Test failed. Delaying shut-down by 30 seconds to collect metrics.");
Log($"Test failed after {successfulUploads} successful uploads and {successfulDownloads} successful downloads");
Thread.Sleep(TimeSpan.FromSeconds(30));
throw;
}
}
Thread.Sleep(TimeSpan.FromSeconds(3));
Thread.Sleep(TimeSpan.FromSeconds(5));
}
}