Can enable metrics on codex node startup.

This commit is contained in:
benbierens 2023-03-27 10:27:08 +02:00
parent 8c16ae3385
commit 4fb0e7c281
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 48 additions and 12 deletions

View File

@ -2,7 +2,7 @@
{ {
public class CodexNodeContainer public class CodexNodeContainer
{ {
public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir) public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir, int metricsPort)
{ {
Name = name; Name = name;
ServicePort = servicePort; ServicePort = servicePort;
@ -12,6 +12,7 @@
DiscoveryPort = discoveryPort; DiscoveryPort = discoveryPort;
ListenPort = listenPort; ListenPort = listenPort;
DataDir = dataDir; DataDir = dataDir;
MetricsPort = metricsPort;
} }
public string Name { get; } public string Name { get; }
@ -22,6 +23,7 @@
public int DiscoveryPort { get; } public int DiscoveryPort { get; }
public int ListenPort { get; } public int ListenPort { get; }
public string DataDir { get; } public string DataDir { get; }
public int MetricsPort { get; }
} }
public class CodexGroupNumberSource public class CodexGroupNumberSource
@ -57,7 +59,7 @@
this.groupContainerFactory = groupContainerFactory; this.groupContainerFactory = groupContainerFactory;
} }
public CodexNodeContainer CreateNext() public CodexNodeContainer CreateNext(OfflineCodexNodes offline)
{ {
var n = containerNameSource.GetNextNumber(); var n = containerNameSource.GetNextNumber();
return new CodexNodeContainer( return new CodexNodeContainer(
@ -68,8 +70,15 @@
containerPortName: $"api-{n}", containerPortName: $"api-{n}",
discoveryPort: codexPortSource.GetNextNumber(), discoveryPort: codexPortSource.GetNextNumber(),
listenPort: codexPortSource.GetNextNumber(), listenPort: codexPortSource.GetNextNumber(),
dataDir: $"datadir{n}" dataDir: $"datadir{n}",
metricsPort: GetMetricsPort(offline)
); );
} }
private int GetMetricsPort(OfflineCodexNodes offline)
{
if (offline.MetricsEnabled) return codexPortSource.GetNextNumber();
return 0;
}
} }
} }

View File

