Metrics test passed
This commit is contained in:
parent
1ca3ddc67e
commit
53bb9968ff
@ -67,15 +67,15 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
AddEnvVar("CODEX_BLOCK_MN", config.BlockMaintenanceNumber.ToString()!);
|
AddEnvVar("CODEX_BLOCK_MN", config.BlockMaintenanceNumber.ToString()!);
|
||||||
}
|
}
|
||||||
//if (config.MetricsMode != Metrics.MetricsMode.None)
|
if (config.MetricsEnabled)
|
||||||
//{
|
{
|
||||||
// var metricsPort = AddInternalPort(MetricsPortTag);
|
var metricsPort = AddInternalPort(MetricsPortTag);
|
||||||
// AddEnvVar("CODEX_METRICS", "true");
|
AddEnvVar("CODEX_METRICS", "true");
|
||||||
// AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0");
|
AddEnvVar("CODEX_METRICS_ADDRESS", "0.0.0.0");
|
||||||
// AddEnvVar("CODEX_METRICS_PORT", metricsPort);
|
AddEnvVar("CODEX_METRICS_PORT", metricsPort);
|
||||||
// AddPodAnnotation("prometheus.io/scrape", "true");
|
AddPodAnnotation("prometheus.io/scrape", "true");
|
||||||
// AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString());
|
AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString());
|
||||||
//}
|
}
|
||||||
|
|
||||||
//if (config.MarketplaceConfig != null)
|
//if (config.MarketplaceConfig != null)
|
||||||
//{
|
//{
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
using Core;
|
using Core;
|
||||||
using KubernetesWorkflow;
|
using KubernetesWorkflow;
|
||||||
|
using MetricsPlugin;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace CodexPlugin
|
namespace CodexPlugin
|
||||||
{
|
{
|
||||||
public interface ICodexNodeGroup : IEnumerable<IOnlineCodexNode>
|
public interface ICodexNodeGroup : IEnumerable<IOnlineCodexNode>, IManyMetricScrapeTargets
|
||||||
{
|
{
|
||||||
void BringOffline();
|
void BringOffline();
|
||||||
IOnlineCodexNode this[int index] { get; }
|
IOnlineCodexNode this[int index] { get; }
|
||||||
@ -41,6 +42,7 @@ namespace CodexPlugin
|
|||||||
public RunningContainers[] Containers { get; private set; }
|
public RunningContainers[] Containers { get; private set; }
|
||||||
public OnlineCodexNode[] Nodes { get; private set; }
|
public OnlineCodexNode[] Nodes { get; private set; }
|
||||||
public CodexDebugVersionResponse Version { get; private set; }
|
public CodexDebugVersionResponse Version { get; private set; }
|
||||||
|
public IMetricsScrapeTarget[] ScrapeTargets => Nodes.Select(n => n.MetricsScrapeTarget).ToArray();
|
||||||
|
|
||||||
public IEnumerator<IOnlineCodexNode> GetEnumerator()
|
public IEnumerator<IOnlineCodexNode> GetEnumerator()
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Core\Core.csproj" />
|
<ProjectReference Include="..\Core\Core.csproj" />
|
||||||
<ProjectReference Include="..\KubernetesWorkflow\KubernetesWorkflow.csproj" />
|
<ProjectReference Include="..\KubernetesWorkflow\KubernetesWorkflow.csproj" />
|
||||||
|
<ProjectReference Include="..\MetricsPlugin\MetricsPlugin.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -12,7 +12,7 @@ namespace CodexPlugin
|
|||||||
ICodexSetup WithBlockTTL(TimeSpan duration);
|
ICodexSetup WithBlockTTL(TimeSpan duration);
|
||||||
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
||||||
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
||||||
//ICodexSetup EnableMetrics();
|
ICodexSetup EnableMetrics();
|
||||||
//ICodexSetup EnableMarketplace(TestToken initialBalance);
|
//ICodexSetup EnableMarketplace(TestToken initialBalance);
|
||||||
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
|
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther);
|
||||||
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
|
//ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther, bool isValidator);
|
||||||
@ -70,11 +70,11 @@ namespace CodexPlugin
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public ICodexSetup EnableMetrics()
|
public ICodexSetup EnableMetrics()
|
||||||
//{
|
{
|
||||||
// MetricsMode = Metrics.MetricsMode.Record;
|
MetricsEnabled = true;
|
||||||
// return this;
|
return this;
|
||||||
//}
|
}
|
||||||
|
|
||||||
//public ICodexSetup EnableMarketplace(TestToken initialBalance)
|
//public ICodexSetup EnableMarketplace(TestToken initialBalance)
|
||||||
//{
|
//{
|
||||||
|
@ -14,7 +14,7 @@ namespace CodexPlugin
|
|||||||
public Location Location { get; set; }
|
public Location Location { get; set; }
|
||||||
public CodexLogLevel LogLevel { get; }
|
public CodexLogLevel LogLevel { get; }
|
||||||
public ByteSize? StorageQuota { get; set; }
|
public ByteSize? StorageQuota { get; set; }
|
||||||
//public MetricsMode MetricsMode { get; set; }
|
public bool MetricsEnabled { get; set; }
|
||||||
//public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
|
//public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
|
||||||
public string? BootstrapSpr { get; set; }
|
public string? BootstrapSpr { get; set; }
|
||||||
public int? BlockTTL { get; set; }
|
public int? BlockTTL { get; set; }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Core;
|
using Core;
|
||||||
using FileUtils;
|
using FileUtils;
|
||||||
using Logging;
|
using Logging;
|
||||||
|
using MetricsPlugin;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Utils;
|
using Utils;
|
||||||
|
|
||||||
@ -15,10 +16,9 @@ namespace CodexPlugin
|
|||||||
TrackedFile? DownloadContent(ContentId contentId, string fileLabel = "");
|
TrackedFile? DownloadContent(ContentId contentId, string fileLabel = "");
|
||||||
void ConnectToPeer(IOnlineCodexNode node);
|
void ConnectToPeer(IOnlineCodexNode node);
|
||||||
IDownloadedLog DownloadLog(int? tailLines = null);
|
IDownloadedLog DownloadLog(int? tailLines = null);
|
||||||
//IMetricsAccess Metrics { get; }
|
|
||||||
//IMarketplaceAccess Marketplace { get; }
|
|
||||||
CodexDebugVersionResponse Version { get; }
|
CodexDebugVersionResponse Version { get; }
|
||||||
void BringOffline();
|
void BringOffline();
|
||||||
|
IMetricsScrapeTarget MetricsScrapeTarget { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OnlineCodexNode : IOnlineCodexNode
|
public class OnlineCodexNode : IOnlineCodexNode
|
||||||
@ -27,21 +27,26 @@ namespace CodexPlugin
|
|||||||
private const string UploadFailedMessage = "Unable to store block";
|
private const string UploadFailedMessage = "Unable to store block";
|
||||||
private readonly IPluginTools tools;
|
private readonly IPluginTools tools;
|
||||||
|
|
||||||
public OnlineCodexNode(IPluginTools tools, CodexAccess codexAccess, CodexNodeGroup group/*, IMetricsAccess metricsAccess, IMarketplaceAccess marketplaceAccess*/)
|
public OnlineCodexNode(IPluginTools tools, CodexAccess codexAccess, CodexNodeGroup group)
|
||||||
{
|
{
|
||||||
this.tools = tools;
|
this.tools = tools;
|
||||||
CodexAccess = codexAccess;
|
CodexAccess = codexAccess;
|
||||||
Group = group;
|
Group = group;
|
||||||
//Metrics = metricsAccess;
|
|
||||||
//Marketplace = marketplaceAccess;
|
|
||||||
Version = new CodexDebugVersionResponse();
|
Version = new CodexDebugVersionResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodexAccess CodexAccess { get; }
|
public CodexAccess CodexAccess { get; }
|
||||||
public CodexNodeGroup Group { get; }
|
public CodexNodeGroup Group { get; }
|
||||||
//public IMetricsAccess Metrics { get; }
|
|
||||||
//public IMarketplaceAccess Marketplace { get; }
|
|
||||||
public CodexDebugVersionResponse Version { get; private set; }
|
public CodexDebugVersionResponse Version { get; private set; }
|
||||||
|
public IMetricsScrapeTarget MetricsScrapeTarget
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var port = CodexAccess.Container.Recipe.GetPortByTag(CodexContainerRecipe.MetricsPortTag);
|
||||||
|
if (port == null) throw new Exception("Metrics is not available for this Codex node. Please start it with the option '.EnableMetrics()' to enable it.");
|
||||||
|
return new MetricsScrapeTarget(CodexAccess.Container, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetName()
|
public string GetName()
|
||||||
{
|
{
|
||||||
|
@ -37,12 +37,12 @@ namespace Core
|
|||||||
private readonly IFileManager fileManager;
|
private readonly IFileManager fileManager;
|
||||||
private ILog log;
|
private ILog log;
|
||||||
|
|
||||||
public PluginTools(ILog log, Configuration configuration, string fileManagerRootFolder, ITimeSet timeSet)
|
public PluginTools(ILog log, WorkflowCreator workflowCreator, string fileManagerRootFolder, ITimeSet timeSet)
|
||||||
{
|
{
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
this.workflowCreator = workflowCreator;
|
||||||
this.timeSet = timeSet;
|
this.timeSet = timeSet;
|
||||||
fileManager = new FileManager(log, fileManagerRootFolder);
|
fileManager = new FileManager(log, fileManagerRootFolder);
|
||||||
workflowCreator = new WorkflowCreator(log, configuration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyLogPrefix(string prefix)
|
public void ApplyLogPrefix(string prefix)
|
||||||
|
@ -11,21 +11,21 @@ namespace Core
|
|||||||
internal class ToolsFactory : IToolsFactory
|
internal class ToolsFactory : IToolsFactory
|
||||||
{
|
{
|
||||||
private readonly ILog log;
|
private readonly ILog log;
|
||||||
private readonly Configuration configuration;
|
private readonly WorkflowCreator workflowCreator;
|
||||||
private readonly string fileManagerRootFolder;
|
private readonly string fileManagerRootFolder;
|
||||||
private readonly ITimeSet timeSet;
|
private readonly ITimeSet timeSet;
|
||||||
|
|
||||||
public ToolsFactory(ILog log, Configuration configuration, string fileManagerRootFolder, ITimeSet timeSet)
|
public ToolsFactory(ILog log, Configuration configuration, string fileManagerRootFolder, ITimeSet timeSet)
|
||||||
{
|
{
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.configuration = configuration;
|
workflowCreator = new WorkflowCreator(log, configuration);
|
||||||
this.fileManagerRootFolder = fileManagerRootFolder;
|
this.fileManagerRootFolder = fileManagerRootFolder;
|
||||||
this.timeSet = timeSet;
|
this.timeSet = timeSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginTools CreateTools()
|
public PluginTools CreateTools()
|
||||||
{
|
{
|
||||||
return new PluginTools(log, configuration, fileManagerRootFolder, timeSet);
|
return new PluginTools(log, workflowCreator, fileManagerRootFolder, timeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@
|
|||||||
public VolumeMount[] Volumes { get; }
|
public VolumeMount[] Volumes { get; }
|
||||||
public object[] Additionals { get; }
|
public object[] Additionals { get; }
|
||||||
|
|
||||||
public Port GetPortByTag(string tag)
|
public Port? GetPortByTag(string tag)
|
||||||
{
|
{
|
||||||
return ExposedPorts.Concat(InternalPorts).Single(p => p.Tag == tag);
|
return ExposedPorts.Concat(InternalPorts).SingleOrDefault(p => p.Tag == tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -16,6 +16,11 @@ namespace MetricsPlugin
|
|||||||
return Plugin(ci).CreateAccessForTarget(metricsContainer, scrapeTarget);
|
return Plugin(ci).CreateAccessForTarget(metricsContainer, scrapeTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, params IManyMetricScrapeTargets[] manyScrapeTargets)
|
||||||
|
{
|
||||||
|
return ci.GetMetricsFor(manyScrapeTargets.SelectMany(t => t.ScrapeTargets).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets)
|
public static IMetricsAccess[] GetMetricsFor(this CoreInterface ci, params IMetricsScrapeTarget[] scrapeTargets)
|
||||||
{
|
{
|
||||||
var rc = ci.StartMetricsCollector(scrapeTargets);
|
var rc = ci.StartMetricsCollector(scrapeTargets);
|
||||||
|
@ -4,6 +4,7 @@ namespace MetricsPlugin
|
|||||||
{
|
{
|
||||||
public interface IMetricsAccess
|
public interface IMetricsAccess
|
||||||
{
|
{
|
||||||
|
string TargetName { get; }
|
||||||
Metrics? GetAllMetrics();
|
Metrics? GetAllMetrics();
|
||||||
MetricsSet GetMetric(string metricName);
|
MetricsSet GetMetric(string metricName);
|
||||||
MetricsSet GetMetric(string metricName, TimeSpan timeout);
|
MetricsSet GetMetric(string metricName, TimeSpan timeout);
|
||||||
@ -18,19 +19,10 @@ namespace MetricsPlugin
|
|||||||
{
|
{
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
TargetName = target.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public void AssertThat(string metricName, IResolveConstraint constraint, string message = "")
|
public string TargetName { get; }
|
||||||
//{
|
|
||||||
// AssertHelpers.RetryAssert(constraint, () =>
|
|
||||||
// {
|
|
||||||
// var metricSet = GetMetricWithTimeout(metricName);
|
|
||||||
// var metricValue = metricSet.Values[0].Value;
|
|
||||||
|
|
||||||
// log.Log($"{node.Name} metric '{metricName}' = {metricValue}");
|
|
||||||
// return metricValue;
|
|
||||||
// }, message);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public Metrics? GetAllMetrics()
|
public Metrics? GetAllMetrics()
|
||||||
{
|
{
|
||||||
|
@ -4,20 +4,27 @@ namespace MetricsPlugin
|
|||||||
{
|
{
|
||||||
public interface IMetricsScrapeTarget
|
public interface IMetricsScrapeTarget
|
||||||
{
|
{
|
||||||
|
string Name { get; }
|
||||||
string Ip { get; }
|
string Ip { get; }
|
||||||
int Port { get; }
|
int Port { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IManyMetricScrapeTargets
|
||||||
|
{
|
||||||
|
IMetricsScrapeTarget[] ScrapeTargets { get; }
|
||||||
|
}
|
||||||
|
|
||||||
public class MetricsScrapeTarget : IMetricsScrapeTarget
|
public class MetricsScrapeTarget : IMetricsScrapeTarget
|
||||||
{
|
{
|
||||||
public MetricsScrapeTarget(string ip, int port)
|
public MetricsScrapeTarget(string ip, int port, string name)
|
||||||
{
|
{
|
||||||
Ip = ip;
|
Ip = ip;
|
||||||
Port = port;
|
Port = port;
|
||||||
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetricsScrapeTarget(RunningContainer container, int port)
|
public MetricsScrapeTarget(RunningContainer container, int port)
|
||||||
: this(container.Pod.PodInfo.Ip, port)
|
: this(container.Pod.PodInfo.Ip, port, container.Name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +33,7 @@ namespace MetricsPlugin
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
public string Ip { get; }
|
public string Ip { get; }
|
||||||
public int Port { get; }
|
public int Port { get; }
|
||||||
}
|
}
|
||||||
|
@ -24,23 +24,23 @@ namespace Tests.BasicTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void TwoMetricsExample()
|
public void TwoMetricsExample()
|
||||||
{
|
{
|
||||||
var rc = Ci.StartMetricsCollector();
|
var group = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
|
||||||
|
var group2 = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
|
||||||
|
|
||||||
//var group = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
|
var primary = group[0];
|
||||||
//var group2 = Ci.SetupCodexNodes(2, s => s.EnableMetrics());
|
var secondary = group[1];
|
||||||
|
var primary2 = group2[0];
|
||||||
|
var secondary2 = group2[1];
|
||||||
|
|
||||||
//var primary = group[0];
|
var metrics = Ci.GetMetricsFor(primary.MetricsScrapeTarget, primary2.MetricsScrapeTarget);
|
||||||
//var secondary = group[1];
|
|
||||||
//var primary2 = group2[0];
|
|
||||||
//var secondary2 = group2[1];
|
|
||||||
|
|
||||||
//primary.ConnectToPeer(secondary);
|
primary.ConnectToPeer(secondary);
|
||||||
//primary2.ConnectToPeer(secondary2);
|
primary2.ConnectToPeer(secondary2);
|
||||||
|
|
||||||
//Thread.Sleep(TimeSpan.FromMinutes(2));
|
Thread.Sleep(TimeSpan.FromMinutes(2));
|
||||||
|
|
||||||
//primary.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
|
metrics[0].AssertThat("libp2p_peers", Is.EqualTo(1));
|
||||||
//primary2.Metrics.AssertThat("libp2p_peers", Is.EqualTo(1));
|
metrics[1].AssertThat("libp2p_peers", Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
22
Tests/MetricsAccessExtensions.cs
Normal file
22
Tests/MetricsAccessExtensions.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using DistTestCore.Helpers;
|
||||||
|
using Logging;
|
||||||
|
using MetricsPlugin;
|
||||||
|
using NUnit.Framework.Constraints;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public static class MetricsAccessExtensions
|
||||||
|
{
|
||||||
|
public static void AssertThat(this IMetricsAccess access, string metricName, IResolveConstraint constraint, ILog? log = null, string message = "")
|
||||||
|
{
|
||||||
|
AssertHelpers.RetryAssert(constraint, () =>
|
||||||
|
{
|
||||||
|
var metricSet = access.GetMetric(metricName);
|
||||||
|
var metricValue = metricSet.Values[0].Value;
|
||||||
|
|
||||||
|
if (log != null) log.Log($"{access.TargetName} metric '{metricName}' = {metricValue}");
|
||||||
|
return metricValue;
|
||||||
|
}, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user