Automatic quota line. Holding test.

This commit is contained in:
benbierens 2023-08-14 10:26:04 +02:00
parent f2346d5d09
commit 9f0600d6c1
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 106 additions and 61 deletions

View File

@ -85,7 +85,7 @@ namespace CodexNetDeployer
if (setup.MetricsMode == DistTestCore.Metrics.MetricsMode.Record) return (prometheusContainer, null); if (setup.MetricsMode == DistTestCore.Metrics.MetricsMode.Record) return (prometheusContainer, null);
Log("Starting dashboard service..."); Log("Starting dashboard service...");
var grafanaStartInfo = lifecycle.GrafanaStarter.StartDashboard(prometheusContainer); var grafanaStartInfo = lifecycle.GrafanaStarter.StartDashboard(prometheusContainer, setup);
return (prometheusContainer, grafanaStartInfo); return (prometheusContainer, grafanaStartInfo);
} }

View File

@ -74,7 +74,7 @@ namespace DistTestCore
if (codexSetup.MetricsMode == MetricsMode.Dashboard) if (codexSetup.MetricsMode == MetricsMode.Dashboard)
{ {
lifecycle.GrafanaStarter.StartDashboard(runningContainers.Containers.First()); lifecycle.GrafanaStarter.StartDashboard(runningContainers.Containers.First(), codexSetup);
} }
return new CodexNodeMetricsAccessFactory(lifecycle, runningContainers); return new CodexNodeMetricsAccessFactory(lifecycle, runningContainers);

View File

@ -8,11 +8,14 @@ namespace DistTestCore
{ {
public class GrafanaStarter : BaseStarter public class GrafanaStarter : BaseStarter
{ {
private const string StorageQuotaThresholdReplaceToken = "\"<CODEX_STORAGEQUOTA>\"";
private const string BytesUsedGraphAxisSoftMaxReplaceToken = "\"<CODEX_BYTESUSED_SOFTMAX>\"";
public GrafanaStarter(TestLifecycle lifecycle) public GrafanaStarter(TestLifecycle lifecycle)
: base(lifecycle) : base(lifecycle)
{ {
} }
public GrafanaStartInfo StartDashboard(RunningContainer prometheusContainer) public GrafanaStartInfo StartDashboard(RunningContainer prometheusContainer, CodexSetup codexSetup)
{ {
LogStart($"Starting dashboard server"); LogStart($"Starting dashboard server");
@ -25,7 +28,7 @@ namespace DistTestCore
AddDataSource(http, prometheusContainer); AddDataSource(http, prometheusContainer);
Log("Uploading dashboard configurations..."); Log("Uploading dashboard configurations...");
var jsons = ReadEachDashboardJsonFile(); var jsons = ReadEachDashboardJsonFile(codexSetup);
var dashboardUrls = jsons.Select(j => UploadDashboard(http, grafanaContainer, j)).ToArray(); var dashboardUrls = jsons.Select(j => UploadDashboard(http, grafanaContainer, j)).ToArray();
LogEnd("Dashboard server started."); LogEnd("Dashboard server started.");
@ -86,7 +89,7 @@ namespace DistTestCore
return grafanaAddress.Host + ":" + grafanaAddress.Port + jsonResponse.url; return grafanaAddress.Host + ":" + grafanaAddress.Port + jsonResponse.url;
} }
private static string[] ReadEachDashboardJsonFile() private static string[] ReadEachDashboardJsonFile(CodexSetup codexSetup)
{ {
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();
var resourceNames = new[] var resourceNames = new[]
@ -94,15 +97,45 @@ namespace DistTestCore
"DistTestCore.Metrics.dashboard.json" "DistTestCore.Metrics.dashboard.json"
}; };
return resourceNames.Select(r => GetManifestResource(assembly, r)).ToArray(); return resourceNames.Select(r => GetManifestResource(assembly, r, codexSetup)).ToArray();
} }
private static string GetManifestResource(Assembly assembly, string resourceName) private static string GetManifestResource(Assembly assembly, string resourceName, CodexSetup codexSetup)
{ {
using var stream = assembly.GetManifestResourceStream(resourceName); using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream == null) throw new Exception("Unable to find resource " + resourceName); if (stream == null) throw new Exception("Unable to find resource " + resourceName);
using var reader = new StreamReader(stream); using var reader = new StreamReader(stream);
return reader.ReadToEnd(); return ApplyReplacements(reader.ReadToEnd(), codexSetup);
}
private static string ApplyReplacements(string input, CodexSetup codexSetup)
{
var quotaString = GetQuotaString(codexSetup);
var softMaxString = GetSoftMaxString(codexSetup);
return input
.Replace(StorageQuotaThresholdReplaceToken, quotaString)
.Replace(BytesUsedGraphAxisSoftMaxReplaceToken, softMaxString);
}
private static string GetQuotaString(CodexSetup codexSetup)
{
return GetCodexStorageQuotaInBytes(codexSetup).ToString();
}
private static string GetSoftMaxString(CodexSetup codexSetup)
{
var quota = GetCodexStorageQuotaInBytes(codexSetup);
var softMax = Convert.ToInt64(quota * 1.1); // + 10%, for nice viewing.
return softMax.ToString();
}
private static long GetCodexStorageQuotaInBytes(CodexSetup codexSetup)
{
if (codexSetup.StorageQuota != null) return codexSetup.StorageQuota.SizeInBytes;
// Codex default: 8GB
return 8.GB().SizeInBytes;
} }
private static string GetDashboardCreateRequest(string dashboardJson) private static string GetDashboardCreateRequest(string dashboardJson)

View File

@ -148,14 +148,7 @@ namespace DistTestCore
private T Retry<T>(Func<T> operation, string description) private T Retry<T>(Func<T> operation, string description)
{ {
try return Time.Retry(operation, timeSet.HttpCallRetryTime(), timeSet.HttpCallRetryDelay(), description);
{
return operation();
}
catch (Exception ex)
{
throw new Exception(description, ex);
}
} }
private HttpClient GetClient() private HttpClient GetClient()

View File

@ -431,6 +431,8 @@
"axisColorMode": "text", "axisColorMode": "text",
"axisLabel": "", "axisLabel": "",
"axisPlacement": "auto", "axisPlacement": "auto",
"axisSoftMax": "<CODEX_BYTESUSED_SOFTMAX>",
"axisSoftMin": 0,
"barAlignment": 0, "barAlignment": 0,
"drawStyle": "line", "drawStyle": "line",
"fillOpacity": 0, "fillOpacity": 0,
@ -453,7 +455,7 @@
"mode": "none" "mode": "none"
}, },
"thresholdsStyle": { "thresholdsStyle": {
"mode": "off" "mode": "line"
} }
}, },
"mappings": [], "mappings": [],
@ -466,7 +468,7 @@
}, },
{ {
"color": "red", "color": "red",
"value": 80 "value": "<CODEX_STORAGEQUOTA>"
} }
] ]
} }

