2023-09-13 07:12:18 +00:00
|
|
|
|
using Core;
|
2023-11-12 09:07:23 +00:00
|
|
|
|
using KubernetesWorkflow.Types;
|
2023-09-13 09:25:08 +00:00
|
|
|
|
using Logging;
|
2023-09-13 07:12:18 +00:00
|
|
|
|
|
|
|
|
|
namespace MetricsPlugin
|
|
|
|
|
{
|
|
|
|
|
public static class CoreInterfaceExtensions
|
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
public static RunningPod DeployMetricsCollector(this CoreInterface ci, TimeSpan scrapeInterval, params IHasMetricsScrapeTarget[] scrapeTargets)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
return Plugin(ci).DeployMetricsCollector(scrapeTargets.Select(t => t.MetricsScrapeTarget).ToArray(), scrapeInterval);
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 14:10:07 +00:00
|
|
|
|
public static RunningPod DeployMetricsCollector(this CoreInterface ci, TimeSpan scrapeInterval, params IMetricsScrapeTarget[] scrapeTargets)
|
2023-09-13 07:12:18 +00:00
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
return Plugin(ci).DeployMetricsCollector(scrapeTargets, scrapeInterval);
|
2023-09-13 09:25:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
|
public static IMetricsAccess WrapMetricsCollector(this CoreInterface ci, RunningPod metricsPod, IHasMetricsScrapeTarget scrapeTarget)
|
2023-09-26 12:32:28 +00:00
|
|
|
|
{
|
2024-04-13 14:09:17 +00:00
|
|
|
|
return ci.WrapMetricsCollector(metricsPod, scrapeTarget.MetricsScrapeTarget);
|
2023-09-26 12:32:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
|
public static IMetricsAccess WrapMetricsCollector(this CoreInterface ci, RunningPod metricsPod, IMetricsScrapeTarget scrapeTarget)
|
2023-09-13 09:25:08 +00:00
|
|
|
|
{
|
2024-04-13 14:09:17 +00:00
|
|
|
|
return Plugin(ci).WrapMetricsCollectorDeployment(metricsPod, scrapeTarget);
|
2023-09-13 09:25:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 14:10:07 +00:00
|
|
|
|
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, TimeSpan scrapeInterval, params IHasManyMetricScrapeTargets[] manyScrapeTargets)
|
2023-09-13 09:59:21 +00:00
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
return ci.GetMetricsFor(scrapeInterval, manyScrapeTargets.SelectMany(t => t.ScrapeTargets).ToArray());
|
2023-09-13 09:59:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 14:10:07 +00:00
|
|
|
|
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, TimeSpan scrapeInterval, params IHasMetricsScrapeTarget[] scrapeTargets)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
return ci.GetMetricsFor(scrapeInterval, scrapeTargets.Select(t => t.MetricsScrapeTarget).ToArray());
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 14:10:07 +00:00
|
|
|
|
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, TimeSpan scrapeInterval, params IMetricsScrapeTarget[] scrapeTargets)
|
2023-09-13 09:25:08 +00:00
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
var rc = ci.DeployMetricsCollector(scrapeInterval, scrapeTargets);
|
2023-09-20 07:16:57 +00:00
|
|
|
|
return scrapeTargets.Select(t => ci.WrapMetricsCollector(rc, t)).ToArray();
|
2023-09-13 09:25:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static LogFile? DownloadAllMetrics(this CoreInterface ci, IMetricsAccess metricsAccess, string targetName)
|
|
|
|
|
{
|
|
|
|
|
return Plugin(ci).DownloadAllMetrics(metricsAccess, targetName);
|
2023-09-13 07:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static MetricsPlugin Plugin(CoreInterface ci)
|
|
|
|
|
{
|
|
|
|
|
return ci.GetPlugin<MetricsPlugin>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|