diff --git a/CodexNetDeployer/CodexNodeStarter.cs b/CodexNetDeployer/CodexNodeStarter.cs index 0a3b373..836e8f8 100644 --- a/CodexNetDeployer/CodexNodeStarter.cs +++ b/CodexNetDeployer/CodexNodeStarter.cs @@ -84,7 +84,7 @@ namespace CodexNetDeployer var marketplaceConfig = new MarketplaceInitialConfig(100000.Eth(), 0.TestTokens(), validatorsLeft > 0); marketplaceConfig.AccountIndexOverride = i; codexStart.MarketplaceConfig = marketplaceConfig; - codexStart.MetricsEnabled = config.RecordMetrics; + codexStart.MetricsMode = config.Metrics; if (config.BlockTTL != Configuration.SecondsIn1Day) { diff --git a/CodexNetDeployer/Configuration.cs b/CodexNetDeployer/Configuration.cs index ee7ac7e..0257389 100644 --- a/CodexNetDeployer/Configuration.cs +++ b/CodexNetDeployer/Configuration.cs @@ -1,5 +1,6 @@ using ArgsUniform; using DistTestCore.Codex; +using DistTestCore.Metrics; namespace CodexNetDeployer { @@ -43,8 +44,8 @@ namespace CodexNetDeployer [Uniform("block-ttl", "bt", "BLOCKTTL", false, "Block timeout in seconds. Default is 24 hours.")] public int BlockTTL { get; set; } = SecondsIn1Day; - [Uniform("record-metrics", "rm", "RECORDMETRICS", false, "If true, metrics will be collected for all Codex nodes.")] - public bool RecordMetrics { get; set; } = false; + [Uniform("metrics", "m", "METRICS", false, "[None*, Record, Dashboard]. Determines if metrics will be recorded and if a dashboard service will be created.")] + public MetricsMode Metrics { get; set; } = MetricsMode.None; [Uniform("teststype-podlabel", "ttpl", "TESTSTYPE-PODLABEL", false, "Each kubernetes pod will be created with a label 'teststype' with value 'continuous'. " + "set this option to override the label value.")] diff --git a/CodexNetDeployer/Deployer.cs b/CodexNetDeployer/Deployer.cs index feb750e..e790320 100644 --- a/CodexNetDeployer/Deployer.cs +++ b/CodexNetDeployer/Deployer.cs @@ -27,7 +27,7 @@ namespace CodexNetDeployer // We trick the Geth companion node into unlocking all of its accounts, by saying we want to start 999 codex nodes. var setup = new CodexSetup(999, config.CodexLogLevel); setup.WithStorageQuota(config.StorageQuota!.Value.MB()).EnableMarketplace(0.TestTokens()); - setup.MetricsEnabled = config.RecordMetrics; + setup.MetricsMode = config.Metrics; Log("Creating Geth instance and deploying contracts..."); var gethStarter = new GethStarter(lifecycle); @@ -52,9 +52,9 @@ namespace CodexNetDeployer if (container != null) codexContainers.Add(container); } - var prometheusContainer = StartMetricsService(lifecycle, setup, codexContainers); + var (prometheusContainer, grafanaStartInfo) = StartMetricsService(lifecycle, setup, codexContainers); - return new CodexDeployment(gethResults, codexContainers.ToArray(), prometheusContainer, CreateMetadata()); + return new CodexDeployment(gethResults, codexContainers.ToArray(), prometheusContainer, grafanaStartInfo, CreateMetadata()); } private TestLifecycle CreateTestLifecycle() @@ -74,13 +74,19 @@ namespace CodexNetDeployer return new TestLifecycle(log, lifecycleConfig, timeset, config.TestsTypePodLabel, string.Empty); } - private RunningContainer? StartMetricsService(TestLifecycle lifecycle, CodexSetup setup, List codexContainers) + private (RunningContainer?, GrafanaStartInfo?) StartMetricsService(TestLifecycle lifecycle, CodexSetup setup, List codexContainers) { - if (!setup.MetricsEnabled) return null; + if (setup.MetricsMode == DistTestCore.Metrics.MetricsMode.None) return (null, null); Log("Starting metrics service..."); var runningContainers = new[] { new RunningContainers(null!, null!, codexContainers.ToArray()) }; - return lifecycle.PrometheusStarter.CollectMetricsFor(runningContainers).Containers.Single(); + var prometheusContainer = lifecycle.PrometheusStarter.CollectMetricsFor(runningContainers).Containers.Single(); + + if (setup.MetricsMode == DistTestCore.Metrics.MetricsMode.Record) return (prometheusContainer, null); + + Log("Starting dashboard service..."); + var grafanaStartInfo = lifecycle.GrafanaStarter.StartDashboard(prometheusContainer); + return (prometheusContainer, grafanaStartInfo); } private string? GetKubeConfig(string kubeConfigFile) diff --git a/CodexNetDeployer/deploy-continuous-testnet.sh b/CodexNetDeployer/deploy-continuous-testnet.sh index 338b8c1..c0460c8 100644 --- a/CodexNetDeployer/deploy-continuous-testnet.sh +++ b/CodexNetDeployer/deploy-continuous-testnet.sh @@ -10,4 +10,4 @@ dotnet run \ --max-collateral=1024 \ --max-duration=3600000 \ --block-ttl=300 \ - --record-metrics=true + --metrics=Dashboard diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index c600c01..64f85c3 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -51,7 +51,7 @@ namespace DistTestCore.Codex { AddEnvVar("CODEX_BLOCK_TTL", config.BlockTTL.ToString()!); } - if (config.MetricsEnabled) + if (config.MetricsMode != Metrics.MetricsMode.None) { AddEnvVar("CODEX_METRICS", "true"); AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0"); diff --git a/DistTestCore/Codex/CodexDeployment.cs b/DistTestCore/Codex/CodexDeployment.cs index 52192dc..b22c77a 100644 --- a/DistTestCore/Codex/CodexDeployment.cs +++ b/DistTestCore/Codex/CodexDeployment.cs @@ -5,17 +5,19 @@ namespace DistTestCore.Codex { public class CodexDeployment { - public CodexDeployment(GethStartResult gethStartResult, RunningContainer[] codexContainers, RunningContainer? prometheusContainer, DeploymentMetadata metadata) + public CodexDeployment(GethStartResult gethStartResult, RunningContainer[] codexContainers, RunningContainer? prometheusContainer, GrafanaStartInfo? grafanaStartInfo, DeploymentMetadata metadata) { GethStartResult = gethStartResult; CodexContainers = codexContainers; PrometheusContainer = prometheusContainer; + GrafanaStartInfo = grafanaStartInfo; Metadata = metadata; } public GethStartResult GethStartResult { get; } public RunningContainer[] CodexContainers { get; } public RunningContainer? PrometheusContainer { get; } + public GrafanaStartInfo? GrafanaStartInfo { get; } public DeploymentMetadata Metadata { get; } } diff --git a/DistTestCore/Codex/CodexStartupConfig.cs b/DistTestCore/Codex/CodexStartupConfig.cs index 2a17334..5e72755 100644 --- a/DistTestCore/Codex/CodexStartupConfig.cs +++ b/DistTestCore/Codex/CodexStartupConfig.cs @@ -1,4 +1,5 @@ using DistTestCore.Marketplace; +using DistTestCore.Metrics; using KubernetesWorkflow; namespace DistTestCore.Codex @@ -14,7 +15,7 @@ namespace DistTestCore.Codex public Location Location { get; set; } public CodexLogLevel LogLevel { get; } public ByteSize? StorageQuota { get; set; } - public bool MetricsEnabled { get; set; } + public MetricsMode MetricsMode { get; set; } public MarketplaceInitialConfig? MarketplaceConfig { get; set; } public string? BootstrapSpr { get; set; } public int? BlockTTL { get; set; } diff --git a/DistTestCore/CodexSetup.cs b/DistTestCore/CodexSetup.cs index 0ffb713..4aefd39 100644 --- a/DistTestCore/CodexSetup.cs +++ b/DistTestCore/CodexSetup.cs @@ -59,7 +59,7 @@ namespace DistTestCore public ICodexSetup EnableMetrics() { - MetricsEnabled = true; + MetricsMode = Metrics.MetricsMode.Record; return this; } diff --git a/DistTestCore/CodexStarter.cs b/DistTestCore/CodexStarter.cs index a1e38b7..52686f1 100644 --- a/DistTestCore/CodexStarter.cs +++ b/DistTestCore/CodexStarter.cs @@ -68,9 +68,15 @@ namespace DistTestCore private IMetricsAccessFactory CollectMetrics(CodexSetup codexSetup, RunningContainers[] containers) { - if (!codexSetup.MetricsEnabled) return new MetricsUnavailableAccessFactory(); + if (codexSetup.MetricsMode == MetricsMode.None) return new MetricsUnavailableAccessFactory(); var runningContainers = lifecycle.PrometheusStarter.CollectMetricsFor(containers); + + if (codexSetup.MetricsMode == MetricsMode.Dashboard) + { + var info = lifecycle.GrafanaStarter.StartDashboard(runningContainers.Containers.First()); + } + return new CodexNodeMetricsAccessFactory(lifecycle, runningContainers); } diff --git a/DistTestCore/Metrics/MetricsMode.cs b/DistTestCore/Metrics/MetricsMode.cs new file mode 100644 index 0000000..60b4f5e --- /dev/null +++ b/DistTestCore/Metrics/MetricsMode.cs @@ -0,0 +1,9 @@ +namespace DistTestCore.Metrics +{ + public enum MetricsMode + { + None, + Record, + Dashboard + } +}