From ea66b5b4084faa72f69aae7fe0f2c42cf06b9a01 Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 7 Nov 2023 12:02:17 +0100 Subject: [PATCH] debugging address selection in cluster --- .../KubernetesWorkflow/RunningContainers.cs | 16 +++++++++++----- .../CodexContractsContainerRecipe.cs | 3 ++- ProjectPlugins/CodexPlugin/CodexAccess.cs | 2 +- ProjectPlugins/GethPlugin/GethNode.cs | 2 +- ProjectPlugins/MetricsPlugin/MetricsQuery.cs | 4 ++-- .../MetricsPlugin/PrometheusStarter.cs | 7 ++++--- Tests/CodexContinuousTests/StartupChecker.cs | 2 +- Tests/DistTestCore/Configuration.cs | 2 +- 8 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Framework/KubernetesWorkflow/RunningContainers.cs b/Framework/KubernetesWorkflow/RunningContainers.cs index 0410aed..2a9a50e 100644 --- a/Framework/KubernetesWorkflow/RunningContainers.cs +++ b/Framework/KubernetesWorkflow/RunningContainers.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Logging; +using Newtonsoft.Json; using Utils; namespace KubernetesWorkflow @@ -46,20 +47,24 @@ namespace KubernetesWorkflow [JsonIgnore] public RunningContainers RunningContainers { get; internal set; } = null!; - public Address GetAddress(string portTag) + public Address GetAddress(ILog log, string portTag) { var addresses = Addresses.Where(a => a.PortTag == portTag).ToArray(); if (!addresses.Any()) throw new Exception("No addresses found for portTag: " + portTag); var location = RunningContainers.StartResult.RunnerLocation; + ContainerAddress select = null!; if (location == RunnerLocation.InternalToCluster) { - return addresses.Single(a => a.IsInteral).Address; + select = addresses.Single(a => a.IsInteral); } else { - return addresses.Single(a => !a.IsInteral).Address; + select = addresses.Single(a => !a.IsInteral); } + + log.Log($"Container '{Name}' selected for tag '{portTag}' address: '{select}'"); + return select.Address; } public Address GetInternalAddress(string portTag) @@ -84,7 +89,8 @@ namespace KubernetesWorkflow public override string ToString() { - return $"{PortTag} -> '{Address}'"; + var indicator = IsInteral ? "int" : "ext"; + return $"{indicator} {PortTag} -> '{Address}'"; } } diff --git a/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs b/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs index 36ca448..26d6461 100644 --- a/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs +++ b/ProjectPlugins/CodexContractsPlugin/CodexContractsContainerRecipe.cs @@ -1,5 +1,6 @@ using GethPlugin; using KubernetesWorkflow; +using Logging; namespace CodexContractsPlugin { @@ -17,7 +18,7 @@ namespace CodexContractsPlugin { var config = startupConfig.Get(); - var address = config.GethNode.StartResult.Container.GetAddress(GethContainerRecipe.HttpPortTag); + var address = config.GethNode.StartResult.Container.GetAddress(new ConsoleLog(), GethContainerRecipe.HttpPortTag); AddEnvVar("DISTTEST_NETWORK_URL", address.ToString()); AddEnvVar("HARDHAT_NETWORK", "codexdisttestnetwork"); diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index a50c902..90d0dda 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -115,7 +115,7 @@ namespace CodexPlugin private Address GetAddress() { - return Container.GetAddress(CodexContainerRecipe.ApiPortTag); + return Container.GetAddress(tools.GetLog(), CodexContainerRecipe.ApiPortTag); } private void CheckContainerCrashed(HttpClient client) diff --git a/ProjectPlugins/GethPlugin/GethNode.cs b/ProjectPlugins/GethPlugin/GethNode.cs index b08a1e0..2e6a30b 100644 --- a/ProjectPlugins/GethPlugin/GethNode.cs +++ b/ProjectPlugins/GethPlugin/GethNode.cs @@ -71,7 +71,7 @@ namespace GethPlugin private NethereumInteraction StartInteraction() { - var address = StartResult.Container.GetAddress(GethContainerRecipe.HttpPortTag); + var address = StartResult.Container.GetAddress(log, GethContainerRecipe.HttpPortTag); var account = StartResult.Account; var creator = new NethereumInteractionCreator(log, address.Host, address.Port, account.PrivateKey); diff --git a/ProjectPlugins/MetricsPlugin/MetricsQuery.cs b/ProjectPlugins/MetricsPlugin/MetricsQuery.cs index ab94a81..62a0553 100644 --- a/ProjectPlugins/MetricsPlugin/MetricsQuery.cs +++ b/ProjectPlugins/MetricsPlugin/MetricsQuery.cs @@ -13,8 +13,8 @@ namespace MetricsPlugin public MetricsQuery(IPluginTools tools, RunningContainer runningContainer) { RunningContainer = runningContainer; - http = tools.CreateHttp(RunningContainer.GetAddress(PrometheusContainerRecipe.PortTag), "api/v1"); log = tools.GetLog(); + http = tools.CreateHttp(RunningContainer.GetAddress(log, PrometheusContainerRecipe.PortTag), "api/v1"); } public RunningContainer RunningContainer { get; } @@ -122,7 +122,7 @@ namespace MetricsPlugin private string GetInstanceNameForNode(IMetricsScrapeTarget target) { - return ScrapeTargetHelper.FormatTarget(target); + return ScrapeTargetHelper.FormatTarget(log, target); } private string GetInstanceStringForNode(IMetricsScrapeTarget target) diff --git a/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs b/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs index 15413ff..6c04c72 100644 --- a/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs +++ b/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs @@ -1,5 +1,6 @@ using Core; using KubernetesWorkflow; +using Logging; using System.Text; namespace MetricsPlugin @@ -68,15 +69,15 @@ namespace MetricsPlugin private string FormatTarget(IMetricsScrapeTarget target) { - return ScrapeTargetHelper.FormatTarget(target); + return ScrapeTargetHelper.FormatTarget(tools.GetLog(), target); } } public static class ScrapeTargetHelper { - public static string FormatTarget(IMetricsScrapeTarget target) + public static string FormatTarget(ILog log, IMetricsScrapeTarget target) { - var a = target.Container.GetAddress(target.MetricsPortTag); + var a = target.Container.GetAddress(log, target.MetricsPortTag); var host = a.Host.Replace("http://", "").Replace("https://", ""); return $"{host}:{a.Port}"; } diff --git a/Tests/CodexContinuousTests/StartupChecker.cs b/Tests/CodexContinuousTests/StartupChecker.cs index bc629ba..cb7c6ce 100644 --- a/Tests/CodexContinuousTests/StartupChecker.cs +++ b/Tests/CodexContinuousTests/StartupChecker.cs @@ -92,7 +92,7 @@ namespace ContinuousTests { cancelToken.ThrowIfCancellationRequested(); - var address = n.Container.GetAddress(CodexContainerRecipe.ApiPortTag); + var address = n.Container.GetAddress(log, CodexContainerRecipe.ApiPortTag); log.Log($"Checking {n.Container.Name} @ '{address}'..."); if (EnsureOnline(log, n)) diff --git a/Tests/DistTestCore/Configuration.cs b/Tests/DistTestCore/Configuration.cs index 35b9823..679264f 100644 --- a/Tests/DistTestCore/Configuration.cs +++ b/Tests/DistTestCore/Configuration.cs @@ -14,7 +14,7 @@ namespace DistTestCore { kubeConfigFile = GetNullableEnvVarOrDefault("KUBECONFIG", null); logPath = GetEnvVarOrDefault("LOGPATH", "CodexTestLogs"); - logDebug = GetEnvVarOrDefault("LOGDEBUG", "false").ToLowerInvariant() == "true"; + logDebug = true;// GetEnvVarOrDefault("LOGDEBUG", "false").ToLowerInvariant() == "true"; dataFilesPath = GetEnvVarOrDefault("DATAFILEPATH", "TestDataFiles"); }