Test for detecting common log lines

This commit is contained in:
Ben 2024-04-25 10:25:12 +02:00
parent 899d775873
commit 0c700ded9d
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
2 changed files with 64 additions and 4 deletions

View File

@ -0,0 +1,61 @@
using CodexPlugin;
using NUnit.Framework;
using Utils;
namespace CodexTests.BasicTests
{
[TestFixture]
public class LogHelperTests : CodexDistTest
{
[Test]
public void FindMostCommonLogMessages()
{
var node = AddCodex(s => s.WithLogLevel(CodexLogLevel.Trace));
node.UploadFile(GenerateTestFile(1.GB()));
var map = GetLogMap(node).OrderByDescending(p => p.Value);
foreach (var entry in map)
{
Log($"'{entry.Key}' = {entry.Value}");
}
}
private Dictionary<string, int> GetLogMap(ICodexNode node)
{
var log = Ci.DownloadLog(node);
var map = new Dictionary<string, int>();
log.IterateLines(line =>
{
if (string.IsNullOrEmpty(line) ||
!line.Contains(" ") ||
!line.Contains("=") ||
line.Length < 34 ||
line[33] != ' '
) return;
// "INF 2024-04-14 10:40:50.042+00:00 Creating a private key and saving it tid=1 count=2"
var start = 34;
var msg = line.Substring(start);
// "Creating a private key and saving it tid=1 count=2"
var firstEqualSign = msg.IndexOf("=");
msg = msg.Substring(0, firstEqualSign);
// "Creating a private key and saving it tid"
var lastSpace = msg.LastIndexOf(" ");
msg = msg.Substring(0, lastSpace);
// "Creating a private key and saving it "
msg = msg.Trim();
// "Creating a private key and saving it"
if (map.ContainsKey(msg)) map[msg] += 1;
else map.Add(msg, 1);
});
return map;
}
}
}

View File

@ -1,5 +1,4 @@
using CodexPlugin;
using DistTestCore;
using NUnit.Framework;
using Utils;
@ -11,7 +10,7 @@ namespace CodexTests.BasicTests
[Test]
public void OneClientTest()
{
var primary = Ci.StartCodexNode();
var primary = AddCodex();
PerformOneClientTest(primary);
}
@ -19,11 +18,11 @@ namespace CodexTests.BasicTests
[Test]
public void RestartTest()
{
var primary = Ci.StartCodexNode();
var primary = AddCodex();
primary.Stop(waitTillStopped: true);
primary = Ci.StartCodexNode();
primary = AddCodex();
PerformOneClientTest(primary);
}