Fixes pod logging for multiple codex nodes.

This commit is contained in:
benbierens 2023-03-22 13:52:01 +01:00
parent e9168dc168
commit 5ccc3f0177
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 30 additions and 20 deletions

View File

@ -39,7 +39,7 @@ namespace CodexDistTestCore
public OnlineCodexNode[] Nodes { get; }
public V1Deployment? Deployment { get; set; }
public V1Service? Service { get; set; }
public List<string> ActivePodNames { get; } = new List<string>();
public string? PodName { get; set; }
public CodexNodeContainer[] GetContainers()
{

View File

@ -50,29 +50,34 @@ namespace CodexDistTestCore
public void FetchAllPodsLogs(CodexNodeGroup[] onlines, IPodLogsHandler logHandler)
{
var logNumberSource = new NumberSource(0);
foreach (var online in onlines)
{
var nodeDescription = online.Describe();
foreach (var podName in online.ActivePodNames)
foreach (var node in online)
{
var stream = client.ReadNamespacedPodLog(podName, K8sNamespace);
logHandler.Log(online.OrderNumber, $"{nodeDescription}:{podName}", stream);
WritePodLogs(online, node, logHandler, logNumberSource);
}
}
}
private void WritePodLogs(CodexNodeGroup online, IOnlineCodexNode node, IPodLogsHandler logHandler, NumberSource logNumberSource)
{
var n = (OnlineCodexNode)node;
var nodeDescription = $"{online.Describe()} contains {n.GetName()}";
var stream = client.ReadNamespacedPodLog(online.PodName, K8sNamespace, n.Container.Name);
logHandler.Log(logNumberSource.GetNextNumber(), nodeDescription, stream);
}
private void AssignActivePodNames(CodexNodeGroup online)
{
var pods = client.ListNamespacedPod(K8sNamespace);
var podNames = pods.Items.Select(p => p.Name());
foreach (var podName in podNames)
{
if (!knownPods.Contains(podName))
{
knownPods.Add(podName);
online.ActivePodNames.Add(podName);
}
}
var newPodNames = podNames.Where(p => !knownPods.Contains(p)).ToArray();
Assert.That(newPodNames.Length, Is.EqualTo(1), "Expected only 1 pod to be created. Test infra failure.");
online.PodName = newPodNames.Single();
}
#region Waiting

View File

@ -27,10 +27,15 @@ namespace CodexDistTestCore
public CodexNodeContainer Container { get; }
public string GetName()
{
return $"<{Container.Name}>";
}
public CodexDebugResponse GetDebugInfo()
{
var response = Http().HttpGetJson<CodexDebugResponse>("debug/info");
Log($"Got DebugInfo with id: {response.id}.");
Log($"Got DebugInfo with id: '{response.id}'.");
return response;
}
@ -43,16 +48,16 @@ namespace CodexDistTestCore
{
Assert.Fail("Node failed to store block.");
}
Log($"Uploaded file. Received contentId: {response}.");
Log($"Uploaded file. Received contentId: '{response}'.");
return new ContentId(response);
}
public TestFile? DownloadContent(ContentId contentId)
{
Log($"Downloading for contentId: {contentId.Id}...");
Log($"Downloading for contentId: '{contentId.Id}'...");
var file = fileManager.CreateEmptyTestFile();
DownloadToFile(contentId.Id, file);
Log($"Downloaded file of size {file.GetFileSize()} to {file.Filename}.");
Log($"Downloaded file of size {file.GetFileSize()} to '{file.Filename}'.");
return file;
}
@ -60,7 +65,7 @@ namespace CodexDistTestCore
{
var peer = (OnlineCodexNode)node;
Log($"Connecting to peer <{peer.Container.Name}>...");
Log($"Connecting to peer {peer.GetName()}...");
var peerInfo = node.GetDebugInfo();
var peerId = peerInfo.id;
var peerMultiAddress = GetPeerMultiAddress(peer, peerInfo);
@ -68,7 +73,7 @@ namespace CodexDistTestCore
var response = Http().HttpGetString($"connect/{peerId}?addrs={peerMultiAddress}");
Assert.That(response, Is.EqualTo(SuccessfullyConnectedMessage), "Unable to connect codex nodes.");
Log($"Successfully connected to peer <{peer.Container.Name}>.");
Log($"Successfully connected to peer {peer.GetName()}.");
}
private string GetPeerMultiAddress(OnlineCodexNode peer, CodexDebugResponse peerInfo)
@ -93,7 +98,7 @@ namespace CodexDistTestCore
private void Log(string msg)
{
log.Log($"<{Container.Name}>: {msg}");
log.Log($"{GetName()}: {msg}");
}
}