View File

@ -1,5 +1,4 @@
using ContinuousTests; using DistTestCore;
using DistTestCore;
using NUnit.Framework; using NUnit.Framework;
using Utils; using Utils;
@ -12,53 +11,34 @@ namespace Tests.BasicTests
[UseLongTimeouts] [UseLongTimeouts]
public void ContinuousTestSubstitute() public void ContinuousTestSubstitute()
{ {
var nodes = new List<OnlineCodexNode>(); var group = SetupCodexNodes(5, o => o
for (var i = 0; i < 5; i++) .EnableMetrics()
.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true)
.WithBlockTTL(TimeSpan.FromMinutes(2))
.WithStorageQuota(3.GB()));
var nodes = group.Cast<OnlineCodexNode>().ToArray();
foreach (var node in nodes)
{ {
nodes.Add((OnlineCodexNode)SetupCodexNode(o => o node.Marketplace.MakeStorageAvailable(
.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: i < 2) size: 1.GB(),
.WithStorageQuota(3.GB()) minPricePerBytePerSecond: 1.TestTokens(),
)); maxCollateral: 1024.TestTokens(),
maxDuration: TimeSpan.FromMinutes(5));
} }
var cts = new CancellationTokenSource(); var endTime = DateTime.UtcNow + TimeSpan.FromHours(10);
var ct = cts.Token; while (DateTime.UtcNow < endTime)
var dlPath = Path.Combine(new FileInfo(Get().Log.LogFile.FullFilename)!.Directory!.FullName, "continuouslogs");
Directory.CreateDirectory(dlPath);
var containers = nodes.Select(n => n.CodexAccess.Container).ToArray();
var cd = new ContinuousLogDownloader(Get(), containers, dlPath, ct);
var logTask = Task.Run(cd.Run);
try
{ {
foreach (var node in nodes) var allNodes = nodes.ToList();
{ var primary = allNodes.PickOneRandom();
node.Marketplace.MakeStorageAvailable( var secondary = allNodes.PickOneRandom();
size: 1.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 1024.TestTokens(),
maxDuration: TimeSpan.FromMinutes(5));
}
var endTime = DateTime.UtcNow + TimeSpan.FromHours(1); Log("Run Test");
while (DateTime.UtcNow < endTime) PerformTest(primary, secondary);
{
var allNodes = nodes.ToList();
var primary = allNodes.PickOneRandom();
var secondary = allNodes.PickOneRandom();
Log("Run Test"); Thread.Sleep(TimeSpan.FromSeconds(5));
PerformTest(primary, secondary);
Thread.Sleep(TimeSpan.FromSeconds(5));
}
}
finally
{
cts.Cancel();
logTask.Wait();
} }
} }
@ -77,5 +57,42 @@ namespace Tests.BasicTests
testFile.AssertIsEqual(downloadedFile); testFile.AssertIsEqual(downloadedFile);
}); });
} }
[Test]
[UseLongTimeouts]
public void HoldMyBeerTest()
{
var group = SetupCodexNodes(5, o => o
.EnableMetrics()
.EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true)
.WithBlockTTL(TimeSpan.FromMinutes(2))
.WithStorageQuota(3.GB()));
var nodes = group.Cast<OnlineCodexNode>().ToArray();
foreach (var node in nodes)
{
node.Marketplace.MakeStorageAvailable(
size: 1.GB(),
minPricePerBytePerSecond: 1.TestTokens(),
maxCollateral: 1024.TestTokens(),
maxDuration: TimeSpan.FromMinutes(5));
}
var endTime = DateTime.UtcNow + TimeSpan.FromHours(2);
while (DateTime.UtcNow < endTime)
{
foreach (var node in nodes)
{
var file = GenerateTestFile(80.MB());
var cid = node.UploadFile(file);
var dl = node.DownloadContent(cid);
file.AssertIsEqual(dl);
}
Thread.Sleep(TimeSpan.FromMinutes(2));
}
}
} }
} }