2
0
mirror of synced 2025-01-11 17:14:25 +00:00

setting up for metrics

This commit is contained in:
benbierens 2023-09-13 09:12:18 +02:00
parent 7e7414d491
commit d900416d7c
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
18 changed files with 109 additions and 53 deletions

View File

@ -23,8 +23,8 @@ namespace CodexPlugin
{ {
Image = GetDockerImage(); Image = GetDockerImage();
Resources.Requests = new ContainerResourceSet(milliCPUs: 1000, memory: 6.GB()); //Resources.Requests = new ContainerResourceSet(milliCPUs: 1000, memory: 6.GB());
Resources.Limits = new ContainerResourceSet(milliCPUs: 4000, memory: 12.GB()); //Resources.Limits = new ContainerResourceSet(milliCPUs: 4000, memory: 12.GB());
} }
protected override void InitializeRecipe(StartupConfig startupConfig) protected override void InitializeRecipe(StartupConfig startupConfig)

View File

@ -7,10 +7,12 @@ namespace CodexPlugin
public class CodexStarter public class CodexStarter
{ {
private readonly IPluginTools pluginTools; private readonly IPluginTools pluginTools;
private readonly ILog log;
public CodexStarter(IPluginTools pluginTools) public CodexStarter(IPluginTools pluginTools)
{ {
this.pluginTools = pluginTools; this.pluginTools = pluginTools;
log = new LogPrefixer(pluginTools.GetLog(), "(CodexStarter) ");
} }
public RunningContainers[] BringOnline(CodexSetup codexSetup) public RunningContainers[] BringOnline(CodexSetup codexSetup)
@ -118,7 +120,7 @@ namespace CodexPlugin
try try
{ {
Stopwatch.Measure(pluginTools.GetLog(), "(CodexStarter) EnsureOnline", group.EnsureOnline); // log prefixer plz Stopwatch.Measure(log, "EnsureOnline", group.EnsureOnline);
} }
catch catch
{ {
@ -131,7 +133,7 @@ namespace CodexPlugin
private void CodexNodesNotOnline(RunningContainers[] runningContainers) private void CodexNodesNotOnline(RunningContainers[] runningContainers)
{ {
pluginTools.GetLog().Log("Codex nodes failed to start"); Log("Codex nodes failed to start");
// todo: // todo:
//foreach (var container in runningContainers.Containers()) lifecycle.DownloadLog(container); //foreach (var container in runningContainers.Containers()) lifecycle.DownloadLog(container);
} }
@ -148,7 +150,7 @@ namespace CodexPlugin
private void Log(string message) private void Log(string message)
{ {
pluginTools.GetLog().Log($"(CodexStarter) {message}"); log.Log(message);
} }
//private void StopCrashWatcher(RunningContainers containers) //private void StopCrashWatcher(RunningContainers containers)

View File

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

34
Logging/LogPrefixer.cs Normal file
View File

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

View File

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

View File

@ -1,6 +1,6 @@
using KubernetesWorkflow; using KubernetesWorkflow;
namespace DistTestCore namespace MetricsPlugin
{ {
public class GrafanaStarter : BaseStarter public class GrafanaStarter : BaseStarter
{ {

View File

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

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -1,13 +1,16 @@
using KubernetesWorkflow; using Core;
using KubernetesWorkflow;
using System.Text; using System.Text;
namespace DistTestCore namespace MetricsPlugin
{ {
public class PrometheusStarter : BaseStarter public class PrometheusStarter
{ {
public PrometheusStarter(TestLifecycle lifecycle) private readonly IPluginTools tools;
: base(lifecycle)
public PrometheusStarter(IPluginTools tools)
{ {
this.tools = tools;
} }
public RunningContainers CollectMetricsFor(RunningContainers[] containers) public RunningContainers CollectMetricsFor(RunningContainers[] containers)