mirror of
https://github.com/codex-storage/cs-codex-dist-tests.git
synced 2025-02-03 07:43:52 +00:00
Fixes missing name and null events
This commit is contained in:
parent
87271f4f37
commit
9d9f65c5a3
@ -34,7 +34,7 @@ namespace Core
|
||||
entryPoint.Tools.GetLog().Log(msg);
|
||||
var logHandler = new WriteToFileLogHandler(entryPoint.Tools.GetLog(), msg);
|
||||
workflow.DownloadContainerLog(container, logHandler, tailLines);
|
||||
return new DownloadedLog(logHandler);
|
||||
return new DownloadedLog(logHandler, container.Name);
|
||||
}
|
||||
|
||||
public string ExecuteContainerCommand(IHasContainer containerSource, string command, params string[] args)
|
||||
|
@ -5,6 +5,8 @@ namespace Core
|
||||
{
|
||||
public interface IDownloadedLog
|
||||
{
|
||||
string ContainerName { get; }
|
||||
|
||||
void IterateLines(Action<string> action, params string[] thatContain);
|
||||
string[] GetLinesContaining(string expectedString);
|
||||
string[] FindLinesThatContain(params string[] tags);
|
||||
@ -16,10 +18,13 @@ namespace Core
|
||||
{
|
||||
private readonly LogFile logFile;
|
||||
|
||||
internal DownloadedLog(WriteToFileLogHandler logHandler)
|
||||
internal DownloadedLog(WriteToFileLogHandler logHandler, string containerName)
|
||||
{
|
||||
logFile = logHandler.LogFile;
|
||||
ContainerName = containerName;
|
||||
}
|
||||
|
||||
public string ContainerName { get; }
|
||||
|
||||
public void IterateLines(Action<string> action, params string[] thatContain)
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
{
|
||||
public ContainerRecipe(DateTime recipeCreatedUtc, int number, string? nameOverride, string image, ContainerResources resources, SchedulingAffinity schedulingAffinity, CommandOverride commandOverride, bool setCriticalPriority, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, ContainerAdditionals additionals)
|
||||
{
|
||||
RecipeCreatedUtc = recipeCreatedUtc;
|
||||
Number = number;
|
||||
NameOverride = nameOverride;
|
||||
Image = image;
|
||||
|
@ -19,7 +19,7 @@ namespace CodexPlugin.OverwatchSupport
|
||||
public void ProcessLog(IDownloadedLog log)
|
||||
{
|
||||
var peerId = DeterminPeerId(log);
|
||||
var runner = new ConversionRunner(writer, peerId);
|
||||
var runner = new ConversionRunner(writer, log.ContainerName, peerId);
|
||||
runner.Run(log);
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ namespace CodexPlugin.OverwatchSupport
|
||||
public class ConversionRunner
|
||||
{
|
||||
private readonly ITranscriptWriter writer;
|
||||
private readonly string name;
|
||||
private readonly string peerId;
|
||||
private readonly ILineConverter[] converters = new ILineConverter[]
|
||||
{
|
||||
@ -58,8 +59,9 @@ namespace CodexPlugin.OverwatchSupport
|
||||
new BootstrapLineConverter()
|
||||
};
|
||||
|
||||
public ConversionRunner(ITranscriptWriter writer, string peerId)
|
||||
public ConversionRunner(ITranscriptWriter writer, string name, string peerId)
|
||||
{
|
||||
this.name = name;
|
||||
this.writer = writer;
|
||||
this.peerId = peerId;
|
||||
}
|
||||
@ -79,10 +81,12 @@ namespace CodexPlugin.OverwatchSupport
|
||||
{
|
||||
var e = new OverwatchCodexEvent
|
||||
{
|
||||
Name = name,
|
||||
PeerId = peerId,
|
||||
};
|
||||
action(e);
|
||||
writer.Add(utc, e);
|
||||
|
||||
e.Write(utc, writer);
|
||||
}
|
||||
|
||||
private void ProcessLine(string line, ILineConverter converter)
|
||||
|
@ -23,11 +23,6 @@ namespace CodexPlugin.OverwatchSupport
|
||||
writer.AddHeader(CodexHeaderKey, CreateCodexHeader());
|
||||
|
||||
writer.Write(outputFilepath);
|
||||
|
||||
we need:
|
||||
total number of events
|
||||
min max utc, time range
|
||||
total number of codex nodes
|
||||
}
|
||||
|
||||
public ICodexNodeHooks CreateHooks(string nodeName)
|
||||
@ -59,6 +54,7 @@ namespace CodexPlugin.OverwatchSupport
|
||||
{
|
||||
writer.Add(DateTime.UtcNow, new OverwatchCodexEvent
|
||||
{
|
||||
Name = string.Empty,
|
||||
PeerId = string.Empty,
|
||||
ScenarioFinished = new ScenarioFinishedEvent
|
||||
{
|
||||
@ -102,7 +98,6 @@ namespace CodexPlugin.OverwatchSupport
|
||||
{
|
||||
e.NodeStarting = new NodeStartingEvent
|
||||
{
|
||||
Name = name,
|
||||
Image = image
|
||||
};
|
||||
});
|
||||
@ -162,11 +157,12 @@ namespace CodexPlugin.OverwatchSupport
|
||||
{
|
||||
var e = new OverwatchCodexEvent
|
||||
{
|
||||
Name = name,
|
||||
PeerId = peerId
|
||||
};
|
||||
action(e);
|
||||
|
||||
writer.Add(utc, e);
|
||||
e.Write(utc, writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
{
|
||||
public class BootstrapLineConverter : ILineConverter
|
||||
{
|
||||
private const string peerIdTag = "peerId: ";
|
||||
|
||||
public string Interest => "Starting codex node";
|
||||
|
||||
public void Process(CodexLogLine line, Action<Action<OverwatchCodexEvent>> addEvent)
|
||||
@ -48,17 +50,22 @@
|
||||
// )"
|
||||
|
||||
var config = line.Attributes["config"];
|
||||
var openIndex = config.IndexOf("peerId:") + 7;
|
||||
var closeIndex = config.IndexOf(",", openIndex);
|
||||
var bootPeerId = config.Substring(openIndex, closeIndex - openIndex);
|
||||
|
||||
addEvent(e =>
|
||||
|
||||
while (config.Contains(peerIdTag))
|
||||
{
|
||||
e.BootstrapConfig = new BootstrapConfigEvent
|
||||
var openIndex = config.IndexOf(peerIdTag) + peerIdTag.Length;
|
||||
var closeIndex = config.IndexOf(",", openIndex);
|
||||
var bootPeerId = config.Substring(openIndex, closeIndex - openIndex);
|
||||
config = config.Substring(closeIndex);
|
||||
|
||||
addEvent(e =>
|
||||
{
|
||||
BootstrapPeerId = bootPeerId
|
||||
};
|
||||
});
|
||||
e.BootstrapConfig = new BootstrapConfigEvent
|
||||
{
|
||||
BootstrapPeerId = bootPeerId
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace CodexPlugin.OverwatchSupport
|
||||
using OverwatchTranscript;
|
||||
|
||||
namespace CodexPlugin.OverwatchSupport
|
||||
{
|
||||
[Serializable]
|
||||
public class OverwatchCodexHeader
|
||||
@ -9,6 +11,7 @@
|
||||
[Serializable]
|
||||
public class OverwatchCodexEvent
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string PeerId { get; set; } = string.Empty;
|
||||
public ScenarioFinishedEvent? ScenarioFinished { get; set; }
|
||||
public NodeStartingEvent? NodeStarting { get; set; }
|
||||
@ -18,6 +21,23 @@
|
||||
public FileUploadedEvent? FileUploaded { get; set; }
|
||||
public FileDownloadedEvent? FileDownloaded { get; set; }
|
||||
public BlockReceivedEvent? BlockReceived { get; set; }
|
||||
|
||||
public void Write(DateTime utc, ITranscriptWriter writer)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name)) throw new Exception("Name required");
|
||||
if (AllNull()) throw new Exception("No event data was set");
|
||||
|
||||
writer.Add(utc, this);
|
||||
}
|
||||
|
||||
private bool AllNull()
|
||||
{
|
||||
var props = GetType()
|
||||
.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
|
||||
.Where(p => p.PropertyType != typeof(string)).ToArray();
|
||||
|
||||
return props.All(p => p.GetValue(this) == null);
|
||||
}
|
||||
}
|
||||
|
||||
#region Scenario Generated Events
|
||||
@ -32,7 +52,6 @@
|
||||
[Serializable]
|
||||
public class NodeStartingEvent
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Image { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ namespace OverwatchTranscript
|
||||
CheckClosed();
|
||||
var typeName = payload.GetType().FullName;
|
||||
if (string.IsNullOrEmpty(typeName)) throw new Exception("Empty typename for payload");
|
||||
if (utc == default) throw new Exception("DateTimeUtc not set");
|
||||
|
||||
var newEvent = new OverwatchEvent
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user