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
{
//string HttpGetString(string route);
//T HttpGetJson<T>(string route);
//TResponse HttpPostJson<TRequest, TResponse>(string route, TRequest body);
//string HttpPostJson<TRequest>(string route, TRequest body);
//TResponse HttpPostString<TResponse>(string route, string body);
//string HttpPostStream(string route, Stream stream);
//Stream HttpGetStream(string route);
//T Deserialize<T>(string json);
string HttpGetString(string route);
T HttpGetJson<T>(string route);
TResponse HttpPostJson<TRequest, TResponse>(string route, TRequest body);
string HttpPostJson<TRequest>(string route, TRequest body);
TResponse HttpPostString<TResponse>(string route, string body);
string HttpPostStream(string route, Stream stream);
Stream HttpGetStream(string route);
T Deserialize<T>(string json);
T OnClient<T>(Func<HttpClient, T> action);
}

View File

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

View File

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

View File

@ -20,7 +20,7 @@ namespace CodexPlugin
this.starter = starter;
Containers = containers;
Nodes = containers.Containers().Select(c => CreateOnlineCodexNode(c, tools, codexNodeFactory)).ToArray();
Version = new CodexDebugVersionResponse();
Version = new DebugVersion();
}
public ICodexNode this[int index]
@ -41,7 +41,7 @@ namespace CodexPlugin
public RunningContainers[] Containers { 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 IEnumerator<ICodexNode> GetEnumerator()
@ -65,7 +65,7 @@ namespace CodexPlugin
var versionResponses = Nodes.Select(n => n.Version);
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: " +
string.Join(",", versionResponses.Select(v => v.ToString())));

View File

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

View File

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

View File

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

View File

@ -3,10 +3,14 @@
public class DebugInfo
{
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 bool IsPeerFound { get; set; }
}
@ -17,7 +21,8 @@
public class DebugVersion
{
public string Version { get; internal set; } = string.Empty;
public string Revision { get; internal set; } = string.Empty;
}
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 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()),
"Not all created nodes provided a unique id.");
@ -24,7 +24,7 @@ namespace CodexLongTests.BasicTests
{
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 CodexDebugResponse Response { get; }
public DebugInfo Response { get; }
public override string ToString()
{
if (Response == null || string.IsNullOrEmpty(Response.id)) return "UNKNOWN";
return Response.id;
if (Response == null || string.IsNullOrEmpty(Response.Id)) return "UNKNOWN";
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 allOthers = GetAllOtherResponses(info, allResponses);
@ -84,9 +84,9 @@ namespace CodexTests.PeerDiscoveryTests
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();
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
if (!string.IsNullOrWhiteSpace(debugInfo.Spr))
{
Console.Write("Online\t");