@ -25,12 +25,12 @@ namespace CodexDistTestCore.Config
{ {
public List<V1EnvVar> Result { get; } = new List<V1EnvVar>(); public List<V1EnvVar> Result { get; } = new List<V1EnvVar>();
public void Create(OfflineCodexNodes node, CodexNodeContainer environment) public void Create(OfflineCodexNodes node, CodexNodeContainer container)
{ {
AddVar("API_PORT", environment.ApiPort.ToString()); AddVar("API_PORT", container.ApiPort.ToString());
AddVar("DATA_DIR", environment.DataDir); AddVar("DATA_DIR", container.DataDir);
AddVar("DISC_PORT", environment.DiscoveryPort.ToString()); AddVar("DISC_PORT", container.DiscoveryPort.ToString());
AddVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{environment.ListenPort}"); AddVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{container.ListenPort}");
if (node.BootstrapNode != null) if (node.BootstrapNode != null)
{ {
@ -45,6 +45,11 @@ namespace CodexDistTestCore.Config
{ {
AddVar("STORAGE_QUOTA", node.StorageQuota.SizeInBytes.ToString()!); AddVar("STORAGE_QUOTA", node.StorageQuota.SizeInBytes.ToString()!);
} }
if (node.MetricsEnabled)
{
AddVar("METRICS_ADDR", "0.0.0.0");
AddVar("METRICS_PORT", container.MetricsPort.ToString());
}
} }
private void AddVar(string key, string value) private void AddVar(string key, string value)

View File

@ -60,18 +60,18 @@
private CodexNodeGroup CreateOnlineCodexNodes(OfflineCodexNodes offline) private CodexNodeGroup CreateOnlineCodexNodes(OfflineCodexNodes offline)
{ {
var containers = CreateContainers(offline.NumberOfNodes); var containers = CreateContainers(offline);
var online = containers.Select(c => new OnlineCodexNode(log, fileManager, c)).ToArray(); var online = containers.Select(c => new OnlineCodexNode(log, fileManager, c)).ToArray();
var result = new CodexNodeGroup(log, codexGroupNumberSource.GetNextCodexNodeGroupNumber(), offline, this, online); var result = new CodexNodeGroup(log, codexGroupNumberSource.GetNextCodexNodeGroupNumber(), offline, this, online);
onlineCodexNodeGroups.Add(result); onlineCodexNodeGroups.Add(result);
return result; return result;
} }
private CodexNodeContainer[] CreateContainers(int number) private CodexNodeContainer[] CreateContainers(OfflineCodexNodes offline)
{ {
var factory = new CodexNodeContainerFactory(codexGroupNumberSource); var factory = new CodexNodeContainerFactory(codexGroupNumberSource);
var containers = new List<CodexNodeContainer>(); var containers = new List<CodexNodeContainer>();
for (var i = 0; i < number; i++) containers.Add(factory.CreateNext()); for (var i = 0; i < offline.NumberOfNodes; i++) containers.Add(factory.CreateNext(offline));
return containers.ToArray(); return containers.ToArray();
} }

View File

@ -6,6 +6,7 @@
IOfflineCodexNodes WithLogLevel(CodexLogLevel level); IOfflineCodexNodes WithLogLevel(CodexLogLevel level);
IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node); IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node);
IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota); IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota);
IOfflineCodexNodes EnableMetrics();
ICodexNodeGroup BringOnline(); ICodexNodeGroup BringOnline();
} }
@ -34,12 +35,14 @@
public CodexLogLevel? LogLevel { get; private set; } public CodexLogLevel? LogLevel { get; private set; }
public IOnlineCodexNode? BootstrapNode { get; private set; } public IOnlineCodexNode? BootstrapNode { get; private set; }
public ByteSize? StorageQuota { get; private set; } public ByteSize? StorageQuota { get; private set; }
public bool MetricsEnabled { get; private set; }
public OfflineCodexNodes(IK8sManager k8SManager, int numberOfNodes) public OfflineCodexNodes(IK8sManager k8SManager, int numberOfNodes)
{ {
this.k8SManager = k8SManager; this.k8SManager = k8SManager;
NumberOfNodes = numberOfNodes; NumberOfNodes = numberOfNodes;
Location = Location.Unspecified; Location = Location.Unspecified;
MetricsEnabled = false;
} }
public ICodexNodeGroup BringOnline() public ICodexNodeGroup BringOnline()
@ -71,6 +74,12 @@
return this; return this;
} }
public IOfflineCodexNodes EnableMetrics()
{
MetricsEnabled = true;
return this;
}
public string Describe() public string Describe()
{ {
var args = string.Join(',', DescribeArgs()); var args = string.Join(',', DescribeArgs());

View File

@ -8,7 +8,9 @@ namespace LongTests.BasicTests
[Test, UseLongTimeouts] [Test, UseLongTimeouts]
public void TestInfraShouldHave1000AddressSpacesPerPod() public void TestInfraShouldHave1000AddressSpacesPerPod()
{ {
var group = SetupCodexNodes(1000).BringOnline(); var group = SetupCodexNodes(1000)
.EnableMetrics() // Increases use of port address space per node.
.BringOnline();
var nodeIds = group.Select(n => n.GetDebugInfo().id).ToArray(); var nodeIds = group.Select(n => n.GetDebugInfo().id).ToArray();

View File

@ -79,6 +79,17 @@ namespace Tests.BasicTests
PerformTwoClientTest(primary, secondary); PerformTwoClientTest(primary, secondary);
} }
[Test]
public void MetricsExample()
{
var group = SetupCodexNodes(1)
.EnableMetrics()
.BringOnline();
var metrics = BeginGatheringMetrics(group);
}
private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary) private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
{ {
primary.ConnectToPeer(secondary); primary.ConnectToPeer(secondary);