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
|
|
|
|
|
{
|
2023-09-13 14:06:05 +00:00
|
|
|
|
public class MetricsPlugin : IProjectPlugin, IHasLogPrefix, IHasMetadata
|
2023-09-13 07:12:18 +00:00
|
|
|
|
{
|
2023-09-13 08:23:05 +00:00
|
|
|
|
private readonly IPluginTools tools;
|
|
|
|
|
private readonly PrometheusStarter starter;
|
|
|
|
|
|
|
|
|
|
public MetricsPlugin(IPluginTools tools)
|
|
|
|
|
{
|
|
|
|
|
this.tools = tools;
|
|
|
|
|
starter = new PrometheusStarter(tools);
|
|
|
|
|
}
|
2023-09-13 07:12:18 +00:00
|
|
|
|
|
2023-09-13 14:06:05 +00:00
|
|
|
|
public string LogPrefix => "(Metrics) ";
|
|
|
|
|
|
2023-09-13 08:03:11 +00:00
|
|
|
|
public void Announce()
|
2023-09-13 07:12:18 +00:00
|
|
|
|
{
|
2023-09-13 14:06:05 +00:00
|
|
|
|
tools.GetLog().Log($"Prometheus plugin loaded with '{starter.GetPrometheusId()}'.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddMetadata(IAddMetadata metadata)
|
|
|
|
|
{
|
|
|
|
|
metadata.Add("prometheusid", starter.GetPrometheusId());
|
2023-09-13 07:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 08:03:11 +00:00
|
|
|
|
public void Decommission()
|
2023-09-13 07:12:18 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 14:10:07 +00:00
|
|
|
|
public RunningPod DeployMetricsCollector(IMetricsScrapeTarget[] scrapeTargets, TimeSpan scrapeInterval)
|
2023-09-13 07:12:18 +00:00
|
|
|
|
{
|
2024-10-24 14:10:07 +00:00
|
|
|
|
return starter.CollectMetricsFor(scrapeTargets, scrapeInterval);
|
2023-09-13 07:12:18 +00:00
|
|
|
|
}
|
2023-09-13 09:25:08 +00:00
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
|
public IMetricsAccess WrapMetricsCollectorDeployment(RunningPod runningPod, IMetricsScrapeTarget target)
|
2023-09-13 09:25:08 +00:00
|
|
|
|
{
|
2024-04-13 14:09:17 +00:00
|
|
|
|
runningPod = SerializeGate.Gate(runningPod);
|
|
|
|
|
return starter.CreateAccessForTarget(runningPod, target);
|
2023-09-13 09:25:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LogFile? DownloadAllMetrics(IMetricsAccess metricsAccess, string targetName)
|
|
|
|
|
{
|
|
|
|
|
var downloader = new MetricsDownloader(tools.GetLog());
|
|
|
|
|
return downloader.DownloadAllMetrics(targetName, metricsAccess);
|
|
|
|
|
}
|
2023-09-13 07:12:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|