restoring debug-info

This commit is contained in:
Ben 2024-03-26 08:58:16 +01:00
parent c122aa9910
commit b69059fd37
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
13 changed files with 59 additions and 30 deletions

View File

@ -9,14 +9,14 @@ namespace Core
{ {
public interface IHttp public interface IHttp
{ {
//string HttpGetString(string route); string HttpGetString(string route);
//T HttpGetJson<T>(string route); T HttpGetJson<T>(string route);
//TResponse HttpPostJson<TRequest, TResponse>(string route, TRequest body); TResponse HttpPostJson<TRequest, TResponse>(string route, TRequest body);
//string HttpPostJson<TRequest>(string route, TRequest body); string HttpPostJson<TRequest>(string route, TRequest body);
//TResponse HttpPostString<TResponse>(string route, string body); TResponse HttpPostString<TResponse>(string route, string body);
//string HttpPostStream(string route, Stream stream); string HttpPostStream(string route, Stream stream);
//Stream HttpGetStream(string route); Stream HttpGetStream(string route);
//T Deserialize<T>(string json); T Deserialize<T>(string json);
T OnClient<T>(Func<HttpClient, T> action); T OnClient<T>(Func<HttpClient, T> action);
} }

View File

@ -9,6 +9,7 @@ namespace CodexPlugin
public class CodexAccess : ILogHandler public class CodexAccess : ILogHandler
{ {
private readonly IPluginTools tools; private readonly IPluginTools tools;
private readonly Mapper mapper = new Mapper();
private bool hasContainerCrashed; private bool hasContainerCrashed;
public CodexAccess(IPluginTools tools, RunningContainer container, CrashWatcher crashWatcher) public CodexAccess(IPluginTools tools, RunningContainer container, CrashWatcher crashWatcher)
@ -24,9 +25,9 @@ namespace CodexPlugin
public RunningContainer Container { get; } public RunningContainer Container { get; }
public CrashWatcher CrashWatcher { get; } public CrashWatcher CrashWatcher { get; }
public CodexOpenApi.DebugInfo GetDebugInfo() public DebugInfo GetDebugInfo()
{ {
return OnCodex(api => api.GetDebugInfoAsync()); return Map(OnCodex(api => api.GetDebugInfoAsync()));
} }
public CodexDebugPeerResponse GetDebugPeer(string peerId) public CodexDebugPeerResponse GetDebugPeer(string peerId)
@ -108,6 +109,11 @@ namespace CodexPlugin
return workflow.GetPodInfo(Container); return workflow.GetPodInfo(Container);
} }
private dynamic Map(dynamic input)
{
return mapper.Map(input);
}
private T OnCodex<T>(Func<CodexApi, Task<T>> action) private T OnCodex<T>(Func<CodexApi, Task<T>> action)
{ {
var address = GetAddress(); var address = GetAddress();

View File

@ -31,14 +31,14 @@ namespace CodexPlugin
public class CodexInstance public class CodexInstance
{ {
public CodexInstance(RunningContainers containers, CodexDebugResponse info) public CodexInstance(RunningContainers containers, DebugInfo info)
{ {
Containers = containers; Containers = containers;
Info = info; Info = info;
} }
public RunningContainers Containers { get; } public RunningContainers Containers { get; }
public CodexDebugResponse Info { get; } public DebugInfo Info { get; }
} }
public class DeploymentMetadata public class DeploymentMetadata

View File

@ -20,7 +20,7 @@ namespace CodexPlugin
this.starter = starter; this.starter = starter;
Containers = containers; Containers = containers;
Nodes = containers.Containers().Select(c => CreateOnlineCodexNode(c, tools, codexNodeFactory)).ToArray(); Nodes = containers.Containers().Select(c => CreateOnlineCodexNode(c, tools, codexNodeFactory)).ToArray();
Version = new CodexDebugVersionResponse(); Version = new DebugVersion();
} }
public ICodexNode this[int index] public ICodexNode this[int index]
@ -41,7 +41,7 @@ namespace CodexPlugin
public RunningContainers[] Containers { get; private set; } public RunningContainers[] Containers { get; private set; }
public CodexNode[] Nodes { get; private set; } public CodexNode[] Nodes { get; private set; }
public CodexDebugVersionResponse Version { get; private set; } public DebugVersion Version { get; private set; }
public IMetricsScrapeTarget[] ScrapeTargets => Nodes.Select(n => n.MetricsScrapeTarget).ToArray(); public IMetricsScrapeTarget[] ScrapeTargets => Nodes.Select(n => n.MetricsScrapeTarget).ToArray();
public IEnumerator<ICodexNode> GetEnumerator() public IEnumerator<ICodexNode> GetEnumerator()
@ -65,7 +65,7 @@ namespace CodexPlugin
var versionResponses = Nodes.Select(n => n.Version); var versionResponses = Nodes.Select(n => n.Version);
var first = versionResponses.First(); var first = versionResponses.First();
if (!versionResponses.All(v => v.version == first.version && v.revision == first.revision)) if (!versionResponses.All(v => v.Version == first.Version && v.Revision == first.Revision))
{ {
throw new Exception("Inconsistent version information received from one or more Codex nodes: " + throw new Exception("Inconsistent version information received from one or more Codex nodes: " +
string.Join(",", versionResponses.Select(v => v.ToString()))); string.Join(",", versionResponses.Select(v => v.ToString())));

View File

@ -35,7 +35,7 @@
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet run -p $(ProjectDir)\..\CodexPluginPrebuild" /> <Exec Command="dotnet run --project $(ProjectDir)\..\CodexPluginPrebuild" />
</Target> </Target>
</Project> </Project>

View File

@ -75,7 +75,7 @@ namespace CodexPlugin
public ICodexSetup WithBootstrapNode(ICodexNode node) public ICodexSetup WithBootstrapNode(ICodexNode node)
{ {
BootstrapSpr = node.GetDebugInfo().spr; BootstrapSpr = node.GetDebugInfo().Spr;
return this; return this;
} }

View File

@ -9,7 +9,7 @@ namespace CodexPlugin
{ {
private readonly IPluginTools pluginTools; private readonly IPluginTools pluginTools;
private readonly CodexContainerRecipe recipe = new CodexContainerRecipe(); private readonly CodexContainerRecipe recipe = new CodexContainerRecipe();
private CodexDebugVersionResponse? versionResponse; private DebugVersion? versionResponse;
public CodexStarter(IPluginTools pluginTools) public CodexStarter(IPluginTools pluginTools)
{ {
@ -62,13 +62,13 @@ namespace CodexPlugin
public string GetCodexId() public string GetCodexId()
{ {
if (versionResponse != null) return versionResponse.version; if (versionResponse != null) return versionResponse.Version;
return recipe.Image; return recipe.Image;
} }
public string GetCodexRevision() public string GetCodexRevision()
{ {
if (versionResponse != null) return versionResponse.revision; if (versionResponse != null) return versionResponse.Revision;
return "unknown"; return "unknown";
} }

View File

@ -3,10 +3,14 @@
public class DebugInfo public class DebugInfo
{ {
public string[] Addrs { get; set; } = Array.Empty<string>(); public string[] Addrs { get; set; } = Array.Empty<string>();
public string Spr { get; set; } = string.Empty;
public string Id { get; set; } = string.Empty;
public string[] AnnounceAddresses { get; set; } = Array.Empty<string>();
} }
public class DebugPeer public class DebugPeer
{ {
public bool IsPeerFound { get; set; }
} }
@ -17,7 +21,8 @@
public class DebugVersion public class DebugVersion
{ {
public string Version { get; internal set; } = string.Empty;
public string Revision { get; internal set; } = string.Empty;
} }
public class ContentId public class ContentId

View File

@ -0,0 +1,18 @@
using Newtonsoft.Json.Linq;
namespace CodexPlugin
{
public class Mapper
{
public DebugInfo Map(CodexOpenApi.DebugInfo debugInfo)
{
return new DebugInfo
{
Id = debugInfo.Id,
Spr = debugInfo.Spr,
Addrs = debugInfo.Addrs.ToArray(),
AnnounceAddresses = ((JArray) debugInfo.AdditionalProperties["announceAddresses"]).Select(x => x.ToString()).ToArray(),
};
}
}
}

View File

@ -11,7 +11,7 @@ namespace CodexLongTests.BasicTests
{ {
var group = AddCodex(1000, s => s.EnableMetrics()); var group = AddCodex(1000, s => s.EnableMetrics());
var nodeIds = group.Select(n => n.GetDebugInfo().id).ToArray(); var nodeIds = group.Select(n => n.GetDebugInfo().Id).ToArray();
Assert.That(nodeIds.Length, Is.EqualTo(nodeIds.Distinct().Count()), Assert.That(nodeIds.Length, Is.EqualTo(nodeIds.Distinct().Count()),
"Not all created nodes provided a unique id."); "Not all created nodes provided a unique id.");
@ -24,7 +24,7 @@ namespace CodexLongTests.BasicTests
{ {
var n = AddCodex(); var n = AddCodex();
Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().id)); Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().Id));
} }
} }
} }

View File

@ -114,12 +114,12 @@ namespace CodexTests.Helpers
} }
public ICodexNode Node { get; } public ICodexNode Node { get; }
public CodexDebugResponse Response { get; } public DebugInfo Response { get; }
public override string ToString() public override string ToString()
{ {
if (Response == null || string.IsNullOrEmpty(Response.id)) return "UNKNOWN"; if (Response == null || string.IsNullOrEmpty(Response.Id)) return "UNKNOWN";
return Response.id; return Response.Id;
} }
} }

