Cleanup codex log level and namespace override
This commit is contained in:
parent
ec5aebb47b
commit
ca5981e852
|
@ -7,6 +7,7 @@ namespace CodexPlugin
|
|||
{
|
||||
private readonly CodexStarter codexStarter;
|
||||
private readonly IPluginTools tools;
|
||||
private readonly CodexLogLevel defaultLogLevel = CodexLogLevel.Trace;
|
||||
|
||||
public CodexPlugin(IPluginTools tools)
|
||||
{
|
||||
|
@ -27,7 +28,8 @@ namespace CodexPlugin
|
|||
|
||||
public RunningContainers[] StartCodexNodes(int numberOfNodes, Action<ICodexSetup> setup)
|
||||
{
|
||||
var codexSetup = new CodexSetup(numberOfNodes, CodexLogLevel.Trace);
|
||||
var codexSetup = new CodexSetup(numberOfNodes);
|
||||
codexSetup.LogLevel = defaultLogLevel;
|
||||
setup(codexSetup);
|
||||
return codexStarter.BringOnline(codexSetup);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace CodexPlugin
|
|||
{
|
||||
public interface ICodexSetup
|
||||
{
|
||||
ICodexSetup WithLogLevel(CodexLogLevel logLevel);
|
||||
ICodexSetup WithName(string name);
|
||||
ICodexSetup At(Location location);
|
||||
ICodexSetup WithBootstrapNode(IOnlineCodexNode node);
|
||||
|
@ -22,12 +23,17 @@ namespace CodexPlugin
|
|||
{
|
||||
public int NumberOfNodes { get; }
|
||||
|
||||
public CodexSetup(int numberOfNodes, CodexLogLevel logLevel)
|
||||
: base(logLevel)
|
||||
public CodexSetup(int numberOfNodes)
|
||||
{
|
||||
NumberOfNodes = numberOfNodes;
|
||||
}
|
||||
|
||||
public ICodexSetup WithLogLevel(CodexLogLevel logLevel)
|
||||
{
|
||||
LogLevel = logLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup WithName(string name)
|
||||
{
|
||||
NameOverride = name;
|
||||
|
|
|
@ -5,14 +5,9 @@ namespace CodexPlugin
|
|||
{
|
||||
public class CodexStartupConfig
|
||||
{
|
||||
public CodexStartupConfig(CodexLogLevel logLevel)
|
||||
{
|
||||
LogLevel = logLevel;
|
||||
}
|
||||
|
||||
public string? NameOverride { get; set; }
|
||||
public Location Location { get; set; }
|
||||
public CodexLogLevel LogLevel { get; }
|
||||
public CodexLogLevel LogLevel { get; set; }
|
||||
public ByteSize? StorageQuota { get; set; }
|
||||
public bool MetricsEnabled { get; set; }
|
||||
//public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
|
||||
|
|
|
@ -62,8 +62,7 @@ namespace Core
|
|||
|
||||
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
||||
{
|
||||
if (namespaceOverride != null) throw new Exception("Namespace override is not supported in the DistTest environment. (It would mess up automatic resource cleanup.)");
|
||||
return workflowCreator.CreateWorkflow();
|
||||
return workflowCreator.CreateWorkflow(namespaceOverride);
|
||||
}
|
||||
|
||||
public IFileManager GetFileManager()
|
||||
|
|
|
@ -8,8 +8,6 @@ namespace DistTestCore
|
|||
private readonly string logPath;
|
||||
private readonly bool logDebug;
|
||||
private readonly string dataFilesPath;
|
||||
//private readonly CodexLogLevel codexLogLevel;
|
||||
private readonly string k8sNamespacePrefix;
|
||||
|
||||
public Configuration()
|
||||
{
|
||||
|
@ -17,28 +15,28 @@ namespace DistTestCore
|
|||
logPath = GetEnvVarOrDefault("LOGPATH", "CodexTestLogs");
|
||||
logDebug = GetEnvVarOrDefault("LOGDEBUG", "false").ToLowerInvariant() == "true";
|
||||
dataFilesPath = GetEnvVarOrDefault("DATAFILEPATH", "TestDataFiles");
|
||||
//codexLogLevel = ParseEnum.Parse<CodexLogLevel>(GetEnvVarOrDefault("LOGLEVEL", nameof(CodexLogLevel.Trace)));
|
||||
k8sNamespacePrefix = "ct-";
|
||||
}
|
||||
|
||||
public Configuration(string? kubeConfigFile, string logPath, bool logDebug, string dataFilesPath, /*CodexLogLevel codexLogLevel,*/ string k8sNamespacePrefix)
|
||||
public Configuration(string? kubeConfigFile, string logPath, bool logDebug, string dataFilesPath)
|
||||
{
|
||||
this.kubeConfigFile = kubeConfigFile;
|
||||
this.logPath = logPath;
|
||||
this.logDebug = logDebug;
|
||||
this.dataFilesPath = dataFilesPath;
|
||||
//this.codexLogLevel = codexLogLevel;
|
||||
this.k8sNamespacePrefix = k8sNamespacePrefix;
|
||||
}
|
||||
|
||||
public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet, string k8sNamespace)
|
||||
{
|
||||
return new KubernetesWorkflow.Configuration(
|
||||
var config = new KubernetesWorkflow.Configuration(
|
||||
kubeConfigFile: kubeConfigFile,
|
||||
operationTimeout: timeSet.K8sOperationTimeout(),
|
||||
retryDelay: timeSet.WaitForK8sServiceDelay(),
|
||||
kubernetesNamespace: k8sNamespace
|
||||
);
|
||||
|
||||
config.AllowNamespaceOverride = false;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public Logging.LogConfig GetLogConfig()
|
||||
|
@ -51,11 +49,6 @@ namespace DistTestCore
|
|||
return dataFilesPath;
|
||||
}
|
||||
|
||||
//public CodexLogLevel GetCodexLogLevel()
|
||||
//{
|
||||
// return codexLogLevel;
|
||||
//}
|
||||
|
||||
private static string GetEnvVarOrDefault(string varName, string defaultValue)
|
||||
{
|
||||
var v = Environment.GetEnvironmentVariable(varName);
|
||||
|
@ -70,6 +63,4 @@ namespace DistTestCore
|
|||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -113,59 +113,6 @@ namespace DistTestCore
|
|||
Get().GetFileManager().ScopedFiles(action);
|
||||
}
|
||||
|
||||
//public IOnlineCodexNode SetupCodexBootstrapNode()
|
||||
//{
|
||||
// return SetupCodexBootstrapNode(s => { });
|
||||
//}
|
||||
|
||||
//public virtual IOnlineCodexNode SetupCodexBootstrapNode(Action<ICodexSetup> setup)
|
||||
//{
|
||||
// return SetupCodexNode(s =>
|
||||
// {
|
||||
// setup(s);
|
||||
// s.WithName("Bootstrap");
|
||||
// });
|
||||
//}
|
||||
|
||||
//public IOnlineCodexNode SetupCodexNode()
|
||||
//{
|
||||
// return SetupCodexNode(s => { });
|
||||
//}
|
||||
|
||||
//public IOnlineCodexNode SetupCodexNode(Action<ICodexSetup> setup)
|
||||
//{
|
||||
// return SetupCodexNodes(1, setup)[0];
|
||||
//}
|
||||
|
||||
//public ICodexNodeGroup SetupCodexNodes(int numberOfNodes)
|
||||
//{
|
||||
// return SetupCodexNodes(numberOfNodes, s => { });
|
||||
//}
|
||||
|
||||
//public virtual ICodexNodeGroup SetupCodexNodes(int numberOfNodes, Action<ICodexSetup> setup)
|
||||
//{
|
||||
// var codexSetup = CreateCodexSetup(numberOfNodes);
|
||||
|
||||
// setup(codexSetup);
|
||||
|
||||
// return BringOnline(codexSetup);
|
||||
//}
|
||||
|
||||
//public ICodexNodeGroup BringOnline(ICodexSetup codexSetup)
|
||||
//{
|
||||
// return Get().CodexStarter.BringOnline((CodexSetup)codexSetup);
|
||||
//}
|
||||
|
||||
//public IEnumerable<IOnlineCodexNode> GetAllOnlineCodexNodes()
|
||||
//{
|
||||
// return Get().CodexStarter.RunningGroups.SelectMany(g => g.Nodes);
|
||||
//}
|
||||
|
||||
//public override T GetPlugin<T>()
|
||||
//{
|
||||
// return Get().GetPlugin<T>();
|
||||
//}
|
||||
|
||||
public ILog GetTestLog()
|
||||
{
|
||||
return Get().Log;
|
||||
|
@ -188,11 +135,6 @@ namespace DistTestCore
|
|||
Stopwatch.Measure(Get().Log, name, action);
|
||||
}
|
||||
|
||||
//protected CodexSetup CreateCodexSetup(int numberOfNodes)
|
||||
//{
|
||||
// return new CodexSetup(numberOfNodes, configuration.GetCodexLogLevel());
|
||||
//}
|
||||
|
||||
protected TestLifecycle Get()
|
||||
{
|
||||
lock (lifecycleLock)
|
||||
|
@ -293,37 +235,6 @@ namespace DistTestCore
|
|||
}
|
||||
}
|
||||
|
||||
//private void DownloadAllLogs(TestLifecycle lifecycle)
|
||||
//{
|
||||
// OnEachCodexNode(lifecycle, node =>
|
||||
// {
|
||||
// lifecycle.DownloadLog(node.CodexAccess.Container);
|
||||
// });
|
||||
//}
|
||||
|
||||
//private void DownloadAllMetrics(TestLifecycle lifecycle)
|
||||
//{
|
||||
// var metricsDownloader = new MetricsDownloader(lifecycle.Log);
|
||||
|
||||
// OnEachCodexNode(lifecycle, node =>
|
||||
// {
|
||||
// var m = node.Metrics as MetricsAccess;
|
||||
// if (m != null)
|
||||
// {
|
||||
// metricsDownloader.DownloadAllMetricsForNode(node.GetName(), m);
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
|
||||
//private void OnEachCodexNode(TestLifecycle lifecycle, Action<OnlineCodexNode> action)
|
||||
//{
|
||||
// var allNodes = lifecycle.CodexStarter.RunningGroups.SelectMany(g => g.Nodes);
|
||||
// foreach (var node in allNodes)
|
||||
// {
|
||||
// action(node);
|
||||
// }
|
||||
//}
|
||||
|
||||
private string GetCurrentTestName()
|
||||
{
|
||||
return $"[{TestContext.CurrentContext.Test.Name}]";
|
||||
|
|
|
@ -45,29 +45,12 @@ namespace DistTestCore
|
|||
return entryPoint.Tools.GetFileManager();
|
||||
}
|
||||
|
||||
//public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
|
||||
//{
|
||||
// var subFile = Log.CreateSubfile();
|
||||
// var description = container.Name;
|
||||
// var handler = new LogDownloadHandler(container, description, subFile);
|
||||
|
||||
// Log.Log($"Downloading logs for {description} to file '{subFile.FullFilename}'");
|
||||
// //CodexStarter.DownloadLog(container, handler, tailLines);
|
||||
|
||||
// return new DownloadedLog(subFile, description);
|
||||
//}
|
||||
|
||||
public string GetTestDuration()
|
||||
{
|
||||
var testDuration = DateTime.UtcNow - testStart;
|
||||
return Time.FormatDuration(testDuration);
|
||||
}
|
||||
|
||||
////public void SetCodexVersion(CodexDebugVersionResponse version)
|
||||
////{
|
||||
//// if (CodexVersion == null) CodexVersion = version;
|
||||
////}
|
||||
|
||||
//public ApplicationIds GetApplicationIds()
|
||||
//{
|
||||
// //return new ApplicationIds(
|
||||
|
|
|
@ -14,5 +14,6 @@
|
|||
public TimeSpan OperationTimeout { get; }
|
||||
public TimeSpan RetryDelay { get; }
|
||||
public string KubernetesNamespace { get; }
|
||||
public bool AllowNamespaceOverride { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,22 +10,33 @@ namespace KubernetesWorkflow
|
|||
private readonly KnownK8sPods knownPods = new KnownK8sPods();
|
||||
private readonly K8sCluster cluster;
|
||||
private readonly ILog log;
|
||||
private readonly Configuration configuration;
|
||||
private readonly string k8sNamespace;
|
||||
|
||||
public WorkflowCreator(ILog log, Configuration configuration)
|
||||
{
|
||||
this.log = log;
|
||||
|
||||
this.configuration = configuration;
|
||||
cluster = new K8sCluster(configuration);
|
||||
k8sNamespace = configuration.KubernetesNamespace.ToLowerInvariant();
|
||||
}
|
||||
|
||||
public IStartupWorkflow CreateWorkflow()
|
||||
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
||||
{
|
||||
var workflowNumberSource = new WorkflowNumberSource(numberSource.GetNextNumber(),
|
||||
containerNumberSource);
|
||||
|
||||
return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, k8sNamespace);
|
||||
return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, GetNamespace(namespaceOverride));
|
||||
}
|
||||
|
||||
private string GetNamespace(string? namespaceOverride)
|
||||
{
|
||||
if (namespaceOverride != null)
|
||||
{
|
||||
if (!configuration.AllowNamespaceOverride) throw new Exception("Namespace override is not allowed.");
|
||||
return namespaceOverride;
|
||||
}
|
||||
return k8sNamespace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue