Container simplify for metrics plugin

This commit is contained in:
ThatBen 2023-09-14 15:30:09 +02:00
parent 7ef3f615e1
commit ae7ab3d84b
5 changed files with 17 additions and 14 deletions

View File

@ -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);
}

View File

@ -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()
{

View File

@ -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)

View File

@ -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)
{

View File

@ -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);