diff --git a/CodexDistTestCore/CodexNodeContainer.cs b/CodexDistTestCore/CodexNodeContainer.cs index fa0e348..4a1f239 100644 --- a/CodexDistTestCore/CodexNodeContainer.cs +++ b/CodexDistTestCore/CodexNodeContainer.cs @@ -2,7 +2,7 @@ { 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; ServicePort = servicePort; @@ -12,6 +12,7 @@ DiscoveryPort = discoveryPort; ListenPort = listenPort; DataDir = dataDir; + MetricsPort = metricsPort; } public string Name { get; } @@ -22,6 +23,7 @@ public int DiscoveryPort { get; } public int ListenPort { get; } public string DataDir { get; } + public int MetricsPort { get; } } public class CodexGroupNumberSource @@ -57,7 +59,7 @@ this.groupContainerFactory = groupContainerFactory; } - public CodexNodeContainer CreateNext() + public CodexNodeContainer CreateNext(OfflineCodexNodes offline) { var n = containerNameSource.GetNextNumber(); return new CodexNodeContainer( @@ -68,8 +70,15 @@ containerPortName: $"api-{n}", discoveryPort: 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; + } } } diff --git a/CodexDistTestCore/Config/CodexDockerImage.cs b/CodexDistTestCore/Config/CodexDockerImage.cs index 7cd938e..333ec0d 100644 --- a/CodexDistTestCore/Config/CodexDockerImage.cs +++ b/CodexDistTestCore/Config/CodexDockerImage.cs @@ -25,12 +25,12 @@ namespace CodexDistTestCore.Config { public List Result { get; } = new List(); - public void Create(OfflineCodexNodes node, CodexNodeContainer environment) + public void Create(OfflineCodexNodes node, CodexNodeContainer container) { - AddVar("API_PORT", environment.ApiPort.ToString()); - AddVar("DATA_DIR", environment.DataDir); - AddVar("DISC_PORT", environment.DiscoveryPort.ToString()); - AddVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{environment.ListenPort}"); + AddVar("API_PORT", container.ApiPort.ToString()); + AddVar("DATA_DIR", container.DataDir); + AddVar("DISC_PORT", container.DiscoveryPort.ToString()); + AddVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{container.ListenPort}"); if (node.BootstrapNode != null) { @@ -45,6 +45,11 @@ namespace CodexDistTestCore.Config { 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) diff --git a/CodexDistTestCore/K8sManager.cs b/CodexDistTestCore/K8sManager.cs index 22ec144..16a8cba 100644 --- a/CodexDistTestCore/K8sManager.cs +++ b/CodexDistTestCore/K8sManager.cs @@ -60,18 +60,18 @@ 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 result = new CodexNodeGroup(log, codexGroupNumberSource.GetNextCodexNodeGroupNumber(), offline, this, online); onlineCodexNodeGroups.Add(result); return result; } - private CodexNodeContainer[] CreateContainers(int number) + private CodexNodeContainer[] CreateContainers(OfflineCodexNodes offline) { var factory = new CodexNodeContainerFactory(codexGroupNumberSource); var containers = new List(); - 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(); } diff --git a/CodexDistTestCore/OfflineCodexNodes.cs b/CodexDistTestCore/OfflineCodexNodes.cs index 9092618..f5527af 100644 --- a/CodexDistTestCore/OfflineCodexNodes.cs +++ b/CodexDistTestCore/OfflineCodexNodes.cs @@ -6,6 +6,7 @@ IOfflineCodexNodes WithLogLevel(CodexLogLevel level); IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node); IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota); + IOfflineCodexNodes EnableMetrics(); ICodexNodeGroup BringOnline(); } @@ -34,12 +35,14 @@ public CodexLogLevel? LogLevel { get; private set; } public IOnlineCodexNode? BootstrapNode { get; private set; } public ByteSize? StorageQuota { get; private set; } + public bool MetricsEnabled { get; private set; } public OfflineCodexNodes(IK8sManager k8SManager, int numberOfNodes) { this.k8SManager = k8SManager; NumberOfNodes = numberOfNodes; Location = Location.Unspecified; + MetricsEnabled = false; } public ICodexNodeGroup BringOnline() @@ -71,6 +74,12 @@ return this; } + public IOfflineCodexNodes EnableMetrics() + { + MetricsEnabled = true; + return this; + } + public string Describe() { var args = string.Join(',', DescribeArgs()); diff --git a/LongTests/BasicTests/TestInfraTests.cs b/LongTests/BasicTests/TestInfraTests.cs index 1e2f62e..705b4fc 100644 --- a/LongTests/BasicTests/TestInfraTests.cs +++ b/LongTests/BasicTests/TestInfraTests.cs @@ -8,7 +8,9 @@ namespace LongTests.BasicTests [Test, UseLongTimeouts] 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(); diff --git a/Tests/BasicTests/SimpleTests.cs b/Tests/BasicTests/SimpleTests.cs index 01e671d..80d05b1 100644 --- a/Tests/BasicTests/SimpleTests.cs +++ b/Tests/BasicTests/SimpleTests.cs @@ -79,6 +79,17 @@ namespace Tests.BasicTests PerformTwoClientTest(primary, secondary); } + [Test] + public void MetricsExample() + { + var group = SetupCodexNodes(1) + .EnableMetrics() + .BringOnline(); + + var metrics = BeginGatheringMetrics(group); + + } + private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary) { primary.ConnectToPeer(secondary);