Example of setting codex log topics for libp2p and discv5

This commit is contained in:
benbierens 2023-10-07 09:48:12 +02:00
parent 092128d77b
commit 1a48c40ad7
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 41 additions and 11 deletions

View File

@ -11,11 +11,7 @@ namespace CodexPlugin
ICodexSetup At(ILocation location); ICodexSetup At(ILocation location);
ICodexSetup WithBootstrapNode(ICodexNode node); ICodexSetup WithBootstrapNode(ICodexNode node);
ICodexSetup WithLogLevel(CodexLogLevel level); ICodexSetup WithLogLevel(CodexLogLevel level);
/// <summary> ICodexSetup WithLogLevel(CodexLogLevel level, CodexLogCustomTopics customTopics);
/// Sets the log level for codex. The default level is INFO and the
/// log level is applied only to the supplied topics.
/// </summary>
ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics);
ICodexSetup WithStorageQuota(ByteSize storageQuota); ICodexSetup WithStorageQuota(ByteSize storageQuota);
ICodexSetup WithBlockTTL(TimeSpan duration); ICodexSetup WithBlockTTL(TimeSpan duration);
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration); ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
@ -28,6 +24,18 @@ namespace CodexPlugin
ICodexSetup WithSimulateProofFailures(uint failEveryNProofs); ICodexSetup WithSimulateProofFailures(uint failEveryNProofs);
} }
public class CodexLogCustomTopics
{
public CodexLogCustomTopics(CodexLogLevel discV5, CodexLogLevel libp2p)
{
DiscV5 = discV5;
Libp2p = libp2p;
}
public CodexLogLevel DiscV5 { get; set; }
public CodexLogLevel Libp2p { get; set; }
}
public class CodexSetup : CodexStartupConfig, ICodexSetup public class CodexSetup : CodexStartupConfig, ICodexSetup
{ {
public int NumberOfNodes { get; } public int NumberOfNodes { get; }
@ -61,10 +69,10 @@ namespace CodexPlugin
return this; return this;
} }
public ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics) public ICodexSetup WithLogLevel(CodexLogLevel level, CodexLogCustomTopics customTopics)
{ {
LogLevel = level; LogLevel = level;
LogTopics = topics; CustomTopics = customTopics;
return this; return this;
} }

View File

@ -8,7 +8,7 @@ namespace CodexPlugin
public string? NameOverride { get; set; } public string? NameOverride { get; set; }
public ILocation Location { get; set; } = KnownLocations.UnspecifiedLocation; public ILocation Location { get; set; } = KnownLocations.UnspecifiedLocation;
public CodexLogLevel LogLevel { get; set; } public CodexLogLevel LogLevel { get; set; }
public string[]? LogTopics { get; set; } public CodexLogCustomTopics? CustomTopics { get; set; }
public ByteSize? StorageQuota { get; set; } public ByteSize? StorageQuota { get; set; }
public bool MetricsEnabled { get; set; } public bool MetricsEnabled { get; set; }
public MarketplaceInitialConfig? MarketplaceConfig { get; set; } public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
@ -22,9 +22,30 @@ namespace CodexPlugin
public string LogLevelWithTopics() public string LogLevelWithTopics()
{ {
var level = LogLevel.ToString()!.ToUpperInvariant(); var level = LogLevel.ToString()!.ToUpperInvariant();
if (LogTopics != null && LogTopics.Count() > 0) if (CustomTopics != null)
{ {
level = $"INFO;{level}: {string.Join(",", LogTopics.Where(s => !string.IsNullOrEmpty(s)))}"; var discV5Topics = new[]
{
"discv5",
"providers",
"manager",
"cache",
};
var libp2pTopics = new[]
{
"libp2p",
"multistream",
"switch",
"transport",
"tcptransport",
"semaphore",
"asyncstreamwrapper",
"lpstream"
};
level = $"{level};" +
$"{CustomTopics.DiscV5.ToString()!.ToLowerInvariant()}:{string.Join(",", discV5Topics)};" +
$"{CustomTopics.Libp2p.ToString()!.ToLowerInvariant()}:{string.Join(",", libp2pTopics)}";
} }
return level; return level;
} }

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin; using CodexContractsPlugin;
using CodexPlugin;
using DistTestCore; using DistTestCore;
using GethPlugin; using GethPlugin;
using MetricsPlugin; using MetricsPlugin;
@ -13,7 +14,7 @@ namespace Tests.BasicTests
[Test] [Test]
public void CodexLogExample() public void CodexLogExample()
{ {
var primary = AddCodex(); var primary = AddCodex(s => s.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Warn, CodexLogLevel.Warn)));
primary.UploadFile(GenerateTestFile(5.MB())); primary.UploadFile(GenerateTestFile(5.MB()));