View File

@ -70,7 +70,7 @@ namespace CodexTests.PeerDiscoveryTests
} }
} }
private string AreAllPresent(CodexDebugResponse info, CodexDebugResponse[] allResponses) private string AreAllPresent(DebugInfo info, DebugInfo[] allResponses)
{ {
var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray(); var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray();
var allOthers = GetAllOtherResponses(info, allResponses); var allOthers = GetAllOtherResponses(info, allResponses);
@ -84,9 +84,9 @@ namespace CodexTests.PeerDiscoveryTests
return string.Empty; return string.Empty;
} }
private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses) private DebugInfo[] GetAllOtherResponses(DebugInfo exclude, DebugInfo[] allResponses)
{ {
return allResponses.Where(r => r.id != exclude.id).ToArray(); return allResponses.Where(r => r.Id != exclude.Id).ToArray();
} }
} }
} }

View File

@ -61,7 +61,7 @@ namespace CodexNetDeployer
}); });
var debugInfo = codexNode.GetDebugInfo(); var debugInfo = codexNode.GetDebugInfo();
if (!string.IsNullOrWhiteSpace(debugInfo.spr)) if (!string.IsNullOrWhiteSpace(debugInfo.Spr))
{ {
Console.Write("Online\t"); Console.Write("Online\t");