From ae7ab3d84bcb6fe1e584cedeb8b3c33c3e32cb8c Mon Sep 17 00:00:00 2001 From: ThatBen Date: Thu, 14 Sep 2023 15:30:09 +0200 Subject: [PATCH] Container simplify for metrics plugin --- MetricsPlugin/CoreInterfaceExtensions.cs | 4 ++-- MetricsPlugin/MetricsAccess.cs | 7 +++++-- MetricsPlugin/MetricsPlugin.cs | 6 +++--- MetricsPlugin/MetricsQuery.cs | 8 ++++---- MetricsPlugin/PrometheusStarter.cs | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/MetricsPlugin/CoreInterfaceExtensions.cs b/MetricsPlugin/CoreInterfaceExtensions.cs index 03ea973..46a7021 100644 --- a/MetricsPlugin/CoreInterfaceExtensions.cs +++ b/MetricsPlugin/CoreInterfaceExtensions.cs @@ -6,12 +6,12 @@ namespace MetricsPlugin { public static class CoreInterfaceExtensions { - public static RunningContainers StartMetricsCollector(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets) + public static RunningContainer StartMetricsCollector(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets) { return Plugin(ci).StartMetricsCollector(scrapeTargets); } - public static IMetricsAccess GetMetricsFor(this CoreInterface ci, RunningContainers metricsContainer, IMetricsScrapeTarget scrapeTarget) + public static IMetricsAccess GetMetricsFor(this CoreInterface ci, RunningContainer metricsContainer, IMetricsScrapeTarget scrapeTarget) { return Plugin(ci).CreateAccessForTarget(metricsContainer, scrapeTarget); } diff --git a/MetricsPlugin/MetricsAccess.cs b/MetricsPlugin/MetricsAccess.cs index aa172f9..ae6470c 100644 --- a/MetricsPlugin/MetricsAccess.cs +++ b/MetricsPlugin/MetricsAccess.cs @@ -1,8 +1,10 @@ -using Utils; +using Core; +using KubernetesWorkflow; +using Utils; namespace MetricsPlugin { - public interface IMetricsAccess + public interface IMetricsAccess : IHasContainer { string TargetName { get; } Metrics? GetAllMetrics(); @@ -23,6 +25,7 @@ namespace MetricsPlugin } public string TargetName { get; } + public RunningContainer Container => query.RunningContainer; public Metrics? GetAllMetrics() { diff --git a/MetricsPlugin/MetricsPlugin.cs b/MetricsPlugin/MetricsPlugin.cs index 09ad08c..0a7c7d0 100644 --- a/MetricsPlugin/MetricsPlugin.cs +++ b/MetricsPlugin/MetricsPlugin.cs @@ -31,14 +31,14 @@ namespace MetricsPlugin { } - public RunningContainers StartMetricsCollector(IMetricsScrapeTarget[] scrapeTargets) + public RunningContainer StartMetricsCollector(IMetricsScrapeTarget[] scrapeTargets) { return starter.CollectMetricsFor(scrapeTargets); } - public MetricsAccess CreateAccessForTarget(RunningContainers runningContainers, IMetricsScrapeTarget target) + public MetricsAccess CreateAccessForTarget(RunningContainer runningContainer, IMetricsScrapeTarget target) { - return starter.CreateAccessForTarget(runningContainers, target); + return starter.CreateAccessForTarget(runningContainer, target); } public LogFile? DownloadAllMetrics(IMetricsAccess metricsAccess, string targetName) diff --git a/MetricsPlugin/MetricsQuery.cs b/MetricsPlugin/MetricsQuery.cs index 8d75f20..425907e 100644 --- a/MetricsPlugin/MetricsQuery.cs +++ b/MetricsPlugin/MetricsQuery.cs @@ -8,13 +8,13 @@ namespace MetricsPlugin { private readonly Http http; - public MetricsQuery(IPluginTools tools, RunningContainers runningContainers) + public MetricsQuery(IPluginTools tools, RunningContainer runningContainer) { - RunningContainers = runningContainers; - http = tools.CreateHttp(runningContainers.Containers[0].Address, "api/v1"); + RunningContainer = runningContainer; + http = tools.CreateHttp(RunningContainer.Address, "api/v1"); } - public RunningContainers RunningContainers { get; } + public RunningContainer RunningContainer { get; } public Metrics? GetMostRecent(string metricName, IMetricsScrapeTarget target) { diff --git a/MetricsPlugin/PrometheusStarter.cs b/MetricsPlugin/PrometheusStarter.cs index 57b8b3e..b1b79a1 100644 --- a/MetricsPlugin/PrometheusStarter.cs +++ b/MetricsPlugin/PrometheusStarter.cs @@ -14,7 +14,7 @@ namespace MetricsPlugin this.tools = tools; } - public RunningContainers CollectMetricsFor(IMetricsScrapeTarget[] targets) + public RunningContainer CollectMetricsFor(IMetricsScrapeTarget[] targets) { Log($"Starting metrics server for {targets.Length} targets..."); var startupConfig = new StartupConfig(); @@ -25,10 +25,10 @@ namespace MetricsPlugin if (runningContainers.Containers.Length != 1) throw new InvalidOperationException("Expected only 1 Prometheus container to be created."); Log("Metrics server started."); - return runningContainers; + return runningContainers.Containers.Single(); } - public MetricsAccess CreateAccessForTarget(RunningContainers metricsContainer, IMetricsScrapeTarget target) + public MetricsAccess CreateAccessForTarget(RunningContainer metricsContainer, IMetricsScrapeTarget target) { var metricsQuery = new MetricsQuery(tools, metricsContainer); return new MetricsAccess(metricsQuery, target);