From 5ddec99114792ddb4a3ebd4086e107e88b3f26df Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 8 Aug 2024 10:24:16 +0200 Subject: [PATCH] ensures long-ids for transcript events --- .../OverwatchSupport/CodexLogConverter.cs | 28 +++++++++++++++++-- .../CodexPlugin/OverwatchSupport/NameIdMap.cs | 13 +++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs index 23fa642..8f87eff 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs @@ -19,7 +19,7 @@ namespace CodexPlugin.OverwatchSupport public void ProcessLog(IDownloadedLog log) { var peerId = DeterminPeerId(log); - var runner = new ConversionRunner(writer, log.ContainerName, peerId); + var runner = new ConversionRunner(writer, nameIdMap, log.ContainerName, peerId); runner.Run(log); } @@ -51,6 +51,7 @@ namespace CodexPlugin.OverwatchSupport public class ConversionRunner { private readonly ITranscriptWriter writer; + private readonly NameIdMap nameIdMap; private readonly string name; private readonly string peerId; private readonly ILineConverter[] converters = new ILineConverter[] @@ -61,10 +62,11 @@ namespace CodexPlugin.OverwatchSupport new PeerDroppedLineConverter() }; - public ConversionRunner(ITranscriptWriter writer, string name, string peerId) + public ConversionRunner(ITranscriptWriter writer, NameIdMap nameIdMap, string name, string peerId) { this.name = name; this.writer = writer; + this.nameIdMap = nameIdMap; this.peerId = peerId; } @@ -96,13 +98,35 @@ namespace CodexPlugin.OverwatchSupport if (!line.Contains(converter.Interest)) return; var codexLine = CodexLogLine.Parse(line); + if (codexLine == null) throw new Exception("Unable to parse required line"); + EnsureFullIds(codexLine); converter.Process(codexLine, (action) => { AddEvent(codexLine.TimestampUtc, action); }); } + + private void EnsureFullIds(CodexLogLine codexLine) + { + // The issue is: node IDs occure both in full and short version. + // Downstream tools will assume that a node ID string-equals its own ID. + // So we replace all shortened IDs we can find with their full ones. + + // Usually, the shortID appears as the entire string of an attribute: + // "peerId=123*567890" + // But sometimes, it is part of a larger string: + // "thing=abc:123*567890,def" + + foreach (var pair in codexLine.Attributes) + { + if (pair.Value.Contains("*")) + { + codexLine.Attributes[pair.Key] = nameIdMap.ReplaceShortIds(pair.Value); + } + } + } } public interface ILineConverter diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/NameIdMap.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/NameIdMap.cs index 768fefa..091c8d8 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/NameIdMap.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/NameIdMap.cs @@ -3,10 +3,13 @@ public class NameIdMap { private readonly Dictionary map = new Dictionary(); + private readonly Dictionary shortToLong = new Dictionary(); public void Add(string name, string peerId) { map.Add(name, peerId); + + shortToLong.Add(CodexUtils.ToShortId(peerId), peerId); } public string GetPeerId(string name) @@ -14,6 +17,16 @@ return map[name]; } + public string ReplaceShortIds(string value) + { + var result = value; + foreach (var pair in shortToLong) + { + result = result.Replace(pair.Key, pair.Value); + } + return result; + } + public int Size { get { return map.Count; }