diff --git a/Framework/KubernetesWorkflow/RunningPod.cs b/Framework/KubernetesWorkflow/RunningPod.cs index 4eca6af..2ec7162 100644 --- a/Framework/KubernetesWorkflow/RunningPod.cs +++ b/Framework/KubernetesWorkflow/RunningPod.cs @@ -109,32 +109,6 @@ namespace KubernetesWorkflow } } - public class RunningPod - { - public RunningPod(K8sCluster cluster, PodInfo podInfo, string deploymentName, string serviceName, ContainerRecipePortMapEntry[] portMapEntries) - { - Cluster = cluster; - PodInfo = podInfo; - DeploymentName = deploymentName; - ServiceName = serviceName; - PortMapEntries = portMapEntries; - } - - public K8sCluster Cluster { get; } - public PodInfo PodInfo { get; } - public ContainerRecipePortMapEntry[] PortMapEntries { get; } - public string DeploymentName { get; } - public string ServiceName { get; } - - public Port[] GetServicePortsForContainerRecipe(ContainerRecipe containerRecipe) - { - return PortMapEntries - .Where(p => p.RecipeNumber == containerRecipe.Number) - .SelectMany(p => p.Ports) - .ToArray(); - } - } - public class ContainerRecipePortMapEntry { public ContainerRecipePortMapEntry(int recipeNumber, Port[] ports) diff --git a/ProjectPlugins/MetricsPlugin/MetricsAccess.cs b/ProjectPlugins/MetricsPlugin/MetricsAccess.cs index ae6470c..0f8ef01 100644 --- a/ProjectPlugins/MetricsPlugin/MetricsAccess.cs +++ b/ProjectPlugins/MetricsPlugin/MetricsAccess.cs @@ -21,7 +21,7 @@ namespace MetricsPlugin { this.query = query; this.target = target; - TargetName = target.Name; + TargetName = target.Container.Name; } public string TargetName { get; } diff --git a/ProjectPlugins/MetricsPlugin/MetricsQuery.cs b/ProjectPlugins/MetricsPlugin/MetricsQuery.cs index 3a5ad3f..ab94a81 100644 --- a/ProjectPlugins/MetricsPlugin/MetricsQuery.cs +++ b/ProjectPlugins/MetricsPlugin/MetricsQuery.cs @@ -122,7 +122,7 @@ namespace MetricsPlugin private string GetInstanceNameForNode(IMetricsScrapeTarget target) { - return target.Address.ToString(); + return ScrapeTargetHelper.FormatTarget(target); } private string GetInstanceStringForNode(IMetricsScrapeTarget target) @@ -148,7 +148,7 @@ namespace MetricsPlugin private void Log(IMetricsScrapeTarget target, string metricName, Metrics result) { - Log($"{target.Name} '{metricName}' = {result}"); + Log($"{target.Container.Name} '{metricName}' = {result}"); } private void Log(string metricName, Metrics result) @@ -158,7 +158,7 @@ namespace MetricsPlugin private void Log(IMetricsScrapeTarget target, Metrics result) { - Log($"{target.Name} => {result}"); + Log($"{target.Container.Name} => {result}"); } private void Log(string msg) diff --git a/ProjectPlugins/MetricsPlugin/MetricsScrapeTarget.cs b/ProjectPlugins/MetricsPlugin/MetricsScrapeTarget.cs index 84651c5..1913712 100644 --- a/ProjectPlugins/MetricsPlugin/MetricsScrapeTarget.cs +++ b/ProjectPlugins/MetricsPlugin/MetricsScrapeTarget.cs @@ -1,12 +1,11 @@ using KubernetesWorkflow; -using Utils; namespace MetricsPlugin { public interface IMetricsScrapeTarget { - string Name { get; } - Address Address { get; } + RunningContainer Container { get; } + string MetricsPortTag { get; } } public interface IHasMetricsScrapeTarget @@ -21,23 +20,13 @@ namespace MetricsPlugin public class MetricsScrapeTarget : IMetricsScrapeTarget { - public MetricsScrapeTarget(Address address, string name) + public MetricsScrapeTarget(RunningContainer container, string metricsPortTag) { - Address = address; - Name = name; + Container = container; + MetricsPortTag = metricsPortTag; } - public MetricsScrapeTarget(string ip, int port, string name) - : this(new Address("http://" + ip, port), name) - { - } - - public MetricsScrapeTarget(RunningContainer container, string portTag) - : this(container.GetAddress(portTag), container.Name) - { - } - - public string Name { get; } - public Address Address { get; } + public RunningContainer Container { get; } + public string MetricsPortTag { get; } } } diff --git a/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs b/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs index 8dfc341..a3605e8 100644 --- a/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs +++ b/ProjectPlugins/MetricsPlugin/PrometheusStarter.cs @@ -44,7 +44,7 @@ namespace MetricsPlugin tools.GetLog().Log(msg); } - private static string GeneratePrometheusConfig(IMetricsScrapeTarget[] targets) + private string GeneratePrometheusConfig(IMetricsScrapeTarget[] targets) { var config = ""; config += "global:\n"; @@ -59,11 +59,26 @@ namespace MetricsPlugin foreach (var target in targets) { - config += $" - '{target.Address.Host}:{target.Address.Port}'\n"; + config += $" - '{FormatTarget(target)}'\n"; } var bytes = Encoding.ASCII.GetBytes(config); return Convert.ToBase64String(bytes); } + + private string FormatTarget(IMetricsScrapeTarget target) + { + return ScrapeTargetHelper.FormatTarget(target); + } + } + + public static class ScrapeTargetHelper + { + public static string FormatTarget(IMetricsScrapeTarget target) + { + var a = target.Container.GetAddress(target.MetricsPortTag); + var host = a.Host.Replace("http://", "").Replace("https://", ""); + return $"{host}:{a.Port}"; + } } }