From d900416d7c63a6814185495ff08b18b3a55ba6bc Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 13 Sep 2023 09:12:18 +0200 Subject: [PATCH] setting up for metrics --- CodexPlugin/CodexContainerRecipe.cs | 4 +- CodexPlugin/CodexStarter.cs | 8 ++-- DistTestCore/BaseStarter.cs | 42 ------------------- Logging/LogPrefixer.cs | 34 +++++++++++++++ MetricsPlugin/CoreInterfaceExtensions.cs | 18 ++++++++ .../GrafanaContainerRecipe.cs | 0 .../GrafanaStarter.cs | 2 +- .../MetricsAccess.cs | 0 .../MetricsAccessFactory.cs | 0 .../MetricsDownloader.cs | 0 .../Metrics => MetricsPlugin}/MetricsMode.cs | 0 MetricsPlugin/MetricsPlugin.cs | 32 ++++++++++++++ MetricsPlugin/MetricsPlugin.csproj | 9 ++++ .../Metrics => MetricsPlugin}/MetricsQuery.cs | 0 .../PrometheusContainerRecipe.cs | 0 .../PrometheusStarter.cs | 13 +++--- .../PrometheusStartupConfig.cs | 0 .../Metrics => MetricsPlugin}/dashboard.json | 0 18 files changed, 109 insertions(+), 53 deletions(-) delete mode 100644 DistTestCore/BaseStarter.cs create mode 100644 Logging/LogPrefixer.cs create mode 100644 MetricsPlugin/CoreInterfaceExtensions.cs rename {CodexPlugin/Metrics => MetricsPlugin}/GrafanaContainerRecipe.cs (100%) rename {DistTestCore => MetricsPlugin}/GrafanaStarter.cs (99%) rename {CodexPlugin/Metrics => MetricsPlugin}/MetricsAccess.cs (100%) rename {CodexPlugin/Metrics => MetricsPlugin}/MetricsAccessFactory.cs (100%) rename {CodexPlugin/Metrics => MetricsPlugin}/MetricsDownloader.cs (100%) rename {CodexPlugin/Metrics => MetricsPlugin}/MetricsMode.cs (100%) create mode 100644 MetricsPlugin/MetricsPlugin.cs create mode 100644 MetricsPlugin/MetricsPlugin.csproj rename {CodexPlugin/Metrics => MetricsPlugin}/MetricsQuery.cs (100%) rename {CodexPlugin/Metrics => MetricsPlugin}/PrometheusContainerRecipe.cs (100%) rename {DistTestCore => MetricsPlugin}/PrometheusStarter.cs (88%) rename {CodexPlugin/Metrics => MetricsPlugin}/PrometheusStartupConfig.cs (100%) rename {CodexPlugin/Metrics => MetricsPlugin}/dashboard.json (100%) diff --git a/CodexPlugin/CodexContainerRecipe.cs b/CodexPlugin/CodexContainerRecipe.cs index f16a88b..1eb72f7 100644 --- a/CodexPlugin/CodexContainerRecipe.cs +++ b/CodexPlugin/CodexContainerRecipe.cs @@ -23,8 +23,8 @@ namespace CodexPlugin { Image = GetDockerImage(); - Resources.Requests = new ContainerResourceSet(milliCPUs: 1000, memory: 6.GB()); - Resources.Limits = new ContainerResourceSet(milliCPUs: 4000, memory: 12.GB()); + //Resources.Requests = new ContainerResourceSet(milliCPUs: 1000, memory: 6.GB()); + //Resources.Limits = new ContainerResourceSet(milliCPUs: 4000, memory: 12.GB()); } protected override void InitializeRecipe(StartupConfig startupConfig) diff --git a/CodexPlugin/CodexStarter.cs b/CodexPlugin/CodexStarter.cs index 18ebc28..7558a88 100644 --- a/CodexPlugin/CodexStarter.cs +++ b/CodexPlugin/CodexStarter.cs @@ -7,10 +7,12 @@ namespace CodexPlugin public class CodexStarter { private readonly IPluginTools pluginTools; + private readonly ILog log; public CodexStarter(IPluginTools pluginTools) { this.pluginTools = pluginTools; + log = new LogPrefixer(pluginTools.GetLog(), "(CodexStarter) "); } public RunningContainers[] BringOnline(CodexSetup codexSetup) @@ -118,7 +120,7 @@ namespace CodexPlugin try { - Stopwatch.Measure(pluginTools.GetLog(), "(CodexStarter) EnsureOnline", group.EnsureOnline); // log prefixer plz + Stopwatch.Measure(log, "EnsureOnline", group.EnsureOnline); } catch { @@ -131,7 +133,7 @@ namespace CodexPlugin private void CodexNodesNotOnline(RunningContainers[] runningContainers) { - pluginTools.GetLog().Log("Codex nodes failed to start"); + Log("Codex nodes failed to start"); // todo: //foreach (var container in runningContainers.Containers()) lifecycle.DownloadLog(container); } @@ -148,7 +150,7 @@ namespace CodexPlugin private void Log(string message) { - pluginTools.GetLog().Log($"(CodexStarter) {message}"); + log.Log(message); } //private void StopCrashWatcher(RunningContainers containers) diff --git a/DistTestCore/BaseStarter.cs b/DistTestCore/BaseStarter.cs deleted file mode 100644 index 4d10643..0000000 --- a/DistTestCore/BaseStarter.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Logging; - -namespace DistTestCore -{ - public class BaseStarter - { - protected readonly TestLifecycle lifecycle; - private Stopwatch? stopwatch; - - public BaseStarter(TestLifecycle lifecycle) - { - this.lifecycle = lifecycle; - } - - protected void LogStart(string msg) - { - Log(msg); - stopwatch = Stopwatch.Begin(lifecycle.Log, GetClassName()); - } - - protected void LogEnd(string msg) - { - stopwatch!.End(msg); - stopwatch = null; - } - - protected void Log(string msg) - { - lifecycle.Log.Log($"{GetClassName()} {msg}"); - } - - protected void Debug(string msg) - { - lifecycle.Log.Debug($"{GetClassName()} {msg}", 1); - } - - private string GetClassName() - { - return $"({GetType().Name})"; - } - } -} diff --git a/Logging/LogPrefixer.cs b/Logging/LogPrefixer.cs new file mode 100644 index 0000000..de05730 --- /dev/null +++ b/Logging/LogPrefixer.cs @@ -0,0 +1,34 @@ +namespace Logging +{ + public class LogPrefixer : ILog + { + private readonly ILog backingLog; + private readonly string prefix; + + public LogPrefixer(ILog backingLog, string prefix) + { + this.backingLog = backingLog; + this.prefix = prefix; + } + + public LogFile CreateSubfile(string ext = "log") + { + return backingLog.CreateSubfile(ext); + } + + public void Debug(string message = "", int skipFrames = 0) + { + backingLog.Debug(prefix + message, skipFrames); + } + + public void Error(string message) + { + backingLog.Error(prefix + message); + } + + public void Log(string message) + { + backingLog.Log(prefix + message); + } + } +} diff --git a/MetricsPlugin/CoreInterfaceExtensions.cs b/MetricsPlugin/CoreInterfaceExtensions.cs new file mode 100644 index 0000000..df62c06 --- /dev/null +++ b/MetricsPlugin/CoreInterfaceExtensions.cs @@ -0,0 +1,18 @@ +using Core; +using KubernetesWorkflow; + +namespace MetricsPlugin +{ + public static class CoreInterfaceExtensions + { + public static RunningContainer StartMetricsCollector(this CoreInterface ci, RunningContainers[] scrapeTargets) + { + return Plugin(ci).StartMetricsCollector(scrapeTargets); + } + + private static MetricsPlugin Plugin(CoreInterface ci) + { + return ci.GetPlugin(); + } + } +} diff --git a/CodexPlugin/Metrics/GrafanaContainerRecipe.cs b/MetricsPlugin/GrafanaContainerRecipe.cs similarity index 100% rename from CodexPlugin/Metrics/GrafanaContainerRecipe.cs rename to MetricsPlugin/GrafanaContainerRecipe.cs diff --git a/DistTestCore/GrafanaStarter.cs b/MetricsPlugin/GrafanaStarter.cs similarity index 99% rename from DistTestCore/GrafanaStarter.cs rename to MetricsPlugin/GrafanaStarter.cs index f6dd43f..b2f14f7 100644 --- a/DistTestCore/GrafanaStarter.cs +++ b/MetricsPlugin/GrafanaStarter.cs @@ -1,6 +1,6 @@ using KubernetesWorkflow; -namespace DistTestCore +namespace MetricsPlugin { public class GrafanaStarter : BaseStarter { diff --git a/CodexPlugin/Metrics/MetricsAccess.cs b/MetricsPlugin/MetricsAccess.cs similarity index 100% rename from CodexPlugin/Metrics/MetricsAccess.cs rename to MetricsPlugin/MetricsAccess.cs diff --git a/CodexPlugin/Metrics/MetricsAccessFactory.cs b/MetricsPlugin/MetricsAccessFactory.cs similarity index 100% rename from CodexPlugin/Metrics/MetricsAccessFactory.cs rename to MetricsPlugin/MetricsAccessFactory.cs diff --git a/CodexPlugin/Metrics/MetricsDownloader.cs b/MetricsPlugin/MetricsDownloader.cs similarity index 100% rename from CodexPlugin/Metrics/MetricsDownloader.cs rename to MetricsPlugin/MetricsDownloader.cs diff --git a/CodexPlugin/Metrics/MetricsMode.cs b/MetricsPlugin/MetricsMode.cs similarity index 100% rename from CodexPlugin/Metrics/MetricsMode.cs rename to MetricsPlugin/MetricsMode.cs diff --git a/MetricsPlugin/MetricsPlugin.cs b/MetricsPlugin/MetricsPlugin.cs new file mode 100644 index 0000000..8d6fc26 --- /dev/null +++ b/MetricsPlugin/MetricsPlugin.cs @@ -0,0 +1,32 @@ +using Core; +using KubernetesWorkflow; +using Logging; + +namespace MetricsPlugin +{ + public class MetricsPlugin : IProjectPlugin + { + + #region IProjectPlugin Implementation + + public void Announce(ILog log) + { + log.Log("Hi from the metrics plugin."); + } + + public void Initialize(IPluginTools tools) + { + } + + public void Finalize(ILog log) + { + } + + #endregion + + public RunningContainer StartMetricsCollector(RunningContainers[] scrapeTargets) + { + return null!; + } + } +} diff --git a/MetricsPlugin/MetricsPlugin.csproj b/MetricsPlugin/MetricsPlugin.csproj new file mode 100644 index 0000000..cfadb03 --- /dev/null +++ b/MetricsPlugin/MetricsPlugin.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + enable + enable + + + diff --git a/CodexPlugin/Metrics/MetricsQuery.cs b/MetricsPlugin/MetricsQuery.cs similarity index 100% rename from CodexPlugin/Metrics/MetricsQuery.cs rename to MetricsPlugin/MetricsQuery.cs diff --git a/CodexPlugin/Metrics/PrometheusContainerRecipe.cs b/MetricsPlugin/PrometheusContainerRecipe.cs similarity index 100% rename from CodexPlugin/Metrics/PrometheusContainerRecipe.cs rename to MetricsPlugin/PrometheusContainerRecipe.cs diff --git a/DistTestCore/PrometheusStarter.cs b/MetricsPlugin/PrometheusStarter.cs similarity index 88% rename from DistTestCore/PrometheusStarter.cs rename to MetricsPlugin/PrometheusStarter.cs index bfba12b..fbf9a3a 100644 --- a/DistTestCore/PrometheusStarter.cs +++ b/MetricsPlugin/PrometheusStarter.cs @@ -1,13 +1,16 @@ -using KubernetesWorkflow; +using Core; +using KubernetesWorkflow; using System.Text; -namespace DistTestCore +namespace MetricsPlugin { - public class PrometheusStarter : BaseStarter + public class PrometheusStarter { - public PrometheusStarter(TestLifecycle lifecycle) - : base(lifecycle) + private readonly IPluginTools tools; + + public PrometheusStarter(IPluginTools tools) { + this.tools = tools; } public RunningContainers CollectMetricsFor(RunningContainers[] containers) diff --git a/CodexPlugin/Metrics/PrometheusStartupConfig.cs b/MetricsPlugin/PrometheusStartupConfig.cs similarity index 100% rename from CodexPlugin/Metrics/PrometheusStartupConfig.cs rename to MetricsPlugin/PrometheusStartupConfig.cs diff --git a/CodexPlugin/Metrics/dashboard.json b/MetricsPlugin/dashboard.json similarity index 100% rename from CodexPlugin/Metrics/dashboard.json rename to MetricsPlugin/dashboard.json