MetricsPlugin.cs
1 using Core; 2 using KubernetesWorkflow.Types; 3 using Logging; 4 using Utils; 5 6 namespace MetricsPlugin 7 { 8 public class MetricsPlugin : IProjectPlugin, IHasLogPrefix, IHasMetadata 9 { 10 private readonly IPluginTools tools; 11 private readonly PrometheusStarter starter; 12 13 public MetricsPlugin(IPluginTools tools) 14 { 15 this.tools = tools; 16 starter = new PrometheusStarter(tools); 17 } 18 19 public string LogPrefix => "(Metrics) "; 20 21 public void Awake(IPluginAccess access) 22 { 23 } 24 25 public void Announce() 26 { 27 tools.GetLog().Log($"Prometheus plugin loaded with '{starter.GetPrometheusId()}'."); 28 } 29 30 public void AddMetadata(IAddMetadata metadata) 31 { 32 metadata.Add("prometheusid", starter.GetPrometheusId()); 33 } 34 35 public void Decommission() 36 { 37 } 38 39 public RunningPod DeployMetricsCollector(Address[] scrapeTargets, TimeSpan scrapeInterval) 40 { 41 return starter.CollectMetricsFor(scrapeTargets, scrapeInterval); 42 } 43 44 public IMetricsAccess WrapMetricsCollectorDeployment(RunningPod runningPod, Address target) 45 { 46 runningPod = SerializeGate.Gate(runningPod); 47 return starter.CreateAccessForTarget(runningPod, target); 48 } 49 50 public LogFile? DownloadAllMetrics(IMetricsAccess metricsAccess, string targetName) 51 { 52 var downloader = new MetricsDownloader(tools.GetLog()); 53 return downloader.DownloadAllMetrics(targetName, metricsAccess); 54 } 55 } 56 }