Restores debug/peer

This commit is contained in:
Ben 2024-03-26 10:31:49 +01:00
parent 05d28d1d0a
commit 8fcf351613
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
5 changed files with 39 additions and 28 deletions

View File

@ -30,20 +30,21 @@ namespace CodexPlugin
return Map(OnCodex(api => api.GetDebugInfoAsync()));
}
public CodexDebugPeerResponse GetDebugPeer(string peerId)
public DebugPeer GetDebugPeer(string peerId)
{
var http = Http();
var str = http.HttpGetString($"debug/peer/{peerId}");
// Cannot use openAPI: debug/peer endpoint is not specified there.
var endoint = GetEndpoint();
var str = endoint.HttpGetString($"debug/peer/{peerId}");
if (str.ToLowerInvariant() == "unable to find peer!")
{
return new CodexDebugPeerResponse
return new DebugPeer
{
IsPeerFound = false
};
}
var result = http.Deserialize<CodexDebugPeerResponse>(str);
var result = endoint.Deserialize<DebugPeer>(str);
result.IsPeerFound = true;
return result;
}
@ -117,7 +118,8 @@ namespace CodexPlugin
private T OnCodex<T>(Func<CodexApi, Task<T>> action)
{
var address = GetAddress();
var result = tools.CreateHttp().OnClient(client =>
var result = tools.CreateHttp(CheckContainerCrashed)
.OnClient(client =>
{
var api = new CodexApi(client);
api.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
@ -150,6 +152,13 @@ namespace CodexPlugin
// return tools.CreateHttp(GetAddress(), baseUrl: "/api/codex/v1", CheckContainerCrashed, new LongTimeSet(), Container.Name);
//}
private IEndpoint GetEndpoint()
{
return tools
.CreateHttp(CheckContainerCrashed)
.CreateEndpoint(GetAddress(), "/api/codex/v1/", Container.Name);
}
private Address GetAddress()
{
return Container.GetAddress(tools.GetLog(), CodexContainerRecipe.ApiPortTag);

View File

@ -46,7 +46,8 @@ namespace CodexPlugin
public class DebugPeer
{
public bool IsPeerFound { get; set; }
public string PeerId { get; set; } = string.Empty;
public string[] Addresses { get; set; } = Array.Empty<string>();
}
public class LocalDataset

View File

@ -31,6 +31,8 @@ namespace CodexTests.Helpers
private void AssertFullyConnected(ICodexNode[] nodes)
{
Log($"Asserting '{implementation.Description()}' for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'...");
Assert.That(nodes.Length, Is.GreaterThan(1));
var entries = CreateEntries(nodes);
var pairs = CreatePairs(entries);

View File

@ -26,12 +26,12 @@ namespace CodexTests.Helpers
public string ValidateEntry(Entry entry, Entry[] allEntries)
{
var result = string.Empty;
foreach (var peer in entry.Response.table.nodes)
foreach (var peer in entry.Response.Table.Nodes)
{
var expected = GetExpectedDiscoveryEndpoint(allEntries, peer);
if (expected != peer.address)
if (expected != peer.Address)
{
result += $"Node:{entry.Node.GetName()} has incorrect peer table entry. Was: '{peer.address}', expected: '{expected}'. ";
result += $"Node:{entry.Node.GetName()} has incorrect peer table entry. Was: '{peer.Address}', expected: '{expected}'. ";
}
}
return result;
@ -39,24 +39,24 @@ namespace CodexTests.Helpers
public PeerConnectionState Check(Entry from, Entry to)
{
var peerId = to.Response.id;
var peerId = to.Response.Id;
var response = from.Node.GetDebugPeer(peerId);
if (!response.IsPeerFound)
{
return PeerConnectionState.NoConnection;
}
if (!string.IsNullOrEmpty(response.peerId) && response.addresses.Any())
if (!string.IsNullOrEmpty(response.PeerId) && response.Addresses.Any())
{
return PeerConnectionState.Connection;
}
return PeerConnectionState.Unknown;
}
private static string GetExpectedDiscoveryEndpoint(Entry[] allEntries, CodexDebugTableNodeResponse node)
private static string GetExpectedDiscoveryEndpoint(Entry[] allEntries, DebugInfoTableNode node)
{
var peer = allEntries.SingleOrDefault(e => e.Response.table.localNode.peerId == node.peerId);
if (peer == null) return $"peerId: {node.peerId} is not known.";
var peer = allEntries.SingleOrDefault(e => e.Response.Table.LocalNode.PeerId == node.PeerId);
if (peer == null) return $"peerId: {node.PeerId} is not known.";
var container = peer.Node.Container;
var podInfo = peer.Node.GetPodInfo();

View File

@ -1,5 +1,4 @@
using CodexPlugin;
using NUnit.Framework;
using NUnit.Framework;
namespace CodexTests.PeerDiscoveryTests
{
@ -9,10 +8,10 @@ namespace CodexTests.PeerDiscoveryTests
[Test]
public void TwoLayersTest()
{
var root = Ci.StartCodexNode();
var l1Source = Ci.StartCodexNode(s => s.WithBootstrapNode(root));
var l1Node = Ci.StartCodexNode(s => s.WithBootstrapNode(root));
var l2Target = Ci.StartCodexNode(s => s.WithBootstrapNode(l1Node));
var root = AddCodex();
var l1Source = AddCodex(s => s.WithBootstrapNode(root));
var l1Node = AddCodex(s => s.WithBootstrapNode(root));
var l2Target = AddCodex(s => s.WithBootstrapNode(l1Node));
AssertAllNodesConnected();
}
@ -20,11 +19,11 @@ namespace CodexTests.PeerDiscoveryTests
[Test]
public void ThreeLayersTest()
{
var root = Ci.StartCodexNode();
var l1Source = Ci.StartCodexNode(s => s.WithBootstrapNode(root));
var l1Node = Ci.StartCodexNode(s => s.WithBootstrapNode(root));
var l2Node = Ci.StartCodexNode(s => s.WithBootstrapNode(l1Node));
var l3Target = Ci.StartCodexNode(s => s.WithBootstrapNode(l2Node));
var root = AddCodex();
var l1Source = AddCodex(s => s.WithBootstrapNode(root));
var l1Node = AddCodex(s => s.WithBootstrapNode(root));
var l2Node = AddCodex(s => s.WithBootstrapNode(l1Node));
var l3Target = AddCodex(s => s.WithBootstrapNode(l2Node));
AssertAllNodesConnected();
}
@ -34,10 +33,10 @@ namespace CodexTests.PeerDiscoveryTests
[TestCase(10)]
public void NodeChainTest(int chainLength)
{
var node = Ci.StartCodexNode();
var node = AddCodex();
for (var i = 1; i < chainLength; i++)
{
node = Ci.StartCodexNode(s => s.WithBootstrapNode(node));
node = AddCodex(s => s.WithBootstrapNode(node));
}
AssertAllNodesConnected();